This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from nlnwa/checksum
Create checksum file (optional)
- Loading branch information
Showing
7 changed files
with
108 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/no/nb/nna/veidemann/warcvalidator/service/ChecksumTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package no.nb.nna.veidemann.warcvalidator.service; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.DirectoryStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.NoSuchFileException; | ||
import java.nio.file.Path; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ChecksumTest { | ||
|
||
@TempDir | ||
public File temporaryFolder; | ||
|
||
@Test | ||
public void createChecksumFile() throws IOException { | ||
ValidationService validationService = new ValidationService(null); | ||
Path tmp = temporaryFolder.toPath(); | ||
|
||
// Generate files | ||
Files.writeString(tmp.resolve("file.txt"), "This is a text"); | ||
|
||
// Generate checksum files, and assert | ||
try (DirectoryStream<Path> warcPaths = Files.newDirectoryStream(tmp)) { | ||
for (Path path : warcPaths) { | ||
Path sum = validationService.generateChecksumFile(path); | ||
|
||
String expected = validationService.md5sum(path); | ||
String actual = Files.readString(sum); | ||
String[] parts = actual.split(" "); | ||
|
||
assertEquals(2, parts.length); | ||
assertEquals(expected, parts[0]); | ||
assertEquals(path.getFileName().toString(), parts[1].stripTrailing()); | ||
} | ||
} catch (NoSuchFileException e) { | ||
// warcs directory empty and non existant in remote git repo | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters