Added API versioning backwards compability and tests.
Change-Id: I8a7b512bea67e07e449074a4d04c257b65ae1454
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/ApiVersionTest.java b/full/src/test/java/de/ids_mannheim/korap/web/ApiVersionTest.java
new file mode 100644
index 0000000..b8ca799
--- /dev/null
+++ b/full/src/test/java/de/ids_mannheim/korap/web/ApiVersionTest.java
@@ -0,0 +1,39 @@
+package de.ids_mannheim.korap.web;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.URI;
+
+import javax.ws.rs.core.MediaType;
+
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.Test;
+
+import com.sun.jersey.api.client.ClientResponse;
+
+import de.ids_mannheim.korap.config.SpringJerseyTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+
+public class ApiVersionTest extends SpringJerseyTest {
+
+ @Test
+ public void testSearchWithoutVersion () throws KustvaktException {
+ ClientResponse response = resource().path("api").path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+ assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
+ URI location = response.getLocation();
+ assertEquals("/api/v1.0/search", location.getPath());
+ }
+
+ @Test
+ public void testSearchWrongVersion () throws KustvaktException {
+ ClientResponse response = resource().path("api").path("v0.2")
+ .path("search").queryParam("q", "[orth=der]")
+ .queryParam("ql", "poliqarp").accept(MediaType.APPLICATION_JSON)
+ .get(ClientResponse.class);
+ assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
+ URI location = response.getLocation();
+ assertEquals("/api/v1.0/search", location.getPath());
+ }
+}
diff --git a/full/src/test/resources/kustvakt-test.conf b/full/src/test/resources/kustvakt-test.conf
index 304e649..9a522ba 100644
--- a/full/src/test/resources/kustvakt-test.conf
+++ b/full/src/test/resources/kustvakt-test.conf
@@ -12,6 +12,8 @@
ldap.config = file-path-to-ldap-config
# Kustvakt
+
+current.api.version = v1.0
# multiple versions separated by space
supported.api.version = v0.1 v1.0