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;
*/
@Ignore
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.trep-de-dariah-eu.properties";
// **
// STATICS
// **
// Some JAXRS things.
private static String oaipmhEndpoint;
private static OAIPMHProducer JAXRSClient;
private static Client oaipmhWebClient;
// Properties
private static String expectedListSets;
private static String checkGetRecordDC;
private static String expectedGetRecordDC;
private static String checkGetRecordDATACITE;
private static String expectedGetRecordDATACITE;
private static String checkListRecordsDC;
private static String checkListRecordsDCFrom;
private static String checkListRecordsDCUntil;
private static String checkListRecordsDATACITEFrom;
private static String checkListRecordsDATACITEUntil;
private static String checkListIdentifiersSet;
private static List<String> checkGetRecordIDList = new ArrayList<String>();
// **
// PREPARATIONS
// **
/**
* @throws Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
// Load properties file.
Properties p = new Properties();
p.load(new FileInputStream(
OaiPmhTestUtilities.getResource(PROPERTIES_FILE)));
System.out.println("Properties file: " + PROPERTIES_FILE);
p.list(System.out);
// Get other needed properties.
oaipmhEndpoint = p.getProperty("oaipmhEndpoint");
expectedListSets = p.getProperty("expectedListSets");
checkGetRecordDC = p.getProperty("checkGetRecordDC");
expectedGetRecordDC = p.getProperty("expectedGetRecordDC");
checkGetRecordDATACITE = p.getProperty("checkGetRecordDATACITE");
expectedGetRecordDATACITE = p.getProperty("expectedGetRecordDATACITE");
checkListRecordsDC = p.getProperty("checkListRecordsDC");
checkListRecordsDCFrom = p.getProperty("checkListRecordsDCFrom");
checkListRecordsDCUntil = p.getProperty("checkListRecordsDCUntil");
checkListRecordsDATACITEFrom = p
.getProperty("checkListRecordsDATACITEFrom");
checkListRecordsDATACITEUntil = p
.getProperty("checkListRecordsDATACITEUntil");
checkListIdentifiersSet = p.getProperty("checkListIdentifiersSet");
checkGetRecordIDList = OaiPmhTestUtilities
.getListFromProperties((String) p.get("checkGetRecordIDList"));
// Get OAI-PMH REST endpoint and HTTP client.
System.out.println(
"Getting OAI-PMH HTTP client --> " + oaipmhEndpoint + " <--");
// Get proxy first, set policy.
JAXRSClient = JAXRSClientFactory.create(oaipmhEndpoint,
OAIPMHProducer.class);
HTTPConduit conduit = WebClient.getConfig(JAXRSClient).getHttpConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setReceiveTimeout(OaiPmhTestUtilities.OAIPMH_CLIENT_TIMEOUT);
conduit.setClient(policy);
// Create Web Client from Web Proxy.
oaipmhWebClient = WebClient.client(JAXRSClient);
}
/**
* @throws Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
/**
* @throws Exception
*/
@Before
public void setUp() throws Exception {
}
/**
* @throws Exception
*/
@After
public void tearDown() throws Exception {
}
// **
// TESTS
// **
/**
* @throws IOException
*/
@Test
public void testGetVersion() throws IOException {
String shouldStartWith = "oaipmh-core";
System.out.println(OaiPmhTestUtilities.TESTING + "#GETVERSION for '"
+ shouldStartWith + "'");
String versionString = JAXRSClient.getVersion();
if (!versionString.startsWith(shouldStartWith)) {
System.err.println(OaiPmhTestUtilities.ERROR
+ ": response should start with '" + shouldStartWith + "'");
assertTrue(false);
}
System.out.println("\tresponse: " + versionString);
System.out.println(OaiPmhTestUtilities.OK);
}
/**
* @throws IOException
*/
@Test
public void testRootWithSlash() throws IOException {
String url = "oai/";
String shouldContain = "DARIAH-DE Repository";
testRootURL(url, shouldContain);
}
/**
* @throws IOException
*/
@Test
public void testRootWithoutSlash() throws IOException {
String url = "oai";
String shouldContain = "DARIAH-DE Repository";
testRootURL(url, shouldContain);
}
/**
* @throws IOException
*/
@Test
public void testBlubbVerb() throws IOException {
String url = "verb=BLUBB";
String shouldContain = "Illegal OAI verb";
testRootURL(url, shouldContain);
}
/**
* @throws IOException
*/
@Test
public void testIdentify() throws IOException {
String verb = "Identify";
String shouldContain = "DARIAH-DE Repository";
System.out.println(OaiPmhTestUtilities.TESTING + "#IDENTIFY");
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
"verb=" + verb);
int status = response.getStatus();
String responseString = IOUtils
.readStringFromStream((InputStream) response.getEntity());
if (status != HttpStatus.SC_OK
|| !responseString.contains(shouldContain)) {
System.err.println("\tstatus: " + status);
System.err.println(OaiPmhTestUtilities.ERROR
+ ": response should contain '" + shouldContain + "'");
assertTrue(false);
}
System.out.println("\tresponse: " + responseString);
System.out.println(OaiPmhTestUtilities.OK);
}
// **
// FINALS
// **
// 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";
// **
// STATICS
// **
// Some JAXRS things.
private static String oaipmhEndpoint;
private static OAIPMHProducer JAXRSClient;
private static Client oaipmhWebClient;
// Properties
private static String expectedListSets;
private static String checkGetRecordDC;
private static String expectedGetRecordDC;
private static String checkGetRecordDATACITE;
private static String expectedGetRecordDATACITE;
private static String checkListRecordsDC;
private static String checkListRecordsDCFrom;
private static String checkListRecordsDCUntil;
private static String checkListRecordsDATACITEFrom;
private static String checkListRecordsDATACITEUntil;
private static String checkListIdentifiersSet;
private static List<String> checkGetRecordIDList = new ArrayList<String>();
// **
// PREPARATIONS
// **
/**
* @throws Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
// Load properties file.
Properties p = new Properties();
p.load(new FileInputStream(
OaiPmhTestUtilities.getResource(PROPERTIES_FILE)));
System.out.println("Properties file: " + PROPERTIES_FILE);
p.list(System.out);
// Get other needed properties.
oaipmhEndpoint = p.getProperty("oaipmhEndpoint");
expectedListSets = p.getProperty("expectedListSets");
checkGetRecordDC = p.getProperty("checkGetRecordDC");
expectedGetRecordDC = p.getProperty("expectedGetRecordDC");
checkGetRecordDATACITE = p.getProperty("checkGetRecordDATACITE");
expectedGetRecordDATACITE = p.getProperty("expectedGetRecordDATACITE");
checkListRecordsDC = p.getProperty("checkListRecordsDC");
checkListRecordsDCFrom = p.getProperty("checkListRecordsDCFrom");
checkListRecordsDCUntil = p.getProperty("checkListRecordsDCUntil");
checkListRecordsDATACITEFrom = p
.getProperty("checkListRecordsDATACITEFrom");
checkListRecordsDATACITEUntil = p
.getProperty("checkListRecordsDATACITEUntil");
checkListIdentifiersSet = p.getProperty("checkListIdentifiersSet");
checkGetRecordIDList = OaiPmhTestUtilities
.getListFromProperties((String) p.get("checkGetRecordIDList"));
// Get OAI-PMH REST endpoint and HTTP client.
System.out.println(
"Getting OAI-PMH HTTP client --> " + oaipmhEndpoint + " <--");
// Get proxy first, set policy.
JAXRSClient = JAXRSClientFactory.create(oaipmhEndpoint,
OAIPMHProducer.class);
HTTPConduit conduit = WebClient.getConfig(JAXRSClient).getHttpConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setReceiveTimeout(OaiPmhTestUtilities.OAIPMH_CLIENT_TIMEOUT);
conduit.setClient(policy);
// Create Web Client from Web Proxy.
oaipmhWebClient = WebClient.client(JAXRSClient);
}
/**
* @throws Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {}
/**
* @throws Exception
*/
@Before
public void setUp() throws Exception {}
/**
* @throws Exception
*/
@After
public void tearDown() throws Exception {}
// **
// TESTS
// **
/**
* @throws IOException
*/
@Test
public void testGetVersion() throws IOException {
String shouldStartWith = "oaipmh-core";
System.out.println(OaiPmhTestUtilities.TESTING + "#GETVERSION for '"
+ shouldStartWith + "'");
String versionString = JAXRSClient.getVersion();
if (!versionString.startsWith(shouldStartWith)) {
System.err.println(OaiPmhTestUtilities.ERROR
+ ": response should start with '" + shouldStartWith + "'");
assertTrue(false);
}
System.out.println("\tresponse: " + versionString);
System.out.println(OaiPmhTestUtilities.OK);
}
/**
* @throws IOException
*/
@Test
public void testRootWithSlash() throws IOException {
String url = "oai/";
String shouldContain = "DARIAH-DE Repository";
testRootURL(url, shouldContain);
}
/**
* @throws IOException
*/
@Test
public void testRootWithoutSlash() throws IOException {
String url = "oai";
String shouldContain = "DARIAH-DE Repository";
testRootURL(url, shouldContain);
}
/**
* @throws IOException
*/
@Test
public void testBlubbVerb() throws IOException {
String url = "verb=BLUBB";
String shouldContain = "Illegal OAI verb";
testRootURL(url, shouldContain);
}
/**
* @throws IOException
*/
@Test
public void testIdentify() throws IOException {
String verb = "Identify";
String shouldContain = "DARIAH-DE Repository";
System.out.println(OaiPmhTestUtilities.TESTING + "#IDENTIFY");
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
"verb=" + verb);
int status = response.getStatus();
String responseString = IOUtils
.readStringFromStream((InputStream) response.getEntity());
if (status != HttpStatus.SC_OK
|| !responseString.contains(shouldContain)) {
System.err.println("\tstatus: " + status);
System.err.println(OaiPmhTestUtilities.ERROR
+ ": response should contain '" + shouldContain + "'");
assertTrue(false);
}
System.out.println("\tresponse: " + responseString);
System.out.println(OaiPmhTestUtilities.OK);
}
/**
* @throws IOException
*/
@Test
public void testListSets() throws IOException {
testListSet(expectedListSets, expectedListSets);
}
/**
* @throws IOException
*/
@Test
public void testListSets() throws IOException {
testListSet(expectedListSets, expectedListSets);
}
/**
* @throws IOException
*/
@Test
public void testListRecordsDC() throws IOException {
/**
* @throws IOException
*/
@Test
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
*/
@Test
public void testListRecordsDCFromUntil() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS");
testList("ListRecords", "oai_dc", OaiPmhTestUtilities.NO_SET,
checkListRecordsDCFrom, checkListRecordsDCUntil);
}
/**
* @throws IOException
*/
@Test
public void testListRecordsDATASITE() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS");
testList("ListRecords", "oai_datacite", OaiPmhTestUtilities.NO_SET);
}
/**
* @throws IOException
*/
@Test
public void testListRecordsDATASITEFromUntil() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS");
testList("ListRecords", "oai_datacite", OaiPmhTestUtilities.NO_SET,
checkListRecordsDATACITEFrom, checkListRecordsDATACITEUntil);
}
/**
* @throws IOException
*/
@Test
@Ignore
public void testGetRecordDC() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#GETRECORD");
String identifier = "";
String shouldContain = "";
String path = "verb=GetRecord&identifier=" + identifier
+ "&metadataPrefix=oai_dc";
// FIXME Complete test!
}
/**
* @throws IOException
*/
@Test
@Ignore
public void testGetRecordDATASITE() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#GETRECORD");
String identifier = "";
String shouldContain = "";
String path = "verb=GetRecord&identifier=" + identifier
+ "&metadataPrefix=oai_datacite";
// FIXME Complete test!
}
/**
* @throws IOException
*/
@Test
public void testListIdentifiersDC() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS");
testList("ListIdentifiers", "oai_dc", OaiPmhTestUtilities.NO_SET);
}
/**
* @throws IOException
*/
@Test
public void testListIdentifiersDATASITE() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS");
testList("ListIdentifiers", "oai_datacite", OaiPmhTestUtilities.NO_SET);
}
// **
// PRIVATE METHODS
// **
/**
* TODO Generalise in OaiPmhTestUtilities!
*
* @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(Response theResponse,
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);
assertTrue(false);
}
// Count response objects at first.
int recordCount = 0;
int i = responseString.indexOf("<" + recordOrHeader + ">", 0);
while (i != -1) {
recordCount++;
i++;
i = responseString.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");
if (tokStart == -1 && tokEnd == -1) {
System.out.println("\ttoken: no token");
return "-1";
}
String restokTmp = responseString.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 (OaiPmhDariahdeOnlineTests.class) {
// Check <record> or <header> count, must be 100!
if (recordCount != 100) {
System.err.println(OaiPmhTestUtilities.ERROR + ": "
+ recordOrHeader
+ " count mismatch, must be 100 if token is provided, but is "
+ recordCount);
}
if (size <= 100) {
System.err.println(OaiPmhTestUtilities.ERROR
+ ": completeListSize count mismatch, must be > 100 if token is provided, but is "
+ size);
}
if (recordCount != 100 || size <= 100) {
assertTrue(false);
}
}
}
// If no token is provided, stop querying.
else {
// Check <record> count, must be completeListSize % 100.
if (recordCount != size % 100) {
System.err.println(OaiPmhTestUtilities.ERROR + ": "
+ recordOrHeader + " count mismatch, should be "
+ size % 100 + ", but is " + recordCount);
assertTrue(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,
OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL);
}
/**
* TODO Generalise in OaiPmhTestUtilities!
*
* @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(OaiPmhTestUtilities.VERB_LIST_RECORDS)) {
testOccurance = "record";
}
String path = "verb=" + theVerb + "&metadataPrefix="
+ theMetadataPrefix;
if (theSet != null && !theSet.isEmpty()) {
path += "&set=" + theSet;
}
if (from != null && until != null) {
path += "&from=" + from + "&until=" + until;
}
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
path);
int status = response.getStatus();
long timeRunning = System.currentTimeMillis() - startTime;
System.out.println("\ttime: "
+ OaiPmhTestUtilities.getDurationInSecs(timeRunning));
String restok = examineResumptionTokenTag(response, testOccurance, "");
result = 1;
while (status == HttpStatus.SC_OK && !restok.equals("-1")) {
path = "verb=" + theVerb + "&resumptionToken=" + restok;
response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
path);
timeRunning = System.currentTimeMillis() - startTime;
System.out.println("\ttime: "
+ OaiPmhTestUtilities.getDurationInSecs(timeRunning));
restok = examineResumptionTokenTag(response, testOccurance, restok);
result++;
}
System.out.println("\tpage amount: " + result);
System.out.println(OaiPmhTestUtilities.OK);
return result;
}
/**
* @param theSet
* @throws IOException
*/
private static void testListSet(String theSet, String theExpectedResponse)
throws IOException {
String verb = "ListSets";
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTSETS");
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
"verb=" + verb);
int status = response.getStatus();
String responseString = IOUtils
.readStringFromStream((InputStream) response.getEntity());
if (status != HttpStatus.SC_OK
|| !responseString.contains(theExpectedResponse)) {
System.err.println("\tstatus: " + status);
System.err.println(
OaiPmhTestUtilities.ERROR + ": response should contain '"
+ theExpectedResponse + "'");
System.err.println(responseString);
assertTrue(false);
}
System.out.println("\tresponse: " + responseString);
System.out.println(OaiPmhTestUtilities.OK);
}
/**
* @param theURL
* @param shouldContain
* @throws IOException
*/
private static void testRootURL(String theURL, String shouldContain)
throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#ROOTURL");
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
theURL);
int status = response.getStatus();
String responseString = IOUtils
.readStringFromStream((InputStream) response.getEntity());
if (status != HttpStatus.SC_OK
|| !responseString.contains(shouldContain)) {
System.err.println("\tstatus: " + status);
System.err.println(OaiPmhTestUtilities.ERROR
+ ": response should contain '" + shouldContain + "'");
assertTrue(false);
}
System.out.println("\tresponse: " + responseString);
System.out.println(OaiPmhTestUtilities.OK);
}
/**
* @throws IOException
*/
@Test
public void testListRecordsDCFromUntil() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS");
testList("ListRecords", "oai_dc", OaiPmhTestUtilities.NO_SET,
checkListRecordsDCFrom, checkListRecordsDCUntil);
}
/**
* @throws IOException
*/
@Test
public void testListRecordsDATASITE() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS");
testList("ListRecords", "oai_datacite", OaiPmhTestUtilities.NO_SET);
}
/**
* @throws IOException
*/
@Test
public void testListRecordsDATASITEFromUntil() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS");
testList("ListRecords", "oai_datacite", OaiPmhTestUtilities.NO_SET,
checkListRecordsDATACITEFrom, checkListRecordsDATACITEUntil);
}
/**
* @throws IOException
*/
@Test
@Ignore
public void testGetRecordDC() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#GETRECORD");
String identifier = "";
String shouldContain = "";
String path = "verb=GetRecord&identifier=" + identifier
+ "&metadataPrefix=oai_dc";
// FIXME Complete test!
}
/**
* @throws IOException
*/
@Test
@Ignore
public void testGetRecordDATASITE() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#GETRECORD");
String identifier = "";
String shouldContain = "";
String path = "verb=GetRecord&identifier=" + identifier
+ "&metadataPrefix=oai_datacite";
// FIXME Complete test!
}
/**
* @throws IOException
*/
@Test
public void testListIdentifiersDC() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS");
testList("ListIdentifiers", "oai_dc", OaiPmhTestUtilities.NO_SET);
}
/**
* @throws IOException
*/
@Test
public void testListIdentifiersDATASITE() throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS");
testList("ListIdentifiers", "oai_datacite", OaiPmhTestUtilities.NO_SET);
}
// **
// PRIVATE METHODS
// **
/**
* TODO Generalise in OaiPmhTestUtilities!
*
* @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(Response theResponse,
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);
assertTrue(false);
}
// Count response objects at first.
int recordCount = 0;
int i = responseString.indexOf("<" + recordOrHeader + ">", 0);
while (i != -1) {
recordCount++;
i++;
i = responseString.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");
if (tokStart == -1 && tokEnd == -1) {
System.out.println("\ttoken: no token");
return "-1";
}
String restokTmp = responseString.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 (OaiPmhDariahdeOnlineTests.class) {
// Check <record> or <header> count, must be 100!
if (recordCount != 100) {
System.err.println(OaiPmhTestUtilities.ERROR + ": "
+ recordOrHeader
+ " count mismatch, must be 100 if token is provided, but is "
+ recordCount);
}
if (size <= 100) {
System.err.println(OaiPmhTestUtilities.ERROR
+ ": completeListSize count mismatch, must be > 100 if token is provided, but is "
+ size);
}
if (recordCount != 100 || size <= 100) {
assertTrue(false);
}
}
}
// If no token is provided, stop querying.
else {
// Check <record> count, must be completeListSize % 100.
if (recordCount != size % 100) {
System.err.println(OaiPmhTestUtilities.ERROR + ": "
+ recordOrHeader + " count mismatch, should be "
+ size % 100 + ", but is " + recordCount);
assertTrue(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,
OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL);
}
/**
* TODO Generalise in OaiPmhTestUtilities!
*
* @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(OaiPmhTestUtilities.VERB_LIST_RECORDS)) {
testOccurance = "record";
}
String path = "verb=" + theVerb + "&metadataPrefix="
+ theMetadataPrefix;
if (theSet != null && !theSet.isEmpty()) {
path += "&set=" + theSet;
}
if (from != null && until != null) {
path += "&from=" + from + "&until=" + until;
}
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
path);
int status = response.getStatus();
long timeRunning = System.currentTimeMillis() - startTime;
System.out.println("\ttime: "
+ OaiPmhTestUtilities.getDurationInSecs(timeRunning));
String restok = examineResumptionTokenTag(response, testOccurance, "");
result = 1;
while (status == HttpStatus.SC_OK && !restok.equals("-1")) {
path = "verb=" + theVerb + "&resumptionToken=" + restok;
response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
path);
timeRunning = System.currentTimeMillis() - startTime;
System.out.println("\ttime: "
+ OaiPmhTestUtilities.getDurationInSecs(timeRunning));
restok = examineResumptionTokenTag(response, testOccurance, restok);
result++;
}
System.out.println("\tpage amount: " + result);
System.out.println(OaiPmhTestUtilities.OK);
return result;
}
/**
* @param theSet
* @throws IOException
*/
private static void testListSet(String theSet, String theExpectedResponse)
throws IOException {
String verb = "ListSets";
System.out.println(OaiPmhTestUtilities.TESTING + "#LISTSETS");
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
"verb=" + verb);
int status = response.getStatus();
String responseString = IOUtils
.readStringFromStream((InputStream) response.getEntity());
if (status != HttpStatus.SC_OK
|| !responseString.contains(theExpectedResponse)) {
System.err.println("\tstatus: " + status);
System.err.println(
OaiPmhTestUtilities.ERROR + ": response should contain '"
+ theExpectedResponse + "'");
System.err.println(responseString);
assertTrue(false);
}
System.out.println("\tresponse: " + responseString);
System.out.println(OaiPmhTestUtilities.OK);
}
/**
* @param theURL
* @param shouldContain
* @throws IOException
*/
private static void testRootURL(String theURL, String shouldContain)
throws IOException {
System.out.println(OaiPmhTestUtilities.TESTING + "#ROOTURL");
Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient,
theURL);
int status = response.getStatus();
String responseString = IOUtils
.readStringFromStream((InputStream) response.getEntity());
if (status != HttpStatus.SC_OK
|| !responseString.contains(shouldContain)) {
System.err.println("\tstatus: " + status);
System.err.println(OaiPmhTestUtilities.ERROR
+ ": response should contain '" + shouldContain + "'");
assertTrue(false);
}
System.out.println("\tresponse: " + responseString);
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