Resolved #42 - Added close index controller.

Change-Id: I0df990b1bf2f7d7f92ac4f0e90aced584aad265e
diff --git a/lite/Changes b/lite/Changes
index aa4374e..1bc17e8 100644
--- a/lite/Changes
+++ b/lite/Changes
@@ -1,3 +1,7 @@
+version 0.62
+19/03/2019
+  - Added close index controller (margaretha)  
+
 version 0.61.3
 05/02/2019
   - Updated kustvakt-lite.conf (margaretha)
diff --git a/lite/pom.xml b/lite/pom.xml
index 0753db9..a830c0c 100644
--- a/lite/pom.xml
+++ b/lite/pom.xml
@@ -3,7 +3,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>de.ids_mannheim.korap</groupId>
 	<artifactId>Kustvakt-lite</artifactId>
-	<version>0.61.3</version>
+	<version>0.62</version>
 	<properties>
 		<java.version>1.8</java.version>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -137,7 +137,7 @@
 		<dependency>
 			<groupId>de.ids_mannheim.korap</groupId>
 			<artifactId>Kustvakt-core</artifactId>
-			<version>[0.61.6,)</version>
+			<version>[0.62,)</version>
 		</dependency>
 		<!-- Jersey test framework -->
 		<dependency>
diff --git a/lite/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java b/lite/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java
index d2373d3..c1b533f 100644
--- a/lite/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java
+++ b/lite/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java
@@ -29,7 +29,8 @@
 
         properties.load(in);
         in.close();
-        config = new KustvaktConfiguration(properties);
+        config = new KustvaktConfiguration();
+        config.loadBasicProperties(properties);
 
         kargs.setSpringConfig("lite-config.xml");
         rootPackages = "de.ids_mannheim.korap.web";
