Skip to content

Commit

Permalink
A test for the new "don't list until exported" OAI set feature (#3322)
Browse files Browse the repository at this point in the history
  • Loading branch information
landreev committed Jan 11, 2024
1 parent 50425d3 commit 15ad04e
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/test/java/edu/harvard/iq/dataverse/api/HarvestingServerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public void testNativeSetAPI() {
}

@Test
public void testSetEditAPIandOAIlistSets() {
public void testSetEditAPIandOAIlistSets() throws InterruptedException {
// This test focuses on testing the Edit functionality of the Dataverse
// OAI Set API and the ListSets method of the Dataverse OAI server.

Expand All @@ -299,7 +299,8 @@ public void testSetEditAPIandOAIlistSets() {
// expected HTTP result codes.

String setName = UtilIT.getRandomString(6);
String setDef = "*";
String persistentId = extraDatasetsIdentifiers.get(0);
String setDef = "dsPersistentId:"+persistentId;

// Make sure the set does not exist
String setPath = String.format("/api/harvest/server/oaisets/%s", setName);
Expand Down Expand Up @@ -369,16 +370,35 @@ public void testSetEditAPIandOAIlistSets() {

XmlPath responseXmlPath = validateOaiVerbResponse(listSetsResponse, "ListSets");

// 2. Validate the payload of the response, by confirming that the set
// 2. The set hasn't been exported yet, so it shouldn't be listed in
// ListSets (#3322). Let's confirm that:

List<Node> listSets = responseXmlPath.getList("OAI-PMH.ListSets.set.list().findAll{it.setName=='"+setName+"'}", Node.class);
// 2a. Confirm that our set is listed:
assertNotNull(listSets, "Unexpected response from ListSets");
assertEquals(0, listSets.size(), "An unexported OAI set is listed in ListSets");

// export the set:

Response exportSetResponse = UtilIT.exportOaiSet(setName);
assertEquals(200, exportSetResponse.getStatusCode());
Thread.sleep(1000L); // sleep for a sec to be sure

// ... try again:

listSetsResponse = UtilIT.getOaiListSets();
responseXmlPath = validateOaiVerbResponse(listSetsResponse, "ListSets");

// 3. Validate the payload of the response, by confirming that the set
// we created and modified, above, is being listed by the OAI server
// and its xml record is properly formatted

List<Node> listSets = responseXmlPath.getList("OAI-PMH.ListSets.set.list().findAll{it.setName=='"+setName+"'}", Node.class);
listSets = responseXmlPath.getList("OAI-PMH.ListSets.set.list().findAll{it.setName=='"+setName+"'}", Node.class);

// 2a. Confirm that our set is listed:
// 3a. Confirm that our set is listed:
assertNotNull(listSets, "Unexpected response from ListSets");
assertEquals(1, listSets.size(), "Newly-created set isn't properly listed by the OAI server");
// 2b. Confirm that the set entry contains the updated description:
// 3b. Confirm that the set entry contains the updated description:
assertEquals(newDescription, listSets.get(0).getPath("setDescription.metadata.element.field", String.class), "Incorrect description in the ListSets entry");

// ok, the xml record looks good!
Expand Down

0 comments on commit 15ad04e

Please sign in to comment.