Uses Jersey test framework for the test suite.

Change-Id: Ibe57a7e3b79809d582dedddad9a19038f5b1d63b
diff --git a/pom.xml b/pom.xml
index d49199c..9047b67 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,6 +78,18 @@
 			<artifactId>org.apache.commons.lang</artifactId>
 			<version>2.6</version>
 		</dependency>
+		<dependency>
+			<groupId>com.sun.jersey.jersey-test-framework</groupId>
+			<artifactId>jersey-test-framework-core</artifactId>
+			<version>${jersey.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.jersey.jersey-test-framework</groupId>
+			<artifactId>jersey-test-framework-grizzly</artifactId>
+			<version>${jersey.version}</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 1631075..10e4412 100644
--- a/src/main/java/de/ids_mannheim/korap/sru/KorapEndpointDescription.java
+++ b/src/main/java/de/ids_mannheim/korap/sru/KorapEndpointDescription.java
@@ -51,19 +51,25 @@
     
     public KorapEndpointDescription (ServletContext context)
             throws SRUConfigException {
+        
+        String endpointDesc = context.getInitParameter("de.ids_mannheim.korap.endpointDescription");
+        if (endpointDesc==null || endpointDesc.isEmpty()){
+            endpointDesc = "/WEB-INF/endpoint-description.xml";
+        }
+        
         try {
-            URL url = context.getResource("/WEB-INF/endpoint-description.xml");
-            EndpointDescription simpleEndpointDescription = SimpleEndpointDescriptionParser
-                    .parse(url);
+            URL url = context.getResource(endpointDesc);
+            EndpointDescription simpleEndpointDescription =
+                    SimpleEndpointDescriptionParser.parse(url);
             if (simpleEndpointDescription != null) {
-                setSupportedLayers(simpleEndpointDescription
-                        .getSupportedLayers());
-                setAnnotationLayers(simpleEndpointDescription
-                        .getSupportedLayers());
-                setSupportedDataViews(simpleEndpointDescription
-                        .getSupportedDataViews());
-                setDefaultDataViews(simpleEndpointDescription
-                        .getSupportedDataViews());
+                setSupportedLayers(
+                        simpleEndpointDescription.getSupportedLayers());
+                setAnnotationLayers(
+                        simpleEndpointDescription.getSupportedLayers());
+                setSupportedDataViews(
+                        simpleEndpointDescription.getSupportedDataViews());
+                setDefaultDataViews(
+                        simpleEndpointDescription.getSupportedDataViews());
                 setCapabilities(simpleEndpointDescription.getCapabilities());
             }
 
@@ -76,37 +82,39 @@
     }
 
     @Override
-    public void destroy() {
-        dataviews.clear();
-        capabilities.clear();
+    public void destroy () {
+        //dataviews.clear();
+        //capabilities.clear();
+        dataviews = null;
+        capabilities = null;
         languages.clear();
     }
 
-    public void setLanguages() {
+    public void setLanguages () {
         languages = new ArrayList<String>();
         languages.add("deu");
     }
 
     @Override
-    public List<URI> getCapabilities() {
+    public List<URI> getCapabilities () {
         return capabilities;
     }
 
-    public void setCapabilities(List<URI> list) throws SRUConfigException {
+    public void setCapabilities (List<URI> list) throws SRUConfigException {
         capabilities = list;
     }
 
     @Override
-    public List<DataView> getSupportedDataViews() {
+    public List<DataView> getSupportedDataViews () {
         return dataviews;
     }
 
-    public void setSupportedDataViews(List<DataView> list) {
+    public void setSupportedDataViews (List<DataView> list) {
         dataviews = list;
     }
 
     @Override
-    public List<ResourceInfo> getResourceList(String pid) throws SRUException {
+    public List<ResourceInfo> getResourceList (String pid) throws SRUException {
 
         List<ResourceInfo> resourceList = new ArrayList<ResourceInfo>();
 
@@ -116,12 +124,13 @@
         JsonNode resources;
 
         try {
-            //resources = KorapSRU.korapClient.retrieveResources();
-            InputStream is = getClass().getClassLoader().getResourceAsStream("resources.json");
-            resources = mapper.readTree(is); 
+            // resources = KorapSRU.korapClient.retrieveResources();
+            InputStream is = getClass().getClassLoader()
+                    .getResourceAsStream("resources.json");
+            resources = mapper.readTree(is);
         }
-        catch ( //URISyntaxException | 
-                IOException e) {
+        catch ( // URISyntaxException |
+        IOException e) {
             throw new SRUException(SRUConstants.SRU_GENERAL_SYSTEM_ERROR,
                     "Failed retrieving resources.");
         }
@@ -143,11 +152,11 @@
         return resourceList;
     }
 
-    public List<String> getDefaultDataViews() {
+    public List<String> getDefaultDataViews () {
         return defaultDataviews;
     }
 
-    public void setDefaultDataViews(List<DataView> supportedDataViews) {
+    public void setDefaultDataViews (List<DataView> supportedDataViews) {
         defaultDataviews = new ArrayList<String>();
         for (DataView d : supportedDataViews) {
             if (d.getDeliveryPolicy() == DeliveryPolicy.SEND_BY_DEFAULT) {
@@ -156,20 +165,20 @@
         }
     }
 
-    public void setSupportedLayers(List<Layer> layers) {
+    public void setSupportedLayers (List<Layer> layers) {
         this.layers = layers;
     }
 
     @Override
-    public List<Layer> getSupportedLayers() {
+    public List<Layer> getSupportedLayers () {
         return layers;
     }
 
-    public List<AnnotationLayer> getAnnotationLayers() {
+    public List<AnnotationLayer> getAnnotationLayers () {
         return annotationLayers;
     }
 
-    public void setAnnotationLayers(List<Layer> layers) {
+    public void setAnnotationLayers (List<Layer> layers) {
         annotationLayers = new ArrayList<AnnotationLayer>(layers.size());
 
         String layerCode;
@@ -191,7 +200,8 @@
                     if (type.equals(AnnotationLayer.TYPE.POS.toString())) {
                         sb.append("/p");
                     }
-                    else if (type.equals(AnnotationLayer.TYPE.LEMMA.toString())) {
+                    else if (type
+                            .equals(AnnotationLayer.TYPE.LEMMA.toString())) {
                         sb.append("/l");
                     }
                     else {
@@ -201,17 +211,17 @@
                 layerCode = sb.toString();
             }
 
-            AnnotationLayer annotationLayer = new AnnotationLayer(layerCode,
-                    l.getResultId());
+            AnnotationLayer annotationLayer =
+                    new AnnotationLayer(layerCode, l.getResultId());
             annotationLayers.add(annotationLayer);
         }
     }
 
-    public Layer getTextLayer() {
+    public Layer getTextLayer () {
         return textLayer;
     }
 
-    public void setTextLayer(Layer textLayer) {
+    public void setTextLayer (Layer textLayer) {
         this.textLayer = textLayer;
     }
 }
diff --git a/src/main/webapp/WEB-INF/endpoint-description.xml b/src/main/webapp/WEB-INF/endpoint-description.xml
index 1bd2b25..bd3e7a7 100644
--- a/src/main/webapp/WEB-INF/endpoint-description.xml
+++ b/src/main/webapp/WEB-INF/endpoint-description.xml
@@ -16,25 +16,25 @@
     </SupportedDataViews>

     <SupportedLayers>

         <SupportedLayer id="l1" result-id="http://clarin.ids-mannheim.de/korapsru/layers/text">text</SupportedLayer>

-        <SupportedLayer id="l2" result-id="http://clarin.ids-mannheim.de/korapsru/layers/pos1" qualifier="cnx"

+        <SupportedLayer id="l2" result-id="http://clarin.ids-mannheim.de/korapsru/layers/pos/cnx" qualifier="cnx"

         	alt-value-info="based on STTS tagset"

         	alt-value-info-uri="http://www.ims.uni-stuttgart.de/forschung/ressourcen/lexika/TagSets/stts-table.html">pos</SupportedLayer>

-        <SupportedLayer id="l3" result-id="http://clarin.ids-mannheim.de/korapsru/layers/pos2" qualifier="tt"

+        <SupportedLayer id="l3" result-id="http://clarin.ids-mannheim.de/korapsru/layers/pos/tt" qualifier="tt"

             alt-value-info="based on STTS tagset"

             alt-value-info-uri="http://www.ims.uni-stuttgart.de/forschung/ressourcen/lexika/TagSets/stts-table.html">pos</SupportedLayer>

-        <SupportedLayer id="l4" result-id="http://clarin.ids-mannheim.de/korapsru/layers/pos3" qualifier="opennlp"

+        <SupportedLayer id="l4" result-id="http://clarin.ids-mannheim.de/korapsru/layers/pos/opennlp" qualifier="opennlp"

             alt-value-info="based on STTS tagset"

             alt-value-info-uri="http://www.ims.uni-stuttgart.de/forschung/ressourcen/lexika/TagSets/stts-table.html">pos</SupportedLayer>

-       <SupportedLayer id="l5" result-id="http://clarin.ids-mannheim.de/korapsru/layers/pos4" qualifier="mate"

+       <SupportedLayer id="l5" result-id="http://clarin.ids-mannheim.de/korapsru/layers/pos/mate" qualifier="mate"

             alt-value-info="based on STTS tagset"

             alt-value-info-uri="http://www.ims.uni-stuttgart.de/forschung/ressourcen/lexika/TagSets/stts-table.html">pos</SupportedLayer>        

-        <SupportedLayer id="l6" result-id="http://clarin.ids-mannheim.de/korapsru/layers/pos5" qualifier="xip"

+        <SupportedLayer id="l6" result-id="http://clarin.ids-mannheim.de/korapsru/layers/pos/xip" qualifier="xip"

             alt-value-info="based on STTS tagset"

             alt-value-info-uri="http://www.ims.uni-stuttgart.de/forschung/ressourcen/lexika/TagSets/stts-table.html">pos</SupportedLayer>       

-        <SupportedLayer id="l7" result-id="http://clarin.ids-mannheim.de/korapsru/layers/lemma1" qualifier="cnx">lemma</SupportedLayer>

-        <SupportedLayer id="l8" result-id="http://clarin.ids-mannheim.de/korapsru/layers/lemma2" qualifier="tt">lemma</SupportedLayer>

-        <SupportedLayer id="l9" result-id="http://clarin.ids-mannheim.de/korapsru/layers/lemma3" qualifier="mate">lemma</SupportedLayer>

-        <SupportedLayer id="l10" result-id="http://clarin.ids-mannheim.de/korapsru/layers/lemma4" qualifier="xip">lemma</SupportedLayer>

+        <SupportedLayer id="l7" result-id="http://clarin.ids-mannheim.de/korapsru/layers/lemma/cnx" qualifier="cnx">lemma</SupportedLayer>

+        <SupportedLayer id="l8" result-id="http://clarin.ids-mannheim.de/korapsru/layers/lemma/tt" qualifier="tt">lemma</SupportedLayer>

+        <SupportedLayer id="l9" result-id="http://clarin.ids-mannheim.de/korapsru/layers/lemma/mate" qualifier="mate">lemma</SupportedLayer>

+        <SupportedLayer id="l10" result-id="http://clarin.ids-mannheim.de/korapsru/layers/lemma/xip" qualifier="xip">lemma</SupportedLayer>

     </SupportedLayers>

     <Resources>

      	<Resource pid="dummy pid">

diff --git a/src/test/java/de/ids_mannheim/korap/test/FCSQLRequestTest.java b/src/test/java/de/ids_mannheim/korap/test/FCSQLRequestTest.java
index a60947e..7b030c3 100644
--- a/src/test/java/de/ids_mannheim/korap/test/FCSQLRequestTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/FCSQLRequestTest.java
@@ -36,7 +36,7 @@
  * @author margaretha
  *
  */
-public class FCSQLRequestTest {
+public class FCSQLRequestTest extends KorapJerseyTest {
 
     private String korapSruUri = "http://localhost:8080/KorapSRU";
     private static DocumentBuilder documentBuilder;
diff --git a/src/test/java/de/ids_mannheim/korap/test/KorapJerseyTest.java b/src/test/java/de/ids_mannheim/korap/test/KorapJerseyTest.java
new file mode 100644
index 0000000..a2de639
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/test/KorapJerseyTest.java
@@ -0,0 +1,44 @@
+package de.ids_mannheim.korap.test;
+
+import com.sun.jersey.test.framework.AppDescriptor;
+import com.sun.jersey.test.framework.JerseyTest;
+import com.sun.jersey.test.framework.WebAppDescriptor;
+import com.sun.jersey.test.framework.spi.container.TestContainerException;
+import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
+import com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory;
+
+import eu.clarin.sru.server.utils.SRUServerServlet;
+
+public class KorapJerseyTest extends JerseyTest {
+
+    @Override
+    protected AppDescriptor configure () {
+        return new WebAppDescriptor.Builder()
+                .servletClass(SRUServerServlet.class)
+                .initParam("eu.clarin.sru.server.utils.sruServerConfigLocation",
+                        "/src/main/webapp/WEB-INF/sru-server-config.xml")
+                .initParam(
+                        "eu.clarin.sru.server.utils.sruServerSearchEngineClass",
+                        "de.ids_mannheim.korap.sru.KorapSRU")
+                .initParam("eu.clarin.sru.server.database", "korapsru")
+                .initParam("eu.clarin.sru.server.sruSupportedVersionMax", "2.0")
+                .initParam("eu.clarin.sru.server.sruSupportedVersionDefault", "2.0")
+                .initParam("eu.clarin.sru.server.numberOfRecords", "25")
+                .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/")
+                .build();
+    }
+
+    @Override
+    protected TestContainerFactory getTestContainerFactory ()
+            throws TestContainerException {
+        return new GrizzlyWebTestContainerFactory();
+    }
+
+    @Override
+    protected int getPort (int defaultPort) {
+        return 8080;
+    }
+}
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 b5b6c1c..542c815 100644
--- a/src/test/java/de/ids_mannheim/korap/test/KorapSRUTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/KorapSRUTest.java
@@ -33,7 +33,7 @@
  * @author margaretha
  *
  */
-public class KorapSRUTest {
+public class KorapSRUTest extends KorapJerseyTest{
 	private int port = 8080;
 	
 	DocumentBuilder docBuilder;
@@ -110,7 +110,7 @@
 		
 		node = node.getFirstChild();
 		attr = node.getAttributes().getNamedItem("id").getNodeValue();
-		assertEquals("http://clarin.ids-mannheim.de/korapsru/layers/text", attr);
+		assertEquals("http://clarin.ids-mannheim.de/korapsru/layers/pos/opennlp", attr);
 //		assertEquals(50, node.getChildNodes().getLength());
 	}
 	
@@ -142,9 +142,9 @@
 		
 		NodeList children = nodelist.item(0).getChildNodes();
 		assertEquals("zr:host", children.item(0).getNodeName());
-		assertEquals("clarin.ids-mannheim.de", children.item(0).getTextContent());
+		assertEquals("127.0.0.1", children.item(0).getTextContent());
 		assertEquals("zr:port", children.item(1).getNodeName());
-		assertEquals("80", children.item(1).getTextContent());
+		assertEquals("8080", children.item(1).getTextContent());
 		assertEquals("zr:database", children.item(2).getNodeName());
 		assertEquals("korapsru", children.item(2).getTextContent());