Skip to content

Commit

Permalink
api tests (work in progress) #3437
Browse files Browse the repository at this point in the history
  • Loading branch information
landreev committed Jan 9, 2024
1 parent 4b6fb50 commit c6ec7fa
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
50 changes: 48 additions & 2 deletions src/test/java/edu/harvard/iq/dataverse/api/HarvestingServerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -39,6 +40,7 @@ public class HarvestingServerIT {
private static String adminUserAPIKey;
private static String singleSetDatasetIdentifier;
private static String singleSetDatasetPersistentId;
private static Integer singleSetDatasetDatabaseId;
private static List<String> extraDatasetsIdentifiers = new ArrayList<>();

@BeforeAll
Expand Down Expand Up @@ -84,7 +86,7 @@ private static void setupDatasets() {
// create dataset:
Response createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, adminUserAPIKey);
createDatasetResponse.prettyPrint();
Integer datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse);
singleSetDatasetDatabaseId = UtilIT.getDatasetIdFromResponse(createDatasetResponse);

// retrieve the global id:
singleSetDatasetPersistentId = UtilIT.getDatasetPersistentIdFromResponse(createDatasetResponse);
Expand All @@ -110,7 +112,7 @@ private static void setupDatasets() {
// create dataset:
createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, adminUserAPIKey);
createDatasetResponse.prettyPrint();
datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse);
Integer datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse);

// retrieve the global id:
String thisDatasetPersistentId = UtilIT.getDatasetPersistentIdFromResponse(createDatasetResponse);
Expand Down Expand Up @@ -395,6 +397,11 @@ public void testSetEditAPIandOAIlistSets() {
// OAI set with a single dataset, and attempt to retrieve
// it and validate the OAI server responses of the corresponding
// ListIdentifiers, ListRecords and GetRecord methods.
// Finally, we will make sure that the test reexport survives
// a reexport when the control dataset is dropped from the search
// index temporarily (if, for example, the site admin cleared their
// solr index in order to reindex everything from scratch - which
// can take a while on a large database). This is per #3437
@Test
public void testSingleRecordOaiSet() throws InterruptedException {
// Let's try and create an OAI set with the "single set dataset" that
Expand Down Expand Up @@ -549,7 +556,46 @@ public void testSingleRecordOaiSet() throws InterruptedException {
assertEquals("Medicine, Health and Life Sciences", responseXmlPath.getString("OAI-PMH.GetRecord.record.metadata.dc.subject"));

// ok, looks legit!

// Now, let's clear this dataset from Solr:
Response solrClearResponse = UtilIT.indexClearDataset(singleSetDatasetDatabaseId);
assertEquals(200, solrClearResponse.getStatusCode());

// Now, let's re-export the set. The search query that defines the set
// will no longer find it (todo: confirm this first?). However, since
// the dataset still exists in the database; and would in real life
// be reindexed again, we don't want to mark the OAI record for the
// dataset as "deleted" just yet. (this is a new feature, as of 6.2)
// So, let's re-export the set...

exportSetResponse = UtilIT.exportOaiSet(setName);
assertEquals(200, exportSetResponse.getStatusCode());
Thread.sleep(10000L); // wait for just a second, to be safe

// OAI Test 5. Check ListIdentifiers again:

Response listIdentifiersResponse = UtilIT.getOaiListIdentifiers(setName, "oai_dc");
assertEquals(OK.getStatusCode(), listIdentifiersResponse.getStatusCode());

// Validate the service section of the OAI response:
responseXmlPath = validateOaiVerbResponse(listIdentifiersResponse, "ListIdentifiers");

// ... and confirm that the record for our dataset is still listed
// as active:
List ret = responseXmlPath.getList("OAI-PMH.ListIdentifiers.header");

assertEquals(1, ret.size());
assertEquals(singleSetDatasetPersistentId, responseXmlPath
.getString("OAI-PMH.ListIdentifiers.header.identifier"));
assertEquals(setName, responseXmlPath
.getString("OAI-PMH.ListIdentifiers.header.setSpec"));
// ... and, most importantly, make sure the record does not have a
// `status="deleted"` attribute:
assertNull(responseXmlPath.getString("OAI-PMH.ListIdentifiers.header.@status"));

// TODO: (?) we could also destroy the dataset for real now, and make
// sure the "deleted" attribute has been added to the OAI record.

}

// This test will attempt to create a set with multiple records (enough
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,11 @@ static Response reindexDataset(String persistentId) {
return response;
}

static Response indexClearDataset(Integer datasetId) {
return given()
.delete("/api/admin/index/datasets/"+datasetId+"/clear");
}

static Response reindexDataverse(String dvId) {
Response response = given()
.get("/api/admin/index/dataverses/" + dvId);
Expand Down Expand Up @@ -2066,7 +2071,7 @@ static Response indexClear() {
return given()
.get("/api/admin/index/clear");
}

static Response index() {
return given()
.get("/api/admin/index");
Expand Down

0 comments on commit c6ec7fa

Please sign in to comment.