Merge branch 'dev'
diff --git a/pom.xml b/pom.xml
index 13e0025..2272a63 100644
--- a/pom.xml
+++ b/pom.xml
@@ -176,6 +176,9 @@
<exclude>**/*APITest.java</exclude>
<exclude>de/ids_mannheim/korap/suites/*.java</exclude>
<exclude>**/KustvaktServerTest.java</exclude>
+ <exclude>**/ResourceServiceTest.java</exclude>
+ <exclude>**/ResourceInfoServiceTest.java</exclude>
+ <exclude>**/PolicyServiceTest.java</exclude>
</excludes>
<includes>
<include>de/ids_mannheim/korap/**/*.java</include>
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
index f2742ce..07c963a 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -76,7 +76,7 @@
private String default_token;
private String default_dep;
private String default_const;
-
+ @Deprecated
private String policyConfig;
private ArrayList<String> foundries;
private ArrayList<String> layers;
@@ -163,14 +163,14 @@
ldapConfig = properties.getProperty("ldap.config");
- // EM: replace this later with KoralQuery
+ // EM: regex for matching availability in Krill matches
freeLicensePattern = Pattern.compile(properties.getProperty("kustvakt.regex.free",""));
publicLicensePattern = Pattern.compile(properties.getProperty("kustvakt.regex.public",""));
allLicensePattern = Pattern.compile(properties.getProperty("kustvakt.regex.all",""));
// EM: not use in the future
- policyConfig = properties.getProperty("policies.config");
- setFoundriesAndLayers(policyConfig);
+ //policyConfig = properties.getProperty("policies.config");
+ //setFoundriesAndLayers(policyConfig);
KUSTVAKT_USER.put(Attributes.ID, Integer.parseInt(properties.getProperty("kustvakt.init.user.id")));
KUSTVAKT_USER.put(Attributes.USERNAME, properties.getProperty("kustvakt.init.user.username"));
diff --git a/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java b/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
index b30a915..e611f4e 100644
--- a/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
+++ b/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
@@ -31,6 +31,7 @@
*/
public static final int NO_QUERY = 301;
+ public static final int SERIALIZATION_FAILED = 302;
/**
@@ -40,7 +41,7 @@
// fixme: use unsupported resource and include type in return message
public static final int POLICY_ERROR_DEFAULT = 400;
public static final int UNSUPPORTED_RESOURCE = 402;
- public static final int FAILED_REWRITE = 403;
+ public static final int REWRITE_FAILED = 403;
//public static final int UNSUPPORTED_FOUNDRY = 403;
//public static final int UNSUPPORTED_CORPUS = 404;
//public static final int UNSUPPORTED_LAYER = 405;
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
index b6508f5..406c342 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
@@ -20,14 +20,15 @@
* @author hanl
* @date 04/07/2015
*/
+// EM: use CollectionRewrite instead
+@Deprecated
public class PublicCollection implements RewriteTask.RewriteQuery {
public PublicCollection () {
super();
}
-
- @Override
+ @Deprecated
public JsonNode rewriteQuery (KoralNode node, KustvaktConfiguration config,
User user) throws KustvaktException {
JsonNode subnode = node.rawNode();
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java b/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
index 6efdb4f..368a36f 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
@@ -96,7 +96,7 @@
Permissions.Permission.READ);
}
-
+ @Deprecated
public static <T extends KustvaktResource> Set<T> searchPublic (
Class<T> clazz) throws KustvaktException {
return searchPublicFiltered(clazz);
@@ -133,6 +133,7 @@
return sets;
}
+ @Deprecated
public static <T extends KustvaktResource> Set<T> searchPublicFiltered (
Class<T> clazz, String ... ids) throws KustvaktException {
overrideProviders(null);
diff --git a/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java b/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java
index 811c227..d2671be 100644
--- a/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java
@@ -1,19 +1,22 @@
package de.ids_mannheim.korap.utils;
+import java.util.List;
+
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor;
-import edu.emory.mathcs.backport.java.util.Arrays;
-import java.io.IOError;
-import java.util.Map;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor;
+import de.ids_mannheim.korap.response.Notifications;
+import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
+import edu.emory.mathcs.backport.java.util.Arrays;
/**
* convenience builder class for collection query
*
- * @author hanl
- * @date 16/09/2014
+ * @author hanl, margaretha
+ * @date 29/06/2017
*/
public class KoralCollectionQueryBuilder {
@@ -98,7 +101,7 @@
}
- public Object rebaseCollection () {
+ public Object rebaseCollection (){
if (this.builder.length() == 0 && this.base == null)
return null;
@@ -107,6 +110,21 @@
CollectionQueryProcessor tree = new CollectionQueryProcessor(
this.verbose);
tree.process(this.builder.toString());
+ if (tree.getErrors().size() > 0){
+ Notifications notif = new Notifications();
+ int code;
+ for (List<Object> e : tree.getErrors()){
+ code = (int) e.get(0);
+ if (e.get(1) instanceof String){
+ notif.addError(code, (String) e.get(1));
+ }
+ else{
+ notif.addError(code, (String[]) e.get(1));
+ }
+ }
+
+ throw KustvaktResponseHandler.throwit(StatusCodes.SERIALIZATION_FAILED,notif.toJsonString());
+ }
request = JsonUtils.valueToTree(tree.getRequestMap());
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
index 5c50194..355ce67 100644
--- a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
+++ b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
@@ -242,9 +242,11 @@
// Get numbers from index (currently slow)
try {
docs = kc.numberOf("documents");
- tokens = kc.numberOf("tokens");
- sentences = kc.numberOf("sentences");
- paragraphs = kc.numberOf("paragraphs");
+ if (docs > 0) {
+ tokens = kc.numberOf("tokens");
+ sentences = kc.numberOf("base/sentences");
+ paragraphs = kc.numberOf("base/paragraphs");
+ };
}
catch (IOException e) {
e.printStackTrace();
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java b/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
index 514afcf..5485896 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
@@ -26,9 +26,11 @@
* @date 12/01/2016
* @lastupdate 19/04/2017
*/
+@Deprecated
public class CollectionLoader implements BootableBeanInterface {
@Override
+ @Deprecated
public void load (ContextHolder beans) throws KustvaktException {
SecurityManager.overrideProviders(beans);
ResourceFinder.overrideProviders(beans);
@@ -37,33 +39,6 @@
.toUser(KustvaktConfiguration.KUSTVAKT_USER);
KustvaktConfiguration config = beans.getConfiguration();
-
- // KoralCollectionQueryBuilder bui = new KoralCollectionQueryBuilder();
- // bui.with("creationDate since 1775 & corpusSigle=GOE");
- //
- // VirtualCollection c1 = new VirtualCollection();
- // c1.setName("Weimarer Werke");
- //
- // c1.setFields(bui.toJSON());
- //
- // c1.setDescription("Goethe-Werke in Weimar (seit 1775)");
- //
- // bui = new KoralCollectionQueryBuilder();
- // bui.with("textType=Aphorismus");
- //
- // VirtualCollection c2 = new VirtualCollection();
- // c2.setName("Aphorismen");
- // c2.setFields(bui.toJSON());
- // c2.setDescription("Aphorismentexte Goethes");
- //
- // bui = new KoralCollectionQueryBuilder();
- // bui.with("title ~ \"Werther\"");
- //
- // VirtualCollection c3 = new VirtualCollection();
- // c3.setName("Werther");
- // c3.setFields(bui.toJSON());
- // c3.setDescription("Goethe - Die Leiden des jungen Werther");
-
PolicyBuilder builder = new PolicyBuilder(user);
String result = null;
BufferedReader br;
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
index 34da8d9..74cb2a9 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
@@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -73,7 +72,7 @@
/**
* @author hanl, margaretha
* @date 29/01/2014
- * @lastUpdate 04/2017
+ * @lastUpdate 06/2017
*/
@Path(KustvaktServer.API_VERSION + "/")
@ResourceFilters({ AuthFilter.class, DemoUserFilter.class, PiwikFilter.class })
@@ -318,10 +317,28 @@
}
+ /* EM: potentially an unused service! */
+ /** Builds a json query serialization from the given parameters.
+ *
+ * @param locale
+ * @param securityContext
+ * @param q query string
+ * @param ql query language
+ * @param v version
+ * @param context
+ * @param cutoff true if the number of results should be limited
+ * @param pageLength number of results per page
+ * @param pageIndex
+ * @param startPage
+ * @param cq collection query
+ * @return
+ */
// ref query parameter removed!
- @TRACE
- @Path("search")
- public Response buildQuery (@Context Locale locale,
+ // EM: change the HTTP method to from TRACE to GET
+ // EM: change path from search to query
+ @GET
+ @Path("query")
+ public Response serializeQuery (@Context Locale locale,
@Context SecurityContext securityContext, @QueryParam("q") String q,
@QueryParam("ql") String ql, @QueryParam("v") String v,
@QueryParam("context") String context,
@@ -348,7 +365,7 @@
ss.setMeta(meta.raw());
String result = ss.toJSON();
- jlog.debug("Query result: "+result);
+ jlog.debug("Query: "+result);
return Response.ok(result).build();
}
@@ -369,9 +386,15 @@
// todo: does cq have any sensible worth here? --> would say no! --> is
// useful in non type/id scenarios
- @TRACE
- @Path("{type}/{id}/search")
- public Response buildQueryWithId (@Context Locale locale,
+
+ /* EM: potentially an unused service! */
+ // EM: build query using the given virtual collection id
+ // EM: change the HTTP method to from TRACE to GET
+ // EM: change path from search to query
+ // EM: there is no need to check resource licenses since the service just serialize a query serialization
+ @GET
+ @Path("{type}/{id}/query")
+ public Response serializeQueryWithResource (@Context Locale locale,
@Context SecurityContext securityContext, @QueryParam("q") String q,
@QueryParam("ql") String ql, @QueryParam("v") String v,
@QueryParam("context") String context,
@@ -404,32 +427,9 @@
cquery.setBaseQuery(ss.toJSON());
String query = "";
- KustvaktResource resource;
- try {
-
- if (ctx.isDemo()) {
- Set set = ResourceFinder.searchPublicFiltered(
- ResourceFactory.getResourceClass(type), id);
- resource = (KustvaktResource) set.toArray()[0];
- }
- else {
- User user = controller.getUser(ctx.getUsername());
- if (StringUtils.isInteger(id))
- resource = this.resourceHandler
- .findbyIntId(Integer.valueOf(id), user);
- else
- resource = this.resourceHandler.findbyStrId(id, user,
- ResourceFactory.getResourceClass(type));
- }
- }
- // todo: instead of throwing exception, build notification and rewrites
- // into result query
- catch (KustvaktException e) {
- jlog.error("Exception encountered: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
- }
-
- if (resource != null) {
+ // EM: is this necessary at all?
+ KustvaktResource resource = isCollectionIdValid(ctx.getName(), id);
+ if (resource!=null){
if (resource instanceof VirtualCollection) {
JsonNode node = cquery.and().mergeWith(resource.getData());
query = JsonUtils.toJSON(node);
@@ -440,9 +440,43 @@
query = cquery.toJSON();
}
}
+
+ jlog.debug("Query: "+query);
return Response.ok(query).build();
}
+ // EM: prototype
+ private KustvaktResource isCollectionIdValid (String username, String collectionId) {
+
+// try {
+// if (ctx.isDemo()) {
+// // EM: FIX ME: Is there public VCs? set default username
+ // for nonlogin user, change demo?
+// Set set = ResourceFinder.searchPublicFiltered(
+// ResourceFactory.getResourceClass(type), id);
+// resource = (KustvaktResource) set.toArray()[0];
+// }
+// else {
+// // EM: FIX ME: search in user VC
+// User user = controller.getUser(ctx.getUsername());
+// if (StringUtils.isInteger(id))
+// resource = this.resourceHandler
+// .findbyIntId(Integer.valueOf(id), user);
+// else
+// resource = this.resourceHandler.findbyStrId(id, user,
+// ResourceFactory.getResourceClass(type));
+// }
+// }
+// // todo: instead of throwing exception, build notification and rewrites
+// // into result query
+// catch (KustvaktException e) {
+// jlog.error("Exception encountered: {}", e.string());
+// throw KustvaktResponseHandler.throwit(e);
+// }
+
+ return null;
+ }
+
@POST
@Path("search")
@@ -718,24 +752,34 @@
}
}
-
- @POST
- @Path("stats")
- public Response getStats (@Context SecurityContext context,
- @Context Locale locale, String json) {
+ // EM: changed method POST to GET
+ @GET
+ @Path("statistics")
+ public Response getStatistics (@Context SecurityContext context,
+ @Context Locale locale, @QueryParam("collectionQuery")
+ String collectionQuery) {
+
+ if (collectionQuery == null || collectionQuery.isEmpty()){
+ throw KustvaktResponseHandler.throwit(new KustvaktException(
+ StatusCodes.MISSING_ARGUMENT, "Parameter collectionQuery is missing.",
+ "collectionQuery"));
+ }
+
+
KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
- builder.with(json);
- String stats = searchKrill.getStatistics(builder.toJSON());
-
+ builder.with(collectionQuery);
+ String json = builder.toJSON();
+
+ String stats = searchKrill.getStatistics(json);
if (stats.contains("-1"))
throw KustvaktResponseHandler.throwit(StatusCodes.NO_VALUE_FOUND);
-
+ jlog.debug("Stats: "+stats);
return Response.ok(stats).build();
}
-
+ // EM: what is child?
@GET
- @Path("{type}/{id}/{child}/stats")
+ @Path("{type}/{id}/{child}/statistics")
public Response getStatisticsbyIdChild (@Context SecurityContext context,
@Context Locale locale, @PathParam("type") String type,
@PathParam("id") String id, @PathParam("child") String child) {
@@ -948,32 +992,32 @@
KoralCollectionQueryBuilder cquery = new KoralCollectionQueryBuilder();
cquery.setBaseQuery(base);
- cachetmp = ResourceFactory.getCachedCollection(cquery.toJSON());
+ try {
+ cachetmp = ResourceFactory.getCachedCollection(cquery.toJSON());
- // see if collection was cached!
- VirtualCollection tmp = resourceHandler.getCache(cachetmp.getId(),
- VirtualCollection.class);
- // if not cached, fill with stats values
- if (tmp == null) {
- String stats = searchKrill.getStatistics(cquery.toJSON());
- cachetmp.setStats(JsonUtils.readSimple(stats, Map.class));
- }
-
- if (!cache) {
- collection = ResourceFactory.getPermanentCollection(cachetmp,
- name, description);
- vals = collection.toMap();
- try {
- resourceHandler.storeResources(user, collection);
+ // see if collection was cached!
+ VirtualCollection tmp = resourceHandler.getCache(cachetmp.getId(),
+ VirtualCollection.class);
+ // if not cached, fill with stats values
+ if (tmp == null) {
+ String stats = searchKrill.getStatistics(cquery.toJSON());
+ cachetmp.setStats(JsonUtils.readSimple(stats, Map.class));
}
- catch (KustvaktException e) {
- jlog.error("Exception encountered: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+
+ if (!cache) {
+ collection = ResourceFactory.getPermanentCollection(cachetmp,
+ name, description);
+ vals = collection.toMap();
+ resourceHandler.storeResources(user, collection);
}
+ else {
+ resourceHandler.cache(cachetmp);
+ vals = cachetmp.toMap();
+ }
+
}
- else {
- resourceHandler.cache(cachetmp);
- vals = cachetmp.toMap();
+ catch (KustvaktException e) {
+ throw KustvaktResponseHandler.throwit(e);
}
}
return Response.ok(JsonUtils.toJSON(vals)).build();
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java b/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
index c9785f4..a422904 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
@@ -20,12 +20,15 @@
import org.slf4j.LoggerFactory;
import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.UriBuilder;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
/**
@@ -274,22 +277,39 @@
}
- //todo: switch to new serialization
- @POST
- @Path("stats")
- public Response getStats (String json) {
+// //todo: switch to new serialization
+// @POST
+// @Path("stats")
+// public Response getStats (String json) {
+// KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
+// builder.with(json);
+//
+// // todo: policy override in extension!
+// String stats = searchKrill.getStatistics(builder.toJSON());
+// if (stats.contains("-1"))
+// throw KustvaktResponseHandler.throwit(StatusCodes.NO_VALUE_FOUND);
+//
+// return Response.ok(stats).build();
+// }
+
+ @GET
+ @Path("statistics")
+ public Response getStatistics (@QueryParam("collectionQuery")
+ String collectionQuery) {
+
KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
- builder.with(json);
-
- // todo: policy override in extension!
- String stats = searchKrill.getStatistics(builder.toJSON());
+ builder.with(collectionQuery);
+ String json = builder.toJSON();
+
+ String stats = searchKrill.getStatistics(json);
if (stats.contains("-1"))
throw KustvaktResponseHandler.throwit(StatusCodes.NO_VALUE_FOUND);
-
+ jlog.debug("Stats: "+stats);
return Response.ok(stats).build();
}
+
/*
* TODO: The problem here is, that the matchinfo path makes no
* distinction between docs and texts - unlike DeReKo, the backend
diff --git a/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java b/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
index 086336b..44fb085 100644
--- a/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
+++ b/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
@@ -40,7 +40,6 @@
return new WebApplicationException(s);
}
-
public static WebApplicationException throwit (int code) {
return new WebApplicationException(Response.status(getStatus(code))
.entity(buildNotification(code, "", "")).build());
@@ -53,7 +52,11 @@
.entity(buildNotification(code, message, entity)).build());
}
-
+ public static WebApplicationException throwit (int code, String notification) {
+ return new WebApplicationException(Response.status(getStatus(code))
+ .entity(notification).build());
+ }
+
private static String buildNotification (KustvaktException e) {
register(e.getRecords());
return buildNotification(e.getStatusCode(), e.getMessage(),
diff --git a/src/test/java/LocalQueryTest.java b/src/test/java/LocalQueryTest.java
index 0f9d007..ae0e494 100644
--- a/src/test/java/LocalQueryTest.java
+++ b/src/test/java/LocalQueryTest.java
@@ -73,7 +73,7 @@
@Override
public void initMethod () throws KustvaktException {
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
index = helper().getContext().getConfiguration().getIndexDir();
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java b/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java
index 4407fb6..0d24bcc 100644
--- a/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java
+++ b/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java
@@ -46,7 +46,6 @@
BeansFactory.closeApplication();
}
-
public abstract void initMethod () throws KustvaktException;
diff --git a/src/test/java/de/ids_mannheim/korap/config/CollectionLoaderTest.java b/src/test/java/de/ids_mannheim/korap/config/CollectionLoaderTest.java
index 6f0ee8b..82af51b 100644
--- a/src/test/java/de/ids_mannheim/korap/config/CollectionLoaderTest.java
+++ b/src/test/java/de/ids_mannheim/korap/config/CollectionLoaderTest.java
@@ -5,12 +5,15 @@
import de.ids_mannheim.korap.web.service.CollectionLoader;
import de.ids_mannheim.korap.web.service.UserLoader;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
/**
* @author hanl
* @date 11/02/2016
*/
+@Deprecated
+@Ignore
public class CollectionLoaderTest extends BeanConfigTest {
@Test
diff --git a/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java b/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
index 390ae00..eabb0a3 100644
--- a/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
+++ b/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
@@ -83,8 +83,8 @@
@Test
- public void testBootConfigRun () {
- helper().runBootInterfaces();
+ public void testBootConfigRun () throws KustvaktException {
+// helper().runBootInterfaces();
helper().setupAccount();
assertNotNull(helper().getUser());
diff --git a/src/test/java/de/ids_mannheim/korap/config/LoaderTest.java b/src/test/java/de/ids_mannheim/korap/config/LoaderTest.java
index 192c561..009a4c0 100644
--- a/src/test/java/de/ids_mannheim/korap/config/LoaderTest.java
+++ b/src/test/java/de/ids_mannheim/korap/config/LoaderTest.java
@@ -38,6 +38,8 @@
@Test
+ @Ignore
+ @Deprecated
public void runBootInterfaces () {
Set<Class<? extends BootableBeanInterface>> set = new HashSet<>();
set.add(CollectionLoader.class);
diff --git a/src/test/java/de/ids_mannheim/korap/config/PolicyLoaderTest.java b/src/test/java/de/ids_mannheim/korap/config/PolicyLoaderTest.java
index 3d3f8f7..32660bc 100644
--- a/src/test/java/de/ids_mannheim/korap/config/PolicyLoaderTest.java
+++ b/src/test/java/de/ids_mannheim/korap/config/PolicyLoaderTest.java
@@ -10,13 +10,17 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
+import org.junit.Ignore;
+
/**
* @author hanl
* @date 11/02/2016
*/
+@Deprecated
public class PolicyLoaderTest extends BeanConfigTest {
@Test
+ @Ignore
public void testPolicyLoader () {
boolean error = false;
UserLoader u = new UserLoader();
diff --git a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
index 3698e9c..8c71eae 100644
--- a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
+++ b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
@@ -113,11 +113,11 @@
}
- public TestHelper setupAccount () {
+ public TestHelper setupAccount () throws KustvaktException {
KustvaktBaseDaoInterface dao = getBean(ContextHolder.KUSTVAKT_USERDB);
KustvaktAuthenticationManager manager = getBean(ContextHolder.KUSTVAKT_AUTHENTICATION_MANAGER);
-
+// manager.createUserAccount(KustvaktConfiguration.KUSTVAKT_USER, false);
try {
User user = getUser();
jlog.debug("found user, skipping setup ...");
@@ -247,6 +247,7 @@
}
+ @Deprecated
public TestHelper runBootInterfaces () {
Set<Class<? extends BootableBeanInterface>> set = KustvaktClassLoader
.loadSubTypes(BootableBeanInterface.class);
diff --git a/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java b/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
index 02bfe4a..f21e305 100644
--- a/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
+++ b/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
@@ -38,7 +38,7 @@
@Override
public void initMethod () {
- helper().setupAccount();
+// helper().setupAccount();
List<Class<? extends KustvaktResource>> classes = new ArrayList<>(
KustvaktClassLoader.loadSubTypes(KustvaktResource.class));
diff --git a/src/test/java/de/ids_mannheim/korap/handlers/UserDaoTest.java b/src/test/java/de/ids_mannheim/korap/handlers/UserDaoTest.java
index 8e0616e..855383f 100644
--- a/src/test/java/de/ids_mannheim/korap/handlers/UserDaoTest.java
+++ b/src/test/java/de/ids_mannheim/korap/handlers/UserDaoTest.java
@@ -110,6 +110,6 @@
@Override
public void initMethod () throws KustvaktException {
helper().setupAccount();
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java
index 90e37eb..fe35d64 100644
--- a/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java
+++ b/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java
@@ -27,7 +27,7 @@
@Override
public void initMethod () throws KustvaktException {
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
config = helper().getContext().getConfiguration();
}
@@ -215,7 +215,7 @@
public void testPublicCollectionRewriteEmptyAdd () throws KustvaktException {
RewriteHandler handler = new RewriteHandler();
handler.insertBeans(helper().getContext());
- handler.add(PublicCollection.class);
+ handler.add(CollectionRewrite.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
@@ -223,12 +223,14 @@
JsonNode node = JsonUtils.readTree(handler.processQuery(org,
User.UserFactory.getUser("test_user")));
assertNotNull(node);
- assertEquals("corpusSigle", node.at("/collection/operands/0/key")
+ assertEquals("availability", node.at("/collection/key")
.asText());
- assertEquals("corpusSigle", node.at("/collection/operands/1/key")
+ assertEquals("CC-BY.*", node.at("/collection/value")
.asText());
assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type")
.asText());
+ assertEquals("availability(FREE)", node.at("/collection/rewrites/0/scope")
+ .asText());
//todo:
}
@@ -238,7 +240,7 @@
throws KustvaktException {
RewriteHandler handler = new RewriteHandler();
handler.insertBeans(helper().getContext());
- handler.add(PublicCollection.class);
+ handler.add(CollectionRewrite.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
@@ -248,12 +250,18 @@
User.UserFactory.getUser("test_user")));
assertNotNull(node);
assertEquals(2, node.at("/collection/operands").size());
- assertEquals("corpusSigle",
+ assertEquals("availability",
+ node.at("/collection/operands/0/key").asText());
+ assertEquals("CC-BY.*",
+ node.at("/collection/operands/0/value").asText());
+ assertEquals("docSigle",
node.at("/collection/operands/1/operands/0/key").asText());
- assertEquals("corpusSigle",
+ assertEquals("textClass",
node.at("/collection/operands/1/operands/1/key").asText());
assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type")
.asText());
+ assertEquals("availability(FREE)", node.at("/collection/rewrites/0/scope")
+ .asText());
}
diff --git a/src/test/java/de/ids_mannheim/korap/security/PolicyDaoTest.java b/src/test/java/de/ids_mannheim/korap/security/PolicyDaoTest.java
index 8c2a00d..98895ae 100644
--- a/src/test/java/de/ids_mannheim/korap/security/PolicyDaoTest.java
+++ b/src/test/java/de/ids_mannheim/korap/security/PolicyDaoTest.java
@@ -21,17 +21,19 @@
import static org.junit.Assert.*;
-/**
+/** EM: needs reimplementation
+ *
* @author hanl
* @date 09/02/2016
*/
+@Ignore
public class PolicyDaoTest extends BeanConfigTest {
@Override
public void initMethod () throws KustvaktException {
helper().setupAccount();
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
helper().setupResource(new Corpus("WPD_1"));
}
@@ -181,6 +183,8 @@
@Test
+ @Deprecated
+ @Ignore
public void testPoliciesPublic () {
PolicyHandlerIface dao = helper().getContext().getPolicyDbProvider();
Collection<SecurityPolicy> policies = dao.getPolicies(
diff --git a/src/test/java/de/ids_mannheim/korap/security/ResourceFinderTest.java b/src/test/java/de/ids_mannheim/korap/security/ResourceFinderTest.java
index ce7be2b..a96378d 100644
--- a/src/test/java/de/ids_mannheim/korap/security/ResourceFinderTest.java
+++ b/src/test/java/de/ids_mannheim/korap/security/ResourceFinderTest.java
@@ -5,6 +5,8 @@
import de.ids_mannheim.korap.resources.Corpus;
import de.ids_mannheim.korap.resources.VirtualCollection;
import de.ids_mannheim.korap.security.ac.ResourceFinder;
+
+import org.junit.Ignore;
import org.junit.Test;
import java.util.Set;
@@ -17,6 +19,8 @@
* @author hanl
* @date 06/02/2016
*/
+@Deprecated
+@Ignore
public class ResourceFinderTest extends BeanConfigTest {
@Test
@@ -36,6 +40,7 @@
@Test
+ @Deprecated
public void testResourcesDemoFiltered () throws KustvaktException {
Set<Corpus> resources = ResourceFinder.searchPublicFiltered(
Corpus.class, "WPD13");
@@ -52,6 +57,6 @@
@Override
public void initMethod () throws KustvaktException {
helper().setupAccount();
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/security/ResourcesTest.java b/src/test/java/de/ids_mannheim/korap/security/ResourcesTest.java
index 677f167..dd90bb0 100644
--- a/src/test/java/de/ids_mannheim/korap/security/ResourcesTest.java
+++ b/src/test/java/de/ids_mannheim/korap/security/ResourcesTest.java
@@ -108,6 +108,8 @@
@Test
+ @Deprecated
+ @Ignore
public void getDemoResources () throws KustvaktException {
Set s = ResourceFinder.searchPublic(Corpus.class);
assertEquals(2, s.size());
@@ -117,6 +119,8 @@
@Test
+ @Deprecated
+ @Ignore
public void getDemoResourceFiltered () throws KustvaktException {
Set s = ResourceFinder.searchPublicFiltered(Corpus.class, "WPD13");
assertEquals(1, s.size());
@@ -127,7 +131,7 @@
public void initMethod () throws KustvaktException {
helper().setupAccount();
c1 = new Corpus("WPD_test");
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
helper().setupResource(c1);
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/security/SecurityPolicyTest.java b/src/test/java/de/ids_mannheim/korap/security/SecurityPolicyTest.java
index 0235e81..cd3a32b 100644
--- a/src/test/java/de/ids_mannheim/korap/security/SecurityPolicyTest.java
+++ b/src/test/java/de/ids_mannheim/korap/security/SecurityPolicyTest.java
@@ -142,7 +142,7 @@
@Override
public void initMethod () throws KustvaktException {
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
helper().setupAccount();
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktCoreRestTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktCoreRestTest.java
index 4c2b8fa..0cf4dcc 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktCoreRestTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktCoreRestTest.java
@@ -1,17 +1,14 @@
package de.ids_mannheim.korap.web.service.full;
-import com.sun.jersey.api.client.ClientResponse;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor;
-import de.ids_mannheim.korap.query.serialize.QuerySerializer;
-import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import com.sun.jersey.api.client.ClientResponse;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.query.serialize.QuerySerializer;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
/**
* @author hanl
@@ -21,8 +18,8 @@
@Override
public void initMethod () throws KustvaktException {
-// helper().setupAccount();
- helper().runBootInterfaces();
+ helper().setupAccount();
+// helper().runBootInterfaces();
}
@BeforeClass
@@ -75,35 +72,7 @@
ClientResponse response = resource().path(getAPIVersion()).get(
ClientResponse.class);
}
-
-
- // @Test
- public void testGetStatsThrowsNoException () {
- CollectionQueryProcessor pr = new CollectionQueryProcessor();
- pr.process("corpusSigle=WPD & textClass=Sport");
- Map map = new LinkedHashMap();
- map.put("collection", pr.getRequestMap());
- ClientResponse response = resource().path(getAPIVersion())
- .path("stats")
- .post(ClientResponse.class, JsonUtils.toJSON(map));
- assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
- }
-
-
- @Test
- @Ignore
- public void testGetStats2ThrowsNoException () {
- ClientResponse response = resource().path(getAPIVersion())
- .path("stats")
- .post(ClientResponse.class, "creationDate in 1787");
- String ent = response.getEntity(String.class);
- assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
- // System.out
- // .println("___________________________________________________");
- // System.out.println("STATS ENTITY " + ent);
- }
-
-
+
// @Test
public void testBuildQueryThrowsNoException () {
ClientResponse response = resource().path(getAPIVersion())
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktServerTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktServerTest.java
index a5002c9..6a5674d 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktServerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktServerTest.java
@@ -5,27 +5,12 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.security.KeyManagementException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-import java.util.List;
import java.util.UUID;
-import javax.net.ssl.SSLContext;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
@@ -37,20 +22,13 @@
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
-import org.apache.http.config.Registry;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.conn.ssl.SSLContexts;
-import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.io.Files;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.core.util.MultivaluedMapImpl;
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
index 0153e44..170ab18 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
@@ -124,6 +124,6 @@
@Override
public void initMethod () throws KustvaktException {
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/PolicyServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/PolicyServiceTest.java
index c48f40c..ecff17b 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/PolicyServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/PolicyServiceTest.java
@@ -28,7 +28,7 @@
import de.ids_mannheim.korap.user.User.UserFactory;
import de.ids_mannheim.korap.web.service.FastJerseyTest;
-/**
+/** FIX ME: Database restructure
* @author margaretha
*/
public class PolicyServiceTest extends FastJerseyTest {
@@ -171,7 +171,7 @@
@Override
public void initMethod () throws KustvaktException {
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
index fe8c672..f735063 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
@@ -2,7 +2,7 @@
/**
* @author hanl, margaretha
* @lastUpdate 19/04/2017
- *
+ * EM: FIX ME: Database restructure
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -12,6 +12,7 @@
import java.util.Iterator;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
@@ -23,11 +24,14 @@
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.service.FastJerseyTest;
+/* EM: potentially an unused service! */
+
+@Ignore
public class QuerySerializationServiceTest extends FastJerseyTest {
@Override
public void initMethod () throws KustvaktException {
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
}
@@ -42,11 +46,11 @@
public void testQuerySerializationFilteredPublic () {
ClientResponse response = resource()
.path(getAPIVersion())
- .path("corpus/WPD13/search")
+ .path("corpus/WPD13/query")
.queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp")
.queryParam("context", "base/s:s")
- .method("TRACE", ClientResponse.class);
+ .method("GET", ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
String ent = response.getEntity(String.class);
@@ -62,11 +66,11 @@
public void testQuerySerializationUnexistingResource () {
ClientResponse response = resource()
.path(getAPIVersion())
- .path("corpus/ZUW19/search")
+ .path("corpus/ZUW19/query")
.queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp")
.queryParam("context", "base/s:s")
- .method("TRACE", ClientResponse.class);
+ .method("GET", ClientResponse.class);
assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
String ent = response.getEntity(String.class);
@@ -80,11 +84,11 @@
public void testQuerySerializationWithNonPublicCorpus () {
ClientResponse response = resource()
.path(getAPIVersion())
- .path("corpus/BRZ10/search")
+ .path("corpus/BRZ10/query")
.queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp")
.queryParam("context", "base/s:s")
- .method("TRACE", ClientResponse.class);
+ .method("GET", ClientResponse.class);
assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
String ent = response.getEntity(String.class);
@@ -98,12 +102,12 @@
public void testQuerySerializationWithAuthentication () {
ClientResponse response = resource()
.path(getAPIVersion())
- .path("corpus/BRZ10/search")
+ .path("corpus/BRZ10/query")
.queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp")
.header(Attributes.AUTHORIZATION,
BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
- .method("TRACE", ClientResponse.class);
+ .method("GET", ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
String ent = response.getEntity(String.class);
@@ -165,13 +169,13 @@
.path(getAPIVersion())
.path("collection")
.path(id)
- .path("search")
+ .path("query")
.queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp")
.queryParam("context", "base/s:s")
.header(Attributes.AUTHORIZATION,
BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
- .method("TRACE", ClientResponse.class);
+ .method("GET", ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
ent = response.getEntity(String.class);
@@ -204,11 +208,11 @@
public void testQuerySerializationOfVirtualCollection () {
ClientResponse response = resource()
.path(getAPIVersion())
- .path("collection/GOE-VC/search")
+ .path("collection/GOE-VC/query")
.queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp")
.queryParam("context", "base/s:s")
- .method("TRACE", ClientResponse.class);
+ .method("GET", ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
String ent = response.getEntity(String.class);
@@ -229,13 +233,14 @@
public void testMetaQuerySerialization () {
ClientResponse response = resource()
.path(getAPIVersion())
- .path("search")
+ .path("query")
.queryParam("context", "sentence")
.queryParam("count", "20")
.queryParam("page", "5")
+ .queryParam("cutoff", "true")
.queryParam("q", "[pos=ADJA]")
.queryParam("ql", "poliqarp")
- .method("TRACE", ClientResponse.class);
+ .method("GET", ClientResponse.class);
assertEquals(response.getStatus(),
ClientResponse.Status.OK.getStatusCode());
@@ -244,8 +249,38 @@
assertEquals("sentence", node.at("/meta/context").asText());
assertEquals(20, node.at("/meta/count").asInt());
- assertEquals(5, node.at("/meta/startPage").asInt());
+ assertEquals(5, node.at("/meta/startPage").asInt());
+ assertEquals(true, node.at("/meta/cutOff").asBoolean());
+
+ assertEquals("koral:term", node.at("/query/wrap/@type").asText());
+ assertEquals("pos", node.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", node.at("/query/wrap/match").asText());
+ assertEquals("ADJA", node.at("/query/wrap/key").asText());
}
+ @Test
+ public void testMetaQuerySerializationWithOffset () {
+ ClientResponse response = resource()
+ .path(getAPIVersion())
+ .path("query")
+ .queryParam("context", "sentence")
+ .queryParam("count", "20")
+ .queryParam("page", "5")
+ .queryParam("offset", "2")
+ .queryParam("cutoff", "true")
+ .queryParam("q", "[pos=ADJA]")
+ .queryParam("ql", "poliqarp")
+ .method("GET", ClientResponse.class);
+ assertEquals(response.getStatus(),
+ ClientResponse.Status.OK.getStatusCode());
+
+ String ent = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(ent);
+
+ assertEquals("sentence", node.at("/meta/context").asText());
+ assertEquals(20, node.at("/meta/count").asInt());
+ assertEquals(2, node.at("/meta/startIndex").asInt());
+ assertEquals(true, node.at("/meta/cutOff").asBoolean());
+ }
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
index d31d91c..c6b7135 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
@@ -19,13 +19,13 @@
/**
* @author hanl, margaretha
* @lastUpdate 19/04/2017
- *
+ * EM: FIX ME: Database restructure
*/
public class ResourceInfoServiceTest extends FastJerseyTest {
@Override
public void initMethod () throws KustvaktException {
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
index 4cdce89..b55fa73 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
@@ -381,6 +381,6 @@
@Override
public void initMethod () throws KustvaktException {
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
index 5fb8e45..e155bde 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
@@ -37,7 +37,8 @@
@Override
public void initMethod () throws KustvaktException {
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
+ helper().setupAccount();
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
index e8d169a..5dc44c2 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
@@ -20,7 +20,7 @@
@Override
public void initMethod () throws KustvaktException {
- helper().runBootInterfaces();
+// helper().runBootInterfaces();
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/StatisticsServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/StatisticsServiceTest.java
new file mode 100644
index 0000000..3252ed8
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/StatisticsServiceTest.java
@@ -0,0 +1,131 @@
+package de.ids_mannheim.korap.web.service.full;
+
+import java.io.IOException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sun.jersey.api.client.ClientResponse;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
+
+/**
+ * @author margaretha
+ * @date 29/06/2017
+ *
+ */
+public class StatisticsServiceTest extends FastJerseyTest {
+
+ private ObjectMapper mapper = new ObjectMapper();
+
+
+ @Override
+ public void initMethod () throws KustvaktException {
+
+ }
+
+ @BeforeClass
+ public static void configure () {
+// FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.light",
+ FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.full",
+ "de.ids_mannheim.korap.web.utils");
+ }
+
+ @Test
+ public void testGetStatisticsNoResource ()
+ throws JsonProcessingException, IOException {
+ String collectionQuery = "corpusSigle=WPD15";
+ ClientResponse response = resource().path(getAPIVersion())
+ .path("statistics")
+ .queryParam("collectionQuery", collectionQuery)
+ .get(ClientResponse.class);
+
+ assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
+
+ String ent = response.getEntity(String.class);
+ JsonNode node = mapper.readTree(ent);
+ assertEquals(node.get("documents").asInt(),0);
+ assertEquals(node.get("tokens").asInt(),0);
+ }
+
+
+ @Test
+ public void testGetStatisticsWithCollectionQuery1 ()
+ throws JsonProcessingException, IOException {
+ String collectionQuery = "corpusSigle=GOE";
+ ClientResponse response = resource().path(getAPIVersion())
+ .path("statistics")
+ .queryParam("collectionQuery", collectionQuery)
+ .get(ClientResponse.class);
+
+ assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
+
+ String ent = response.getEntity(String.class);
+ JsonNode node = mapper.readTree(ent);
+ assertEquals(node.get("documents").asInt(),11);
+ assertEquals(node.get("tokens").asInt(),665842);
+ }
+
+
+ @Test
+ public void testGetStatisticsWithCollectionQuery2 ()
+ throws JsonProcessingException, IOException {
+ ClientResponse response = resource().path(getAPIVersion())
+ .path("statistics")
+ .queryParam("collectionQuery", "creationDate since 1810")
+ .get(ClientResponse.class);
+ String ent = response.getEntity(String.class);
+ JsonNode node = mapper.readTree(ent);
+ assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
+ assertEquals(node.get("documents").asInt(),7);
+ assertEquals(node.get("tokens").asInt(),279402);
+ // EM: why zero?
+ assertEquals(node.get("sentences").asInt(), 11047);
+ assertEquals(node.get("paragraphs").asInt(), 489);
+ }
+
+
+ @Test
+ public void testGetStatisticsWithWrongCollectionQuery ()
+ throws JsonProcessingException, IOException {
+ ClientResponse response = resource().path(getAPIVersion())
+ .path("statistics")
+ .queryParam("collectionQuery", "creationDate geq 1810")
+ .get(ClientResponse.class);
+
+ assert ClientResponse.Status.BAD_REQUEST.getStatusCode() == response
+ .getStatus();
+ String ent = response.getEntity(String.class);
+ JsonNode node = mapper.readTree(ent);
+ assertEquals(node.at("/errors/0/0").asInt(), 302);
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Could not parse query >>> (creationDate geq 1810) <<<.");
+ assertEquals(node.at("/errors/0/2").asText(),
+ "(creationDate geq 1810)");
+ }
+
+
+ @Test
+ public void testGetStatisticsWithWrongCollectionQuery2 ()
+ throws JsonProcessingException, IOException {
+ ClientResponse response = resource().path(getAPIVersion())
+ .path("statistics")
+ .queryParam("collectionQuery", "creationDate >= 1810")
+ .get(ClientResponse.class);
+
+ assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ response.getStatus());
+ String ent = response.getEntity(String.class);
+ JsonNode node = mapper.readTree(ent);
+ assertEquals(node.at("/errors/0/0").asInt(), 305);
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Operator >= is not acceptable.");
+ assertEquals(node.at("/errors/0/2").asText(), ">=");
+ }
+
+}