Skip to content

Commit

Permalink
Add new junit test to confirm hexDigests are included when 'NonMatchi…
Browse files Browse the repository at this point in the history
…ngChecksumException' is thrown and fix innacurate javadoc for a junit test
  • Loading branch information
doulikecookiedough committed Nov 13, 2024
1 parent 51a7048 commit 6321475
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public void storeObject_correctChecksumValue() throws Exception {
*/
@Test
public void storeObject_incorrectChecksumValue() {
assertThrows(IllegalArgumentException.class, () -> {
assertThrows(NonMatchingChecksumException.class, () -> {
// Get test file to "upload"
String pid = "jtao.1700.1";
Path testDataFile = testData.getTestFile(pid);
Expand All @@ -379,6 +379,39 @@ public void storeObject_incorrectChecksumValue() {
});
}

/**
* Verify exception contains hexDigests when NonMatchingChecksumException is thrown
*/
@Test
public void storeObject_nonMatchingChecksumException_hexDigestsIncluded() throws Exception {
// Get test file to "upload"
String pid = "jtao.1700.1";
Path testDataFile = testData.getTestFile(pid);

String checksumIncorrect =
"aaf9b6c88f1f458e410c30c351c6384ea42ac1b5ee1f8430d3e365e43b78a38a";

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

} 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");
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"));
}
}
}

/**
* Verify exception thrown when checksum is empty and algorithm supported
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ public void validateTmpObject_validationRequested_matchingChecksum() throws Exce
}

/**
* Confirm validateTmpObject does not throw exception when requested to validate checksums with
* good values, and that the tmpFile passed is deleted.
* Confirm validateTmpObject throws exception when requested to validate a bad checksum,
* and that the tmpFile passed is deleted.
*/
@Test
public void validateTmpObject_validationRequested_nonMatchingChecksum() throws Exception {
Expand Down

0 comments on commit 6321475

Please sign in to comment.