Skip to content

Commit

Permalink
Revise junit test for 'NonMatchingCheckException' to also check that …
Browse files Browse the repository at this point in the history
…an additional algorithm is included if supplied, and add new junit test for 'storeHardLink'
  • Loading branch information
doulikecookiedough committed Nov 13, 2024
1 parent 6d69c68 commit 7cad413
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ public void storeObject_incorrectChecksumValue() {
}

/**
* Verify exception contains hexDigests when NonMatchingChecksumException is thrown
* Verify exception contains hexDigests when NonMatchingChecksumException is thrown, and that
* an additional algorithm included is also found.
*/
@Test
public void storeObject_nonMatchingChecksumException_hexDigestsIncluded() throws Exception {
Expand All @@ -393,7 +394,7 @@ public void storeObject_nonMatchingChecksumException_hexDigestsIncluded() throws

try (InputStream dataStream = Files.newInputStream(testDataFile)) {
try {
fileHashStore.storeObject(dataStream, pid, null, checksumIncorrect, "SHA-256", -1);
fileHashStore.storeObject(dataStream, pid, "SHA-512/224", checksumIncorrect, "SHA-256", -1);

} catch (NonMatchingChecksumException nmce) {
Map<String, String> hexDigestsRetrieved = nmce.getHexDigests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,40 @@ public void storeHardLink_nonMatchingChecksum() {
}
}

/**
* Check hexDigests included when nonMatchingChecksumException is thrown when storing a hard
* link and that an algorithm that is not part of the default list is generated & included.
*/
@Test
public void storeHardLink_nonMatchingChecksum_hexDigestsIncluded() throws Exception {
for (String pid : testData.pidList) {
String pidFormatted = pid.replace("/", "_");
Path testDataFile = testData.getTestFile(pidFormatted);
assertTrue(Files.exists(testDataFile));

try {
fileHashStoreLinks.storeHardLink(testDataFile, pid, "badchecksum", "SHA-512/224");

} catch (NonMatchingChecksumException nmce) {
Map<String, String> hexDigestsRetrieved = nmce.getHexDigests();

String md5 = testData.pidData.get(pid).get("md5");
String sha1 = testData.pidData.get(pid).get("sha1");
String sha256 = testData.pidData.get(pid).get("sha256");
String sha384 = testData.pidData.get(pid).get("sha384");
String sha512 = testData.pidData.get(pid).get("sha512");
String sha512_224 = testData.pidData.get(pid).get("sha512-224");
assertEquals(md5, hexDigestsRetrieved.get("MD5"));
assertEquals(sha1, hexDigestsRetrieved.get("SHA-1"));
assertEquals(sha256, hexDigestsRetrieved.get("SHA-256"));
assertEquals(sha384, hexDigestsRetrieved.get("SHA-384"));
assertEquals(sha512, hexDigestsRetrieved.get("SHA-512"));
assertEquals(sha512_224, hexDigestsRetrieved.get("SHA-512/224"));
}
}

}

/**
* Confirm that generateChecksums calculates checksums as expected
*/
Expand Down

0 comments on commit 7cad413

Please sign in to comment.