diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java index 3f2727415b11f3b58e50e99afa8b7cb222d1563c..40e78a79e9aac820b2eeb6fda624f17ed97bd677 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java @@ -126,8 +126,8 @@ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstrac // FIXME BTW: We only need ID and DATESTAMP for ListIdentifiers, WHY do we get every // complete RECORD?? - identifierList.getHeader().add( - this.idiomRecord.getRecordById(textgridURI.replace(".0", "")).getRecord().getHeader()); + identifierList.getHeader() + .add(this.idiomRecord.getRecordById(textgridURI).getRecord().getHeader()); } // Check the need for a resumption token! diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/OAIPMHUtilitiesOnline.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/OAIPMHUtilitiesOnline.java index 8fb28f3c255dae2936465fcf190d49638d422901..5f1985a7933a01e353eecf3a0cde58894ee0a6f8 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/OAIPMHUtilitiesOnline.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/OAIPMHUtilitiesOnline.java @@ -21,12 +21,17 @@ import org.apache.cxf.transport.http.HTTPConduit; import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; import org.apache.http.HttpStatus; import info.textgrid.middleware.OAIPMHProducer; +import info.textgrid.middleware.test.online.dh.TestDHOAIPMHOnline; /** * <p> * Some online tests for the TextGrid OAIMPH service. * </p> * + * <p> + * Please set PROPERTIES_FILE and TEST_ALL_PAGES <b>BELOW</b>! + * </p> + * * @author Stefan E. Funk, SUB Göttingen */ public class OAIPMHUtilitiesOnline { @@ -587,10 +592,233 @@ public class OAIPMHUtilitiesOnline { // DH used methods // ** - // FIXME + /** + * @param theResponse + * @return Resumption token string, if existing, -1 if either no <resumptionToken> tag is + * existing, tag is existing and has no token value. + * @throws IOException + */ + public static String examineDHResumptionTokenTag(String theResponseString, String recordOrHeader, + String oldtok) throws IOException { + + // Test for OAIPMH errors. + if (theResponseString.contains("<error code=\"badArgument\">")) { + assertTrue("ERROR IN OAIPMH RESPONSE: " + theResponseString, false); + } + + // Count response objects at first. + int recordCount = 0; + int i = theResponseString.indexOf("<" + recordOrHeader + ">", 0); + while (i != -1) { + recordCount++; + i++; + i = theResponseString.indexOf("<" + recordOrHeader + ">", i); + } + + System.out.println("\t" + recordOrHeader + "s: " + recordCount); + + // Check if token tag is existing. + int tokStart = theResponseString.indexOf("<resumptionToken"); + int tokEnd = theResponseString.indexOf("</resumptionToken"); + + if (tokStart == -1 && tokEnd == -1) { + System.out.println("\ttoken: no token"); + + return "-1"; + } + + String restokTmp = theResponseString.substring(tokStart, tokEnd); + // Get token tag. + String toktag = restokTmp.substring(0, restokTmp.indexOf(">") + 1).trim(); + System.out.println("\ttokentag: " + toktag); + + // Get token. + String restok = restokTmp.substring(restokTmp.indexOf(">") + 1).trim(); + System.out.println("\ttoken: " + restok); + + // Check if old and new token are equal or not. + boolean tokchanged = !oldtok.equals(restok); + System.out.println("\ttokchngd: " + tokchanged); + + // Get completeListSize and cursor. + String sizeStr = toktag.substring(toktag.indexOf("completeListSize=\"") + 18); + int size = Integer.parseInt(sizeStr.substring(0, sizeStr.indexOf("\""))); + String cursorStr = toktag.substring(toktag.indexOf("cursor=\"") + 8); + int cursor = Integer.parseInt(cursorStr.substring(0, cursorStr.indexOf("\""))); + System.out.println("\tsize: " + size + " / " + cursor); + + // If token is provided, and we have less than 100 elements: mekkern! + if (!restok.isEmpty()) { + synchronized (TestDHOAIPMHOnline.class) { + // Check <record> or <header> count, must be 100! + String message = ""; + if (recordCount > 100) { + message = recordOrHeader + " count mismatch, must be 100 if token is provided, but is " + + recordCount; + } else { + message = + "completeListSize count mismatch, must be > 100 if token is provided, but is " + size; + } + if (recordCount != 100 || size <= 100) { + assertTrue(message, false); + } + } + } + + // If no token is provided, stop querying. + else { + // Check <record> count, must be completeListSize % 100. + if (recordCount != size % 100) { + String message = + recordOrHeader + " count mismatch, should be " + size % 100 + ", but is " + recordCount; + assertTrue(message, false); + } + + // No resumption token available in response. + return "-1"; + } + + return restok; + } + + /** + * @param theClient + * @param theVerb + * @param theMetadataPrefix + * @param theSet + * @return + * @throws IOException + */ + public static int testDHList(Client theClient, String theVerb, String theMetadataPrefix, + String theSet) throws IOException { + return testDHList(theClient, theVerb, theMetadataPrefix, theSet, NO_FROM, NO_UNTIL); + } + + /** + * @param theClient + * @param theVerb + * @param theMetadataPrefix + * @param theSet + * @param from + * @param until + * @return How many pages were delivered + * @throws IOException + */ + public static int testDHList(Client theClient, String theVerb, String theMetadataPrefix, + String theSet, String from, String until) throws IOException { + + int result; + + long startTime = System.currentTimeMillis(); + + String testOccurance = "header"; + if (theVerb.equals(VERB_LIST_RECORDS)) { + testOccurance = "record"; + } + + String query = "verb=" + theVerb + "&metadataPrefix=" + theMetadataPrefix; + + if (theSet != null && !theSet.isEmpty()) { + query += "&set=" + theSet; + } + + if (from != null && until != null) { + query += "&from=" + from + "&until=" + until; + } + + Response response = getOAIHttpResponse(theClient, query); + + String responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); + int status = response.getStatus(); + + long timeRunning = System.currentTimeMillis() - startTime; + System.out.println("\ttime: " + getDurationInSecs(timeRunning)); + + String restok = examineDHResumptionTokenTag(responseString, testOccurance, ""); + examineDHIdentifiers(responseString); + + result = 1; + while (status == HttpStatus.SC_OK && !restok.equals("-1")) { + query = "verb=" + theVerb + "&resumptionToken=" + restok; + response = getOAIHttpResponse(theClient, query); + responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); + timeRunning = System.currentTimeMillis() - startTime; + System.out.println("\ttime: " + getDurationInSecs(timeRunning)); + restok = examineDHResumptionTokenTag(responseString, testOccurance, restok); + examineDHIdentifiers(responseString); + result++; + } + + System.out.println("\tpage amount: " + result); + System.out.println(OK); + + return result; + } + + /** + * @param theClient + * @param theSet + * @param theExpectedResponse + * @throws IOException + */ + public static void testDHListSet(Client theClient, String theSet, String theExpectedResponse) + throws IOException { + + System.out.println(TESTING + "#LISTSETS"); + + Response response = getOAIHttpResponse(theClient, "verb=" + VERB_LIST_SETS); + int status = response.getStatus(); + + String responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); + + if (status != HttpStatus.SC_OK || !responseString.contains(theExpectedResponse)) { + String message = "[" + status + "] response should contain '" + theExpectedResponse + "'"; + assertTrue(message, false); + } + + System.out.println("\tresponse: " + responseString); + System.out.println(OK); + } + + /** + * @param theClient + * @param theIdentifier + * @param theVerb + * @param theMetadataPrefix + * @param theExpected + * @throws IOException + */ + public static void testDHRecord(Client theClient, String theIdentifier, String theVerb, + String theMetadataPrefix, String theExpected) throws IOException { + + long startTime = System.currentTimeMillis(); + + String query = + "verb=" + theVerb + "&identifier=" + theIdentifier + "&metadataPrefix=" + theMetadataPrefix; + + Response response = getOAIHttpResponse(theClient, query); + + String responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); + int status = response.getStatus(); + + System.out.println(status); + System.out.println(responseString); + + long timeRunning = System.currentTimeMillis() - startTime; + System.out.println("\ttime: " + getDurationInSecs(timeRunning)); + + examineDHIdentifiers(responseString); + + if (!responseString.contains(theExpected)) { + System.out.println("NOT CONTAINED: " + theExpected); + assertTrue(false); + } else { + System.out.println(OAIPMHUtilitiesOnline.OK); + } + } // ** - // Commonly used (TG & DH) methods + // PRIVATE METHODS // ** /** @@ -608,4 +836,16 @@ public class OAIPMHUtilitiesOnline { return result; } + /** + * @param theResponseString + * @return + * @throws IOException + */ + private static void examineDHIdentifiers(String theResponseString) throws IOException { + if (theResponseString.contains("<identifier>hdl:21</identifier>")) { + String message = "ERROR IN OAIPMH RESPONSE: identifier tag is corrupt!" + theResponseString; + assertTrue(message, false); + } + } + } diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/dh/TestDHOAIPMHOnline.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/dh/TestDHOAIPMHOnline.java index 85f73e46b723ba8f688ea1049dd946266463673c..28d29ff8c8702ef958b77757040aabb6b83d7c7b 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/dh/TestDHOAIPMHOnline.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/dh/TestDHOAIPMHOnline.java @@ -22,6 +22,10 @@ import info.textgrid.middleware.test.online.OAIPMHUtilitiesOnline; * Some online tests for the DARIAH-DE Repository OAIMPH service. * </p> * + * <p> + * Please set PROPERTIES_FILE and TEST_ALL_PAGES <b>HERE</b>! + * </p> + * * @author Stefan E. Funk, SUB Göttingen */ @Ignore @@ -226,7 +230,9 @@ public class TestDHOAIPMHOnline { */ @Test public void testListSets() throws IOException { - testListSet(expectedListSets, expectedListSets); + OAIPMHUtilitiesOnline.testDHListSet(oaipmhWebClient, + OAIPMHUtilitiesOnline.NO_SET, + expectedListSets); } /** @@ -237,7 +243,9 @@ public class TestDHOAIPMHOnline { System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS"); - testList(OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, OAIPMHUtilitiesOnline.NO_SET); } @@ -249,9 +257,11 @@ public class TestDHOAIPMHOnline { System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS"); - int pages = testList(OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, - OAIPMHUtilitiesOnline.OAI_DC_PREFIX, checkListRecordsDCSet); - + int pages = + OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + checkListRecordsDCSet); if (pages != checkListRecordsDCSetExpectedPages) { assertTrue(pages + " != " + checkListRecordsDCSetExpectedPages, false); } @@ -270,8 +280,10 @@ public class TestDHOAIPMHOnline { if (!uri.startsWith(OAIPMHUtilitiesOnline.HDL_PREFIX)) { assertTrue("missing '" + OAIPMHUtilitiesOnline.HDL_PREFIX + "' prefix!", false); } - int pages1 = - testList(OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, uri); + int pages1 = OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + uri); if (pages1 != checkListRecordsDCSetExpectedPages) { System.out.println(pages1 + " != " + checkListRecordsDCSetExpectedPages); } @@ -281,8 +293,10 @@ public class TestDHOAIPMHOnline { if (checkListRecordsDCSet.startsWith(OAIPMHUtilitiesOnline.HDL_PREFIX)) { uri = checkListRecordsDCSet.substring(4); } - int pages2 = - testList(OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, uri); + int pages2 = OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + uri); if (pages2 != checkListRecordsDCSetExpectedPages) { System.out.println(pages2 + " != " + checkListRecordsDCSetExpectedPages); } @@ -310,8 +324,10 @@ public class TestDHOAIPMHOnline { OAIPMHUtilitiesOnline.STAR_PREFIX + checkListRecordsDCSet.substring(4); } - int pages3 = testList(OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, - OAIPMHUtilitiesOnline.OAI_DC_PREFIX, checkListRecordsDCSet); + int pages3 = OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + checkListRecordsDCSet); if (pages3 != 1) { System.out.println(pages3 + " != " + 1); } @@ -325,8 +341,12 @@ public class TestDHOAIPMHOnline { System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS"); - testList(OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, - OAIPMHUtilitiesOnline.NO_SET, checkListRecordsDCFrom, checkListRecordsDCUntil); + OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + OAIPMHUtilitiesOnline.NO_SET, + checkListRecordsDCFrom, + checkListRecordsDCUntil); } /** @@ -337,7 +357,9 @@ public class TestDHOAIPMHOnline { System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS"); - testList(OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, + OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, OAIPMHUtilitiesOnline.NO_SET); } @@ -349,8 +371,11 @@ public class TestDHOAIPMHOnline { System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS"); - testList(OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, - OAIPMHUtilitiesOnline.NO_SET, checkListRecordsDATACITEFrom, checkListRecordsDATACITEUntil); + OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, + OAIPMHUtilitiesOnline.NO_SET, + checkListRecordsDATACITEFrom, checkListRecordsDATACITEUntil); } /** @@ -361,8 +386,11 @@ public class TestDHOAIPMHOnline { System.out.println(OAIPMHUtilitiesOnline.TESTING + "#GETRECORD"); - testRecord(checkGetRecordDC, OAIPMHUtilitiesOnline.VERB_GET_RECORD, - OAIPMHUtilitiesOnline.OAI_DC_PREFIX, expectedGetRecordDC); + OAIPMHUtilitiesOnline.testDHRecord(oaipmhWebClient, + checkGetRecordDC, + OAIPMHUtilitiesOnline.VERB_GET_RECORD, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + expectedGetRecordDC); } /** @@ -373,8 +401,11 @@ public class TestDHOAIPMHOnline { System.out.println(OAIPMHUtilitiesOnline.TESTING + "#GETRECORD"); - testRecord(checkGetRecordDATACITE, OAIPMHUtilitiesOnline.VERB_GET_RECORD, - OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, expectedGetRecordDATACITE); + OAIPMHUtilitiesOnline.testDHRecord(oaipmhWebClient, + checkGetRecordDATACITE, + OAIPMHUtilitiesOnline.VERB_GET_RECORD, + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, + expectedGetRecordDATACITE); } /** @@ -385,7 +416,9 @@ public class TestDHOAIPMHOnline { System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTIDENTIFIERS"); - testList(OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, OAIPMHUtilitiesOnline.NO_SET); } @@ -397,9 +430,10 @@ public class TestDHOAIPMHOnline { System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTIDENTIFIERS"); - int pages = testList(OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, - OAIPMHUtilitiesOnline.OAI_DC_PREFIX, checkListIdentifiersSet); - + int pages = OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + checkListIdentifiersSet); if (pages != checkListIdentifiersSetExpectedPages) { assertTrue(pages + " != " + checkListIdentifiersSetExpectedPages, false); } @@ -419,8 +453,10 @@ public class TestDHOAIPMHOnline { assertTrue("missing '" + OAIPMHUtilitiesOnline.HDL_PREFIX + "' prefix!", false); } System.out.println("uri: " + uri); - int pages1 = testList(OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, - OAIPMHUtilitiesOnline.OAI_DC_PREFIX, uri); + int pages1 = OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + uri); if (pages1 != checkListIdentifiersSetExpectedPages) { System.out.println(pages1 + " != " + checkListIdentifiersSetExpectedPages); } @@ -431,8 +467,10 @@ public class TestDHOAIPMHOnline { uri = checkListIdentifiersSet.substring(4); } System.out.println("uri: " + uri); - int pages2 = testList(OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, - OAIPMHUtilitiesOnline.OAI_DC_PREFIX, uri); + int pages2 = OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + uri); if (pages2 != checkListIdentifiersSetExpectedPages) { System.out.println(pages2 + " != " + checkListIdentifiersSetExpectedPages); } @@ -461,8 +499,11 @@ public class TestDHOAIPMHOnline { OAIPMHUtilitiesOnline.STAR_PREFIX + checkListIdentifiersSet.substring(4); } System.out.println("uri: " + checkListIdentifiersSet); - int pages3 = testList(OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, - OAIPMHUtilitiesOnline.OAI_DC_PREFIX, checkListIdentifiersSet); + + int pages3 = OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + checkListIdentifiersSet); if (pages3 != checkListIdentifiersSetExpectedPages) { System.out.println(pages3 + " != " + checkListIdentifiersSetExpectedPages); } @@ -476,7 +517,9 @@ public class TestDHOAIPMHOnline { System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTIDENTIFIERS"); - testList(OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, + OAIPMHUtilitiesOnline.testDHList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, OAIPMHUtilitiesOnline.NO_SET); } @@ -484,233 +527,6 @@ public class TestDHOAIPMHOnline { // PRIVATE METHODS // ** - /** - * TODO Generalise in OAIPMHUtilitiesOnline! - * - * @param theResponse - * @return Resumption token string, if existing, -1 if either no <resumptionToken> tag is - * existing, tag is existing and has no token value. - * @throws IOException - */ - private static String examineResumptionTokenTag(String theResponseString, - String recordOrHeader, String oldtok) throws IOException { - - // Test for OAIPMH errors. - if (theResponseString.contains("<error code=\"badArgument\">")) { - assertTrue("ERROR IN OAIPMH RESPONSE: " + theResponseString, false); - } - - // Count response objects at first. - int recordCount = 0; - int i = theResponseString.indexOf("<" + recordOrHeader + ">", 0); - while (i != -1) { - recordCount++; - i++; - i = theResponseString.indexOf("<" + recordOrHeader + ">", i); - } - - System.out.println("\t" + recordOrHeader + "s: " + recordCount); - - // Check if token tag is existing. - int tokStart = theResponseString.indexOf("<resumptionToken"); - int tokEnd = theResponseString.indexOf("</resumptionToken"); - - if (tokStart == -1 && tokEnd == -1) { - System.out.println("\ttoken: no token"); - - return "-1"; - } - - String restokTmp = theResponseString.substring(tokStart, tokEnd); - // Get token tag. - String toktag = restokTmp.substring(0, restokTmp.indexOf(">") + 1).trim(); - System.out.println("\ttokentag: " + toktag); - - // Get token. - String restok = restokTmp.substring(restokTmp.indexOf(">") + 1).trim(); - System.out.println("\ttoken: " + restok); - - // Check if old and new token are equal or not. - boolean tokchanged = !oldtok.equals(restok); - System.out.println("\ttokchngd: " + tokchanged); - - // Get completeListSize and cursor. - String sizeStr = toktag.substring(toktag.indexOf("completeListSize=\"") + 18); - int size = Integer.parseInt(sizeStr.substring(0, sizeStr.indexOf("\""))); - String cursorStr = toktag.substring(toktag.indexOf("cursor=\"") + 8); - int cursor = Integer.parseInt(cursorStr.substring(0, cursorStr.indexOf("\""))); - System.out.println("\tsize: " + size + " / " + cursor); - - // If token is provided, and we have less than 100 elements: mekkern! - if (!restok.isEmpty()) { - synchronized (TestDHOAIPMHOnline.class) { - // Check <record> or <header> count, must be 100! - String message = ""; - if (recordCount > 100) { - message = recordOrHeader + " count mismatch, must be 100 if token is provided, but is " - + recordCount; - } else { - message = - "completeListSize count mismatch, must be > 100 if token is provided, but is " + size; - } - if (recordCount != 100 || size <= 100) { - assertTrue(message, false); - } - } - } - - // If no token is provided, stop querying. - else { - // Check <record> count, must be completeListSize % 100. - if (recordCount != size % 100) { - String message = - recordOrHeader + " count mismatch, should be " + size % 100 + ", but is " + recordCount; - assertTrue(message, false); - } - - // No resumption token available in response. - return "-1"; - } - - return restok; - } - - /** - * @param theVerb - * @param theMetadataPrefix - * @param theSet - * @return - * @throws IOException - */ - private static int testList(String theVerb, String theMetadataPrefix, String theSet) - throws IOException { - return testList(theVerb, theMetadataPrefix, theSet, OAIPMHUtilitiesOnline.NO_FROM, - OAIPMHUtilitiesOnline.NO_UNTIL); - } - - /** - * TODO Generalise in OAIPMHUtilitiesOnline?? - * - * @param theVerb - * @param theMetadataPrefix - * @param theSet - * @param from - * @param until - * @return How many pages were delivered - * @throws IOException - */ - private static int testList(String theVerb, String theMetadataPrefix, String theSet, String from, - String until) throws IOException { - - int result; - - long startTime = System.currentTimeMillis(); - - String testOccurance = "header"; - if (theVerb.equals(OAIPMHUtilitiesOnline.VERB_LIST_RECORDS)) { - testOccurance = "record"; - } - - String query = "verb=" + theVerb + "&metadataPrefix=" + theMetadataPrefix; - - if (theSet != null && !theSet.isEmpty()) { - query += "&set=" + theSet; - } - - if (from != null && until != null) { - query += "&from=" + from + "&until=" + until; - } - - Response response = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, query); - - String responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); - int status = response.getStatus(); - - long timeRunning = System.currentTimeMillis() - startTime; - System.out.println("\ttime: " + OAIPMHUtilitiesOnline.getDurationInSecs(timeRunning)); - - String restok = examineResumptionTokenTag(responseString, testOccurance, ""); - examineIdentifiers(responseString); - - result = 1; - while (status == HttpStatus.SC_OK && !restok.equals("-1")) { - query = "verb=" + theVerb + "&resumptionToken=" + restok; - response = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, query); - responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); - timeRunning = System.currentTimeMillis() - startTime; - System.out.println("\ttime: " + OAIPMHUtilitiesOnline.getDurationInSecs(timeRunning)); - restok = examineResumptionTokenTag(responseString, testOccurance, restok); - examineIdentifiers(responseString); - result++; - } - - System.out.println("\tpage amount: " + result); - System.out.println(OAIPMHUtilitiesOnline.OK); - - return result; - } - - /** - * TODO Generalise in OAIPMHUtilitiesOnline?? - * - * @param theIdentifier - * @param theVerb - * @param theMetadataPrefix - * @param theExpected - * @throws IOException - */ - private static void testRecord(String theIdentifier, String theVerb, String theMetadataPrefix, - String theExpected) throws IOException { - - long startTime = System.currentTimeMillis(); - - String query = - "verb=" + theVerb + "&identifier=" + theIdentifier + "&metadataPrefix=" + theMetadataPrefix; - - Response response = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, query); - - String responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); - int status = response.getStatus(); - - System.out.println(status); - System.out.println(responseString); - - long timeRunning = System.currentTimeMillis() - startTime; - System.out.println("\ttime: " + OAIPMHUtilitiesOnline.getDurationInSecs(timeRunning)); - - examineIdentifiers(responseString); - - if (!responseString.contains(theExpected)) { - System.out.println("NOT CONTAINED: " + theExpected); - assertTrue(false); - } else { - System.out.println(OAIPMHUtilitiesOnline.OK); - } - } - - /** - * @param theSet - * @throws IOException - */ - private static void testListSet(String theSet, String theExpectedResponse) throws IOException { - - System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTSETS"); - - Response response = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, - "verb=" + OAIPMHUtilitiesOnline.VERB_LIST_SETS); - int status = response.getStatus(); - - String responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); - - if (status != HttpStatus.SC_OK || !responseString.contains(theExpectedResponse)) { - String message = "[" + status + "] response should contain '" + theExpectedResponse + "'"; - assertTrue(message, false); - } - - System.out.println("\tresponse: " + responseString); - System.out.println(OAIPMHUtilitiesOnline.OK); - } - /** * @param theURL * @param shouldContain @@ -736,16 +552,4 @@ public class TestDHOAIPMHOnline { System.out.println(OAIPMHUtilitiesOnline.OK); } - /** - * @param theResponseString - * @return - * @throws IOException - */ - private static void examineIdentifiers(String theResponseString) throws IOException { - if (theResponseString.contains("<identifier>hdl:21</identifier>")) { - String message = "ERROR IN OAIPMH RESPONSE: identifier tag is corrupt!" + theResponseString; - assertTrue(message, false); - } - } - } diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGBasicsOnline.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGBasicsOnline.java index e5c6aa4adb76936cf4221871ead007464aad6325..f833730d701dc8a89b268dc93abbeb2d13a754b1 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGBasicsOnline.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGBasicsOnline.java @@ -21,6 +21,10 @@ import info.textgrid.middleware.test.online.OAIPMHUtilitiesOnline; * Some basic online tests for the TextGrid OAIMPH service. * </p> * + * <p> + * Please set PROPERTIES_FILE and TEST_ALL_PAGES in class <b>OAIPMHUtilitiesOnline</b>! + * </p> + * * @author Stefan E. Funk, SUB Göttingen */ @Ignore diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGGetRecordOnline.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGGetRecordOnline.java index 6a17b7d1b98accb2aa06a0c57d8ed814ca86811e..2eb8157fffc99f981dfb6357c16ca40a84e9c308 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGGetRecordOnline.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGGetRecordOnline.java @@ -28,6 +28,10 @@ import info.textgrid.middleware.test.online.OAIPMHUtilitiesOnline; * Some online tests for the TextGrid OAIMPH service --> verb=GetRecord <-- * </p> * + * <p> + * Please set PROPERTIES_FILE and TEST_ALL_PAGES in class <b>OAIPMHUtilitiesOnline</b>! + * </p> + * * @author Stefan E. Funk, SUB Göttingen * @version 2022-09-23 * @since 2022-09-08 diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListIdentifiersOnline.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListIdentifiersOnline.java index e596799e825e530e2c531f2f8790cf5a76399297..7fff73041aad61b998702c76bbbfcde6c8f3c314 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListIdentifiersOnline.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListIdentifiersOnline.java @@ -20,6 +20,10 @@ import info.textgrid.middleware.test.online.OAIPMHUtilitiesOnline; * Some online tests for the TextGrid OAIMPH service --> verb=ListIdentifiers <-- * </p> * + * <p> + * Please set PROPERTIES_FILE and TEST_ALL_PAGES in class <b>OAIPMHUtilitiesOnline</b>! + * </p> + * * @author Stefan E. Funk, SUB Göttingen * @version 2022-09-23 * @since 2022-09-12 diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListRecordsOnline.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListRecordsOnline.java index 11def47aa6619b53fc203898172fe0ddce6184be..517adbd98616862fbfd009b46a4e8963c9279d27 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListRecordsOnline.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListRecordsOnline.java @@ -20,8 +20,12 @@ import info.textgrid.middleware.test.online.OAIPMHUtilitiesOnline; * Some online tests for the TextGrid OAIMPH service --> verb=ListRecords <-- * </p> * + * <p> + * Please set PROPERTIES_FILE and TEST_ALL_PAGES in class <b>OAIPMHUtilitiesOnline</b>! + * </p> + * * @author Stefan E. Funk, SUB Göttingen - * @version 2022-09-26 + * @version 2022-09-28 * @since 2022-09-12 */ @Ignore 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 49b28e03fa9b9caeb374484962b184508e223d30..3e107e4863440bcfca4a3626e2102bb262ac537c 100644 --- a/oaipmh-core/src/test/resources/oaipmh.test.textgridlab-org.properties +++ b/oaipmh-core/src/test/resources/oaipmh.test.textgridlab-org.properties @@ -1,5 +1,5 @@ # OAI-PMH host -oaipmhEndpoint = https://textgridlab.org/1.0/tgoaipmh/oai +oaipmhEndpoint = https://textgridlab.org/1.0/tgoaipmh # GetRecord checkGetRecordDC = textgrid:vqn0.0 @@ -21,8 +21,8 @@ checkListRecordsDC = project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c checkListRecordsDCFrom = 2012-01-04T01:00:00 checkListRecordsDCUntil = 2012-01-04T12:00:00 -checkListRecordsIDIOMFrom = 2012-01-04T01:00:00 -checkListRecordsIDIOMUntil = 2012-01-04T12:00:00 +checkListRecordsIDIOMFrom = 2020-11-27T15:00 +checkListRecordsIDIOMUntil = 2021-11-27T20:00 checkListRecordsDATACITEFrom = 2012-01-04T01:00:00 checkListRecordsDATACITEUntil = 2012-01-04T12:00:00