Skip to content
Snippets Groups Projects
Commit 5426a8f6 authored by Stefan E. Funk's avatar Stefan E. Funk
Browse files

Add id log

parent d99e888d
No related branches found
No related tags found
No related merge requests found
...@@ -32,558 +32,554 @@ import org.junit.Test; ...@@ -32,558 +32,554 @@ import org.junit.Test;
*/ */
@Ignore @Ignore
public class OaiPmhDariahdeOnlineTests { public class OaiPmhDariahdeOnlineTests {
// ** // **
// FINALS // FINALS
// ** // **
// private static final String PROPERTIES_FILE = // private static final String PROPERTIES_FILE =
// "oaipmh.test.repository-de-dariah-eu.properties"; // "oaipmh.test.repository-de-dariah-eu.properties";
private static final String PROPERTIES_FILE = "oaipmh.test.trep-de-dariah-eu.properties"; private static final String PROPERTIES_FILE = "oaipmh.test.trep-de-dariah-eu.properties";
// ** // **
// STATICS // STATICS
// ** // **
// Some JAXRS things. // Some JAXRS things.
private static String oaipmhEndpoint; private static String oaipmhEndpoint;
private static OAIPMHProducer JAXRSClient; private static OAIPMHProducer JAXRSClient;
private static Client oaipmhWebClient; private static Client oaipmhWebClient;
// Properties // Properties
private static String expectedListSets; private static String expectedListSets;
private static String checkGetRecordDC; private static String checkGetRecordDC;
private static String expectedGetRecordDC; private static String expectedGetRecordDC;
private static String checkGetRecordDATACITE; private static String checkGetRecordDATACITE;
private static String expectedGetRecordDATACITE; private static String expectedGetRecordDATACITE;
private static String checkListRecordsDC; private static String checkListRecordsDC;
private static String checkListRecordsDCFrom; private static String checkListRecordsDCFrom;
private static String checkListRecordsDCUntil; private static String checkListRecordsDCUntil;
private static String checkListRecordsDATACITEFrom; private static String checkListRecordsDATACITEFrom;
private static String checkListRecordsDATACITEUntil; private static String checkListRecordsDATACITEUntil;
private static String checkListIdentifiersSet; private static String checkListIdentifiersSet;
private static List<String> checkGetRecordIDList = new ArrayList<String>(); private static List<String> checkGetRecordIDList = new ArrayList<String>();
// ** // **
// PREPARATIONS // PREPARATIONS
// ** // **
/** /**
* @throws Exception * @throws Exception
*/ */
@BeforeClass @BeforeClass
public static void setUpBeforeClass() throws Exception { public static void setUpBeforeClass() throws Exception {
// Load properties file. // Load properties file.
Properties p = new Properties(); Properties p = new Properties();
p.load(new FileInputStream( p.load(new FileInputStream(
OaiPmhTestUtilities.getResource(PROPERTIES_FILE))); OaiPmhTestUtilities.getResource(PROPERTIES_FILE)));
System.out.println("Properties file: " + PROPERTIES_FILE); System.out.println("Properties file: " + PROPERTIES_FILE);
p.list(System.out); p.list(System.out);
// Get other needed properties. // Get other needed properties.
oaipmhEndpoint = p.getProperty("oaipmhEndpoint"); oaipmhEndpoint = p.getProperty("oaipmhEndpoint");
expectedListSets = p.getProperty("expectedListSets"); expectedListSets = p.getProperty("expectedListSets");
checkGetRecordDC = p.getProperty("checkGetRecordDC"); checkGetRecordDC = p.getProperty("checkGetRecordDC");
expectedGetRecordDC = p.getProperty("expectedGetRecordDC"); expectedGetRecordDC = p.getProperty("expectedGetRecordDC");
checkGetRecordDATACITE = p.getProperty("checkGetRecordDATACITE"); checkGetRecordDATACITE = p.getProperty("checkGetRecordDATACITE");
expectedGetRecordDATACITE = p.getProperty("expectedGetRecordDATACITE"); expectedGetRecordDATACITE = p.getProperty("expectedGetRecordDATACITE");
checkListRecordsDC = p.getProperty("checkListRecordsDC"); checkListRecordsDC = p.getProperty("checkListRecordsDC");
checkListRecordsDCFrom = p.getProperty("checkListRecordsDCFrom"); checkListRecordsDCFrom = p.getProperty("checkListRecordsDCFrom");
checkListRecordsDCUntil = p.getProperty("checkListRecordsDCUntil"); checkListRecordsDCUntil = p.getProperty("checkListRecordsDCUntil");
checkListRecordsDATACITEFrom = p checkListRecordsDATACITEFrom = p
.getProperty("checkListRecordsDATACITEFrom"); .getProperty("checkListRecordsDATACITEFrom");
checkListRecordsDATACITEUntil = p checkListRecordsDATACITEUntil = p
.getProperty("checkListRecordsDATACITEUntil"); .getProperty("checkListRecordsDATACITEUntil");
checkListIdentifiersSet = p.getProperty("checkListIdentifiersSet"); checkListIdentifiersSet = p.getProperty("checkListIdentifiersSet");
checkGetRecordIDList = OaiPmhTestUtilities checkGetRecordIDList = OaiPmhTestUtilities
.getListFromProperties((String) p.get("checkGetRecordIDList")); .getListFromProperties((String) p.get("checkGetRecordIDList"));
// Get OAI-PMH REST endpoint and HTTP client. // Get OAI-PMH REST endpoint and HTTP client.
System.out.println( System.out.println(
"Getting OAI-PMH HTTP client --> " + oaipmhEndpoint + " <--"); "Getting OAI-PMH HTTP client --> " + oaipmhEndpoint + " <--");
// Get proxy first, set policy. // Get proxy first, set policy.
JAXRSClient = JAXRSClientFactory.create(oaipmhEndpoint, JAXRSClient = JAXRSClientFactory.create(oaipmhEndpoint,
OAIPMHProducer.class); OAIPMHProducer.class);
HTTPConduit conduit = WebClient.getConfig(JAXRSClient).getHttpConduit(); HTTPConduit conduit = WebClient.getConfig(JAXRSClient).getHttpConduit();
HTTPClientPolicy policy = new HTTPClientPolicy(); HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setReceiveTimeout(OaiPmhTestUtilities.OAIPMH_CLIENT_TIMEOUT); policy.setReceiveTimeout(OaiPmhTestUtilities.OAIPMH_CLIENT_TIMEOUT);
conduit.setClient(policy); conduit.setClient(policy);
// Create Web Client from Web Proxy. // Create Web Client from Web Proxy.
oaipmhWebClient = WebClient.client(JAXRSClient); oaipmhWebClient = WebClient.client(JAXRSClient);
} }
/** /**
* @throws Exception * @throws Exception
*/ */
@AfterClass @AfterClass
public static void tearDownAfterClass() throws Exception { public static void tearDownAfterClass() throws Exception {}
}
/**
/** * @throws Exception
* @throws Exception */
*/ @Before
@Before public void setUp() throws Exception {}
public void setUp() throws Exception {
} /**
* @throws Exception
/** */
* @throws Exception @After
*/ public void tearDown() throws Exception {}
@After
public void tearDown() throws Exception { // **
} // TESTS
// **
// **
// TESTS /**
// ** * @throws IOException
*/
/** @Test
* @throws IOException public void testGetVersion() throws IOException {
*/
@Test String shouldStartWith = "oaipmh-core";
public void testGetVersion() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#GETVERSION for '"
String shouldStartWith = "oaipmh-core"; + shouldStartWith + "'");
System.out.println(OaiPmhTestUtilities.TESTING + "#GETVERSION for '" String versionString = JAXRSClient.getVersion();
+ shouldStartWith + "'");
if (!versionString.startsWith(shouldStartWith)) {
String versionString = JAXRSClient.getVersion(); System.err.println(OaiPmhTestUtilities.ERROR
+ ": response should start with '" + shouldStartWith + "'");
if (!versionString.startsWith(shouldStartWith)) { assertTrue(false);
System.err.println(OaiPmhTestUtilities.ERROR }
+ ": response should start with '" + shouldStartWith + "'");
assertTrue(false); System.out.println("\tresponse: " + versionString);
} System.out.println(OaiPmhTestUtilities.OK);
}
System.out.println("\tresponse: " + versionString);
System.out.println(OaiPmhTestUtilities.OK); /**
} * @throws IOException
*/
/** @Test
* @throws IOException public void testRootWithSlash() throws IOException {
*/
@Test String url = "oai/";
public void testRootWithSlash() throws IOException { String shouldContain = "DARIAH-DE Repository";
String url = "oai/"; testRootURL(url, shouldContain);
String shouldContain = "DARIAH-DE Repository"; }
testRootURL(url, shouldContain); /**
} * @throws IOException
*/
/** @Test
* @throws IOException public void testRootWithoutSlash() throws IOException {
*/
@Test String url = "oai";
public void testRootWithoutSlash() throws IOException { String shouldContain = "DARIAH-DE Repository";
String url = "oai"; testRootURL(url, shouldContain);
String shouldContain = "DARIAH-DE Repository"; }
testRootURL(url, shouldContain); /**
} * @throws IOException
*/
/** @Test
* @throws IOException public void testBlubbVerb() throws IOException {
*/
@Test String url = "verb=BLUBB";
public void testBlubbVerb() throws IOException { String shouldContain = "Illegal OAI verb";
String url = "verb=BLUBB"; testRootURL(url, shouldContain);
String shouldContain = "Illegal OAI verb"; }
testRootURL(url, shouldContain); /**
} * @throws IOException
*/
/** @Test
* @throws IOException public void testIdentify() throws IOException {
*/
@Test String verb = "Identify";
public void testIdentify() throws IOException { String shouldContain = "DARIAH-DE Repository";
String verb = "Identify"; System.out.println(OaiPmhTestUtilities.TESTING + "#IDENTIFY");
String shouldContain = "DARIAH-DE Repository";
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
System.out.println(OaiPmhTestUtilities.TESTING + "#IDENTIFY"); "verb=" + verb);
int status = response.getStatus();
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
"verb=" + verb); String responseString = IOUtils
int status = response.getStatus(); .readStringFromStream((InputStream) response.getEntity());
String responseString = IOUtils if (status != HttpStatus.SC_OK
.readStringFromStream((InputStream) response.getEntity()); || !responseString.contains(shouldContain)) {
System.err.println("\tstatus: " + status);
if (status != HttpStatus.SC_OK System.err.println(OaiPmhTestUtilities.ERROR
|| !responseString.contains(shouldContain)) { + ": response should contain '" + shouldContain + "'");
System.err.println("\tstatus: " + status); assertTrue(false);
System.err.println(OaiPmhTestUtilities.ERROR }
+ ": response should contain '" + shouldContain + "'");
assertTrue(false); System.out.println("\tresponse: " + responseString);
} System.out.println(OaiPmhTestUtilities.OK);
}
System.out.println("\tresponse: " + responseString);
System.out.println(OaiPmhTestUtilities.OK);
}
/** /**
* @throws IOException * @throws IOException
*/ */
@Test @Test
public void testListSets() throws IOException { public void testListSets() throws IOException {
testListSet(expectedListSets, expectedListSets); testListSet(expectedListSets, expectedListSets);
} }
/** /**
* @throws IOException * @throws IOException
*/ */
@Test @Test
public void testListRecordsDC() throws IOException { public void testListRecordsDC() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS"); System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS");
testList("ListRecords", "oai_dc", OaiPmhTestUtilities.NO_SET); testList("ListRecords", "oai_dc", OaiPmhTestUtilities.NO_SET);
} }
/** /**
* @throws IOException * @throws IOException
*/ */
@Test @Test
public void testListRecordsDCFromUntil() throws IOException { public void testListRecordsDCFromUntil() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS"); System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS");
testList("ListRecords", "oai_dc", OaiPmhTestUtilities.NO_SET, testList("ListRecords", "oai_dc", OaiPmhTestUtilities.NO_SET,
checkListRecordsDCFrom, checkListRecordsDCUntil); checkListRecordsDCFrom, checkListRecordsDCUntil);
} }
/** /**
* @throws IOException * @throws IOException
*/ */
@Test @Test
public void testListRecordsDATASITE() throws IOException { public void testListRecordsDATASITE() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS"); System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS");
testList("ListRecords", "oai_datacite", OaiPmhTestUtilities.NO_SET); testList("ListRecords", "oai_datacite", OaiPmhTestUtilities.NO_SET);
} }
/** /**
* @throws IOException * @throws IOException
*/ */
@Test @Test
public void testListRecordsDATASITEFromUntil() throws IOException { public void testListRecordsDATASITEFromUntil() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS"); System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS");
testList("ListRecords", "oai_datacite", OaiPmhTestUtilities.NO_SET, testList("ListRecords", "oai_datacite", OaiPmhTestUtilities.NO_SET,
checkListRecordsDATACITEFrom, checkListRecordsDATACITEUntil); checkListRecordsDATACITEFrom, checkListRecordsDATACITEUntil);
} }
/** /**
* @throws IOException * @throws IOException
*/ */
@Test @Test
@Ignore @Ignore
public void testGetRecordDC() throws IOException { public void testGetRecordDC() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#GETRECORD"); System.out.println(OaiPmhTestUtilities.TESTING + "#GETRECORD");
String identifier = ""; String identifier = "";
String shouldContain = ""; String shouldContain = "";
String path = "verb=GetRecord&identifier=" + identifier String path = "verb=GetRecord&identifier=" + identifier
+ "&metadataPrefix=oai_dc"; + "&metadataPrefix=oai_dc";
// FIXME Complete test! // FIXME Complete test!
} }
/** /**
* @throws IOException * @throws IOException
*/ */
@Test @Test
@Ignore @Ignore
public void testGetRecordDATASITE() throws IOException { public void testGetRecordDATASITE() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#GETRECORD"); System.out.println(OaiPmhTestUtilities.TESTING + "#GETRECORD");
String identifier = ""; String identifier = "";
String shouldContain = ""; String shouldContain = "";
String path = "verb=GetRecord&identifier=" + identifier String path = "verb=GetRecord&identifier=" + identifier
+ "&metadataPrefix=oai_datacite"; + "&metadataPrefix=oai_datacite";
// FIXME Complete test! // FIXME Complete test!
} }
/** /**
* @throws IOException * @throws IOException
*/ */
@Test @Test
public void testListIdentifiersDC() throws IOException { public void testListIdentifiersDC() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS"); System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS");
testList("ListIdentifiers", "oai_dc", OaiPmhTestUtilities.NO_SET); testList("ListIdentifiers", "oai_dc", OaiPmhTestUtilities.NO_SET);
} }
/** /**
* @throws IOException * @throws IOException
*/ */
@Test @Test
public void testListIdentifiersDATASITE() throws IOException { public void testListIdentifiersDATASITE() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS"); System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS");
testList("ListIdentifiers", "oai_datacite", OaiPmhTestUtilities.NO_SET); testList("ListIdentifiers", "oai_datacite", OaiPmhTestUtilities.NO_SET);
} }
// ** // **
// PRIVATE METHODS // PRIVATE METHODS
// ** // **
/** /**
* TODO Generalise in OaiPmhTestUtilities! * TODO Generalise in OaiPmhTestUtilities!
* *
* @param theResponse * @param theResponse
* @return Resumption token string, if existing, -1 if either no * @return Resumption token string, if existing, -1 if either no <resumptionToken> tag is
* <resumptionToken> tag is existing, tag is existing and has no * existing, tag is existing and has no token value.
* token value. * @throws IOException
* @throws IOException */
*/ private static String examineResumptionTokenTag(Response theResponse,
private static String examineResumptionTokenTag(Response theResponse, String recordOrHeader, String oldtok) throws IOException {
String recordOrHeader, String oldtok) throws IOException {
String responseString = IOUtils
String responseString = IOUtils .readStringFromStream((InputStream) theResponse.getEntity());
.readStringFromStream((InputStream) theResponse.getEntity());
// Test for OAIPMH errors.
// Test for OAIPMH errors. if (responseString.contains("<error code=\"badArgument\">")) {
if (responseString.contains("<error code=\"badArgument\">")) { System.err.println(OaiPmhTestUtilities.ERROR
System.err.println(OaiPmhTestUtilities.ERROR + " IN OAIPMH RESPONSE: " + responseString);
+ " IN OAIPMH RESPONSE: " + responseString); assertTrue(false);
assertTrue(false); }
}
// Count response objects at first.
// Count response objects at first. int recordCount = 0;
int recordCount = 0; int i = responseString.indexOf("<" + recordOrHeader + ">", 0);
int i = responseString.indexOf("<" + recordOrHeader + ">", 0); while (i != -1) {
while (i != -1) { recordCount++;
recordCount++; i++;
i++; i = responseString.indexOf("<" + recordOrHeader + ">", i);
i = responseString.indexOf("<" + recordOrHeader + ">", i); }
}
System.out.println("\t" + recordOrHeader + "s: " + recordCount);
System.out.println("\t" + recordOrHeader + "s: " + recordCount);
// Check if token tag is existing.
// Check if token tag is existing. int tokStart = responseString.indexOf("<resumptionToken");
int tokStart = responseString.indexOf("<resumptionToken"); int tokEnd = responseString.indexOf("</resumptionToken");
int tokEnd = responseString.indexOf("</resumptionToken");
if (tokStart == -1 && tokEnd == -1) {
if (tokStart == -1 && tokEnd == -1) { System.out.println("\ttoken: no token");
System.out.println("\ttoken: no token");
return "-1";
return "-1"; }
}
String restokTmp = responseString.substring(tokStart, tokEnd);
String restokTmp = responseString.substring(tokStart, tokEnd); // Get token tag.
// Get token tag. String toktag = restokTmp.substring(0, restokTmp.indexOf(">") + 1)
String toktag = restokTmp.substring(0, restokTmp.indexOf(">") + 1) .trim();
.trim(); System.out.println("\ttokentag: " + toktag);
System.out.println("\ttokentag: " + toktag);
// Get token.
// Get token. String restok = restokTmp.substring(restokTmp.indexOf(">") + 1).trim();
String restok = restokTmp.substring(restokTmp.indexOf(">") + 1).trim(); System.out.println("\ttoken: " + restok);
System.out.println("\ttoken: " + restok);
// Check if old and new token are equal or not.
// Check if old and new token are equal or not. boolean tokchanged = !oldtok.equals(restok);
boolean tokchanged = !oldtok.equals(restok); System.out.println("\ttokchngd: " + tokchanged);
System.out.println("\ttokchngd: " + tokchanged);
// Get completeListSize and cursor.
// Get completeListSize and cursor. String sizeStr = toktag
String sizeStr = toktag .substring(toktag.indexOf("completeListSize=\"") + 18);
.substring(toktag.indexOf("completeListSize=\"") + 18); int size = Integer
int size = Integer .parseInt(sizeStr.substring(0, sizeStr.indexOf("\"")));
.parseInt(sizeStr.substring(0, sizeStr.indexOf("\""))); String cursorStr = toktag.substring(toktag.indexOf("cursor=\"") + 8);
String cursorStr = toktag.substring(toktag.indexOf("cursor=\"") + 8); int cursor = Integer
int cursor = Integer .parseInt(cursorStr.substring(0, cursorStr.indexOf("\"")));
.parseInt(cursorStr.substring(0, cursorStr.indexOf("\""))); System.out.println("\tsize: " + size + " / " + cursor);
System.out.println("\tsize: " + size + " / " + cursor);
// If token is provided, and we have less than 100 elements: mekkern!
// If token is provided, and we have less than 100 elements: mekkern! if (!restok.isEmpty()) {
if (!restok.isEmpty()) { synchronized (OaiPmhDariahdeOnlineTests.class) {
synchronized (OaiPmhDariahdeOnlineTests.class) { // Check <record> or <header> count, must be 100!
// Check <record> or <header> count, must be 100! if (recordCount != 100) {
if (recordCount != 100) { System.err.println(OaiPmhTestUtilities.ERROR + ": "
System.err.println(OaiPmhTestUtilities.ERROR + ": " + recordOrHeader
+ recordOrHeader + " count mismatch, must be 100 if token is provided, but is "
+ " count mismatch, must be 100 if token is provided, but is " + recordCount);
+ recordCount); }
} if (size <= 100) {
if (size <= 100) { System.err.println(OaiPmhTestUtilities.ERROR
System.err.println(OaiPmhTestUtilities.ERROR + ": completeListSize count mismatch, must be > 100 if token is provided, but is "
+ ": completeListSize count mismatch, must be > 100 if token is provided, but is " + size);
+ size); }
} if (recordCount != 100 || size <= 100) {
if (recordCount != 100 || size <= 100) { assertTrue(false);
assertTrue(false); }
} }
} }
}
// If no token is provided, stop querying.
// If no token is provided, stop querying. else {
else { // Check <record> count, must be completeListSize % 100.
// Check <record> count, must be completeListSize % 100. if (recordCount != size % 100) {
if (recordCount != size % 100) { System.err.println(OaiPmhTestUtilities.ERROR + ": "
System.err.println(OaiPmhTestUtilities.ERROR + ": " + recordOrHeader + " count mismatch, should be "
+ recordOrHeader + " count mismatch, should be " + size % 100 + ", but is " + recordCount);
+ size % 100 + ", but is " + recordCount); assertTrue(false);
assertTrue(false); }
}
// No resumption token available in response.
// No resumption token available in response. return "-1";
return "-1"; }
}
return restok;
return restok; }
}
/**
/** * @param theVerb
* @param theVerb * @param theMetadataPrefix
* @param theMetadataPrefix * @param theSet
* @param theSet * @return
* @return * @throws IOException
* @throws IOException */
*/ private static int testList(String theVerb, String theMetadataPrefix,
private static int testList(String theVerb, String theMetadataPrefix, String theSet) throws IOException {
String theSet) throws IOException { return testList(theVerb, theMetadataPrefix, theSet,
return testList(theVerb, theMetadataPrefix, theSet, OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL);
OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL); }
}
/**
/** * TODO Generalise in OaiPmhTestUtilities!
* TODO Generalise in OaiPmhTestUtilities! *
* * @param theVerb
* @param theVerb * @param theMetadataPrefix
* @param theMetadataPrefix * @param theSet
* @param theSet * @param from
* @param from * @param until
* @param until * @return How many pages were delivered
* @return How many pages were delivered * @throws IOException
* @throws IOException */
*/ private static int testList(String theVerb, String theMetadataPrefix,
private static int testList(String theVerb, String theMetadataPrefix, String theSet, String from, String until) throws IOException {
String theSet, String from, String until) throws IOException {
int result;
int result;
long startTime = System.currentTimeMillis();
long startTime = System.currentTimeMillis();
String testOccurance = "header";
String testOccurance = "header"; if (theVerb.equals(OaiPmhTestUtilities.VERB_LIST_RECORDS)) {
if (theVerb.equals(OaiPmhTestUtilities.VERB_LIST_RECORDS)) { testOccurance = "record";
testOccurance = "record"; }
}
String path = "verb=" + theVerb + "&metadataPrefix="
String path = "verb=" + theVerb + "&metadataPrefix=" + theMetadataPrefix;
+ theMetadataPrefix;
if (theSet != null && !theSet.isEmpty()) {
if (theSet != null && !theSet.isEmpty()) { path += "&set=" + theSet;
path += "&set=" + theSet; }
}
if (from != null && until != null) {
if (from != null && until != null) { path += "&from=" + from + "&until=" + until;
path += "&from=" + from + "&until=" + until; }
}
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path);
path); int status = response.getStatus();
int status = response.getStatus();
long timeRunning = System.currentTimeMillis() - startTime;
long timeRunning = System.currentTimeMillis() - startTime; System.out.println("\ttime: "
System.out.println("\ttime: " + OaiPmhTestUtilities.getDurationInSecs(timeRunning));
+ OaiPmhTestUtilities.getDurationInSecs(timeRunning));
String restok = examineResumptionTokenTag(response, testOccurance, "");
String restok = examineResumptionTokenTag(response, testOccurance, "");
result = 1;
result = 1; while (status == HttpStatus.SC_OK && !restok.equals("-1")) {
while (status == HttpStatus.SC_OK && !restok.equals("-1")) { path = "verb=" + theVerb + "&resumptionToken=" + restok;
path = "verb=" + theVerb + "&resumptionToken=" + restok; response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path);
path); timeRunning = System.currentTimeMillis() - startTime;
timeRunning = System.currentTimeMillis() - startTime; System.out.println("\ttime: "
System.out.println("\ttime: " + OaiPmhTestUtilities.getDurationInSecs(timeRunning));
+ OaiPmhTestUtilities.getDurationInSecs(timeRunning)); restok = examineResumptionTokenTag(response, testOccurance, restok);
restok = examineResumptionTokenTag(response, testOccurance, restok); result++;
result++; }
}
System.out.println("\tpage amount: " + result);
System.out.println("\tpage amount: " + result); System.out.println(OaiPmhTestUtilities.OK);
System.out.println(OaiPmhTestUtilities.OK);
return result;
return result; }
}
/**
/** * @param theSet
* @param theSet * @throws IOException
* @throws IOException */
*/ private static void testListSet(String theSet, String theExpectedResponse)
private static void testListSet(String theSet, String theExpectedResponse) throws IOException {
throws IOException {
String verb = "ListSets";
String verb = "ListSets";
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTSETS");
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTSETS");
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, "verb=" + verb);
"verb=" + verb); int status = response.getStatus();
int status = response.getStatus();
String responseString = IOUtils
String responseString = IOUtils .readStringFromStream((InputStream) response.getEntity());
.readStringFromStream((InputStream) response.getEntity());
if (status != HttpStatus.SC_OK
if (status != HttpStatus.SC_OK || !responseString.contains(theExpectedResponse)) {
|| !responseString.contains(theExpectedResponse)) { System.err.println("\tstatus: " + status);
System.err.println("\tstatus: " + status); System.err.println(
System.err.println( OaiPmhTestUtilities.ERROR + ": response should contain '"
OaiPmhTestUtilities.ERROR + ": response should contain '" + theExpectedResponse + "'");
+ theExpectedResponse + "'"); System.err.println(responseString);
System.err.println(responseString); assertTrue(false);
assertTrue(false); }
}
System.out.println("\tresponse: " + responseString);
System.out.println("\tresponse: " + responseString); System.out.println(OaiPmhTestUtilities.OK);
System.out.println(OaiPmhTestUtilities.OK); }
}
/**
/** * @param theURL
* @param theURL * @param shouldContain
* @param shouldContain * @throws IOException
* @throws IOException */
*/ private static void testRootURL(String theURL, String shouldContain)
private static void testRootURL(String theURL, String shouldContain) throws IOException {
throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#ROOTURL");
System.out.println(OaiPmhTestUtilities.TESTING + "#ROOTURL");
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, theURL);
theURL); int status = response.getStatus();
int status = response.getStatus();
String responseString = IOUtils
String responseString = IOUtils .readStringFromStream((InputStream) response.getEntity());
.readStringFromStream((InputStream) response.getEntity());
if (status != HttpStatus.SC_OK
if (status != HttpStatus.SC_OK || !responseString.contains(shouldContain)) {
|| !responseString.contains(shouldContain)) { System.err.println("\tstatus: " + status);
System.err.println("\tstatus: " + status); System.err.println(OaiPmhTestUtilities.ERROR
System.err.println(OaiPmhTestUtilities.ERROR + ": response should contain '" + shouldContain + "'");
+ ": response should contain '" + shouldContain + "'"); assertTrue(false);
assertTrue(false); }
}
System.out.println("\tresponse: " + responseString);
System.out.println("\tresponse: " + responseString); System.out.println(OaiPmhTestUtilities.OK);
System.out.println(OaiPmhTestUtilities.OK); }
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment