refactoring
diff --git a/src/test/java/DemoUserTest.java b/src/test/java/DemoUserTest.java
new file mode 100644
index 0000000..1387ead
--- /dev/null
+++ b/src/test/java/DemoUserTest.java
@@ -0,0 +1,65 @@
+import com.sun.jersey.api.client.ClientResponse;
+import de.ids_mannheim.korap.config.BeansFactory;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 04/02/2016
+ */
+public class DemoUserTest extends FastJerseyTest {
+
+    @Override
+    public void initMethod () throws KustvaktException {
+        helper().setupAccount();
+        BeansFactory.setKustvaktContext(helper().getContext());
+    }
+
+
+    @BeforeClass
+    public static void setup () throws Exception {
+        FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.full",
+                "de.ids_mannheim.korap.web.filter",
+                "de.ids_mannheim.korap.web.utils");
+    }
+
+
+    @Test
+    public void testDemoCollectionGet () {
+        //        ClientResponse response = resource().path(getVersion())
+        //                .path("collection").path("i");
+    }
+
+
+    @Test
+    public void testDemoUserInfoGet () {
+
+    }
+
+
+    @Test
+    public void testDemoUserDetailsGet () {
+
+    }
+
+
+    @Test
+    public void testDemoUserSettingsGet () {
+
+    }
+
+
+    @Test
+    public void testSearch () {
+        ClientResponse response = resource().path(getAPIVersion())
+                .path("search").queryParam("q", "[base=Wort]")
+                .queryParam("ql", "poliqarp").get(ClientResponse.class);
+
+        System.out.println("_____________________________");
+        System.out.println(response);
+        System.out.println("entity " + response.getEntity(String.class));
+    }
+
+}
diff --git a/src/test/java/JerseyTest1.java b/src/test/java/JerseyTest1.java
new file mode 100644
index 0000000..dc0ca87
--- /dev/null
+++ b/src/test/java/JerseyTest1.java
@@ -0,0 +1,48 @@
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.test.framework.JerseyTest;
+import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
+import com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory;
+import de.ids_mannheim.korap.config.BeansFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 29/07/2015
+ */
+@Deprecated
+public class JerseyTest1 extends JerseyTest {
+
+    public JerseyTest1 () {
+        super("de.ids_mannheim.korap.web.service",
+                "de.ids_mannheim.korap.web.utils");
+    }
+
+
+    @BeforeClass
+    public static void setup () {
+        BeansFactory.loadClasspathContext();
+    }
+
+
+    @AfterClass
+    public static void close () {
+        BeansFactory.closeApplication();
+    }
+
+
+    @Override
+    protected TestContainerFactory getTestContainerFactory () {
+        return new GrizzlyWebTestContainerFactory();
+    }
+
+
+    @Test
+    public void testFieldsInSearch () {
+        ClientResponse response = resource().path("v0.1/search")
+                .queryParam("q", "[base=Wort]").queryParam("ql", "poliqarp")
+                .get(ClientResponse.class);
+        System.out.println("response " + response);
+    }
+}
diff --git a/src/test/java/KoralNodeTest.java b/src/test/java/KoralNodeTest.java
new file mode 100644
index 0000000..d8f5ab1
--- /dev/null
+++ b/src/test/java/KoralNodeTest.java
@@ -0,0 +1,48 @@
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import de.ids_mannheim.korap.resource.rewrite.KoralNode;
+import de.ids_mannheim.korap.utils.JsonUtils;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 21/10/2015
+ */
+public class KoralNodeTest {
+
+    // todo: 21.10.15 --> e.g. injection does not tell you if an entire node was injected, or just a value!
+    @Test
+    public void addToNode () {
+        ObjectNode node = JsonUtils.createObjectNode();
+        KoralNode knode = KoralNode.wrapNode(node);
+        knode.put("value_1", "setting_1");
+
+        System.out.println(knode.rawNode().toString());
+    }
+
+
+    @Test
+    public void removeFromNode () {
+        ObjectNode node = JsonUtils.createObjectNode();
+        node.put("value_1", "setting_1");
+        KoralNode knode = KoralNode.wrapNode(node);
+        knode.remove("value_1");
+        System.out.println(knode.rawNode().toString());
+    }
+
+
+    @Test
+    public void replaceObject () {
+        ObjectNode node = JsonUtils.createObjectNode();
+        node.put("value_1", "setting_1");
+        KoralNode knode = KoralNode.wrapNode(node);
+        knode.replace("value_1", "settings_2");
+        System.out.println(knode.rawNode().toString());
+    }
+
+
+    // todo: 21.10.15 --> if a node is injected, that node must contain a "rewrites" reference?!
+    @Test
+    public void addNodeToKoral () {
+
+    }
+}
diff --git a/src/test/java/LocalQueryTest.java b/src/test/java/LocalQueryTest.java
new file mode 100644
index 0000000..0f9d007
--- /dev/null
+++ b/src/test/java/LocalQueryTest.java
@@ -0,0 +1,79 @@
+import de.ids_mannheim.korap.KrillCollection;
+import de.ids_mannheim.korap.config.BeanConfigTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor;
+import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder;
+import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.web.SearchKrill;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+
+/**
+ * @author hanl
+ * @date 14/01/2016
+ */
+public class LocalQueryTest extends BeanConfigTest {
+
+    private static String index;
+    private static String qstring;
+
+
+    @BeforeClass
+    public static void setup () throws Exception {
+        qstring = "creationDate since 1786 & creationDate until 1788";
+        //        qstring = "creationDate since 1765 & creationDate until 1768";
+        //        qstring = "textType = Aphorismus";
+        //        qstring = "title ~ \"Werther\"";
+    }
+
+
+    @AfterClass
+    public static void drop () {}
+
+
+    @Test
+    public void testQuery () {
+        SearchKrill krill = new SearchKrill(index);
+        KoralCollectionQueryBuilder coll = new KoralCollectionQueryBuilder();
+        coll.with(qstring);
+        String stats = krill.getStatistics(coll.toJSON());
+        assert stats != null && !stats.isEmpty() && !stats.equals("null");
+    }
+
+
+    @Test
+    public void testCollQuery () throws IOException {
+        CollectionQueryProcessor processor = new CollectionQueryProcessor();
+        processor.process(qstring);
+
+        String s = JsonUtils.toJSON(processor.getRequestMap());
+        KrillCollection c = new KrillCollection(s);
+        c.setIndex(new SearchKrill(index).getIndex());
+        long docs = c.numberOf("documents");
+        assert docs > 0 && docs < 15;
+    }
+
+
+    @Test
+    public void testCollQuery2 () throws IOException {
+        String query = "{\"@context\":\"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld\",\"errors\":[],\"warnings\":[],\"messages\":[],\"collection\":{\"@type\":\"koral:docGroup\",\"operation\":\"operation:and\",\"operands\":[{\"@type\":\"koral:doc\",\"key\":\"creationDate\",\"type\":\"type:date\",\"value\":\"1786\",\"match\":\"match:geq\"},{\"@type\":\"koral:doc\",\"key\":\"creationDate\",\"type\":\"type:date\",\"value\":\"1788\",\"match\":\"match:leq\"}]},\"query\":{},\"meta\":{}}";
+        KrillCollection c = new KrillCollection(query);
+        c.setIndex(new SearchKrill(index).getIndex());
+        long sent = c.numberOf("base/sentences");
+        long docs = c.numberOf("documents");
+    }
+
+
+    @Test
+    public void testQueryHash () {}
+
+
+    @Override
+    public void initMethod () throws KustvaktException {
+        helper().runBootInterfaces();
+        index = helper().getContext().getConfiguration().getIndexDir();
+    }
+}
diff --git a/src/test/java/MetaQueryBuilderTest.java b/src/test/java/MetaQueryBuilderTest.java
new file mode 100644
index 0000000..4bdbedc
--- /dev/null
+++ b/src/test/java/MetaQueryBuilderTest.java
@@ -0,0 +1,30 @@
+import de.ids_mannheim.korap.config.QueryBuilderUtil;
+import de.ids_mannheim.korap.query.serialize.MetaQueryBuilder;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Created by hanl on 17.04.16.
+ */
+public class MetaQueryBuilderTest {
+
+
+
+    @Test
+    public void testSpanContext () {
+        System.out.println("____________________-");
+        MetaQueryBuilder m = QueryBuilderUtil.defaultMetaBuilder(0, 1, 5,
+                "sentence", false);
+        Map map = m.raw();
+
+        assertEquals("sentence", map.get("context"));
+        assertEquals(1, map.get("startPage"));
+        assertEquals(0, map.get("startIndex"));
+        assertEquals(false, map.get("cufOff"));
+
+    }
+}
diff --git a/src/test/java/PublicAPITest.java b/src/test/java/PublicAPITest.java
new file mode 100644
index 0000000..1bc282b
--- /dev/null
+++ b/src/test/java/PublicAPITest.java
@@ -0,0 +1,42 @@
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Created by hanl on 17.04.16.
+ */
+public class PublicAPITest extends FastJerseyTest {
+
+
+    @BeforeClass
+    public static void setup () {
+        FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.light",
+                "de.ids_mannheim.korap.web.filter",
+                "de.ids_mannheim.korap.web.utils");
+    }
+
+
+    @Override
+    public void initMethod () throws KustvaktException {}
+
+
+    @Test
+    public void testContextSpanSent () {
+
+    }
+
+
+    @Test
+    public void testContextSpanPara () {
+
+    }
+
+
+    @Test
+    public void testSimpleSearch () {
+
+    }
+
+
+}
diff --git a/src/test/java/ScopesTest.java b/src/test/java/ScopesTest.java
new file mode 100644
index 0000000..af84402
--- /dev/null
+++ b/src/test/java/ScopesTest.java
@@ -0,0 +1,19 @@
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 20/01/2016
+ */
+public class ScopesTest {
+
+    @Test
+    public void testScopes () {
+
+    }
+
+
+    @Test
+    public void testOpenIDScopes () {
+
+    }
+}
diff --git a/src/test/java/SerializationTest.java b/src/test/java/SerializationTest.java
new file mode 100644
index 0000000..334982a
--- /dev/null
+++ b/src/test/java/SerializationTest.java
@@ -0,0 +1,21 @@
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 21/01/2016
+ */
+public class SerializationTest {
+
+    @Test
+    public void testSettingsObject () {
+        String t = "poliqarp_test";
+
+        //        UserSettings s = new UserSettings();
+        //        Map map = s.toObjectMap();
+        //        map.put(Attributes.QUERY_LANGUAGE, t);
+        //        s.updateObjectSettings(map);
+        //
+        //        assert s.getQueryLanguage().equals(t);
+
+    }
+}
diff --git a/src/test/java/ServiceSuite.java b/src/test/java/ServiceSuite.java
new file mode 100644
index 0000000..f13b776
--- /dev/null
+++ b/src/test/java/ServiceSuite.java
@@ -0,0 +1,11 @@
+import de.ids_mannheim.korap.config.ConfigTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author hanl
+ * @date 29/02/2016
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ ConfigTest.class })
+public class ServiceSuite {}
diff --git a/src/test/java/TestNullableSqls.java b/src/test/java/TestNullableSqls.java
new file mode 100644
index 0000000..a220233
--- /dev/null
+++ b/src/test/java/TestNullableSqls.java
@@ -0,0 +1,5 @@
+/**
+ * @author hanl
+ * @date 30/01/2016
+ */
+public class TestNullableSqls {}
diff --git a/src/test/java/TestUtil.java b/src/test/java/TestUtil.java
new file mode 100644
index 0000000..1fb3ce7
--- /dev/null
+++ b/src/test/java/TestUtil.java
@@ -0,0 +1,62 @@
+import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.utils.SqlBuilder;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 26/11/2015
+ */
+public class TestUtil {
+
+    @Test
+    public void testSqlBuilderSELECT () {
+        SqlBuilder b = new SqlBuilder("users");
+        b.select(Attributes.USERNAME, Attributes.PASSWORD).where(
+                Attributes.USERNAME + "=?");
+        Assert.assertEquals("query does not match",
+                "SELECT username, password FROM users WHERE username=?;",
+                b.toString());
+    }
+
+
+    @Test
+    public void testSqlBuilderINSERT () {
+        SqlBuilder b = new SqlBuilder("users");
+        b.insert(Attributes.USERNAME, Attributes.PASSWORD).params("user",
+                "pass");
+        Assert.assertEquals("query does not match",
+                "INSERT INTO users (username, password) VALUES (user, pass);",
+                b.toString());
+    }
+
+
+    @Test
+    public void testSqlBuilderINSERTExcludeWhere () {
+        SqlBuilder b = new SqlBuilder("users");
+        b.insert(Attributes.USERNAME, Attributes.PASSWORD)
+                .params("user", "pass").where("some=?");
+        Assert.assertEquals("query does not match",
+                "INSERT INTO users (username, password) VALUES (user, pass);",
+                b.toString());
+    }
+
+
+    @Test
+    public void testSqlBuilderDELETE () {
+        SqlBuilder b = new SqlBuilder("users");
+        b.delete().where(Attributes.PERSISTENT_ID + "=?");
+        Assert.assertEquals("query does not match",
+                "DELETE FROM users WHERE persistent_id=?;", b.toString());
+    }
+
+
+    @Test
+    public void testSqlBuilderUPDATE () {
+        SqlBuilder b = new SqlBuilder("users");
+        b.update(Attributes.USERNAME, Attributes.PASSWORD).params("user",
+                "pass");
+        Assert.assertEquals("query does not match",
+                "UPDATE users SET username=user, password=pass;", b.toString());
+    }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java b/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java
new file mode 100644
index 0000000..266b784
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/config/BeanConfigTest.java
@@ -0,0 +1,96 @@
+package de.ids_mannheim.korap.config;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import net.jcip.annotations.NotThreadSafe;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.model.InitializationError;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.annotation.PostConstruct;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * @author hanl
+ * @date 09/03/2016
+ */
+@NotThreadSafe
+@RunWith(BeanConfigTest.SpringExtendedSetupListener.class)
+@ContextConfiguration(classes = TestHelper.AppTestConfig.class)
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
+public abstract class BeanConfigTest {
+
+    @Autowired
+    private ApplicationContext context;
+
+
+    public void init () throws Exception {
+        assertNotNull("Application context must not be null!", this.context);
+        System.out.println("running one-time before init for class "
+                + this.getClass().getSimpleName() + " ...");
+        initMethod();
+        BeansFactory.setKustvaktContext(helper().getContext());
+    }
+
+
+    public void close () {
+        BeansFactory.closeApplication();
+    }
+
+
+    public abstract void initMethod () throws KustvaktException;
+
+
+    protected TestHelper helper () {
+        try {
+            return TestHelper.newInstance(this.context);
+        }
+        catch (Exception e) {
+            return null;
+        }
+    }
+
+
+    public static class SpringExtendedSetupListener extends
+            SpringJUnit4ClassRunner {
+
+        private BeanConfigTest instanceSetupListener;
+
+
+        public SpringExtendedSetupListener (Class<?> clazz)
+                throws InitializationError {
+            super(clazz);
+        }
+
+
+        @Override
+        protected Object createTest () throws Exception {
+            Object test = super.createTest();
+            // Note that JUnit4 will call this createTest() multiple times for each
+            // test method, so we need to ensure to call "beforeClassSetup" only once.
+            if (test instanceof BeanConfigTest && instanceSetupListener == null) {
+                instanceSetupListener = (BeanConfigTest) test;
+                instanceSetupListener.init();
+            }
+            return test;
+        }
+
+
+        @Override
+        public void run (RunNotifier notifier) {
+            super.run(notifier);
+            if (instanceSetupListener != null)
+                instanceSetupListener.close();
+        }
+
+
+    }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/config/EsapiTest.java b/src/test/java/de/ids_mannheim/korap/config/EsapiTest.java
new file mode 100644
index 0000000..5d26cd7
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/config/EsapiTest.java
@@ -0,0 +1,54 @@
+package de.ids_mannheim.korap.config;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.interfaces.EncryptionIface;
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author hanl
+ * @date 08/01/2016
+ */
+public class EsapiTest extends BeanConfigTest {
+
+    @Test
+    public void testInputPassword () throws KustvaktException {
+        String pass = TestHelper.getUserCredentials()[1];
+        EncryptionIface cr = helper().getContext().getEncryption();
+        String spass = cr.validateEntry(pass, Attributes.PASSWORD);
+        assertNotNull(spass);
+        assertFalse(spass.isEmpty());
+    }
+
+
+    @Test
+    public void testMapValidation () throws KustvaktException {
+        int exp_size = KustvaktConfiguration.KUSTVAKT_USER.size();
+        Map map = helper().getContext().getEncryption()
+                .validateMap(KustvaktConfiguration.KUSTVAKT_USER);
+        assertEquals(exp_size, map.size());
+    }
+
+
+    @Test
+    public void testUsernameValidation () throws KustvaktException {
+        String sus = helper()
+                .getContext()
+                .getEncryption()
+                .validateEntry(
+                        (String) KustvaktConfiguration.KUSTVAKT_USER
+                                .get(Attributes.USERNAME),
+                        Attributes.USERNAME);
+        assertNotNull(sus);
+        assertFalse(sus.isEmpty());
+    }
+
+
+    @Override
+    public void initMethod () throws KustvaktException {
+
+    }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/config/KustvaktResourceTest.java b/src/test/java/de/ids_mannheim/korap/config/KustvaktResourceTest.java
new file mode 100644
index 0000000..4222f88
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/config/KustvaktResourceTest.java
@@ -0,0 +1,31 @@
+package de.ids_mannheim.korap.config;
+
+import de.ids_mannheim.korap.resources.KustvaktResource;
+import de.ids_mannheim.korap.resources.VirtualCollection;
+
+/**
+ * @author hanl
+ * @date 11/02/2016
+ */
+public class KustvaktResourceTest {
+
+
+    public void testIDCreation () {
+        KustvaktResource resource = new VirtualCollection(1);
+        resource.addField("field_1", "data");
+
+    }
+
+
+    public void testNullableData () {
+
+    }
+
+
+    public void testWrongDataType () {
+
+    }
+
+
+
+}
diff --git a/src/test/java/de/ids_mannheim/korap/config/LoaderTest.java b/src/test/java/de/ids_mannheim/korap/config/LoaderTest.java
new file mode 100644
index 0000000..ce4de02
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/config/LoaderTest.java
@@ -0,0 +1,89 @@
+package de.ids_mannheim.korap.config;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.web.service.BootableBeanInterface;
+import de.ids_mannheim.korap.web.service.CollectionLoader;
+import de.ids_mannheim.korap.web.service.PolicyLoader;
+import de.ids_mannheim.korap.web.service.UserLoader;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+/**
+ * @author hanl
+ * @date 12/02/2016
+ */
+public class LoaderTest extends BeanConfigTest {
+
+    @Test
+    @Ignore
+    public void testConfigOrder () {
+        System.out.println("done ...");
+
+        List s = new ArrayList<>();
+        s.add("new");
+        s.add("new2");
+    }
+
+
+    @Override
+    public void initMethod () throws KustvaktException {}
+
+
+    @Test
+    public void runBootInterfaces () {
+        Set<Class<? extends BootableBeanInterface>> set = new HashSet<>();
+        set.add(CollectionLoader.class);
+        set.add(PolicyLoader.class);
+        set.add(UserLoader.class);
+
+        List<BootableBeanInterface> list = new ArrayList<>(set.size());
+        for (Class cl : set) {
+            BootableBeanInterface iface;
+            try {
+                iface = (BootableBeanInterface) cl.newInstance();
+                list.add(iface);
+            }
+            catch (InstantiationException | IllegalAccessException e) {
+                // do nothing
+            }
+        }
+        assertEquals(set.size(), list.size());
+        List tracer = new ArrayList();
+        System.out.println("Found boot loading interfaces: " + list);
+        while (!set.isEmpty()) {
+            out_loop: for (BootableBeanInterface iface : new ArrayList<>(list)) {
+                try {
+                    System.out.println("Running boot instructions from class "
+                            + iface.getClass().getSimpleName());
+                    for (Class cl : iface.getDependencies()) {
+                        if (set.contains(cl))
+                            continue out_loop;
+                    }
+                    set.remove(iface.getClass());
+                    list.remove(iface);
+                    iface.load(helper().getContext());
+                    tracer.add(iface.getClass());
+                }
+                catch (KustvaktException e) {
+                    // don't do anything!
+                    System.out.println("An error occurred in class "
+                            + iface.getClass().getSimpleName() + "!\n" + e);
+                    throw new RuntimeException(
+                            "Boot loading interface failed ...");
+                }
+            }
+        }
+        assertEquals(0, tracer.indexOf(UserLoader.class));
+        assertNotEquals(0, tracer.indexOf(CollectionLoader.class));
+        assertNotEquals(0, tracer.indexOf(PolicyLoader.class));
+    }
+
+}
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 4e4aa3f..fbf88c0 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
@@ -6,11 +6,9 @@
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.query.serialize.QuerySerializer;
 import de.ids_mannheim.korap.resources.Corpus;
-import de.ids_mannheim.korap.resources.KustvaktResource;
 import de.ids_mannheim.korap.security.ac.ResourceFinder;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.JsonUtils;
-import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.Set;
@@ -58,14 +56,19 @@
         handler.add(CollectionConstraint.class);
         QuerySerializer s = new QuerySerializer();
         s.setQuery(simple_add_query, "poliqarp");
-        s.setCollection("textClass=politik & corpusID=WPD");
+        s.setCollection("textClass=politik & corpusSigle=WPD");
         String result = s.toJSON();
-        JsonNode node = JsonUtils.readTree(handler.preProcess(result,
+        JsonNode node = JsonUtils.readTree(handler.process(result,
                 User.UserFactory.getUser("test_user")));
         assertNotNull(node);
         assertEquals(1, node.at("/collection/operands").size());
     }
 
+    @Test
+    public void testCollectionNodeDeletionNotification() {
+
+    }
+
 
     @Test
     public void testCollectionNodeRemoveAllCorpusIdNoErrors () {
@@ -74,9 +77,9 @@
         handler.add(CollectionConstraint.class);
         QuerySerializer s = new QuerySerializer();
         s.setQuery(simple_add_query, "poliqarp");
-        s.setCollection("corpusID=BRZ13 & corpusID=WPD");
+        s.setCollection("corpusSigle=BRZ13 & corpusSigle=WPD");
         String result = s.toJSON();
-        JsonNode node = JsonUtils.readTree(handler.preProcess(result,
+        JsonNode node = JsonUtils.readTree(handler.process(result,
                 User.UserFactory.getUser("test_user")));
         //        System.out.println("RESULTING REWR NODE " + node);
         assertNotNull(node);
@@ -91,9 +94,9 @@
         handler.add(CollectionConstraint.class);
         QuerySerializer s = new QuerySerializer();
         s.setQuery(simple_add_query, "poliqarp");
-        s.setCollection("(corpusID=BRZ13 & textClass=Wissenschaft) & corpusID=WPD");
+        s.setCollection("(corpusSigle=BRZ13 & textClass=Wissenschaft) & corpusSigle=WPD");
         String result = s.toJSON();
-        JsonNode node = JsonUtils.readTree(handler.preProcess(result,
+        JsonNode node = JsonUtils.readTree(handler.process(result,
                 User.UserFactory.getUser("test_user")));
 
         assertNotNull(node);
@@ -113,11 +116,13 @@
         handler.add(CollectionCleanupFilter.class);
         QuerySerializer s = new QuerySerializer();
         s.setQuery(simple_add_query, "poliqarp");
-        s.setCollection("(corpusID=BRZ13 & corpusID=WPD) & textClass=Wissenschaft & textClass=Sport");
+        s.setCollection("(corpusSigle=BRZ13 & corpusSigle=WPD) & textClass=Wissenschaft & textClass=Sport");
         String result = s.toJSON();
-        JsonNode node = JsonUtils.readTree(handler.preProcess(result,
+
+        JsonNode node = JsonUtils.readTree(handler.process(result,
                 User.UserFactory.getUser("test_user")));
 
+
         assertNotNull(node);
         assertEquals("koral:docGroup", node.at("/collection/@type").asText());
         assertEquals(2, node.at("/collection/operands").size());
@@ -137,9 +142,9 @@
         handler.add(CollectionCleanupFilter.class);
         QuerySerializer s = new QuerySerializer();
         s.setQuery(simple_add_query, "poliqarp");
-        s.setCollection("(corpusID=BRZ13 & textClass=Wissenschaft)");
+        s.setCollection("(corpusSigle=BRZ13 & textClass=Wissenschaft)");
         String result = s.toJSON();
-        JsonNode node = JsonUtils.readTree(handler.preProcess(result,
+        JsonNode node = JsonUtils.readTree(handler.process(result,
                 User.UserFactory.getUser("test_user")));
         assertNotNull(node);
         assertEquals("koral:doc", node.at("/collection/@type").asText());
@@ -154,9 +159,9 @@
         handler.add(CollectionCleanupFilter.class);
         QuerySerializer s = new QuerySerializer();
         s.setQuery(simple_add_query, "poliqarp");
-        s.setCollection("(corpusID=BRZ13 & corpusID=WPD) & textClass=Wissenschaft");
+        s.setCollection("(corpusSigle=BRZ13 & corpusSigle=WPD) & textClass=Wissenschaft");
         String result = s.toJSON();
-        JsonNode node = JsonUtils.readTree(handler.preProcess(result,
+        JsonNode node = JsonUtils.readTree(handler.process(result,
                 User.UserFactory.getUser("test_user")));
 
         assertNotNull(node);
@@ -173,11 +178,11 @@
         handler.add(CollectionCleanupFilter.class);
         QuerySerializer s = new QuerySerializer();
         s.setQuery(simple_add_query, "poliqarp");
-        s.setCollection("(docID=random & textClass=Wissenschaft) & corpusID=WPD");
+        s.setCollection("(docID=random & textClass=Wissenschaft) & corpusSigle=WPD");
         String org = s.toJSON();
-        JsonNode node = JsonUtils.readTree(handler.preProcess(org,
+        JsonNode node = JsonUtils.readTree(handler.process(org,
                 User.UserFactory.getUser("test_user")));
-
+        System.out.println(node);
         assertNotNull(node);
         assertEquals("koral:docGroup", node.at("/collection/@type").asText());
         assertEquals(2, node.at("/collection/operands").size());
@@ -195,10 +200,12 @@
         QuerySerializer s = new QuerySerializer();
         s.setQuery(simple_add_query, "poliqarp");
         String org = s.toJSON();
-        JsonNode node = JsonUtils.readTree(handler.preProcess(org,
+        JsonNode node = JsonUtils.readTree(handler.process(org,
                 User.UserFactory.getUser("test_user")));
         assertNotNull(node);
-        System.out.println("EMPTY " + node);
+        assertEquals("corpusSigle", node.at("/collection/operands/0/key").asText());
+        assertEquals("corpusSigle", node.at("/collection/operands/1/key").asText());
+        assertEquals("koral:rewrite", node.at("/collection/rewrites/@type").asText());
     }
 
 
@@ -214,11 +221,14 @@
             s.setQuery(simple_add_query, "poliqarp");
             s.setCollection("(docSigle=WPD_AAA & textClass=wissenschaft)");
             String org = s.toJSON();
-            JsonNode node = JsonUtils.readTree(handler.preProcess(org,
+            JsonNode node = JsonUtils.readTree(handler.process(org,
                     User.UserFactory.getUser("test_user")));
             assertNotNull(node);
-            System.out.println("NON EMPTY " + node);
-            Set<Corpus> resourceSet = ResourceFinder.searchPublic(Corpus.class);
+            assertEquals(2, node.at("/collection/operands").size());
+            assertEquals("corpusSigle", node.at("/collection/operands/1/operands/0/key").asText());
+            assertEquals("corpusSigle", node.at("/collection/operands/1/operands/1/key").asText());
+            assertEquals("koral:rewrite", node.at("/collection/rewrites/@type").asText());
+
         }
         catch (Exception e) {
             e.printStackTrace();
diff --git a/src/test/java/de/ids_mannheim/korap/resource/rewrite/FoundryRewriteTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/FoundryRewriteTest.java
index 032b9f7..92ef92c 100644
--- a/src/test/java/de/ids_mannheim/korap/resource/rewrite/FoundryRewriteTest.java
+++ b/src/test/java/de/ids_mannheim/korap/resource/rewrite/FoundryRewriteTest.java
@@ -21,7 +21,7 @@
  * @author hanl
  * @date 18/06/2015
  */
-//todo: refactor and structure tests
+//todo: check position and information of rewrites!
 public class FoundryRewriteTest extends BeanConfigTest {
 
     private static String simple_add_query = "[pos=ADJA]";
@@ -63,9 +63,10 @@
         processor.add(FoundryInject.class);
         QuerySerializer s = new QuerySerializer();
         s.setQuery("[base=Haus]", "poliqarp");
-        String result = processor.preProcess(s.toJSON(), null);
+        String result = processor.process(s.toJSON(), null);
         JsonNode node = JsonUtils.readTree(result);
 
+        System.out.println("REWRITTEN "+ node);
         assertNotNull(node);
         assertFalse(node.at("/query/wrap/foundry").isMissingNode());
         assertEquals(c.getDefault_lemma(), node.at("/query/wrap/foundry")
@@ -88,7 +89,7 @@
         handler.insertBeans(helper().getContext());
         s.setQuery("[pos=ADJA]", "poliqarp");
         assertTrue(handler.add(FoundryInject.class));
-        String result = handler.preProcess(s.toJSON(), null);
+        String result = handler.process(s.toJSON(), null);
         JsonNode node = JsonUtils.readTree(result);
 
         assertNotNull(node);
@@ -113,7 +114,7 @@
         handler.add(FoundryInject.class);
         QuerySerializer s = new QuerySerializer();
         s.setQuery("[pos=ADJA]", "poliqarp");
-        String result = handler.preProcess(s.toJSON(), user);
+        String result = handler.process(s.toJSON(), user);
         JsonNode node = JsonUtils.readTree(result);
 
         UserDataDbIface dao = BeansFactory.getTypeFactory().getTypedBean(
@@ -143,7 +144,7 @@
         handler.add(FoundryInject.class);
         QuerySerializer s = new QuerySerializer();
         s.setQuery("[base=Haus]", "poliqarp");
-        String result = handler.preProcess(s.toJSON(), user);
+        String result = handler.process(s.toJSON(), user);
         JsonNode node = JsonUtils.readTree(result);
 
         UserDataDbIface dao = BeansFactory.getTypeFactory().getTypedBean(
@@ -171,7 +172,7 @@
         handler.insertBeans(helper().getContext());
         s.setQuery("[orth=laufe/i & base!=Lauf]", "poliqarp");
         assertTrue(handler.add(FoundryInject.class));
-        String result = handler.preProcess(s.toJSON(), null);
+        String result = handler.process(s.toJSON(), null);
         JsonNode node = JsonUtils.readTree(result);
 
         assertNotNull(node);
@@ -190,7 +191,7 @@
         handler.insertBeans(helper().getContext());
         s.setQuery("[(base=laufen | base=gehen) & tt/pos=VVFIN]", "poliqarp");
         assertTrue(handler.add(FoundryInject.class));
-        String result = handler.preProcess(s.toJSON(), null);
+        String result = handler.process(s.toJSON(), null);
         JsonNode node = JsonUtils.readTree(result);
 
         assertNotNull(node);
diff --git a/src/test/java/de/ids_mannheim/korap/resource/rewrite/IdRewriteTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/IdRewriteTest.java
index 2f069f1..909f9c9 100644
--- a/src/test/java/de/ids_mannheim/korap/resource/rewrite/IdRewriteTest.java
+++ b/src/test/java/de/ids_mannheim/korap/resource/rewrite/IdRewriteTest.java
@@ -25,7 +25,7 @@
         QuerySerializer s = new QuerySerializer();
         s.setQuery(query, "poliqarp");
 
-        String value = handler.preProcess(s.toJSON(), null);
+        String value = handler.process(s.toJSON(), null);
         JsonNode result = JsonUtils.readTree(value);
 
         assertNotNull(result);
@@ -41,7 +41,7 @@
 
         QuerySerializer s = new QuerySerializer();
         s.setQuery("[base=Haus]", "poliqarp");
-        String result = handler.preProcess(s.toJSON(), null);
+        String result = handler.process(s.toJSON(), null);
         JsonNode node = JsonUtils.readTree(result);
         assertNotNull(node);
         assertFalse(node.at("/query/wrap").isMissingNode());
diff --git a/src/test/java/de/ids_mannheim/korap/resource/rewrite/PostRewriteTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/PostRewriteTest.java
index 78db747..ef0c10a 100644
--- a/src/test/java/de/ids_mannheim/korap/resource/rewrite/PostRewriteTest.java
+++ b/src/test/java/de/ids_mannheim/korap/resource/rewrite/PostRewriteTest.java
@@ -47,7 +47,7 @@
         try {
             Document d = dao.findbyId("BRZ13_APR.00014", null);
             assertNull(d);
-            String v = ha.postProcess(RESULT, null);
+            String v = ha.process(RESULT, null);
             assertEquals("results do not match", JsonUtils.readTree(RESULT),
                     JsonUtils.readTree(v));
         }
@@ -76,7 +76,7 @@
         assertEquals("Handler could not be added to rewriter instance!", true,
                 ha.add(DocMatchRewrite.class));
 
-        String v = ha.postProcess(RESULT, null);
+        String v = ha.process(RESULT, null);
 
         JsonNode node = JsonUtils.readTree(v);
 
diff --git a/src/test/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandlerTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandlerTest.java
index 070e0bb..15df2a9 100644
--- a/src/test/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandlerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandlerTest.java
@@ -51,7 +51,7 @@
         QuerySerializer s = new QuerySerializer();
         s.setQuery("[(base=laufen | base=gehen) & tt/pos=VVFIN]", "poliqarp");
         assertTrue(handler.add(FoundryInject.class));
-        handler.preProcess(s.toJSON(), null);
+        handler.process(s.toJSON(), null);
     }
 
 
@@ -62,7 +62,7 @@
         QuerySerializer s = new QuerySerializer();
         s.setQuery("[(base=laufen | base=gehen) & tt/pos=VVFIN]", "poliqarp");
         assertTrue(handler.add(FoundryInject.class));
-        String res = handler.preProcess(s.toJSON(), null);
+        String res = handler.process(s.toJSON(), null);
         assertNotNull(res);
     }
 
@@ -74,7 +74,7 @@
         QuerySerializer s = new QuerySerializer();
         s.setQuery("[(base=laufen | base=gehen) & tt/pos=VVFIN]", "poliqarp");
         assertTrue(handler.add(FoundryInject.class));
-        String res = handler.preProcess(s.toJSON(), null);
+        String res = handler.process(s.toJSON(), null);
         JsonNode node = JsonUtils.readTree(res);
         assertNotNull(node);
 
@@ -93,7 +93,7 @@
         QuerySerializer s = new QuerySerializer();
         s.setQuery("[(base=laufen | base=gehen) & tt/pos=VVFIN]", "poliqarp");
         assertTrue(handler.add(FoundryInject.class));
-        String res = handler.preProcess(s.toJSON(), helper().getUser());
+        String res = handler.process(s.toJSON(), helper().getUser());
         JsonNode node = JsonUtils.readTree(res);
         assertNotNull(node);
         assertEquals("tt_test",
diff --git a/src/test/java/de/ids_mannheim/korap/security/PermissionBufferTest.java b/src/test/java/de/ids_mannheim/korap/security/PermissionBufferTest.java
new file mode 100644
index 0000000..68e874a
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/security/PermissionBufferTest.java
@@ -0,0 +1,209 @@
+package de.ids_mannheim.korap.security;
+
+import de.ids_mannheim.korap.resources.Permissions;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author hanl
+ * @date 15/02/2016
+ */
+public class PermissionBufferTest {
+
+    @Test
+    public void testDuplicatePermission () {
+        PermissionsBuffer buffer = new PermissionsBuffer();
+        assertEquals(0, buffer.addPermission(4));
+        assertEquals(-1, buffer.addPermission(4));
+
+        // 0 means permission was successfully added, -1 means it wasn't because it's already present
+        assertEquals(0, buffer.addPermission(1));
+        assertEquals(-1, buffer.addPermission(1));
+
+        assertEquals(0, buffer.addPermission(8));
+        assertEquals(-1, buffer.addPermission(4));
+    }
+
+
+    @Test
+    public void testPermissionsAdd () {
+        PermissionsBuffer buffer = new PermissionsBuffer();
+        buffer.addPermissions(Permissions.Permission.READ);
+        assertEquals(1, buffer.getPermissions().size());
+
+        assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
+        assertFalse(buffer
+                .containsPByte(Permissions.Permission.DELETE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.ALL.toByte()));
+
+        buffer = new PermissionsBuffer();
+        buffer.addPermissions(Permissions.Permission.WRITE);
+        buffer.addPermissions(Permissions.Permission.DELETE_POLICY);
+        assertEquals(2, buffer.getPermissions().size());
+        assertFalse(buffer.containsPByte(Permissions.Permission.READ.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
+        assertFalse(buffer
+                .containsPByte(Permissions.Permission.DELETE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
+                .toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.ALL.toByte()));
+    }
+
+
+    @Test
+    public void testPermissionsAddAll2 () {
+        PermissionsBuffer buffer = new PermissionsBuffer();
+        buffer.addPermissions(Permissions.Permission.ALL);
+
+        assertEquals(Permissions.Permission.values().length, buffer
+                .getPermissions().size());
+        assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.READ_POLICY
+                .toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
+                .toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
+                .toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
+                .toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.ALL.toByte()));
+    }
+
+
+    @Test
+    public void testPermissionsAddAll () {
+        PermissionsBuffer buffer = new PermissionsBuffer();
+        buffer.addPermissions(Permissions.Permission.DELETE_POLICY);
+        buffer.addPermissions(Permissions.Permission.CREATE_POLICY);
+        buffer.addPermissions(Permissions.Permission.READ);
+        buffer.addPermissions(Permissions.Permission.MODIFY_POLICY);
+        buffer.addPermissions(Permissions.Permission.DELETE);
+        buffer.addPermissions(Permissions.Permission.READ_POLICY);
+        buffer.addPermissions(Permissions.Permission.WRITE);
+
+        assertEquals(Permissions.Permission.values().length, buffer
+                .getPermissions().size());
+        assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.READ_POLICY
+                .toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
+                .toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
+                .toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
+                .toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.ALL.toByte()));
+
+    }
+
+
+    @Test
+    public void testPermissionsInit () {
+        PermissionsBuffer buffer = new PermissionsBuffer((short) 1);
+        assertEquals(1, buffer.getPermissions().size());
+
+        assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
+        assertFalse(buffer
+                .containsPByte(Permissions.Permission.DELETE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
+                .toByte()));
+
+    }
+
+
+    @Test
+    public void testPermissionsStringConversion () {
+        PermissionsBuffer buffer = new PermissionsBuffer(Short.valueOf("1"));
+        assertEquals(1, buffer.getPermissions().size());
+
+        assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
+        assertFalse(buffer
+                .containsPByte(Permissions.Permission.DELETE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
+                .toByte()));
+
+        buffer = new PermissionsBuffer(Short.valueOf("5"));
+        assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
+                .toByte()));
+
+        buffer = new PermissionsBuffer(Short.valueOf("69"));
+        assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
+                .toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
+                .toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
+                .toByte()));
+    }
+
+
+    @Test
+    public void testPermissionRemovalOne () {
+        PermissionsBuffer buffer = new PermissionsBuffer();
+        buffer.addPermissions(Permissions.Permission.READ,
+                Permissions.Permission.DELETE,
+                Permissions.Permission.MODIFY_POLICY);
+
+        assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
+                .toByte()));
+
+        buffer.removePermission(Permissions.Permission.MODIFY_POLICY);
+
+        assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
+        assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
+        assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
+                .toByte()));
+    }
+
+}
diff --git a/src/test/java/de/ids_mannheim/korap/security/PolicyBenchmarkTest.java b/src/test/java/de/ids_mannheim/korap/security/PolicyBenchmarkTest.java
new file mode 100644
index 0000000..6804770
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/security/PolicyBenchmarkTest.java
@@ -0,0 +1,10 @@
+package de.ids_mannheim.korap.security;
+
+/**
+ * @author hanl
+ * @date 09/02/2016
+ */
+public class PolicyBenchmarkTest {
+
+
+}
diff --git a/src/test/java/de/ids_mannheim/korap/security/PolicyBuilderTest.java b/src/test/java/de/ids_mannheim/korap/security/PolicyBuilderTest.java
new file mode 100644
index 0000000..eb0c3d8
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/security/PolicyBuilderTest.java
@@ -0,0 +1,31 @@
+package de.ids_mannheim.korap.security;
+
+import de.ids_mannheim.korap.config.BeanConfigTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.security.ac.PolicyBuilder;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 20/11/2015
+ */
+public class PolicyBuilderTest extends BeanConfigTest {
+
+    @Test
+    public void testBuild () {
+        PolicyBuilder b = new PolicyBuilder(helper().getUser());
+
+    }
+
+
+    @Override
+    public void initMethod () throws KustvaktException {
+        helper().setupAccount();
+    }
+
+
+    @Test
+    public void testCreateForMultipleResources () {
+        //todo:
+    }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/security/ResourceFinderTest.java b/src/test/java/de/ids_mannheim/korap/security/ResourceFinderTest.java
new file mode 100644
index 0000000..24922e6
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/security/ResourceFinderTest.java
@@ -0,0 +1,44 @@
+package de.ids_mannheim.korap.security;
+
+import de.ids_mannheim.korap.config.BeanConfigTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+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.Test;
+
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+
+/**
+ * @author hanl
+ * @date 06/02/2016
+ */
+public class ResourceFinderTest extends BeanConfigTest {
+
+    @Test
+    public void searchResources () throws KustvaktException {
+        Set<VirtualCollection> resources = ResourceFinder
+                .searchPublic(VirtualCollection.class);
+        assertFalse(resources.isEmpty());
+        assertEquals(3, resources.size());
+    }
+
+
+    @Test
+    public void searchResourcesDemo () throws KustvaktException {
+        Set<Corpus> resources = ResourceFinder.searchPublic(Corpus.class);
+        assertFalse(resources.isEmpty());
+        assertNotEquals(0, resources.size());
+    }
+
+
+    @Override
+    public void initMethod () throws KustvaktException {
+        helper().setupAccount();
+        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
new file mode 100644
index 0000000..99fd537
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/security/ResourcesTest.java
@@ -0,0 +1,124 @@
+package de.ids_mannheim.korap.security;
+
+import de.ids_mannheim.korap.config.BeanConfigTest;
+import de.ids_mannheim.korap.config.ContextHolder;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.NotAuthorizedException;
+import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
+import de.ids_mannheim.korap.resources.*;
+import de.ids_mannheim.korap.security.ac.ResourceFinder;
+import de.ids_mannheim.korap.security.ac.ResourceHandler;
+import de.ids_mannheim.korap.security.ac.SecurityManager;
+import de.ids_mannheim.korap.user.User;
+import de.ids_mannheim.korap.utils.TimeUtils;
+import org.joda.time.DateTime;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * @author hanl
+ * @date 20/11/2015
+ */
+// todo: run functions without data to check for nullpointers!
+public class ResourcesTest extends BeanConfigTest {
+
+    private static Corpus c1;
+
+
+    @Test
+    public void testCreate () throws KustvaktException {
+        ResourceHandler h = new ResourceHandler();
+        Corpus ncorps = new Corpus("new_wiki");
+        h.storeResources(helper().getUser(), ncorps);
+    }
+
+
+    @Test
+    public void testGet () throws KustvaktException {
+        DateTime beg = new DateTime();
+        ResourceHandler h = new ResourceHandler();
+        Corpus c = h.findbyStrId(c1.getPersistentID(), helper().getUser(),
+                Corpus.class);
+        float end = TimeUtils.floating(beg, new DateTime());
+        System.out.println("END ----------------- : " + end);
+        assertNotNull(c);
+    }
+
+
+    @Test(expected = KustvaktException.class)
+    public void testGetthrowsUnauthorizedException () throws KustvaktException {
+        DateTime beg = new DateTime();
+        ResourceHandler h = new ResourceHandler();
+        Corpus c = h.findbyStrId(c1.getPersistentID(),
+                User.UserFactory.getDemoUser(), Corpus.class);
+        float end = TimeUtils.floating(beg, new DateTime());
+        System.out.println("END ----------------- : " + end);
+        assertNotNull(c);
+    }
+
+
+    // in case of null, should not return nullpointer!
+    @Test(expected = KustvaktException.class)
+    @Ignore
+    public void testCollectionGet () throws KustvaktException {
+        //todo: do use test user!
+        User user = User.UserFactory
+                .toUser(KustvaktConfiguration.KUSTVAKT_USER);
+        EntityHandlerIface ice = helper()
+                .getBean(ContextHolder.KUSTVAKT_USERDB);
+        User test = ice.getAccount(user.getUsername());
+        assertNotNull(test);
+        Set<KustvaktResource> resources = ResourceFinder.search(user,
+                ResourceFactory.getResourceClass("collection"));
+
+        assertFalse(resources.isEmpty());
+        KustvaktResource r = (KustvaktResource) resources.toArray()[0];
+
+        assertNotNull(r);
+        ResourceHandler h = new ResourceHandler();
+        h.findbyStrId(r.getPersistentID(), user, VirtualCollection.class);
+    }
+
+
+    // securitymanager does not allow for anonymous retrieval, only resourcefinder!
+    @Test(expected = NotAuthorizedException.class)
+    public void getResource () throws KustvaktException {
+        User user = User.UserFactory.getDemoUser();
+        SecurityManager m = SecurityManager.findbyId(2, user,
+                Permissions.Permission.READ);
+        m.getResource();
+    }
+
+
+    @Test
+    public void getDemoResources () throws KustvaktException {
+        Set s = ResourceFinder.searchPublic(Corpus.class);
+        assertEquals(2, s.size());
+        s = ResourceFinder.searchPublic(Foundry.class);
+        assertEquals(1, s.size());
+    }
+
+
+    @Test
+    public void getDemoResourceFiltered () throws KustvaktException {
+        Set s = ResourceFinder.searchPublicFiltered(Corpus.class, "WPD");
+        assertEquals(1, s.size());
+    }
+
+
+    @Override
+    public void initMethod () throws KustvaktException {
+        helper().setupAccount();
+        c1 = new Corpus("WPD_test");
+        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
new file mode 100644
index 0000000..0235e81
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/security/SecurityPolicyTest.java
@@ -0,0 +1,148 @@
+package de.ids_mannheim.korap.security;
+
+import de.ids_mannheim.korap.config.BeanConfigTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.interfaces.db.PolicyHandlerIface;
+import de.ids_mannheim.korap.resources.Corpus;
+import de.ids_mannheim.korap.resources.Permissions;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author hanl
+ * @date 12/02/2016
+ */
+public class SecurityPolicyTest extends BeanConfigTest {
+
+    @Test
+    public void testConditionUpdate () {
+        SecurityPolicy policy = new SecurityPolicy();
+        policy.addNewCondition(new PolicyCondition("test_1"));
+        policy.addNewCondition(new PolicyCondition("test_2"));
+        policy.setCreator(1);
+        policy.setTarget(new Corpus("WPD"));
+        policy.addPermission(Permissions.Permission.READ);
+
+        assertEquals(2, policy.getAdded().size());
+        policy.removeCondition(new PolicyCondition("test_1"));
+        assertEquals(1, policy.getAdded().size());
+    }
+
+
+    @Test
+    public void testConditionMapping () throws KustvaktException {
+        helper().setupResource(new Corpus("WPD_2"));
+        SecurityPolicy policy = new SecurityPolicy();
+        policy.addNewCondition(new PolicyCondition("test_1"));
+        policy.addNewCondition(new PolicyCondition("test_2"));
+        policy.setCreator(1);
+        policy.setTarget(new Corpus("WPD_2"));
+        policy.addPermission(Permissions.Permission.READ);
+
+        PolicyHandlerIface dao = helper().getContext().getPolicyDbProvider();
+        dao.createPolicy(policy, helper().getUser());
+
+        List<SecurityPolicy>[] list = dao.getPolicies("WPD_2", helper()
+                .getUser(), Permissions.Permission.READ.toByte());
+        assertNotNull(list);
+        List<SecurityPolicy> policies = list[0];
+        assertNotNull(policies);
+        assertFalse(policies.isEmpty());
+        assertEquals(2, policies.size());
+        assertTrue(policies.get(0) instanceof SecurityPolicy.OwnerPolicy);
+        policy = policies.get(1);
+        assertEquals(2, policy.getConditions().size());
+        policy.removeCondition(new PolicyCondition("test_1"));
+        assertEquals(1, policy.getRemoved().size());
+        assertTrue(policy.getAdded().isEmpty());
+    }
+
+
+    @Test
+    public void testPersistingPermissionMapping () throws KustvaktException {
+        helper().setupResource(new Corpus("WPD_3"));
+        SecurityPolicy policy = new SecurityPolicy();
+        policy.addNewCondition(new PolicyCondition("test_1"));
+        policy.addNewCondition(new PolicyCondition("test_2"));
+        policy.setCreator(1);
+        policy.setTarget(new Corpus("WPD_3"));
+        policy.addPermission(Permissions.Permission.READ);
+        policy.addPermission(Permissions.Permission.WRITE);
+
+        PolicyHandlerIface dao = helper().getContext().getPolicyDbProvider();
+        dao.createPolicy(policy, helper().getUser());
+
+        List<SecurityPolicy>[] list = dao.getPolicies("WPD_3", helper()
+                .getUser(), Permissions.Permission.READ.toByte());
+
+        assertNotNull(list);
+        List<SecurityPolicy> policies = list[0];
+        assertNotNull(policies);
+        assertFalse(policies.isEmpty());
+        assertEquals(2, policies.size());
+        assertTrue(policies.get(0) instanceof SecurityPolicy.OwnerPolicy);
+        policy = policies.get(1);
+
+        Set<Permissions.Permission> check = new HashSet<>();
+        check.add(Permissions.Permission.READ);
+        check.add(Permissions.Permission.WRITE);
+        assertEquals(check, policy.getPermissions());
+    }
+
+
+    @Test
+    public void testConditionRemoval () throws KustvaktException {
+        helper().setupResource(new Corpus("WPD_1"));
+        SecurityPolicy policy = new SecurityPolicy();
+        policy.addNewCondition(new PolicyCondition("test_1"));
+        policy.addNewCondition(new PolicyCondition("test_2"));
+        policy.setCreator(1);
+        policy.setTarget(new Corpus("WPD_1"));
+        policy.addPermission(Permissions.Permission.READ);
+
+        PolicyHandlerIface dao = helper().getContext().getPolicyDbProvider();
+        dao.createPolicy(policy, helper().getUser());
+
+        Object[] list = dao.getPolicies("WPD_1", helper().getUser(),
+                Permissions.Permission.READ.toByte());
+        assertNotNull(list);
+        List<SecurityPolicy> policies = (List<SecurityPolicy>) list[0];
+        assertNotNull(policies);
+        assertFalse(policies.isEmpty());
+        policy = policies.get(1);
+
+        assertEquals(2, policy.getConditions().size());
+        policy.removeCondition(new PolicyCondition("test_1"));
+        assertEquals(1, policy.getRemoved().size());
+        assertTrue(policy.getAdded().isEmpty());
+
+        dao.updatePolicy(policy, helper().getUser());
+        policies = dao.getPolicies("WPD_1", helper().getUser(),
+                Permissions.Permission.READ.toByte())[0];
+        policy = policies.get(1);
+        assertEquals(1, policy.getConditions().size());
+    }
+
+
+    @Test
+    public void testPermissionConversion () {
+        SecurityPolicy policy = new SecurityPolicy();
+        policy.setPOSIX("3");
+        Set<Permissions.Permission> perms = new HashSet<>();
+        perms.add(Permissions.Permission.READ);
+        perms.add(Permissions.Permission.WRITE);
+        assertEquals(perms, policy.getPermissions());
+    }
+
+
+    @Override
+    public void initMethod () throws KustvaktException {
+        helper().runBootInterfaces();
+        helper().setupAccount();
+    }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java b/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
index 2c0d83e..35d06af 100644
--- a/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
@@ -96,9 +96,7 @@
                 .getAuthenticationManager();
 
         User user = new KorAPUser(10, "random");
-
-        Userdata data = manager.getUserData(user, UserDetails.class);
-        assertNotNull(data);
+        manager.getUserData(user, UserDetails.class);
     }
 
 
@@ -109,9 +107,7 @@
                 .getAuthenticationManager();
 
         User user = new KorAPUser(10, "random");
-
-        Userdata data = manager.getUserData(user, UserSettings.class);
-        assertNotNull(data);
+        manager.getUserData(user, UserSettings.class);
     }
 
 
diff --git a/src/test/java/de/ids_mannheim/korap/suites/LoaderTestSuite.java b/src/test/java/de/ids_mannheim/korap/suites/LoaderTestSuite.java
new file mode 100644
index 0000000..9f3a05e
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/suites/LoaderTestSuite.java
@@ -0,0 +1,15 @@
+package de.ids_mannheim.korap.suites;
+
+/**
+ * @author hanl
+ * @date 09/03/2016
+ */
+
+import de.ids_mannheim.korap.config.CollectionLoaderTest;
+import de.ids_mannheim.korap.config.PolicyLoaderTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ PolicyLoaderTest.class, CollectionLoaderTest.class })
+public class LoaderTestSuite {}
diff --git a/src/test/java/de/ids_mannheim/korap/suites/SecurityEntityTestSuite.java b/src/test/java/de/ids_mannheim/korap/suites/SecurityEntityTestSuite.java
new file mode 100644
index 0000000..c3cceda
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/suites/SecurityEntityTestSuite.java
@@ -0,0 +1,17 @@
+package de.ids_mannheim.korap.suites;
+
+import de.ids_mannheim.korap.security.PermissionBufferTest;
+import de.ids_mannheim.korap.security.PolicyBuilderTest;
+import de.ids_mannheim.korap.security.SecurityPolicyTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author hanl
+ * @date 09/03/2016
+ */
+// test object serialization and I/O buffers
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ PermissionBufferTest.class, PolicyBuilderTest.class,
+        SecurityPolicyTest.class })
+public class SecurityEntityTestSuite {}
diff --git a/src/test/java/de/ids_mannheim/korap/suites/SecurityTestSuite.java b/src/test/java/de/ids_mannheim/korap/suites/SecurityTestSuite.java
new file mode 100644
index 0000000..45116b5
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/suites/SecurityTestSuite.java
@@ -0,0 +1,12 @@
+package de.ids_mannheim.korap.suites;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author hanl
+ * @date 09/03/2016
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({})
+public class SecurityTestSuite {}
diff --git a/src/test/java/de/ids_mannheim/korap/suites/ServiceTestSuite.java b/src/test/java/de/ids_mannheim/korap/suites/ServiceTestSuite.java
new file mode 100644
index 0000000..e83e232
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/suites/ServiceTestSuite.java
@@ -0,0 +1,15 @@
+package de.ids_mannheim.korap.suites;
+
+/**
+ * @author hanl
+ * @date 09/03/2016
+ */
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({})
+public class ServiceTestSuite {
+
+}
diff --git a/src/test/java/de/ids_mannheim/korap/user/UserFactoryTest.java b/src/test/java/de/ids_mannheim/korap/user/UserFactoryTest.java
new file mode 100644
index 0000000..51d03cb
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/user/UserFactoryTest.java
@@ -0,0 +1,7 @@
+package de.ids_mannheim.korap.user;
+
+/**
+ * @author hanl
+ * @date 04/02/2016
+ */
+public class UserFactoryTest {}
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 ec25c17..72a4a01 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
@@ -72,7 +72,7 @@
     //    @Test
     public void testGetStatsThrowsNoException () {
         CollectionQueryProcessor pr = new CollectionQueryProcessor();
-        pr.process("corpusID=WPD & textClass=Sport");
+        pr.process("corpusSigle=WPD & textClass=Sport");
         Map map = new LinkedHashMap();
         map.put("collection", pr.getRequestMap());
         ClientResponse response = resource().path(getAPIVersion())
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/LightServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/LightServiceTest.java
new file mode 100644
index 0000000..5a604e2
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/LightServiceTest.java
@@ -0,0 +1,184 @@
+package de.ids_mannheim.korap.web.service.full;
+
+import com.fasterxml.jackson.databind.JsonNode;
+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.utils.JsonUtils;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Created by hanl on 29.04.16.
+ */
+public class LightServiceTest extends FastJerseyTest {
+
+    @BeforeClass
+    public static void configure () throws Exception {
+        FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.light");
+    }
+
+
+    @Override
+    public void initMethod () throws KustvaktException {}
+
+
+    @Test
+    public void testQueryTrace () {
+        ClientResponse response = resource().path(getAPIVersion())
+                .path("search").queryParam("q", "[orth=das]")
+                .queryParam("ql", "poliqarp").queryParam("context", "sentence")
+                .queryParam("count", "13")
+                .method("TRACE", ClientResponse.class);
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String query = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(query);
+        assertNotNull(node);
+        assertEquals("orth", node.at("/query/wrap/layer").asText());
+        assertEquals("opennlp", node.at("/query/wrap/foundry").asText());
+        assertEquals("sentence", node.at("/meta/context").asText());
+        assertEquals("13", node.at("/meta/count").asText());
+    }
+
+    @Test
+    public void testbuildAndPostQuery() {
+        ClientResponse response = resource()
+                .path(getAPIVersion())
+                .path("search")
+                .queryParam("q", "[orth=das]")
+                .queryParam("ql", "poliqarp")
+                .queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE")
+                .method("TRACE", ClientResponse.class);
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+
+        String query = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(query);
+        assertNotNull(node);
+
+        response = resource()
+                .path(getAPIVersion())
+                .path("search").post(ClientResponse.class, query);
+
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String matches = response.getEntity(String.class);
+        JsonNode match_node = JsonUtils.readTree(matches);
+        assertNotEquals(0, match_node.path("matches").size());
+    }
+
+
+    @Test
+    public void testQueryGet () {
+        ClientResponse response = resource().path(getAPIVersion())
+                .path("search").queryParam("q", "[orth=das]")
+                .queryParam("ql", "poliqarp").queryParam("context", "sentence")
+                .queryParam("count", "13").get(ClientResponse.class);
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String query = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(query);
+        assertNotNull(node);
+        assertEquals("orth", node.at("/query/wrap/layer").asText());
+        assertEquals("base/s:s", node.at("/meta/context").asText());
+        assertEquals("13", node.at("/meta/count").asText());
+        assertNotEquals(0, node.at("/matches").size());
+    }
+
+
+    @Test
+    public void testFoundryRewrite () {
+        ClientResponse response = resource().path(getAPIVersion())
+                .path("search").queryParam("q", "[orth=das]")
+                .queryParam("ql", "poliqarp").queryParam("context", "sentence")
+                .queryParam("count", "13").get(ClientResponse.class);
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String query = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(query);
+        assertNotNull(node);
+        assertEquals("orth", node.at("/query/wrap/layer").asText());
+        assertEquals("opennlp", node.at("/query/wrap/foundry").asText());
+    }
+
+
+    @Test
+    public void testQueryPost () {
+        QuerySerializer s = new QuerySerializer();
+        s.setQuery("[orth=das]", "poliqarp");
+
+        ClientResponse response = resource().path(getAPIVersion())
+                .path("search").post(ClientResponse.class, s.toJSON());
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String query = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(query);
+        assertNotNull(node);
+        assertEquals("orth", node.at("/query/wrap/layer").asText());
+        assertNotEquals(0, node.at("/matches").size());
+    }
+
+
+    @Test
+    public void testParameterField () {
+        ClientResponse response = resource().path(getAPIVersion())
+                .path("search").queryParam("q", "[orth=das]")
+                .queryParam("ql", "poliqarp")
+                .queryParam("fields", "author, docSigle")
+                .queryParam("context", "sentence").queryParam("count", "13")
+                .get(ClientResponse.class);
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String query = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(query);
+        assertNotNull(node);
+        assertEquals("orth", node.at("/query/wrap/layer").asText());
+        assertNotEquals(0, node.at("/matches").size());
+        assertEquals("[\"author, docSigle\"]", node.at("/meta/fields")
+                .toString());
+    }
+
+
+    @Test
+    public void testCQParameter () {
+        ClientResponse response = resource().path(getAPIVersion())
+                .path("search").queryParam("q", "[orth=das]")
+                .queryParam("ql", "poliqarp")
+                .queryParam("fields", "author, docSigle")
+                .queryParam("context", "sentence").queryParam("count", "13")
+                .queryParam("cq", "textClass=Politik & corpus=WPD")
+                .method("TRACE", ClientResponse.class);
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String query = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(query);
+        assertNotNull(node);
+        assertEquals("orth", node.at("/query/wrap/layer").asText());
+        assertEquals("Politik", node.at("/collection/operands/0/value")
+                .asText());
+        assertEquals("WPD", node.at("/collection/operands/1/value").asText());
+
+        response = resource().path(getAPIVersion()).path("search")
+                .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+                .queryParam("fields", "author, docSigle")
+                .queryParam("context", "sentence").queryParam("count", "13")
+                .queryParam("cq", "textClass=Politik & corpus=WPD")
+                .get(ClientResponse.class);
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        query = response.getEntity(String.class);
+        node = JsonUtils.readTree(query);
+        assertNotNull(node);
+        assertEquals("orth", node.at("/query/wrap/layer").asText());
+        assertEquals("Politik", node.at("/collection/operands/0/value")
+                .asText());
+        assertEquals("WPD", node.at("/collection/operands/1/value").asText());
+    }
+
+}
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 6cb7700..d0a5b96 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
@@ -135,8 +135,10 @@
                 ClientResponse.Status.OK.getStatusCode());
         String ent = response.getEntity(String.class);
         JsonNode node = JsonUtils.readTree(ent);
-        System.out.println("PUBLIC COLLECTION");
-        System.out.println(node);
+        assertNotNull(node);
+        assertEquals("koral:docGroup", node.at("/collection/@type").asText());
+        assertEquals("operation:or", node.at("/collection/operation").asText());
+        assertNotEquals(0, node.at("/collection/operands").size());
     }