From 4fe90539fcba40263c2658216b13bd7afd4a3a48 Mon Sep 17 00:00:00 2001 From: Steven Winship Date: Fri, 29 Mar 2024 10:56:52 -0400 Subject: [PATCH 01/11] add order to test --- .../edu/harvard/iq/dataverse/api/HarvestingClientsIT.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java index 4466182b435..970545376d7 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java @@ -6,9 +6,7 @@ import static io.restassured.RestAssured.given; import io.restassured.path.json.JsonPath; import io.restassured.response.Response; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import static jakarta.ws.rs.core.Response.Status.CREATED; import static jakarta.ws.rs.core.Response.Status.UNAUTHORIZED; @@ -27,6 +25,7 @@ * /api/harvest/clients/ api to run an actual harvest of a control set and * then validate the resulting harvested content. */ +@TestMethodOrder(MethodOrderer.MethodName.class) public class HarvestingClientsIT { private static final Logger logger = Logger.getLogger(HarvestingClientsIT.class.getCanonicalName()); From 30356fd740a5d6ca09b528939ee28bab429914c5 Mon Sep 17 00:00:00 2001 From: Steven Winship Date: Fri, 29 Mar 2024 12:07:53 -0400 Subject: [PATCH 02/11] add order to test --- .../iq/dataverse/api/HarvestingClientsIT.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java index 970545376d7..3d630adbf41 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java @@ -25,7 +25,7 @@ * /api/harvest/clients/ api to run an actual harvest of a control set and * then validate the resulting harvested content. */ -@TestMethodOrder(MethodOrderer.MethodName.class) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class HarvestingClientsIT { private static final Logger logger = Logger.getLogger(HarvestingClientsIT.class.getCanonicalName()); @@ -87,6 +87,7 @@ private static void setupCollection() { } @Test + @Order(1) public void testCreateEditDeleteClient() throws InterruptedException { // This method focuses on testing the native Dataverse harvesting client // API. @@ -169,13 +170,15 @@ public void testCreateEditDeleteClient() throws InterruptedException { } @Test - public void testHarvestingClientRun_AllowHarvestingMissingCVV_False() throws InterruptedException { - harvestingClientRun(false); - } - @Test + @Order(2) public void testHarvestingClientRun_AllowHarvestingMissingCVV_True() throws InterruptedException { harvestingClientRun(true); } + @Test + @Order(3) + public void testHarvestingClientRun_AllowHarvestingMissingCVV_False() throws InterruptedException { + harvestingClientRun(false); + } private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws InterruptedException { int expectedNumberOfSetsHarvested = allowHarvestingMissingCVV ? DATASETS_IN_CONTROL_SET : DATASETS_IN_CONTROL_SET - 1; From 642b65905b3bb2152a9326bc4c6ceb8f206b9e9c Mon Sep 17 00:00:00 2001 From: Steven Winship Date: Fri, 29 Mar 2024 13:34:21 -0400 Subject: [PATCH 03/11] fix test --- .../edu/harvard/iq/dataverse/api/HarvestingClientsIT.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java index 3d630adbf41..3582301ff54 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java @@ -181,7 +181,6 @@ public void testHarvestingClientRun_AllowHarvestingMissingCVV_False() throws In } private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws InterruptedException { - int expectedNumberOfSetsHarvested = allowHarvestingMissingCVV ? DATASETS_IN_CONTROL_SET : DATASETS_IN_CONTROL_SET - 1; // This test will create a client and attempt to perform an actual // harvest and validate the resulting harvested content. @@ -266,7 +265,11 @@ private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws Inte assertEquals(harvestTimeStamp, responseJsonPath.getString("data.lastNonEmpty")); // d) Confirm that the correct number of datasets have been harvested: - assertEquals(expectedNumberOfSetsHarvested, responseJsonPath.getInt("data.lastDatasetsHarvested")); + if (allowHarvestingMissingCVV) { + assertEquals(DATASETS_IN_CONTROL_SET, responseJsonPath.getInt("data.lastDatasetsHarvested")); + } else { + assertTrue(responseJsonPath.getInt("data.lastDatasetsHarvested") < DATASETS_IN_CONTROL_SET); + } // ok, it looks like the harvest has completed successfully. break; From 2ed51c290ffe978fcb3dca36e0b5b046cfded2c4 Mon Sep 17 00:00:00 2001 From: Steven Winship Date: Fri, 29 Mar 2024 17:47:50 -0400 Subject: [PATCH 04/11] fix test --- .../edu/harvard/iq/dataverse/api/HarvestingClientsIT.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java index 3582301ff54..6f10de10997 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java @@ -6,7 +6,9 @@ import static io.restassured.RestAssured.given; import io.restassured.path.json.JsonPath; import io.restassured.response.Response; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import static jakarta.ws.rs.core.Response.Status.CREATED; import static jakarta.ws.rs.core.Response.Status.UNAUTHORIZED; @@ -25,7 +27,6 @@ * /api/harvest/clients/ api to run an actual harvest of a control set and * then validate the resulting harvested content. */ -@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class HarvestingClientsIT { private static final Logger logger = Logger.getLogger(HarvestingClientsIT.class.getCanonicalName()); @@ -87,7 +88,6 @@ private static void setupCollection() { } @Test - @Order(1) public void testCreateEditDeleteClient() throws InterruptedException { // This method focuses on testing the native Dataverse harvesting client // API. @@ -170,12 +170,10 @@ public void testCreateEditDeleteClient() throws InterruptedException { } @Test - @Order(2) public void testHarvestingClientRun_AllowHarvestingMissingCVV_True() throws InterruptedException { harvestingClientRun(true); } @Test - @Order(3) public void testHarvestingClientRun_AllowHarvestingMissingCVV_False() throws InterruptedException { harvestingClientRun(false); } From 38d565fc5016739f3602dd9f0cc2720e7db3e2e1 Mon Sep 17 00:00:00 2001 From: Steven Winship Date: Fri, 29 Mar 2024 17:51:14 -0400 Subject: [PATCH 05/11] fix test --- .../edu/harvard/iq/dataverse/api/HarvestingClientsIT.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java index 6f10de10997..1744cdbe009 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java @@ -169,14 +169,14 @@ public void testCreateEditDeleteClient() throws InterruptedException { assertEquals(OK.getStatusCode(), rDelete.getStatusCode()); } - @Test - public void testHarvestingClientRun_AllowHarvestingMissingCVV_True() throws InterruptedException { - harvestingClientRun(true); - } @Test public void testHarvestingClientRun_AllowHarvestingMissingCVV_False() throws InterruptedException { harvestingClientRun(false); } + @Test + public void testHarvestingClientRun_AllowHarvestingMissingCVV_True() throws InterruptedException { + harvestingClientRun(true); + } private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws InterruptedException { From 627bd58490e426a3b068e0a878338a0502cfc4b2 Mon Sep 17 00:00:00 2001 From: Steven Winship Date: Tue, 9 Apr 2024 12:30:28 -0400 Subject: [PATCH 06/11] fixing test --- .../iq/dataverse/api/HarvestingClientsIT.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java index 1744cdbe009..ead9d9f5cec 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java @@ -179,7 +179,7 @@ public void testHarvestingClientRun_AllowHarvestingMissingCVV_True() throws Int } private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws InterruptedException { - + int expectedNumberOfSetsHarvested = allowHarvestingMissingCVV ? DATASETS_IN_CONTROL_SET : DATASETS_IN_CONTROL_SET - 1; // This test will create a client and attempt to perform an actual // harvest and validate the resulting harvested content. @@ -226,11 +226,11 @@ private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws Inte int i = 0; int maxWait=20; // a very conservative interval; this harvest has no business taking this long do { - // Give it an initial 1 sec. delay, to make sure the client state + // Give it an initial 2 sec. delay, to make sure the client state // has been updated in the database, which can take some appreciable // amount of time on a heavily-loaded server running a full suite of // tests: - Thread.sleep(1000L); + Thread.sleep(2000L); // keep checking the status of the client with the GET api: Response getClientResponse = given() .get(clientApiPath); @@ -263,11 +263,7 @@ private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws Inte assertEquals(harvestTimeStamp, responseJsonPath.getString("data.lastNonEmpty")); // d) Confirm that the correct number of datasets have been harvested: - if (allowHarvestingMissingCVV) { - assertEquals(DATASETS_IN_CONTROL_SET, responseJsonPath.getInt("data.lastDatasetsHarvested")); - } else { - assertTrue(responseJsonPath.getInt("data.lastDatasetsHarvested") < DATASETS_IN_CONTROL_SET); - } + assertEquals(expectedNumberOfSetsHarvested, responseJsonPath.getInt("data.lastDatasetsHarvested")); // ok, it looks like the harvest has completed successfully. break; From 2669bccb6d9c3ed9681709faf614cb5343af373b Mon Sep 17 00:00:00 2001 From: Steven Winship Date: Tue, 9 Apr 2024 12:31:37 -0400 Subject: [PATCH 07/11] fixing test --- .../java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java index ead9d9f5cec..1ad70d2dbb5 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java @@ -180,6 +180,7 @@ public void testHarvestingClientRun_AllowHarvestingMissingCVV_True() throws Int private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws InterruptedException { int expectedNumberOfSetsHarvested = allowHarvestingMissingCVV ? DATASETS_IN_CONTROL_SET : DATASETS_IN_CONTROL_SET - 1; + // This test will create a client and attempt to perform an actual // harvest and validate the resulting harvested content. From e22501d5a100fbb3b5d1225358dcae8f9d896ffe Mon Sep 17 00:00:00 2001 From: Steven Winship <39765413+stevenwinship@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:59:05 -0400 Subject: [PATCH 08/11] adding better cleanup between tests --- .../iq/dataverse/api/HarvestingClientsIT.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java index ac38cc693df..5ab1eda74df 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java @@ -279,11 +279,19 @@ private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws Inte // Fail if it hasn't completed in maxWait seconds assertTrue(i < maxWait); - - // TODO(?) use the native Dataverses/Datasets apis to verify that the expected - // datasets have been harvested. This may or may not be necessary, seeing - // how we have already confirmed the number of successfully harvested - // datasets from the control set; somewhat hard to imagine a practical - // situation where that would not be enough (?). + + // cleanup datasets so other tests can run + Response deleteResponse = given() + .header(UtilIT.API_TOKEN_HTTP_HEADER, adminUserAPIKey) + .delete(clientApiPath); + clientApiPath = null; + System.out.println("deleteResponse.getStatusCode(): " + deleteResponse.getStatusCode()); + + i = 0; + maxWait=20; + do { + Thread.sleep(1000L); + searchHarvestedDatasets = UtilIT.search("metadataSource:" + nickName, adminUserAPIKey); + } while (i++ Date: Thu, 11 Apr 2024 15:05:47 -0400 Subject: [PATCH 09/11] refine cleanup --- .../iq/dataverse/api/HarvestingClientsIT.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java index 5ab1eda74df..fc034e2ad06 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java @@ -36,6 +36,7 @@ public class HarvestingClientsIT { private static final String HARVEST_METADATA_FORMAT = "oai_dc"; private static final String ARCHIVE_DESCRIPTION = "RestAssured harvesting client test"; private static final String CONTROL_OAI_SET = "controlTestSet2"; + private static final String CONTROL_OAI_SET_IDS = "doi:10.5072/FK2"; private static final int DATASETS_IN_CONTROL_SET = 8; private static String normalUserAPIKey; private static String adminUserAPIKey; @@ -54,13 +55,22 @@ public static void setUpClass() { } @AfterEach - public void cleanup() { + public void cleanup() throws InterruptedException { if (clientApiPath != null) { Response deleteResponse = given() .header(UtilIT.API_TOKEN_HTTP_HEADER, adminUserAPIKey) .delete(clientApiPath); clientApiPath = null; System.out.println("deleteResponse.getStatusCode(): " + deleteResponse.getStatusCode()); + + int i = 0; + int maxWait = 20; + do { + if (UtilIT.search("dsPersistentId:" + CONTROL_OAI_SET_IDS, normalUserAPIKey).prettyPrint().contains("count_in_response\": 0")) { + break; + } + Thread.sleep(1000L); + } while (i++ < maxWait); } } @@ -279,19 +289,5 @@ private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws Inte // Fail if it hasn't completed in maxWait seconds assertTrue(i < maxWait); - - // cleanup datasets so other tests can run - Response deleteResponse = given() - .header(UtilIT.API_TOKEN_HTTP_HEADER, adminUserAPIKey) - .delete(clientApiPath); - clientApiPath = null; - System.out.println("deleteResponse.getStatusCode(): " + deleteResponse.getStatusCode()); - - i = 0; - maxWait=20; - do { - Thread.sleep(1000L); - searchHarvestedDatasets = UtilIT.search("metadataSource:" + nickName, adminUserAPIKey); - } while (i++ Date: Thu, 11 Apr 2024 16:32:51 -0400 Subject: [PATCH 10/11] refine cleanup --- .../iq/dataverse/api/HarvestingClientsIT.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java index fc034e2ad06..d25a4f42872 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java @@ -1,6 +1,9 @@ package edu.harvard.iq.dataverse.api; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Logger; +import java.util.stream.Collectors; import io.restassured.RestAssured; import static io.restassured.RestAssured.given; @@ -36,12 +39,12 @@ public class HarvestingClientsIT { private static final String HARVEST_METADATA_FORMAT = "oai_dc"; private static final String ARCHIVE_DESCRIPTION = "RestAssured harvesting client test"; private static final String CONTROL_OAI_SET = "controlTestSet2"; - private static final String CONTROL_OAI_SET_IDS = "doi:10.5072/FK2"; private static final int DATASETS_IN_CONTROL_SET = 8; private static String normalUserAPIKey; private static String adminUserAPIKey; private static String harvestCollectionAlias; String clientApiPath = null; + List globalIdList = new ArrayList(); @BeforeAll public static void setUpClass() { @@ -65,13 +68,15 @@ public void cleanup() throws InterruptedException { int i = 0; int maxWait = 20; + String query = "dsPersistentId:" + globalIdList.stream().map(s -> "\""+s+"\"").collect(Collectors.joining(",")); do { - if (UtilIT.search("dsPersistentId:" + CONTROL_OAI_SET_IDS, normalUserAPIKey).prettyPrint().contains("count_in_response\": 0")) { + if (UtilIT.search(query, normalUserAPIKey).prettyPrint().contains("count_in_response\": 0")) { break; } Thread.sleep(1000L); } while (i++ < maxWait); } + globalIdList.clear(); } private static void setupUsers() { @@ -282,10 +287,16 @@ private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws Inte System.out.println("Waited " + i + " seconds for the harvest to complete."); Response searchHarvestedDatasets = UtilIT.search("metadataSource:" + nickName, normalUserAPIKey); + searchHarvestedDatasets.then().assertThat().statusCode(OK.getStatusCode()); searchHarvestedDatasets.prettyPrint(); - searchHarvestedDatasets.then().assertThat() - .statusCode(OK.getStatusCode()) - .body("data.total_count", equalTo(expectedNumberOfSetsHarvested)); + // Get all global ids for cleanup + JsonPath jsonPath = searchHarvestedDatasets.getBody().jsonPath(); + int sz = jsonPath.getInt("data.items.size()"); + for(int idx = 0; idx < sz; idx++) { + globalIdList.add(jsonPath.getString("data.items["+idx+"].global_id")); + } + // verify count after collecting global ids + assertEquals(expectedNumberOfSetsHarvested, jsonPath.getInt("data.total_count")); // Fail if it hasn't completed in maxWait seconds assertTrue(i < maxWait); From 03aa898140d7c094079315f19751bc67dfee3831 Mon Sep 17 00:00:00 2001 From: landreev Date: Fri, 12 Apr 2024 15:23:56 -0400 Subject: [PATCH 11/11] An extra sec. for indexing --- .../java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java index d25a4f42872..340eab161bb 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/HarvestingClientsIT.java @@ -286,6 +286,8 @@ private void harvestingClientRun(boolean allowHarvestingMissingCVV) throws Inte System.out.println("Waited " + i + " seconds for the harvest to complete."); + // Let's give the asynchronous indexing an extra sec. to finish: + Thread.sleep(1000L); Response searchHarvestedDatasets = UtilIT.search("metadataSource:" + nickName, normalUserAPIKey); searchHarvestedDatasets.then().assertThat().statusCode(OK.getStatusCode()); searchHarvestedDatasets.prettyPrint();