Skip to content

Commit

Permalink
#5867 add some more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sekmiller committed Sep 30, 2019
1 parent 5582a88 commit ff90dd7
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/test/java/edu/harvard/iq/dataverse/api/AdminIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -545,38 +545,54 @@ public void testRecalculateDataFileHash() {
assertTrue("Failed test if Ingest Lock exceeds max duration " + origFileId, UtilIT.sleepForLock(datasetId.longValue(), "Ingest", superuserApiToken, UtilIT.MAXIMUM_INGEST_LOCK_DURATION));

//Bad file id
Response tryIt = UtilIT.computeDataFileHashValue("BadFileId", DataFile.ChecksumType.MD5.toString(), superuserApiToken);
Response computeDataFileHashResponse = UtilIT.computeDataFileHashValue("BadFileId", DataFile.ChecksumType.MD5.toString(), superuserApiToken);

tryIt.then().assertThat()
computeDataFileHashResponse.then().assertThat()
.body("status", equalTo("ERROR"))
.body("message", equalTo("Could not find file with the id: BadFileId"))
.statusCode(BAD_REQUEST.getStatusCode());

//Bad Algorithm
tryIt = UtilIT.computeDataFileHashValue(origFileId.toString(), "Blank", superuserApiToken);
computeDataFileHashResponse = UtilIT.computeDataFileHashValue(origFileId.toString(), "Blank", superuserApiToken);

tryIt.then().assertThat()
computeDataFileHashResponse.then().assertThat()
.body("status", equalTo("ERROR"))
.body("message", equalTo("Unknown algorithm: Blank"))
.statusCode(BAD_REQUEST.getStatusCode());

//Not a Super user
tryIt = UtilIT.computeDataFileHashValue(origFileId.toString(), DataFile.ChecksumType.MD5.toString(), apiToken);
computeDataFileHashResponse = UtilIT.computeDataFileHashValue(origFileId.toString(), DataFile.ChecksumType.MD5.toString(), apiToken);

tryIt.then().assertThat()
computeDataFileHashResponse.then().assertThat()
.body("status", equalTo("ERROR"))
.body("message", equalTo("must be superuser"))
.statusCode(UNAUTHORIZED.getStatusCode());


tryIt = UtilIT.computeDataFileHashValue(origFileId.toString(), DataFile.ChecksumType.MD5.toString(), superuserApiToken);
tryIt.prettyPrint();
computeDataFileHashResponse = UtilIT.computeDataFileHashValue(origFileId.toString(), DataFile.ChecksumType.MD5.toString(), superuserApiToken);
computeDataFileHashResponse.prettyPrint();

tryIt.then().assertThat()
computeDataFileHashResponse.then().assertThat()
.body("data.message", equalTo("Datafile rehashing complete. " + origFileId.toString() + " successfully rehashed. New hash value is: 003b8c67fbdfa6df31c0e43e65b93f0e"))
.statusCode(OK.getStatusCode());

//Not a Super user
Response validationResponse = UtilIT.validateDataFileHashValue(origFileId.toString(), apiToken);

validationResponse.then().assertThat()
.body("status", equalTo("ERROR"))
.body("message", equalTo("must be superuser"))
.statusCode(UNAUTHORIZED.getStatusCode());

//Bad File Id
validationResponse = UtilIT.validateDataFileHashValue("BadFileId", superuserApiToken);

validationResponse.then().assertThat()
.body("status", equalTo("ERROR"))
.body("message", equalTo("Could not find file with the id: BadFileId"))
.statusCode(BAD_REQUEST.getStatusCode());

Response validationResponse = UtilIT.validateDataFileHashValue(origFileId.toString(), superuserApiToken);
validationResponse = UtilIT.validateDataFileHashValue(origFileId.toString(), superuserApiToken);
validationResponse.prettyPrint();
validationResponse.then().assertThat()
.body("data.message", equalTo("Datafile validation complete for " + origFileId.toString() + ". The hash value is: 003b8c67fbdfa6df31c0e43e65b93f0e"))
Expand Down

0 comments on commit ff90dd7

Please sign in to comment.