rewrite post processor; refactoring; tests
diff --git a/src/test/java/CollectionRewriteTest.java b/src/test/java/CollectionRewriteTest.java
index 2649d1e..995cdf7 100644
--- a/src/test/java/CollectionRewriteTest.java
+++ b/src/test/java/CollectionRewriteTest.java
@@ -5,9 +5,14 @@
import de.ids_mannheim.korap.resource.rewrite.CollectionCleanupFilter;
import de.ids_mannheim.korap.resource.rewrite.CollectionConstraint;
import de.ids_mannheim.korap.resource.rewrite.RewriteHandler;
+import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* @author hanl
@@ -22,7 +27,7 @@
@BeforeClass
public static void init() {
- BeanConfiguration.loadClasspathContext();
+ BeanConfiguration.loadClasspathContext("default-config.xml");
config = BeanConfiguration.getBeans().getConfiguration();
}
@@ -31,8 +36,19 @@
BeanConfiguration.closeApplication();
}
+ @Test
+ public void test2() {
+ Pattern p = Pattern.compile("([\\.\\w]+)\\((.+)\\)");
+ String cl = de.ids_mannheim.korap.security.ac.SecurityManager.class
+ .getCanonicalName();
+ Matcher m = p.matcher(cl);
+ System.out.println("FOUND SOMETHING?! " + m.find());
+ while (m.find())
+ System.out.println("group 1 " + m.group(1));
- // @Test
+ }
+
+ @Test
public void testCollectionNodeRemoveCorpusIdNoErrors() {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
@@ -40,12 +56,13 @@
s.setQuery(simple_add_query, "poliqarp");
s.setCollection("textClass=politik & corpusID=WPD");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+ JsonNode node = JsonUtils.readTree(
+ handler.preProcess(result, User.UserFactory.getUser("test_user")));
assert node != null;
assert node.at("/collection/operands").size() == 1;
}
- //@Test
+ @Test
public void testCollectionNodeRemoveAllCorpusIdNoErrors() {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
@@ -53,13 +70,14 @@
s.setQuery(simple_add_query, "poliqarp");
s.setCollection("corpusID=BRZ13 & corpusID=WPD");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.apply(result, null));
-
+ JsonNode node = JsonUtils.readTree(
+ handler.preProcess(result, User.UserFactory.getUser("test_user")));
+ System.out.println("RESULTING REWR NODE " + node);
assert node != null;
assert node.at("/collection/operands").size() == 0;
}
- //@Test
+ @Test
public void testCollectionNodeRemoveGroupedCorpusIdNoErrors() {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
@@ -68,8 +86,10 @@
s.setCollection(
"(corpusID=BRZ13 & textClass=Wissenschaft) & corpusID=WPD");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+ JsonNode node = JsonUtils.readTree(
+ handler.preProcess(result, User.UserFactory.getUser("test_user")));
+ System.out.println("COLLECTION NODE " + result);
assert node != null;
assert node.at("/collection/operands/0/@type").asText()
.equals("koral:docGroup");
@@ -78,7 +98,7 @@
}
//fixme: will probably fail when one doc groups are being refactored
- //@Test
+ @Test
public void testCollectionCleanEmptyDocGroupNoErrors() {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
@@ -88,7 +108,8 @@
s.setCollection(
"(corpusID=BRZ13 & corpusID=WPD) & textClass=Wissenschaft & textClass=Sport");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+ JsonNode node = JsonUtils.readTree(
+ handler.preProcess(result, User.UserFactory.getUser("test_user")));
assert node != null;
assert node.at("/collection/@type").asText().equals("koral:docGroup");
assert node.at("/collection/operands").size() == 2;
@@ -98,7 +119,7 @@
.equals("textClass");
}
- //@Test
+ @Test
public void testCollectionCleanMoveOneDocFromGroupUpNoErrors() {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
@@ -107,12 +128,13 @@
s.setQuery(simple_add_query, "poliqarp");
s.setCollection("(corpusID=BRZ13 & textClass=Wissenschaft)");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+ JsonNode node = JsonUtils.readTree(
+ handler.preProcess(result, User.UserFactory.getUser("test_user")));
assert node != null;
assert node.at("/collection/@type").asText().equals("koral:doc");
}
- //@Test
+ @Test
public void testCollectionCleanEmptyGroupAndMoveOneFromGroupUpNoErrors() {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
@@ -122,13 +144,15 @@
s.setCollection(
"(corpusID=BRZ13 & corpusID=WPD) & textClass=Wissenschaft");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+ JsonNode node = JsonUtils.readTree(
+ handler.preProcess(result, User.UserFactory.getUser("test_user")));
+
assert node != null;
assert node.at("/collection/@type").asText().equals("koral:doc");
assert node.at("/collection/key").asText().equals("textClass");
}
- //@Test
+ @Test
public void testCollectionRemoveAndMoveOneFromGroupUpNoErrors() {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
@@ -138,7 +162,8 @@
s.setCollection(
"(docID=random & textClass=Wissenschaft) & corpusID=WPD");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+ JsonNode node = JsonUtils.readTree(
+ handler.preProcess(result, User.UserFactory.getUser("test_user")));
System.out.println("original node " + result);
System.out.println("result node " + node);
assert node != null;
diff --git a/src/test/java/FoundryRewriteTest.java b/src/test/java/FoundryRewriteTest.java
index 6d23964..1a477d9 100644
--- a/src/test/java/FoundryRewriteTest.java
+++ b/src/test/java/FoundryRewriteTest.java
@@ -42,7 +42,7 @@
processor.add(FoundryInject.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(simple_add_query, "poliqarp");
- String result = processor.apply(s.toJSON(), null);
+ String result = processor.preProcess(s.toJSON(), null);
JsonNode node = JsonUtils.readTree(result);
assert node != null;
@@ -66,7 +66,7 @@
RewriteHandler handler = new RewriteHandler(config);
s.setQuery("[pos=ADJA]", "poliqarp");
assert handler.add(FoundryInject.class);
- String result = handler.apply(s.toJSON(), null);
+ String result = handler.preProcess(s.toJSON(), null);
JsonNode node = JsonUtils.readTree(result);
assert node != null;
@@ -82,7 +82,7 @@
RewriteHandler handler = new RewriteHandler(config);
s.setQuery("[orth=laufe/i & base!=Lauf]", "poliqarp");
assert handler.add(FoundryInject.class);
- String result = handler.apply(s.toJSON(), null);
+ String result = handler.preProcess(s.toJSON(), null);
JsonNode node = JsonUtils.readTree(result);
assert node != null;
@@ -99,7 +99,7 @@
RewriteHandler handler = new RewriteHandler(config);
s.setQuery("[(base=laufen | base=gehen) & tt/pos=VVFIN]", "poliqarp");
assert handler.add(FoundryInject.class);
- String result = handler.apply(s.toJSON(), null);
+ String result = handler.preProcess(s.toJSON(), null);
JsonNode node = JsonUtils.readTree(result);
assert node != null;
diff --git a/src/test/java/IdRewriteTest.java b/src/test/java/IdRewriteTest.java
index be37b7c..8415c2c 100644
--- a/src/test/java/IdRewriteTest.java
+++ b/src/test/java/IdRewriteTest.java
@@ -1,6 +1,9 @@
+import com.fasterxml.jackson.databind.JsonNode;
import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.query.serialize.QuerySerializer;
import de.ids_mannheim.korap.resource.rewrite.IdWriter;
import de.ids_mannheim.korap.resource.rewrite.RewriteHandler;
+import de.ids_mannheim.korap.utils.JsonUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -27,6 +30,15 @@
BeanConfiguration.getBeans().getConfiguration());
assert handler.add(IdWriter.class);
+ String query = "[surface=Wort]";
+ QuerySerializer s = new QuerySerializer();
+ s.setQuery(query, "poliqarp");
+
+ String value = handler.preProcess(s.toJSON(), null);
+ JsonNode result = JsonUtils.readTree(value);
+
+ assert result != null;
+ assert result.path("query").has("idn");
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java b/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java
index 1661263..7af97ea 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java
@@ -37,6 +37,7 @@
.queryParam("q", "[base=Wort]").queryParam("ql", "poliqarp")
.get(ClientResponse.class);
assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
+ System.out.println("RESPONSE IS " + response.getEntity(String.class));
}
@Test