Updated tests by using mockserver for requests with explain operation.
Change-Id: I3fb707e3319b94756a8723d4335c74e5ff0570ee
diff --git a/pom.xml b/pom.xml
index eb5d6f1..cb00dee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -95,6 +95,14 @@
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
+
+ <!-- Mockserver -->
+ <dependency>
+ <groupId>org.mock-server</groupId>
+ <artifactId>mockserver-netty</artifactId>
+ <version>5.11.2</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<repositories>
diff --git a/src/main/java/de/ids_mannheim/korap/sru/KorapEndpointDescription.java b/src/main/java/de/ids_mannheim/korap/sru/KorapEndpointDescription.java
index 22a133f..f31718b 100644
--- a/src/main/java/de/ids_mannheim/korap/sru/KorapEndpointDescription.java
+++ b/src/main/java/de/ids_mannheim/korap/sru/KorapEndpointDescription.java
@@ -133,7 +133,7 @@
description.put("de", r.getDescription());
ResourceInfo ri = new ResourceInfo(r.getResourceId(), r.getTitles(),
- description, KorapSRU.KORAP_WEB_URL,
+ description, KorapSRU.korapWebUri,
Arrays.asList(r.getLanguages()), dataviews,
this.getSupportedLayers(), null);
resourceList.add(ri);
diff --git a/src/main/java/de/ids_mannheim/korap/sru/KorapSRU.java b/src/main/java/de/ids_mannheim/korap/sru/KorapSRU.java
index 082ac5e..af6db64 100644
--- a/src/main/java/de/ids_mannheim/korap/sru/KorapSRU.java
+++ b/src/main/java/de/ids_mannheim/korap/sru/KorapSRU.java
@@ -33,8 +33,8 @@
public class KorapSRU extends SimpleEndpointSearchEngineBase {
public static final String CLARIN_FCS_RECORD_SCHEMA = "http://clarin.eu/fcs/resource";
- public static final String KORAP_WEB_URL = "https://korap.ids-mannheim.de/";
+ public static String korapWebUri;
public static String redirectBaseURI;
public static KorapClient korapClient;
private KorapEndpointDescription korapEndpointDescription;
@@ -55,9 +55,10 @@
SRUQueryParserRegistry.Builder parserRegistryBuilder,
Map<String, String> params) throws SRUConfigException {
- String korapURI = context.getInitParameter("korap.service.uri");
-
- korapClient = new KorapClient(korapURI,
+ korapWebUri = context.getInitParameter("korap.web.uri");
+
+ String korapApiUri = context.getInitParameter("korap.api.uri");
+ korapClient = new KorapClient(korapApiUri,
config.getNumberOfRecords(),
config.getMaximumRecords());
@@ -70,7 +71,7 @@
}
sb.append("/").append(config.getDatabase());
sb.append("/").append("redirect/");
- this.redirectBaseURI = sb.toString();
+ redirectBaseURI = sb.toString();
}
@Override
diff --git a/src/main/webapp/WEB-INF/sru-server-config.xml b/src/main/webapp/WEB-INF/sru-server-config.xml
index 4f2bef6..f9b78e4 100644
--- a/src/main/webapp/WEB-INF/sru-server-config.xml
+++ b/src/main/webapp/WEB-INF/sru-server-config.xml
@@ -5,8 +5,8 @@
<title xml:lang="en" primary="true">KorAP</title>
<description xml:lang="de">Suche mit KorAP via SRU.</description>
<description xml:lang="en" primary="true">Search in KorAP via SRU.</description>
- <author xml:lang="en">Institute for the German language</author>
- <author xml:lang="de" primary="true">Institut für Deutsche Sprache</author>
+ <author xml:lang="en">Leibniz institute for the German language</author>
+ <author xml:lang="de" primary="true">Leibniz Institut für Deutsche Sprache</author>
</databaseInfo>
<indexInfo>
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 17ba3ec..5e33950 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -6,10 +6,14 @@
<display-name>KorapSRU</display-name>
<context-param>
- <param-name>korap.service.uri</param-name>
+ <param-name>korap.api.uri</param-name>
<!-- <param-value>http://localhost:8089/api/v1.0/</param-value> -->
<param-value>https://korap.ids-mannheim.de/api/v1.0</param-value>
</context-param>
+ <context-param>
+ <param-name>korap.web.uri</param-name>
+ <param-value>https://korap.ids-mannheim.de</param-value>
+ </context-param>
<servlet>
<display-name>KorAP SRU/CQL Service (HTTP Interface)</display-name>
diff --git a/src/test/java/de/ids_mannheim/korap/test/KorapJerseyTest.java b/src/test/java/de/ids_mannheim/korap/test/KorapJerseyTest.java
index 388670f..dad2215 100644
--- a/src/test/java/de/ids_mannheim/korap/test/KorapJerseyTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/KorapJerseyTest.java
@@ -27,7 +27,8 @@
.initParam("eu.clarin.sru.server.maximumRecords", "50")
.contextParam("de.ids_mannheim.korap.endpointDescription",
"/src/main/webapp/WEB-INF/endpoint-description.xml")
- .contextParam("korap.service.uri", "http://localhost:8089/api/v1.0")
+ .contextParam("korap.api.uri", "http://localhost:1080")
+ .contextParam("korap.web.uri", "http://localhost:1080")
.build();
}
diff --git a/src/test/java/de/ids_mannheim/korap/test/KorapSRUTest.java b/src/test/java/de/ids_mannheim/korap/test/KorapSRUTest.java
index 4d41ae2..431033d 100644
--- a/src/test/java/de/ids_mannheim/korap/test/KorapSRUTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/KorapSRUTest.java
@@ -1,17 +1,27 @@
package de.ids_mannheim.korap.test;
import static org.junit.Assert.assertEquals;
+import static org.mockserver.integration.ClientAndServer.startClientAndServer;
+import static org.mockserver.model.HttpRequest.request;
+import static org.mockserver.model.HttpResponse.response;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import org.apache.commons.io.IOUtils;
import org.apache.http.client.ClientProtocolException;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
+import org.mockserver.client.MockServerClient;
+import org.mockserver.integration.ClientAndServer;
+import org.mockserver.model.Header;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -33,6 +43,20 @@
public class KorapSRUTest extends KorapJerseyTest{
private DocumentBuilder docBuilder;
+ private ClientAndServer mockServer;
+ private MockServerClient mockClient;
+
+ @Before
+ public void startMockServer () {
+ mockServer = startClientAndServer(1080);
+ mockClient = new MockServerClient("localhost", mockServer.getPort());
+ }
+
+ @After
+ public void stopMockServer () {
+ mockServer.stop();
+ }
+
public KorapSRUTest() throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
docBuilder = factory.newDocumentBuilder();
@@ -146,6 +170,7 @@
@Test
public void explainTest() throws URISyntaxException, ClientProtocolException, IOException, IllegalStateException, SAXException{
+
ClientResponse response = resource().queryParam("operation", "explain")
.get(ClientResponse.class);
@@ -204,6 +229,19 @@
@Test
public void explainEndpointDescriptionTest() throws URISyntaxException, ClientProtocolException, IOException, IllegalStateException, SAXException{
+
+ String korapResources = IOUtils.toString(
+ ClassLoader.getSystemResourceAsStream(
+ "korap-api-responses/resources.json"),
+ StandardCharsets.UTF_8);
+
+ mockClient.reset()
+ .when(request().withMethod("GET").withPath("/resource"))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(korapResources).withStatusCode(200));
+
ClientResponse response = resource().queryParam("operation", "explain")
.queryParam("x-fcs-endpoint-description", "true")
.get(ClientResponse.class);
@@ -238,12 +276,15 @@
nodelist = doc.getElementsByTagName("ed:Resource");
- for (int i=0; i<nodelist.getLength();i++){
- if (nodelist.item(i).getAttributes().getNamedItem("pid").equals("GOE")){
- children = nodelist.item(i).getChildNodes();
- assertEquals("ed:Title", children.item(0).getNodeName());
- assertEquals("Goethe", children.item(0).getTextContent());
- }
- }
+ assertEquals(3, nodelist.getLength());
+ children = nodelist.item(0).getChildNodes();
+ assertEquals(7, children.getLength());
+ assertEquals("ed:Title", children.item(0).getNodeName());
+ assertEquals("ed:Description", children.item(2).getNodeName());
+ assertEquals("ed:LandingPageURI", children.item(3).getNodeName());
+ assertEquals("ed:Languages", children.item(4).getNodeName());
+ assertEquals("ed:AvailableDataViews", children.item(5).getNodeName());
+ assertEquals("ed:AvailableLayers", children.item(6).getNodeName());
}
+
}
diff --git a/src/test/resources/korap-api-responses/resources.json b/src/test/resources/korap-api-responses/resources.json
new file mode 100644
index 0000000..c43cbbd
--- /dev/null
+++ b/src/test/resources/korap-api-responses/resources.json
@@ -0,0 +1,53 @@
+[
+ {
+ "resourceId": "WPD17",
+ "titles": {
+ "de": "Deutsche Wikipedia Artikel 2017",
+ "en": "German Wikipedia Articles 2017"
+ },
+ "description": "A collection of articles of German Wikipedia from July 1st, 2017.",
+ "languages": ["deu"],
+ "layers": {
+ "18": "marmot/m",
+ "19": "marmot/p",
+ "23": "opennlp/p",
+ "11": "corenlp/p",
+ "27": "tt/l",
+ "28": "tt/p"
+ }
+ },
+ {
+ "resourceId": "WDD17",
+ "titles": {
+ "de": "Deutsche Wikipedia-Diskussionskorpus 2017",
+ "en": "German Wikipedia talk corpus 2017"
+ },
+ "description": "A collection of talk pages of German Wikipedia from July 1st, 2017.",
+ "languages": ["deu"],
+ "layers": {
+ "18": "marmot/m",
+ "19": "marmot/p",
+ "23": "opennlp/p",
+ "11": "corenlp/p",
+ "27": "tt/l",
+ "28": "tt/p"
+ }
+ },
+ {
+ "resourceId": "WUD17",
+ "titles": {
+ "de": "Deutsche Wikipedia-Benutzerdiskussionskorpus 2017",
+ "en": "German Wikipedia talk corpus 2017"
+ },
+ "description": "A collection of user talk pages of German Wikipedia from July 1st, 2017.",
+ "languages": ["deu"],
+ "layers": {
+ "18": "marmot/m",
+ "19": "marmot/p",
+ "23": "opennlp/p",
+ "11": "corenlp/p",
+ "27": "tt/l",
+ "28": "tt/p"
+ }
+ }
+]
\ No newline at end of file