diff --git a/lite/src/test/java/de/ids_mannheim/korap/config/LiteJerseyTest.java b/lite/src/test/java/de/ids_mannheim/korap/config/LiteJerseyTest.java
new file mode 100644
index 0000000..bef92bf
--- /dev/null
+++ b/lite/src/test/java/de/ids_mannheim/korap/config/LiteJerseyTest.java
@@ -0,0 +1,78 @@
+package de.ids_mannheim.korap.config;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.concurrent.ThreadLocalRandom;
+
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.context.support.GenericWebApplicationContext;
+
+import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
+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;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("classpath:test-config.xml")
+public abstract class LiteJerseyTest extends JerseyTest{
+    
+    public static final String API_VERSION = "v1.0";
+    
+    @Autowired
+    protected GenericApplicationContext applicationContext;
+    
+    private static String[] classPackages =
+            new String[] { "de.ids_mannheim.korap.web.controller",
+                    "de.ids_mannheim.korap.web.filter",
+                    "de.ids_mannheim.korap.web.utils" };
+    
+    @Override
+    protected TestContainerFactory getTestContainerFactory ()
+            throws TestContainerException {
+        return new GrizzlyWebTestContainerFactory();
+    }
+
+    @Override
+    public void setUp () throws Exception {
+
+        GenericWebApplicationContext genericContext =
+                new GenericWebApplicationContext();
+
+        genericContext.setParent(this.applicationContext);
+        genericContext.setClassLoader(this.applicationContext.getClassLoader());
+
+        StaticContextLoaderListener.applicationContext = genericContext;
+        super.setUp();
+    }
+    
+    @Override
+    protected AppDescriptor configure () {
+        return new WebAppDescriptor.Builder(classPackages)
+                .servletClass(SpringServlet.class)
+                .contextListenerClass(StaticContextLoaderListener.class)
+                .contextParam("adminToken", "secret")
+                .build();
+    }
+
+    @Override
+    protected int getPort (int defaultPort) {
+        int port = ThreadLocalRandom.current().nextInt(5000, 8000 + 1);
+        try {
+            ServerSocket socket = new ServerSocket(port);
+            socket.close();
+        }
+        catch (IOException e) {
+            e.printStackTrace();
+            port = getPort(port);
+        }
+        return port;
+    }
+    
+}
diff --git a/lite/src/test/java/de/ids_mannheim/korap/config/StaticContextLoaderListener.java b/lite/src/test/java/de/ids_mannheim/korap/config/StaticContextLoaderListener.java
new file mode 100644
index 0000000..578c94e
--- /dev/null
+++ b/lite/src/test/java/de/ids_mannheim/korap/config/StaticContextLoaderListener.java
@@ -0,0 +1,22 @@
+package de.ids_mannheim.korap.config;
+
+import org.springframework.web.context.ContextLoaderListener;
+import org.springframework.web.context.WebApplicationContext;
+
+/**
+ * A hack to inject the application context generated by
+ * SpringJUnit4ClassRunner in the test suite.
+ * 
+ * @author margaretha
+ *
+ */
+public class StaticContextLoaderListener extends ContextLoaderListener {
+
+    public static WebApplicationContext applicationContext;
+
+    public StaticContextLoaderListener () {
+        super(applicationContext);
+    }
+
+
+}
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteJerseyTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteJerseyTest.java
deleted file mode 100644
index a0ea0a3..0000000
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteJerseyTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package de.ids_mannheim.korap.web.service;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.util.concurrent.ThreadLocalRandom;
-
-import org.springframework.web.context.ContextLoaderListener;
-
-import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
-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;
-
-public class LiteJerseyTest  extends JerseyTest{
-
-    public static final String API_VERSION = "v1.0";
-    private static String[] classPackages =
-            new String[] { "de.ids_mannheim.korap.web.controller",
-                    "de.ids_mannheim.korap.web.filter",
-                    "de.ids_mannheim.korap.web.utils" };
-    @Override
-    protected TestContainerFactory getTestContainerFactory ()
-            throws TestContainerException {
-        return new GrizzlyWebTestContainerFactory();
-    }
-
-    @Override
-    protected AppDescriptor configure () {
-        return new WebAppDescriptor.Builder(classPackages)
-                .servletClass(SpringServlet.class)
-                .contextListenerClass(ContextLoaderListener.class)
-                .contextParam("contextConfigLocation",
-                        "classpath:test-config.xml")
-                .build();
-    }
-
-    @Override
-    protected int getPort (int defaultPort) {
-        int port = ThreadLocalRandom.current().nextInt(5000, 8000 + 1);
-        try {
-            ServerSocket socket = new ServerSocket(port);
-            socket.close();
-        }
-        catch (IOException e) {
-            e.printStackTrace();
-            port = getPort(port);
-        }
-        return port;
-    }
-    
-}
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
index b30b626..7bd2409 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
@@ -6,26 +6,35 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
 import java.net.URI;
 import java.util.Iterator;
 
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 
 import org.eclipse.jetty.http.HttpStatus;
 import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.google.common.net.HttpHeaders;
 import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
 
 import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
 import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.LiteJerseyTest;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.query.serialize.QuerySerializer;
 import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.web.SearchKrill;
 
 public class LiteSearchControllerTest extends LiteJerseyTest {
 
+    @Autowired
+    private SearchKrill searchKrill;
+    
     @Test
     public void testGetJSONQuery () throws KustvaktException {
         ClientResponse response = resource().path(API_VERSION).path("query")
@@ -374,4 +383,20 @@
         JsonNode node = JsonUtils.readTree(entity);
         assertTrue(node.at("/collection").isMissingNode());
     }
+    
+    @Test
+    public void testCloseIndex () throws IOException {
+        searchKrill.getStatistics(null);
+        assertEquals(true, searchKrill.getIndex().isReaderOpen());
+
+        MultivaluedMap<String, String> m = new MultivaluedMapImpl();
+        m.add("token", "secret");
+
+        ClientResponse response = resource().path(API_VERSION).path("index")
+                .path("close").type(MediaType.APPLICATION_FORM_URLENCODED)
+                .post(ClientResponse.class, m);
+
+        assertEquals(HttpStatus.OK_200, response.getStatus());
+        assertEquals(false, searchKrill.getIndex().isReaderOpen());
+    }
 }
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteStatisticControllerTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteStatisticControllerTest.java
index 0efc39e..3956acd 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteStatisticControllerTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteStatisticControllerTest.java
@@ -7,6 +7,7 @@
 import com.fasterxml.jackson.databind.JsonNode;
 import com.sun.jersey.api.client.ClientResponse;
 
+import de.ids_mannheim.korap.config.LiteJerseyTest;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.utils.JsonUtils;