From f542978603588b6ec635adfa86d9a62c25788b4e Mon Sep 17 00:00:00 2001 From: "Stefan E. Funk" <funk@sub.uni-goettingen.de> Date: Tue, 19 Apr 2022 18:23:12 +0200 Subject: [PATCH] Add dhrep test properties files Add test for false identifiers in ListRecords (#61) --- .../middleware/OaiPmhDariahdeOnlineTests.java | 64 ++++++++++--------- .../middleware/OaiPmhTestUtilities.java | 1 - .../middleware/OaiPmhTextgridOnlineTests.java | 6 +- .../middleware/TestOAIPMHUtilities.java | 4 -- oaipmh-core/src/test/resources/.gitignore | 2 - .../oaipmh.test.textgridlab-org.properties | 4 +- .../oaipmh.test.trep-de-dariah-eu.properties | 19 ++++++ 7 files changed, 59 insertions(+), 41 deletions(-) create mode 100644 oaipmh-core/src/test/resources/oaipmh.test.trep-de-dariah-eu.properties diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDariahdeOnlineTests.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDariahdeOnlineTests.java index 7b7d3d0f..60a935fc 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDariahdeOnlineTests.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDariahdeOnlineTests.java @@ -28,7 +28,6 @@ import org.junit.Test; * </p> * * @author Stefan E. Funk, SUB Göttingen - * */ @Ignore public class OaiPmhDariahdeOnlineTests { @@ -36,8 +35,7 @@ public class OaiPmhDariahdeOnlineTests { // FINALS // ** - // private static final String PROPERTIES_FILE = - // "oaipmh.test.repository-de-dariah-eu.properties"; + // private static final String PROPERTIES_FILE = "oaipmh.test.repository-de-dariah-eu.properties"; private static final String PROPERTIES_FILE = "oaipmh.test.trep-de-dariah-eu.properties"; // ** @@ -350,33 +348,29 @@ public class OaiPmhDariahdeOnlineTests { * existing, tag is existing and has no token value. * @throws IOException */ - private static String examineResumptionTokenTag(Response theResponse, + private static String examineResumptionTokenTag(String theResponseString, String recordOrHeader, String oldtok) throws IOException { - String responseString = IOUtils - .readStringFromStream((InputStream) theResponse.getEntity()); - // Test for OAIPMH errors. - if (responseString.contains("<error code=\"badArgument\">")) { - System.err.println(OaiPmhTestUtilities.ERROR - + " IN OAIPMH RESPONSE: " + responseString); + if (theResponseString.contains("<error code=\"badArgument\">")) { + System.err.println(OaiPmhTestUtilities.ERROR + " IN OAIPMH RESPONSE: " + theResponseString); assertTrue(false); } // Count response objects at first. int recordCount = 0; - int i = responseString.indexOf("<" + recordOrHeader + ">", 0); + int i = theResponseString.indexOf("<" + recordOrHeader + ">", 0); while (i != -1) { recordCount++; i++; - i = responseString.indexOf("<" + recordOrHeader + ">", i); + i = theResponseString.indexOf("<" + recordOrHeader + ">", i); } System.out.println("\t" + recordOrHeader + "s: " + recordCount); // Check if token tag is existing. - int tokStart = responseString.indexOf("<resumptionToken"); - int tokEnd = responseString.indexOf("</resumptionToken"); + int tokStart = theResponseString.indexOf("<resumptionToken"); + int tokEnd = theResponseString.indexOf("</resumptionToken"); if (tokStart == -1 && tokEnd == -1) { System.out.println("\ttoken: no token"); @@ -384,7 +378,7 @@ public class OaiPmhDariahdeOnlineTests { return "-1"; } - String restokTmp = responseString.substring(tokStart, tokEnd); + String restokTmp = theResponseString.substring(tokStart, tokEnd); // Get token tag. String toktag = restokTmp.substring(0, restokTmp.indexOf(">") + 1) .trim(); @@ -495,23 +489,24 @@ public class OaiPmhDariahdeOnlineTests { Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path); + String responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); int status = response.getStatus(); long timeRunning = System.currentTimeMillis() - startTime; - System.out.println("\ttime: " - + OaiPmhTestUtilities.getDurationInSecs(timeRunning)); + System.out.println("\ttime: " + OaiPmhTestUtilities.getDurationInSecs(timeRunning)); - String restok = examineResumptionTokenTag(response, testOccurance, ""); + String restok = examineResumptionTokenTag(responseString, testOccurance, ""); + examineIdentifiers(responseString); result = 1; while (status == HttpStatus.SC_OK && !restok.equals("-1")) { path = "verb=" + theVerb + "&resumptionToken=" + restok; - response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, - path); + response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path); + responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); timeRunning = System.currentTimeMillis() - startTime; - System.out.println("\ttime: " - + OaiPmhTestUtilities.getDurationInSecs(timeRunning)); - restok = examineResumptionTokenTag(response, testOccurance, restok); + System.out.println("\ttime: " + OaiPmhTestUtilities.getDurationInSecs(timeRunning)); + restok = examineResumptionTokenTag(responseString, testOccurance, restok); + examineIdentifiers(responseString); result++; } @@ -543,8 +538,7 @@ public class OaiPmhDariahdeOnlineTests { || !responseString.contains(theExpectedResponse)) { System.err.println("\tstatus: " + status); System.err.println( - OaiPmhTestUtilities.ERROR + ": response should contain '" - + theExpectedResponse + "'"); + OaiPmhTestUtilities.ERROR + ": response should contain '" + theExpectedResponse + "'"); System.err.println(responseString); assertTrue(false); } @@ -570,11 +564,10 @@ public class OaiPmhDariahdeOnlineTests { String responseString = IOUtils .readStringFromStream((InputStream) response.getEntity()); - if (status != HttpStatus.SC_OK - || !responseString.contains(shouldContain)) { + if (status != HttpStatus.SC_OK || !responseString.contains(shouldContain)) { System.err.println("\tstatus: " + status); - System.err.println(OaiPmhTestUtilities.ERROR - + ": response should contain '" + shouldContain + "'"); + System.err + .println(OaiPmhTestUtilities.ERROR + ": response should contain '" + shouldContain + "'"); assertTrue(false); } @@ -582,4 +575,17 @@ public class OaiPmhDariahdeOnlineTests { System.out.println(OaiPmhTestUtilities.OK); } + /** + * @param theResponseString + * @return + * @throws IOException + */ + private static void examineIdentifiers(String theResponseString) throws IOException { + if (theResponseString.contains("<identifier>hdl:21</identifier>")) { + System.err.println(OaiPmhTestUtilities.ERROR + + " IN OAIPMH RESPONSE: identifier tag is corrupt!" + theResponseString); + assertTrue(false); + } + } + } diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestUtilities.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestUtilities.java index 8db8304f..02f272b4 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestUtilities.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestUtilities.java @@ -28,7 +28,6 @@ public class OaiPmhTestUtilities { protected static final String OAI_DC_PREFIX = "oai_dc"; protected static final String OAI_DATACITE_PREFIX = "oai_datacite"; protected static final String OAI_IDIOMMETS_PREFIX = "oai_idiom_mets"; - protected static final String OAI_IDIOM_IMAGE_METS_PREFIX = "oai_idiom_image_mets"; protected static final String EXPECTED_OAIDC_FORMAT_CONTENT = "<oai_dc:dc>"; protected static final String EXPECTED_IDIOMMETS_FORMAT_CONTENT = "<mets "; diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java index fc797d08..10c88aa9 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java @@ -391,9 +391,9 @@ public class OaiPmhTextgridOnlineTests { System.out.println(OaiPmhTestUtilities.TESTING + "testGetRecordIDIOMMETS_Image()"); - String path = "verb=" + OaiPmhTestUtilities.VERB_GET_RECORD + "&identifier=" - + checkGetRecordIDIOM_Images + "&metadataPrefix=" - + OaiPmhTestUtilities.OAI_IDIOM_IMAGE_METS_PREFIX; + String path = + "verb=" + OaiPmhTestUtilities.VERB_GET_RECORD + "&identifier=" + checkGetRecordIDIOM_Images + + "&metadataPrefix=" + OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX; Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path, OaiPmhTestUtilities.NO_THREAD_NAME); diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/TestOAIPMHUtilities.java b/oaipmh-core/src/test/java/info/textgrid/middleware/TestOAIPMHUtilities.java index ef3cc6f1..2bec3247 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/TestOAIPMHUtilities.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/TestOAIPMHUtilities.java @@ -1,8 +1,6 @@ package info.textgrid.middleware; import static org.junit.Assert.assertTrue; - -import java.io.IOException; import java.text.ParseException; import org.junit.Test; @@ -99,8 +97,6 @@ public class TestOAIPMHUtilities { System.out.println(setSpec + " != " + exp); assertTrue(false); } - - } } diff --git a/oaipmh-core/src/test/resources/.gitignore b/oaipmh-core/src/test/resources/.gitignore index b2138af4..e035d810 100644 --- a/oaipmh-core/src/test/resources/.gitignore +++ b/oaipmh-core/src/test/resources/.gitignore @@ -1,4 +1,2 @@ /oaipmh.test.local.properties -/oaipmh.test.dhrepworkshop-de-dariah-eu.properties -/oaipmh.test.trep-de-dariah-eu.properties /oaipmh.test.vm1-dariah-local.properties diff --git a/oaipmh-core/src/test/resources/oaipmh.test.textgridlab-org.properties b/oaipmh-core/src/test/resources/oaipmh.test.textgridlab-org.properties index 631008fa..da78cecb 100644 --- a/oaipmh-core/src/test/resources/oaipmh.test.textgridlab-org.properties +++ b/oaipmh-core/src/test/resources/oaipmh.test.textgridlab-org.properties @@ -7,8 +7,8 @@ checkGetRecordDC = textgrid:vqn0.0 expectedGetRecordDC = Heidi checkGetRecordIDIOM = textgrid:2sg18.0 expectedGetRecordIDIOM = Aguateca -checkGetRecordIDIOM_Images = 11669 -expectedGetRecordIDIOM_Images = Bonampak +checkGetRecordIDIOM_Images = textgrid:3x641.0 +expectedGetRecordIDIOM_Images = Acanceh checkGetRecordDATACITE = textgrid:mq05.0 expectedGetRecordDATACITE = Weise Klugredenn checkGetRecordIDList = textgrid:mq05.0, textgrid:jgv6.0, textgrid:w7rz.0, textgrid:w36b.0, textgrid:mcdv.0, textgrid:v0qx.0, textgrid:xkck.0, textgrid:t3m1.0, textgrid:10rsq.0, textgrid:mq05.0, textgrid:jgv6.0, textgrid:w7rz.0, textgrid:w36b.0, textgrid:mcdv.0, textgrid:v0qx.0, textgrid:xkck.0, textgrid:t3m1.0, textgrid:10rsq.0 diff --git a/oaipmh-core/src/test/resources/oaipmh.test.trep-de-dariah-eu.properties b/oaipmh-core/src/test/resources/oaipmh.test.trep-de-dariah-eu.properties new file mode 100644 index 00000000..48400d67 --- /dev/null +++ b/oaipmh-core/src/test/resources/oaipmh.test.trep-de-dariah-eu.properties @@ -0,0 +1,19 @@ +# OAI-PMH host +oaipmhEndpoint = https://trep.de.dariah.eu/1.0/oaipmh/oai +# ListSets +expectedListSets = hdl:21.T11991/0000-0005-E1A9-E +# GetRecord +checkGetRecordDC = +expectedGetRecordDC = +checkGetRecordDATACITE = +expectedGetRecordDATACITE = +checkGetRecordIDList = +# ListRecords +checkListRecordsDC = +checkListRecordsDCFrom = +checkListRecordsDCUntil = +checkListRecordsDATACITEFrom = +checkListRecordsDATACITEUntil = +# ListIdentifiers +checkListIdentifiersSet = + \ No newline at end of file -- GitLab