Skip to content

Commit

Permalink
#6300 Add unit tests for additional data provided
Browse files Browse the repository at this point in the history
  • Loading branch information
sekmiller committed Dec 6, 2019
1 parent f5435c1 commit b379994
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public Response search(
paginationStart,
dataRelatedToMe,
numResultsPerPage,
true //SEK get query entities always for search API 12/6/2019
true //SEK get query entities always for search API additional Dataset Information 6300 12/6/2019
);
} catch (SearchException ex) {
Throwable cause = ex;
Expand Down
70 changes: 70 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/SearchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static java.lang.Thread.sleep;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static javax.ws.rs.core.Response.Status.OK;
import static javax.ws.rs.core.Response.Status.UNAUTHORIZED;
import org.hamcrest.Matchers;
import org.junit.After;
Expand Down Expand Up @@ -200,7 +201,76 @@ public void testSearchCitation() {
assertEquals(200, deleteUserResponse.getStatusCode());

}

@Test
public void testAdditionalDatasetContent6300() {

Response createUser = UtilIT.createRandomUser();
createUser.prettyPrint();
String username = UtilIT.getUsernameFromResponse(createUser);
String apiToken = UtilIT.getApiTokenFromResponse(createUser);

Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken);
createDataverseResponse.prettyPrint();
String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse);

Response createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken);
createDatasetResponse.prettyPrint();
Integer datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse);

Response datasetAsJson = UtilIT.nativeGet(datasetId, apiToken);
datasetAsJson.then().assertThat()
.statusCode(OK.getStatusCode());

String identifier = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.identifier");

Response getDatasetJsonBeforePublishing = UtilIT.nativeGet(datasetId, apiToken);
getDatasetJsonBeforePublishing.prettyPrint();
String protocol = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.protocol");
String authority = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.authority");

String datasetPersistentId = protocol + ":" + authority + "/" + identifier;
String pathToJsonFile = "doc/sphinx-guides/source/_static/api/dataset-add-metadata.json";
Response addSubjectViaNative = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, apiToken);
addSubjectViaNative.prettyPrint();
addSubjectViaNative.then().assertThat()
.statusCode(OK.getStatusCode());

Response searchResponse = UtilIT.search("id:dataset_" + datasetId + "_draft", apiToken);
searchResponse.prettyPrint();
/*["Astronomy and Astrophysics"]*/
assertTrue(searchResponse.body().jsonPath().getString("data.items[0].subjects").contains("Astronomy and Astrophysics"));
assertTrue(searchResponse.body().jsonPath().getString("data.items[0].versionState").equals("DRAFT"));
/* "versionState": "DRAFT",*/

//We now need to publish to see version number
Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken);
publishDataverse.prettyPrint();
publishDataverse.then().assertThat()
.statusCode(OK.getStatusCode());

Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken);
publishDataset.prettyPrint();
publishDataset.then().assertThat()
.statusCode(OK.getStatusCode());

searchResponse = UtilIT.search("id:dataset_" + datasetId, apiToken);
searchResponse.prettyPrint();
/*["Astronomy and Astrophysics"]*/
assertTrue(searchResponse.body().jsonPath().getString("data.items[0].subjects").contains("Astronomy and Astrophysics"));
assertTrue(searchResponse.body().jsonPath().getString("data.items[0].versionState").equals("RELEASED"));

assertTrue(searchResponse.body().jsonPath().getString("data.items[0].majorVersion").equals("1"));
assertTrue(searchResponse.body().jsonPath().getString("data.items[0].minorVersion").equals("0"));

assertTrue(searchResponse.body().jsonPath().getString("data.items[0].authors").contains("Spruce, Sabrina"));

assertTrue(searchResponse.body().jsonPath().getString("data.items[0].contacts[0].name").contains("Finch, Fiona"));
assertTrue(searchResponse.body().jsonPath().getString("data.items[0].storageIdentifier").contains(identifier));

}


/*
* Note: this test does a lot of checking for permissions with / without privlidged api key.
* Thumbnails access is the same with/without that access as of 4.9.4 --MAD
Expand Down

0 comments on commit b379994

Please sign in to comment.