Added re-caching VC at closing-index service, resolved #44
Change-Id: I72bc0980da63f64f50b9bf92787550a9401fd1c3
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/IndexControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/IndexControllerTest.java
new file mode 100644
index 0000000..fbf56e3
--- /dev/null
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/IndexControllerTest.java
@@ -0,0 +1,89 @@
+package de.ids_mannheim.korap.web.controller;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.apache.http.HttpStatus;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.fasterxml.jackson.databind.JsonNode;
+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.SpringJerseyTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.web.SearchKrill;
+
+/**
+ * @author margaretha
+ *
+ */
+public class IndexControllerTest extends SpringJerseyTest {
+
+ @Autowired
+ private SearchKrill searchKrill;
+
+ @Test
+ public void testCloseIndex () throws IOException, KustvaktException,
+ URISyntaxException, InterruptedException {
+ URI uri = IndexControllerTest.class.getClassLoader()
+ .getResource("vc/named-vc1.jsonld").toURI();
+ Path toLink = Paths.get(uri);
+ Path symLink = Paths.get("vc/named-vc1.jsonld");
+ Path vcPath = Paths.get("vc");
+ if (!Files.exists(vcPath)) {
+ Files.createDirectory(vcPath);
+ }
+ if (Files.exists(symLink)) {
+ Files.delete(symLink);
+ }
+ Files.createSymbolicLink(symLink, toLink);
+
+ 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.SC_OK, response.getStatus());
+ assertEquals(false, searchKrill.getIndex().isReaderOpen());
+
+
+ // Cleaning database and cache
+
+ Thread.sleep(200);
+
+ response = resource().path(API_VERSION).path("vc").path("system")
+ .path("named-vc1")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("admin", "pass"))
+ .delete(ClientResponse.class);
+
+ response = resource().path(API_VERSION).path("vc").path("system")
+ .path("named-vc1")
+ .get(ClientResponse.class);
+
+ String entity = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,node.at("/errors/0/0").asInt());
+ }
+
+}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
index 7e118d1..1fb3915 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
@@ -6,20 +6,14 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.IOException;
-
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import org.apache.http.HttpStatus;
import org.junit.Ignore;
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;
@@ -27,7 +21,6 @@
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;
/**
* @author hanl, margaretha
@@ -36,9 +29,6 @@
*/
public class SearchControllerTest extends SpringJerseyTest {
- @Autowired
- private SearchKrill searchKrill;
-
private JsonNode requestSearchWithFields(String fields) throws KustvaktException{
ClientResponse response = resource().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
@@ -342,21 +332,4 @@
assertNotEquals(0, node.path("matches").size());
// assertEquals(10993, node.at("/meta/totalResults").asInt());
}
-
- @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.SC_OK, response.getStatus());
- assertEquals(false, searchKrill.getIndex().isReaderOpen());
- }
-
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
index 53adca4..814799a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
@@ -125,6 +125,18 @@
assertEquals(VirtualCorpusType.SYSTEM.displayName(),
node.at("/type").asText());
}
+
+ @Test
+ public void testRetrieveSystemVCGuest () throws UniformInterfaceException,
+ ClientHandlerException, KustvaktException {
+
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("system").path("system VC").get(ClientResponse.class);
+ JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+ assertEquals("system VC", node.at("/name").asText());
+ assertEquals(VirtualCorpusType.SYSTEM.displayName(),
+ node.at("/type").asText());
+ }
@Test
public void testRetrieveOwnerPrivateVCInfo ()
diff --git a/full/src/test/resources/kustvakt-test.conf b/full/src/test/resources/kustvakt-test.conf
index 066377c..585d43c 100644
--- a/full/src/test/resources/kustvakt-test.conf
+++ b/full/src/test/resources/kustvakt-test.conf
@@ -36,7 +36,7 @@
default.foundry.dependency = malt
default.foundry.constituent = corenlp
default.foundry.morphology = marmot
-default.foundry.surface = base
+default.foundry.surface = base
## delete configuration (default hard)
# delete.auto.group = hard
diff --git a/full/src/test/resources/test-config.xml b/full/src/test/resources/test-config.xml
index 16f7ee3..82b314e 100644
--- a/full/src/test/resources/test-config.xml
+++ b/full/src/test/resources/test-config.xml
@@ -175,6 +175,7 @@
init-method="initTest">
</bean>
+ <bean id="vcLoader" class="de.ids_mannheim.de.init.VCLoaderImpl"/>
<!-- Krill -->
<bean id="search_krill" class="de.ids_mannheim.korap.web.SearchKrill">