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

New online tests added.

parent 651bb38d
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,6 @@ import info.textgrid.utils.httpclient.TGHttpClient; ...@@ -5,7 +5,6 @@ import info.textgrid.utils.httpclient.TGHttpClient;
import info.textgrid.utils.httpclient.TGHttpResponse; import info.textgrid.utils.httpclient.TGHttpResponse;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.helpers.IOUtils;
...@@ -27,22 +26,17 @@ import org.junit.Test; ...@@ -27,22 +26,17 @@ import org.junit.Test;
public class OaiPmhOnlineTests { public class OaiPmhOnlineTests {
// Time to wait between the single queries using resumption tokens in
// milliseconds.
private static final Long TIME = 100l;
// The OAIPMH host to be tested. // The OAIPMH host to be tested.
private static String host = "http://textgrid-esx1.gwdg.de/1.0/tgoaipmh/"; private static String host = "http://textgrid-esx1.gwdg.de/1.0/tgoaipmh/";
private static String verb = "ListRecords"; // Some output finals.
private static String mdprefix = "oai_dc"; private static final String ERROR = ">>> ERROR";
private static final String OK = ">>> OKIDO";
private static final String TESTING = "\n>>> TESTING ";
// The project ID of the project to be tested. // Time to wait between the single queries using resumption tokens in
// Digitale Bibliothek (esx1 and esx2) // milliseconds.
// private static String set = private static final Long TIME = 100l;
// "project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c";
// fu's shakespeare (esx1)
private static String set = "project:TGPR-962c949c-56a3-7134-9265-582f29a0992d";
// ** // **
// PREPARATIONS // PREPARATIONS
...@@ -82,10 +76,6 @@ public class OaiPmhOnlineTests { ...@@ -82,10 +76,6 @@ public class OaiPmhOnlineTests {
// ** // **
/** /**
* <p>
* Runs a getVersion test.
* </p>
*
* @throws IOException * @throws IOException
*/ */
@Test @Test
...@@ -93,7 +83,7 @@ public class OaiPmhOnlineTests { ...@@ -93,7 +83,7 @@ public class OaiPmhOnlineTests {
String shouldStartWith = "oaipmh-core"; String shouldStartWith = "oaipmh-core";
System.out.println("...testing #GETVERSION for '" + shouldStartWith System.out.println(TESTING + "#GETVERSION for '" + shouldStartWith
+ "'"); + "'");
TGHttpResponse httpResponse = getHttpResponse(host + "oai/version"); TGHttpResponse httpResponse = getHttpResponse(host + "oai/version");
...@@ -103,50 +93,173 @@ public class OaiPmhOnlineTests { ...@@ -103,50 +93,173 @@ public class OaiPmhOnlineTests {
.getInputstream()); .getInputstream());
if (status != HttpStatus.SC_OK || !response.startsWith(shouldStartWith)) { if (status != HttpStatus.SC_OK || !response.startsWith(shouldStartWith)) {
System.out.println("\tstatus: " + status); System.err.println("\tstatus: " + status);
System.out.println("\tresponse should start with '" System.err.println(ERROR + ": response should start with '"
+ shouldStartWith + "'"); + shouldStartWith + "'");
assertTrue(false); assertTrue(false);
} }
System.out.println("\tresponse: " + response); System.out.println("\tresponse: " + response);
System.out.println(OK);
} }
/** /**
* @param args * @throws IOException
* @throws InterruptedException
*/ */
@Test @Test
@Ignore public void testRootUrl() throws IOException {
public void testItest() throws InterruptedException {
try { String shouldContain = "www.textgridrep.de";
String url = host + "/oai?verb=" + verb + "&metadataPrefix="
+ mdprefix + "&set=" + set;
TGHttpResponse httpResponse = getHttpResponse(url); System.out.println(TESTING + "#ROOTURL");
int status = httpResponse.getStatusCode();
System.out.println(" ## status: " + status + " " TGHttpResponse httpResponse = getHttpResponse(host + "oai");
+ httpResponse.getReasonPhrase()); int status = httpResponse.getStatusCode();
String restok = showOAI(httpResponse, "oldtok"); String response = IOUtils.readStringFromStream(httpResponse
.getInputstream());
while (status == HttpStatus.SC_OK && !restok.equals("-1")) { if (status != HttpStatus.SC_OK || !response.contains(shouldContain)) {
url = host + "/oai?verb=" + verb + "&resumptionToken=" + restok; System.err.println("\tstatus: " + status);
httpResponse = getHttpResponse(url); System.err.println(ERROR + ": response should contain '"
restok = showOAI(httpResponse, restok); + shouldContain + "'");
} assertTrue(false);
}
} catch (MalformedURLException e) { System.out.println("\tresponse: " + response);
// TODO Auto-generated catch block System.out.println(OK);
e.printStackTrace(); }
} catch (IOException e) {
// TODO Auto-generated catch block /**
e.printStackTrace(); * @throws IOException
*/
@Test
public void testIdentify() throws IOException {
String verb = "Identify";
String shouldContain = "www.textgridrep.de";
System.out.println(TESTING + "#IDENTIFY");
TGHttpResponse httpResponse = getHttpResponse(host + "oai?verb=" + verb);
int status = httpResponse.getStatusCode();
String response = IOUtils.readStringFromStream(httpResponse
.getInputstream());
if (status != HttpStatus.SC_OK || !response.contains(shouldContain)) {
System.err.println("\tstatus: " + status);
System.err.println(ERROR + ": response should contain '"
+ shouldContain + "'");
assertTrue(false);
}
System.out.println("\tresponse: " + response);
System.out.println(OK);
}
/**
* @throws IOException
*/
@Test
public void testListSets() throws IOException {
String verb = "ListSets";
String shouldContain = "<setSpec>project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c</setSpec>";
System.out.println(TESTING + "#LISTSETS");
TGHttpResponse httpResponse = getHttpResponse(host + "oai?verb=" + verb);
int status = httpResponse.getStatusCode();
String response = IOUtils.readStringFromStream(httpResponse
.getInputstream());
if (status != HttpStatus.SC_OK || !response.contains(shouldContain)) {
System.err.println("\tstatus: " + status);
System.err.println(ERROR + ": response should contain '"
+ shouldContain + "'");
assertTrue(false);
}
System.out.println("\tresponse: " + response);
System.out.println(OK);
}
/**
* @throws IOException
*/
@Test
public void testListRecords() throws IOException {
String verb = "ListRecords";
String prefix = "oai_dc";
String set = "project:TGPR-962c949c-56a3-7134-9265-582f29a0992d";
System.out.println(TESTING + "#LISTRECORDS");
String url = host + "oai?verb=" + verb + "&metadataPrefix=" + prefix
+ "&set=" + set;
TGHttpResponse httpResponse = getHttpResponse(url);
int status = httpResponse.getStatusCode();
String restok = showOAI(httpResponse, "oldtok");
while (status == HttpStatus.SC_OK && !restok.equals("-1")) {
url = host + "/oai?verb=" + verb + "&resumptionToken=" + restok;
httpResponse = getHttpResponse(url);
restok = showOAI(httpResponse, restok);
}
if (status != HttpStatus.SC_OK) {
System.err.println("\tstatus: " + status);
System.err.println(ERROR);
assertTrue(false);
}
System.out.println(OK);
}
/**
* @throws IOException
*/
@Test
public void testListIdentifier() throws IOException {
String verb = "ListIdentifiers";
String prefix = "oai_dc";
String set = "project:TGPR-962c949c-56a3-7134-9265-582f29a0992d";
System.out.println(TESTING + "#LISTIDENTIFIER");
String url = host + "oai?verb=" + verb + "&metadataPrefix=" + prefix
+ "&set=" + set;
TGHttpResponse httpResponse = getHttpResponse(url);
int status = httpResponse.getStatusCode();
String restok = showOAI(httpResponse, "oldtok");
while (status == HttpStatus.SC_OK && !restok.equals("-1")) {
url = host + "/oai?verb=" + verb + "&resumptionToken=" + restok;
httpResponse = getHttpResponse(url);
restok = showOAI(httpResponse, restok);
}
if (status != HttpStatus.SC_OK) {
System.err.println("\tstatus: " + status);
System.err.println(ERROR + ": " + restok);
assertTrue(false);
} }
System.out.println(OK);
} }
// **
// PRIVATE METHODS
// **
/** /**
* @param theUrl * @param theUrl
* @return * @return
...@@ -162,7 +275,7 @@ public class OaiPmhOnlineTests { ...@@ -162,7 +275,7 @@ public class OaiPmhOnlineTests {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("\trequest: " + theUrl); System.out.println("\trequest: " + theUrl);
URL url = new URL(theUrl); URL url = new URL(theUrl);
String host = url.getProtocol() + "://" + url.getHost(); String host = url.getProtocol() + "://" + url.getHost();
...@@ -181,20 +294,20 @@ public class OaiPmhOnlineTests { ...@@ -181,20 +294,20 @@ public class OaiPmhOnlineTests {
String res = IOUtils.readStringFromStream(theResponse.getInputstream()); String res = IOUtils.readStringFromStream(theResponse.getInputstream());
// System.out.println(" ## response: " + res); // System.out.println("\tresponse: " + res);
// String tguri = res.substring(res.indexOf("<ns2:relation>textgrid:", // String tguri = res.substring(res.indexOf("<ns2:relation>textgrid:",
// res.indexOf("</ns2:relation>"))); // res.indexOf("</ns2:relation>")));
// System.out.println(" ## tguri: " + tguri); // System.out.println("\ttguri: " + tguri);
try { try {
String restokTmp = res.substring(res.indexOf("<resumptionToken"), String restokTmp = res.substring(res.indexOf("<resumptionToken"),
res.indexOf("</resumptionToken>")); res.indexOf("</resumptionToken>"));
String restok = restokTmp.substring(restokTmp.indexOf(">") + 1); String restok = restokTmp.substring(restokTmp.indexOf(">") + 1);
System.out.println(" ## token: " + restok); System.out.println("\ttoken: " + restok);
String toktag = restokTmp.substring(0, restokTmp.indexOf(">") + 1); String toktag = restokTmp.substring(0, restokTmp.indexOf(">") + 1);
System.out.println(" ## tokentag: " + toktag); System.out.println("\ttokentag: " + toktag);
String sizeStr = toktag.substring(toktag String sizeStr = toktag.substring(toktag
.indexOf("completeListSize=\"") + 18); .indexOf("completeListSize=\"") + 18);
...@@ -204,7 +317,7 @@ public class OaiPmhOnlineTests { ...@@ -204,7 +317,7 @@ public class OaiPmhOnlineTests {
.substring(toktag.indexOf("cursor=\"") + 8); .substring(toktag.indexOf("cursor=\"") + 8);
int cursor = Integer.parseInt(cursorStr.substring(0, int cursor = Integer.parseInt(cursorStr.substring(0,
cursorStr.indexOf("\""))); cursorStr.indexOf("\"")));
System.out.println(" ## size: " + size + " / " + cursor); System.out.println("\tsize: " + size + " / " + cursor);
// if (restok.equals(theOldtok)) { // if (restok.equals(theOldtok)) {
// System.out.println(" ## ERROR ## oldtok == restok: "); // System.out.println(" ## ERROR ## oldtok == restok: ");
...@@ -212,31 +325,20 @@ public class OaiPmhOnlineTests { ...@@ -212,31 +325,20 @@ public class OaiPmhOnlineTests {
// System.out.println(" ## oldtok: " + theOldtok); // System.out.println(" ## oldtok: " + theOldtok);
// } // }
System.out System.out.println("\t------------");
.println("--------------------------------------------------------------------------------");
if (cursor >= size) {
System.out.println("cursor >= size"); if (cursor >= size && !restok.isEmpty()) {
System.err.println(ERROR
if (restok.isEmpty()) { + ": size exeeded and token still contained");
System.out.println("complete"); assertTrue(false);
} else {
System.out
.println("error: token existing and size exceeded");
}
return "-1";
} }
return restok; return restok;
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
System.out.println("error: " + e.getMessage());
e.printStackTrace(); e.printStackTrace();
return "-1"; return e.getMessage();
} }
} }
......
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