Implemented pipe extension in the search API.

Change-Id: If2a486185a7d16a27b7b46d35d85b7d5f27b66cd
diff --git a/full/Changes b/full/Changes
index 733bb9f..6ce2b2a 100644
--- a/full/Changes
+++ b/full/Changes
@@ -1,3 +1,7 @@
+# version 0.62.3
+03/12/2019
+   - Implemented pipe extension in the search API (margaretha)
+
 # version 0.62.2
 17/10/2019
    - Handled vulnerability CVE-2019-17195. (margaretha)
diff --git a/full/pom.xml b/full/pom.xml
index 564d3be..a1a4f02 100644
--- a/full/pom.xml
+++ b/full/pom.xml
@@ -3,7 +3,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>de.ids_mannheim.korap</groupId>
 	<artifactId>Kustvakt-full</artifactId>
-	<version>0.62.2</version>
+	<version>0.62.3</version>
 	<properties>
 		<java.version>1.8</java.version>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -205,7 +205,7 @@
 		<dependency>
 			<groupId>de.ids_mannheim.korap</groupId>
 			<artifactId>Kustvakt-core</artifactId>
-			<version>[0.62.2,)</version>
+			<version>[0.62.3,)</version>
 		</dependency>
 		<!-- LDAP -->
 		<dependency>
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java b/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
index 8a2f730..cbb6977 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
@@ -32,6 +32,7 @@
 
     public static String[] classPackages =
             new String[] { "de.ids_mannheim.korap.web",
+                    "de.ids_mannheim.korap.test",
                     "com.fasterxml.jackson.jaxrs.json"};
 
     @Override
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java
new file mode 100644
index 0000000..9c55d6e
--- /dev/null
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java
@@ -0,0 +1,73 @@
+package de.ids_mannheim.korap.web.controller;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientResponse;
+
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.config.SpringJerseyTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.utils.JsonUtils;
+
+public class SearchPipeTest extends SpringJerseyTest {
+
+    @Autowired
+    private KustvaktConfiguration config;
+
+    private void setTestPipes () throws IOException {
+        String filename = "test-pipes";
+        File f = new File(filename);
+        if (f.exists()) {
+            f.delete();
+        }
+        f.createNewFile();
+        OutputStreamWriter writer =
+                new OutputStreamWriter(new FileOutputStream(f));
+        writer.append("glemm\t");
+        writer.append(resource().getURI().toString());
+        writer.append(API_VERSION);
+        writer.append("/test/glemm");
+        writer.flush();
+        writer.close();
+
+        config.readPipesFile(filename);
+    }
+
+    @Test
+    public void testSearchWithPipes () throws IOException, KustvaktException {
+        setTestPipes();
+        ClientResponse response = resource().path(API_VERSION).path("search")
+                .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+                .queryParam("pipes", "glemm").get(ClientResponse.class);
+
+        String entity = response.getEntity(String.class);
+
+        JsonNode node = JsonUtils.readTree(entity);
+        assertEquals(3, node.at("/query/wrap/key").size());
+        
+        assertEquals(1, node.at("/collection/rewrites").size());
+        assertEquals("operation:insertion",
+                node.at("/collection/rewrites/0/operation").asText());
+        assertEquals("availability(FREE)",
+                node.at("/collection/rewrites/0/scope").asText());
+        
+        node = node.at("/query/wrap/rewrites");
+        assertEquals(2, node.size());
+        assertEquals("Glemm", node.at("/0/src").asText());
+        assertEquals("operation:override", node.at("/0/operation").asText());
+        assertEquals("key", node.at("/0/scope").asText());
+        
+        assertEquals("Kustvakt", node.at("/1/src").asText());
+        assertEquals("operation:injection", node.at("/1/operation").asText());
+        assertEquals("foundry", node.at("/1/scope").asText());
+    }
+}