Added API versioning backwards compability and tests.
Change-Id: I8a7b512bea67e07e449074a4d04c257b65ae1454
diff --git a/lite/Changes b/lite/Changes
index 942779a..105e619 100644
--- a/lite/Changes
+++ b/lite/Changes
@@ -1,13 +1,16 @@
version 0.61.0
-28/08/2018
- - Added API URL versioning (margaretha)
-
+30/08/2018
+ - Fixed root packages & added api version properties in kustvakt-lite.conf (margaretha)
+ - Added API versioning tests (margaretha)
+
version 0.60.2
05/07/2018
- Added support for unrestricted corpus statistics (ndiewald)
- Do not pass broken queries to Krill (diewald)
27/08/2018
- Added vc reference test (margaretha)
+28/08/2018
+ - Added API URL versioning (margaretha)
version 0.60.1
12/06/2018
diff --git a/lite/pom.xml b/lite/pom.xml
index 9e8ccaf..2e57372 100644
--- a/lite/pom.xml
+++ b/lite/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Kustvakt-lite</artifactId>
- <version>0.60.2</version>
+ <version>0.61.0</version>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
diff --git a/lite/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java b/lite/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java
index 66329ef..448d4f6 100644
--- a/lite/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java
+++ b/lite/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java
@@ -10,7 +10,6 @@
public class KustvaktLiteServer extends KustvaktBaseServer {
-
public static void main (String[] args) throws Exception {
KustvaktLiteServer server = new KustvaktLiteServer();
kargs = server.readAttributes(args);
@@ -20,20 +19,22 @@
File f = new File("kustvakt-lite.conf");
Properties properties = new Properties();
InputStream in = null;
-
- if (!f.exists()){
- in = KustvaktLiteServer.class.getClassLoader().getResourceAsStream("kustvakt-lite.conf");
+
+ if (!f.exists()) {
+ in = KustvaktLiteServer.class.getClassLoader()
+ .getResourceAsStream("kustvakt-lite.conf");
}
- else{
+ else {
in = new FileInputStream(f);
}
-
+
properties.load(in);
in.close();
config = new KustvaktConfiguration(properties);
-
+
kargs.setSpringConfig("lite-config.xml");
- rootPackages = "de.ids_mannheim.korap.web.service.lite";
+ rootPackages =
+ "de.ids_mannheim.korap.web";
server.start();
}
diff --git a/lite/src/main/java/de/ids_mannheim/korap/web/service/lite/LiteService.java b/lite/src/main/java/de/ids_mannheim/korap/web/service/lite/LiteService.java
index f5b648b..d268617 100644
--- a/lite/src/main/java/de/ids_mannheim/korap/web/service/lite/LiteService.java
+++ b/lite/src/main/java/de/ids_mannheim/korap/web/service/lite/LiteService.java
@@ -33,10 +33,10 @@
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
import de.ids_mannheim.korap.resource.rewrite.RewriteHandler;
import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder;
+import de.ids_mannheim.korap.web.APIVersionFilter;
import de.ids_mannheim.korap.web.ClientsHandler;
import de.ids_mannheim.korap.web.CoreResponseHandler;
import de.ids_mannheim.korap.web.SearchKrill;
-import de.ids_mannheim.korap.web.APIVersionFilter;
/**
* @author hanl
@@ -50,7 +50,7 @@
* - removed version from service paths
* - altered service with path /search and method trace to path
* /query and method get
- * - added API versioning
+ * - added API URL versioning
* </pre>
*/
@Controller
@@ -62,7 +62,7 @@
private static Logger jlog = LogManager.getLogger(LiteService.class);
@Autowired
- CoreResponseHandler kustvaktResponseHandler;
+ private CoreResponseHandler kustvaktResponseHandler;
@Autowired
private SearchKrill searchKrill;
private ClientsHandler graphDBhandler;
diff --git a/lite/src/main/resources/kustvakt-lite.conf b/lite/src/main/resources/kustvakt-lite.conf
index 79e2211..f0dd6b3 100644
--- a/lite/src/main/resources/kustvakt-lite.conf
+++ b/lite/src/main/resources/kustvakt-lite.conf
@@ -6,6 +6,15 @@
krill.index.commit.auto = 500
krill.index.relations.max = 100
+krill.namedVC=vc
+
+
+# Kustvakt
+
+current.api.version = v1.0
+# multiple versions separated by space
+supported.api.version = v1.0
+
kustvakt.base.url=/api/*
kustvakt.default.pos = tt
kustvakt.default.lemma = tt
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteServiceTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteServiceTest.java
index 8212e84..3578b21 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteServiceTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteServiceTest.java
@@ -8,9 +8,13 @@
import java.io.IOException;
import java.net.ServerSocket;
+import java.net.URI;
import java.util.Iterator;
import java.util.concurrent.ThreadLocalRandom;
+import javax.ws.rs.core.MediaType;
+
+import org.eclipse.jetty.http.HttpStatus;
import org.junit.Test;
import org.springframework.web.context.ContextLoaderListener;
@@ -41,7 +45,7 @@
*/
public class LiteServiceTest extends JerseyTest{
- public static final String API_VERSION = "v0.1";
+ public static final String API_VERSION = "v1.0";
public static final String classPackage = "de.ids_mannheim.korap.web.service.lite";
@Override
@@ -425,4 +429,25 @@
};
assertEquals(5, checkC);
};
+
+ @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());
+ }
}