Formatted project
Change-Id: I6993ddfab02e06541b4138040280a4777c719562
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/InfoControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/InfoControllerTest.java
index f8b2b1d..27054fd 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/InfoControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/InfoControllerTest.java
@@ -25,15 +25,21 @@
private SearchKrill krill;
@Test
- public void testInfo() throws KustvaktException {
- Response response = target().path(API_VERSION).path("info").request().get();
+ public void testInfo () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("info").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(config.getCurrentVersion(), node.at("/latest_api_version").asText());
- assertEquals(config.getSupportedVersions().size(), node.at("/supported_api_versions").size());
- assertEquals(ServiceInfo.getInfo().getVersion(), node.at("/kustvakt_version").asText());
- assertEquals(krill.getIndex().getVersion(), node.at("/krill_version").asText());
- assertEquals(ServiceInfo.getInfo().getKoralVersion(), node.at("/koral_version").asText());
+ assertEquals(config.getCurrentVersion(),
+ node.at("/latest_api_version").asText());
+ assertEquals(config.getSupportedVersions().size(),
+ node.at("/supported_api_versions").size());
+ assertEquals(ServiceInfo.getInfo().getVersion(),
+ node.at("/kustvakt_version").asText());
+ assertEquals(krill.getIndex().getVersion(),
+ node.at("/krill_version").asText());
+ assertEquals(ServiceInfo.getInfo().getKoralVersion(),
+ node.at("/koral_version").asText());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteMultipleCorpusQueryTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteMultipleCorpusQueryTest.java
index c037f20..5d93355 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteMultipleCorpusQueryTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteMultipleCorpusQueryTest.java
@@ -18,8 +18,12 @@
public class LiteMultipleCorpusQueryTest extends LiteJerseyTest {
@Test
- public void testSearchGet() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "das").queryParam("ql", "poliqarp").queryParam("cq", "pubPlace=München").queryParam("cq", "textSigle=\"GOE/AGA/01784\"").request().get();
+ public void testSearchGet () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "das").queryParam("ql", "poliqarp")
+ .queryParam("cq", "pubPlace=München")
+ .queryParam("cq", "textSigle=\"GOE/AGA/01784\"").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -36,8 +40,11 @@
}
@Test
- public void testStatisticsWithMultipleCq() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("cq", "textType=Abhandlung").queryParam("cq", "corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithMultipleCq ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("cq", "textType=Abhandlung")
+ .queryParam("cq", "corpusSigle=GOE").request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -49,8 +56,12 @@
}
@Test
- public void testStatisticsWithMultipleCorpusQuery() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", "textType=Autobiographie").queryParam("corpusQuery", "corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithMultipleCorpusQuery ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery", "textType=Autobiographie")
+ .queryParam("corpusQuery", "corpusSigle=GOE").request()
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -59,6 +70,7 @@
assertEquals(19387, node.at("/sentences").asInt());
assertEquals(514, node.at("/paragraphs").asInt());
assertEquals(StatusCodes.DEPRECATED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/1").asText(), "Parameter corpusQuery is deprecated in favor of cq.");
+ assertEquals(node.at("/warnings/0/1").asText(),
+ "Parameter corpusQuery is deprecated in favor of cq.");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchControllerTest.java
index 60b6550..610646c0 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchControllerTest.java
@@ -43,8 +43,11 @@
// EM: The API is disabled
@Disabled
@Test
- public void testGetJSONQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("context", "sentence").queryParam("count", "13").request().method("GET");
+ public void testGetJSONQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -58,13 +61,17 @@
// EM: The API is disabled
@Disabled
@Test
- public void testbuildAndPostQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE").request().method("GET");
+ public void testbuildAndPostQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE").request()
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
- response = target().path(API_VERSION).path("search").request().post(Entity.json(query));
+ response = target().path(API_VERSION).path("search").request()
+ .post(Entity.json(query));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String matches = response.readEntity(String.class);
JsonNode match_node = JsonUtils.readTree(matches);
@@ -72,17 +79,21 @@
}
@Test
- public void testApiWelcomeMessage() {
+ public void testApiWelcomeMessage () {
Response response = target().path(API_VERSION).path("").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String message = response.readEntity(String.class);
- assertEquals(response.getHeaders().getFirst("X-Index-Revision"), "Wes8Bd4h1OypPqbWF5njeQ==");
+ assertEquals(response.getHeaders().getFirst("X-Index-Revision"),
+ "Wes8Bd4h1OypPqbWF5njeQ==");
assertEquals(message, config.getApiWelcomeMessage());
}
@Test
- public void testQueryGet() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testQueryGet () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -94,8 +105,11 @@
}
@Test
- public void testQueryFailure() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das").queryParam("ql", "poliqarp").queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE").queryParam("count", "13").request().get();
+ public void testQueryFailure () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das").queryParam("ql", "poliqarp")
+ .queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE")
+ .queryParam("count", "13").request().get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -108,8 +122,11 @@
}
@Test
- public void testFoundryRewrite() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testFoundryRewrite () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -121,10 +138,11 @@
// EM: The API is disabled
@Test
@Disabled
- public void testQueryPost() throws KustvaktException {
+ public void testQueryPost () throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=das]", "poliqarp");
- Response response = target().path(API_VERSION).path("search").request().post(Entity.json(s.toJSON()));
+ Response response = target().path(API_VERSION).path("search").request()
+ .post(Entity.json(s.toJSON()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -134,71 +152,105 @@
}
@Test
- public void testParameterField() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("fields", "author,docSigle").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testParameterField () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("fields", "author,docSigle")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals(node.at("/query/wrap/layer").asText(), "orth");
assertNotEquals(0, node.at("/matches").size());
- assertEquals(node.at("/meta/fields").toString(), "[\"author\",\"docSigle\"]");
+ assertEquals(node.at("/meta/fields").toString(),
+ "[\"author\",\"docSigle\"]");
}
@Test
- public void testMatchInfoGetWithoutSpans() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo").queryParam("foundry", "*").queryParam("spans", "false").request().get();
+ public void testMatchInfoGetWithoutSpans () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
+ .queryParam("foundry", "*").queryParam("spans", "false")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals(node.at("/textSigle").asText(), "GOE/AGA/01784");
- assertEquals(node.at("/matchID").asText(), "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
+ assertEquals(node.at("/matchID").asText(),
+ "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
assertEquals(node.at("/title").asText(), "Belagerung von Mainz");
}
@Test
- public void testMatchInfoGetWithoutHighlights() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo").queryParam("foundry", "xy").queryParam("spans", "false").request().get();
+ public void testMatchInfoGetWithoutHighlights () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
+ .queryParam("foundry", "xy").queryParam("spans", "false")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
- assertEquals(node.at("/snippet").asText(), "<span class=\"context-left\"></span><span class=\"match\">der alte freie Weg nach Mainz war gesperrt, ich mußte über die Schiffbrücke bei Rüsselsheim; in Ginsheim ward <mark>gefüttert; der Ort ist sehr zerschossen; dann über die Schiffbrücke</mark> auf die Nonnenaue, wo viele Bäume niedergehauen lagen, sofort auf dem zweiten Teil der Schiffbrücke über den größern Arm des Rheins.</span><span class=\"context-right\"></span>");
+ assertEquals(node.at("/snippet").asText(),
+ "<span class=\"context-left\"></span><span class=\"match\">der alte freie Weg nach Mainz war gesperrt, ich mußte über die Schiffbrücke bei Rüsselsheim; in Ginsheim ward <mark>gefüttert; der Ort ist sehr zerschossen; dann über die Schiffbrücke</mark> auf die Nonnenaue, wo viele Bäume niedergehauen lagen, sofort auf dem zweiten Teil der Schiffbrücke über den größern Arm des Rheins.</span><span class=\"context-right\"></span>");
assertEquals(node.at("/textSigle").asText(), "GOE/AGA/01784");
- assertEquals(node.at("/matchID").asText(), "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
+ assertEquals(node.at("/matchID").asText(),
+ "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
assertEquals(node.at("/title").asText(), "Belagerung von Mainz");
}
@Test
- public void testMatchInfoWithoutExtension() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42").queryParam("foundry", "-").queryParam("spans", "false").queryParam("expand", "false").request().get();
+ public void testMatchInfoWithoutExtension () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42")
+ .queryParam("foundry", "-").queryParam("spans", "false")
+ .queryParam("expand", "false").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals(node.at("/textSigle").asText(), "GOE/AGA/01784");
- assertEquals(node.at("/matchID").asText(), "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
- assertEquals(node.at("/snippet").asText(), "<span class=\"context-left\"><span class=\"more\"></span></span><span class=\"match\"><mark>gefüttert; der Ort ist sehr zerschossen; dann über die Schiffbrücke</mark></span><span class=\"context-right\"><span class=\"more\"></span></span>");
+ assertEquals(node.at("/matchID").asText(),
+ "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
+ assertEquals(node.at("/snippet").asText(),
+ "<span class=\"context-left\"><span class=\"more\"></span></span><span class=\"match\"><mark>gefüttert; der Ort ist sehr zerschossen; dann über die Schiffbrücke</mark></span><span class=\"context-right\"><span class=\"more\"></span></span>");
assertEquals(node.at("/title").asText(), "Belagerung von Mainz");
}
@Test
- public void testMatchInfoGetWithHighlights() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo").queryParam("foundry", "xy").queryParam("spans", "false").queryParam("hls", "true").request().get();
+ public void testMatchInfoGetWithHighlights () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
+ .queryParam("foundry", "xy").queryParam("spans", "false")
+ .queryParam("hls", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals(node.at("/textSigle").asText(), "GOE/AGA/01784");
- assertEquals("<span class=\"context-left\"></span><span class=\"match\">" + "der alte freie Weg nach Mainz war gesperrt, ich mußte über die " + "Schiffbrücke bei Rüsselsheim; in Ginsheim ward <mark>gefüttert; " + "<mark class=\"class-5 level-0\">der <mark class=\"class-2 level-1\">" + "Ort ist sehr zerschossen; dann</mark> über die Schiffbrücke</mark></mark> " + "auf die Nonnenaue, wo viele Bäume niedergehauen lagen, sofort auf dem " + "zweiten Teil der Schiffbrücke über den größern Arm des Rheins.</span>" + "<span class=\"context-right\"></span>", node.at("/snippet").asText());
- assertEquals(node.at("/matchID").asText(), "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
+ assertEquals(
+ "<span class=\"context-left\"></span><span class=\"match\">"
+ + "der alte freie Weg nach Mainz war gesperrt, ich mußte über die "
+ + "Schiffbrücke bei Rüsselsheim; in Ginsheim ward <mark>gefüttert; "
+ + "<mark class=\"class-5 level-0\">der <mark class=\"class-2 level-1\">"
+ + "Ort ist sehr zerschossen; dann</mark> über die Schiffbrücke</mark></mark> "
+ + "auf die Nonnenaue, wo viele Bäume niedergehauen lagen, sofort auf dem "
+ + "zweiten Teil der Schiffbrücke über den größern Arm des Rheins.</span>"
+ + "<span class=\"context-right\"></span>",
+ node.at("/snippet").asText());
+ assertEquals(node.at("/matchID").asText(),
+ "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
assertEquals(node.at("/title").asText(), "Belagerung von Mainz");
}
@Test
- public void testMatchInfoGet2() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/GOE/AGA/01784/p36-46/matchInfo").queryParam("foundry", "*").request().get();
+ public void testMatchInfoGet2 () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/GOE/AGA/01784/p36-46/matchInfo")
+ .queryParam("foundry", "*").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -210,16 +262,27 @@
// EM: The API is disabled
@Disabled
@Test
- public void testCollectionQueryParameter() throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("fields", "author, docSigle").queryParam("context", "sentence").queryParam("count", "13").queryParam("cq", "textClass=Politik & corpus=WPD").request().method("GET");
+ public void testCollectionQueryParameter () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("fields", "author, docSigle")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .queryParam("cq", "textClass=Politik & corpus=WPD").request()
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals(node.at("/query/wrap/layer").asText(), "orth");
- assertEquals(node.at("/collection/operands/0/value").asText(), "Politik");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "Politik");
assertEquals(node.at("/collection/operands/1/value").asText(), "WPD");
- response = target().path(API_VERSION).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").request().get();
+ response = target().path(API_VERSION).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").request()
+ .get();
// String version =
// LucenePackage.get().getImplementationVersion();;
// System.out.println("VERSION "+ version);
@@ -229,22 +292,33 @@
node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals(node.at("/query/wrap/layer").asText(), "orth");
- assertEquals(node.at("/collection/operands/0/value").asText(), "Politik");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "Politik");
assertEquals(node.at("/collection/operands/1/value").asText(), "WPD");
}
@Test
- public void testTokenRetrieval() throws KustvaktException {
- Response response = target().path(API_VERSION).path("/corpus/GOE/AGA/01784/p104-105/").request().method("GET");
+ public void testTokenRetrieval () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("/corpus/GOE/AGA/01784/p104-105/").request()
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String resp = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(resp);
assertTrue(node.at("/hasSnippet").asBoolean());
assertFalse(node.at("/hasTokens").asBoolean());
assertTrue(node.at("/tokens").isMissingNode());
- assertEquals("<span class=\"context-left\"><span class=\"more\"></span></span>" + "<span class=\"match\"><mark>die</mark></span>" + "<span class=\"context-right\"><span class=\"more\"></span></span>", node.at("/snippet").asText());
+ assertEquals(
+ "<span class=\"context-left\"><span class=\"more\"></span></span>"
+ + "<span class=\"match\"><mark>die</mark></span>"
+ + "<span class=\"context-right\"><span class=\"more\"></span></span>",
+ node.at("/snippet").asText());
// Tokens
- response = target().path(API_VERSION).path("/corpus/GOE/AGA/01784/p104-105").queryParam("show-snippet", "false").queryParam("show-tokens", "true").queryParam("expand", "false").request().method("GET");
+ response = target().path(API_VERSION)
+ .path("/corpus/GOE/AGA/01784/p104-105")
+ .queryParam("show-snippet", "false")
+ .queryParam("show-tokens", "true").queryParam("expand", "false")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
resp = response.readEntity(String.class);
node = JsonUtils.readTree(resp);
@@ -256,8 +330,9 @@
}
@Test
- public void testMetaFields() throws KustvaktException {
- Response response = target().path(API_VERSION).path("/corpus/GOE/AGA/01784").request().method("GET");
+ public void testMetaFields () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("/corpus/GOE/AGA/01784").request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String resp = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(resp);
@@ -276,7 +351,8 @@
break;
case "author":
assertEquals(field.at("/type").asText(), "type:text");
- assertEquals(field.at("/value").asText(), "Goethe, Johann Wolfgang von");
+ assertEquals(field.at("/value").asText(),
+ "Goethe, Johann Wolfgang von");
checkC++;
break;
case "docSigle":
@@ -286,7 +362,8 @@
break;
case "docTitle":
assertEquals(field.at("/type").asText(), "type:text");
- assertEquals(field.at("/value").asText(), "Goethe: Autobiographische Schriften II, (1817-1825, 1832)");
+ assertEquals(field.at("/value").asText(),
+ "Goethe: Autobiographische Schriften II, (1817-1825, 1832)");
checkC++;
break;
case "pubDate":
@@ -294,32 +371,37 @@
assertEquals(1982, field.at("/value").asInt());
checkC++;
break;
- }
- ;
- }
- ;
+ };
+ };
assertEquals(5, checkC);
}
@Test
- public void testSearchWithoutVersion() throws KustvaktException {
- Response response = target().path("api").path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").request().accept(MediaType.APPLICATION_JSON).get();
+ public void testSearchWithoutVersion () throws KustvaktException {
+ Response response = target().path("api").path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .request().accept(MediaType.APPLICATION_JSON).get();
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
assertEquals(location.getPath(), "/api/v1.0/search");
}
@Test
- public void testSearchWrongVersion() throws KustvaktException {
- Response response = target().path("api").path("v0.2").path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").request().accept(MediaType.APPLICATION_JSON).get();
+ public void testSearchWrongVersion () throws KustvaktException {
+ Response response = target().path("api").path("v0.2").path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .request().accept(MediaType.APPLICATION_JSON).get();
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
assertEquals(location.getPath(), "/api/v1.0/search");
}
@Test
- public void testSearchWithIP() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Wasser").queryParam("ql", "poliqarp").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testSearchWithIP () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Wasser").queryParam("ql", "poliqarp")
+ .request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -327,8 +409,13 @@
}
@Test
- public void testSearchWithAuthorizationHeader() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Wasser").queryParam("ql", "poliqarp").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("test", "pwd")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testSearchWithAuthorizationHeader () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Wasser").queryParam("ql", "poliqarp")
+ .request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("test", "pwd"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -336,8 +423,10 @@
}
@Test
- public void testSearchPublicMetadata() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("access-rewrite-disabled", "true").request().get();
+ public void testSearchPublicMetadata () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("access-rewrite-disabled", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -345,45 +434,61 @@
}
@Test
- public void testSearchPublicMetadataWithCustomFields() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Sonne").queryParam("ql", "poliqarp").queryParam("fields", "author,title").queryParam("access-rewrite-disabled", "true").request().get();
+ public void testSearchPublicMetadataWithCustomFields ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+ .queryParam("fields", "author,title")
+ .queryParam("access-rewrite-disabled", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertTrue(node.at("/matches/0/snippet").isMissingNode());
- assertEquals(node.at("/matches/0/author").asText(), "Goethe, Johann Wolfgang von");
- assertEquals(node.at("/matches/0/title").asText(), "Italienische Reise");
+ assertEquals(node.at("/matches/0/author").asText(),
+ "Goethe, Johann Wolfgang von");
+ assertEquals(node.at("/matches/0/title").asText(),
+ "Italienische Reise");
// assertEquals(3, node.at("/matches/0").size());
}
@Test
- public void testSearchPublicMetadataWithNonPublicField() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Sonne").queryParam("ql", "poliqarp").queryParam("fields", "author,title,snippet").queryParam("access-rewrite-disabled", "true").request().get();
+ public void testSearchPublicMetadataWithNonPublicField ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+ .queryParam("fields", "author,title,snippet")
+ .queryParam("access-rewrite-disabled", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.NON_PUBLIC_FIELD_IGNORED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/1").asText(), "The requested non public fields are ignored");
+ assertEquals(StatusCodes.NON_PUBLIC_FIELD_IGNORED,
+ node.at("/warnings/0/0").asInt());
+ assertEquals(node.at("/warnings/0/1").asText(),
+ "The requested non public fields are ignored");
assertEquals(node.at("/warnings/0/2").asText(), "snippet");
}
@Test
- public void testSearchWithInvalidPage() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").queryParam("page", "0").request().get();
+ public void testSearchWithInvalidPage () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .queryParam("page", "0").request().get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/1").asText(), "page must start from 1");
}
@Test
- public void testCloseIndex() throws IOException, KustvaktException {
+ public void testCloseIndex () throws IOException, KustvaktException {
searchKrill.getStatistics(null);
assertEquals(true, searchKrill.getIndex().isReaderOpen());
Form form = new Form();
form.param("token", "secret");
- Response response = target().path(API_VERSION).path("index").path("close").request().post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("index")
+ .path("close").request().post(Entity.form(form));
assertEquals(HttpStatus.OK_200, response.getStatus());
assertEquals(false, searchKrill.getIndex().isReaderOpen());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchPipeTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchPipeTest.java
index f747934..704ae5f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchPipeTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchPipeTest.java
@@ -45,29 +45,43 @@
private String glemmUri = "http://localhost:" + port + "/glemm";
- public LiteSearchPipeTest() throws IOException {
- pipeJson = IOUtils.toString(ClassLoader.getSystemResourceAsStream("pipe-output/test-pipes.jsonld"), StandardCharsets.UTF_8);
- pipeWithParamJson = IOUtils.toString(ClassLoader.getSystemResourceAsStream("pipe-output/with-param.jsonld"), StandardCharsets.UTF_8);
+ public LiteSearchPipeTest () throws IOException {
+ pipeJson = IOUtils.toString(
+ ClassLoader.getSystemResourceAsStream(
+ "pipe-output/test-pipes.jsonld"),
+ StandardCharsets.UTF_8);
+ pipeWithParamJson = IOUtils.toString(
+ ClassLoader.getSystemResourceAsStream(
+ "pipe-output/with-param.jsonld"),
+ StandardCharsets.UTF_8);
}
@BeforeEach
- public void startMockServer() {
+ public void startMockServer () {
mockServer = startClientAndServer(port);
mockClient = new MockServerClient("localhost", mockServer.getPort());
}
@AfterEach
- public void stopMockServer() {
+ public void stopMockServer () {
mockServer.stop();
}
@Test
- public void testMockServer() throws IOException {
- mockClient.reset().when(request().withMethod("POST").withPath("/test").withHeader(new Header("Content-Type", "application/json; charset=utf-8"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody("{test}").withStatusCode(200));
+ public void testMockServer () throws IOException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/test")
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody("{test}").withStatusCode(200));
URL url = new URL("http://localhost:" + port + "/test");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
+ connection.setRequestProperty("Content-Type",
+ "application/json; charset=UTF-8");
connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
String json = "{\"name\" : \"dory\"}";
@@ -76,14 +90,27 @@
os.write(input, 0, input.length);
}
assertEquals(200, connection.getResponseCode());
- BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
+ BufferedReader br = new BufferedReader(
+ new InputStreamReader(connection.getInputStream(), "utf-8"));
assertEquals(br.readLine(), "{test}");
}
@Test
- public void testSearchWithPipes() throws IOException, KustvaktException, URISyntaxException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeJson).withStatusCode(200));
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri).request().get();
+ public void testSearchWithPipes ()
+ throws IOException, KustvaktException, URISyntaxException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeJson).withStatusCode(200));
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri).request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -99,20 +126,44 @@
}
@Test
- public void testSearchWithUrlEncodedPipes() throws IOException, KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeJson).withStatusCode(200));
+ public void testSearchWithUrlEncodedPipes ()
+ throws IOException, KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeJson).withStatusCode(200));
glemmUri = URLEncoder.encode(glemmUri, "utf-8");
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri).request().get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
}
@Test
- public void testSearchWithMultiplePipes() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withQueryStringParameter("param").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeWithParamJson).withStatusCode(200));
+ public void testSearchWithMultiplePipes () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withQueryStringParameter("param").withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeWithParamJson).withStatusCode(200));
String glemmUri2 = glemmUri + "?param=blah";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri + "," + glemmUri2).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri + "," + glemmUri2).request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -120,9 +171,13 @@
}
@Test
- public void testSearchWithUnknownURL() throws IOException, KustvaktException {
- String url = target().getUri().toString() + API_VERSION + "/test/tralala";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", url).request().get();
+ public void testSearchWithUnknownURL ()
+ throws IOException, KustvaktException {
+ String url = target().getUri().toString() + API_VERSION
+ + "/test/tralala";
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", url).request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -131,8 +186,10 @@
}
@Test
- public void testSearchWithUnknownHost() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", "http://glemm").request().get();
+ public void testSearchWithUnknownHost () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", "http://glemm").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -141,21 +198,30 @@
}
@Test
- public void testSearchUnsupportedMediaType() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/non-json-pipe")).respond(response().withStatusCode(415));
+ public void testSearchUnsupportedMediaType () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/non-json-pipe"))
+ .respond(response().withStatusCode(415));
String pipeUri = "http://localhost:" + port + "/non-json-pipe";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", pipeUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", pipeUri).request().get();
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.PIPE_FAILED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/3").asText(), "415 Unsupported Media Type");
+ assertEquals(node.at("/warnings/0/3").asText(),
+ "415 Unsupported Media Type");
}
@Test
- public void testSearchWithMultiplePipeWarnings() throws KustvaktException {
- String url = target().getUri().toString() + API_VERSION + "/test/tralala";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", url + "," + "http://glemm").request().get();
+ public void testSearchWithMultiplePipeWarnings () throws KustvaktException {
+ String url = target().getUri().toString() + API_VERSION
+ + "/test/tralala";
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", url + "," + "http://glemm").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -169,37 +235,73 @@
}
@Test
- public void testSearchWithInvalidJsonResponse() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/invalid-response").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withBody("{blah:}").withStatusCode(200).withHeaders(new Header("Content-Type", "application/json; charset=utf-8")));
+ public void testSearchWithInvalidJsonResponse () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/invalid-response")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response().withBody("{blah:}").withStatusCode(200)
+ .withHeaders(new Header("Content-Type",
+ "application/json; charset=utf-8")));
String pipeUri = "http://localhost:" + port + "/invalid-response";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", pipeUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", pipeUri).request().get();
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.DESERIALIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.DESERIALIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testSearchWithPlainTextResponse() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/plain-text").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withBody("blah").withStatusCode(200));
+ public void testSearchWithPlainTextResponse () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/plain-text")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response().withBody("blah").withStatusCode(200));
String pipeUri = "http://localhost:" + port + "/plain-text";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", pipeUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", pipeUri).request().get();
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.DESERIALIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.DESERIALIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testSearchWithMultipleAndUnknownPipes() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeJson).withStatusCode(200));
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", "http://unknown" + "," + glemmUri).request().get();
+ public void testSearchWithMultipleAndUnknownPipes ()
+ throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeJson).withStatusCode(200));
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", "http://unknown" + "," + glemmUri)
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
assertTrue(node.at("/warnings").isMissingNode());
- response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri + ",http://unknown").request().get();
+ response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri + ",http://unknown").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchTokenSnippetTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchTokenSnippetTest.java
index 75b9920..fb78508 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchTokenSnippetTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchTokenSnippetTest.java
@@ -18,8 +18,12 @@
public class LiteSearchTokenSnippetTest extends LiteJerseyTest {
@Test
- public void testSearchWithTokens() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("show-tokens", "true").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testSearchWithTokens () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("show-tokens", "true")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -31,8 +35,12 @@
}
@Test
- public void testSearchWithoutTokens() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("show-tokens", "false").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testSearchWithoutTokens () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("show-tokens", "false")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -42,8 +50,13 @@
}
@Test
- public void testSearchPublicMetadataWithTokens() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("access-rewrite-disabled", "true").queryParam("show-tokens", "true").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testSearchPublicMetadataWithTokens () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("access-rewrite-disabled", "true")
+ .queryParam("show-tokens", "true")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java
index 65e57c3..4314ef0 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java
@@ -21,10 +21,13 @@
public class LiteStatisticControllerTest extends LiteJerseyTest {
@Test
- public void testStatisticsWithCq() throws KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("cq", "textType=Abhandlung & corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithCq () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- assertEquals(response.getHeaders().getFirst("X-Index-Revision"), "Wes8Bd4h1OypPqbWF5njeQ==");
+ assertEquals(response.getHeaders().getFirst("X-Index-Revision"),
+ "Wes8Bd4h1OypPqbWF5njeQ==");
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertEquals(2, node.at("/documents").asInt());
@@ -35,8 +38,12 @@
}
@Test
- public void testStatisticsWithCqAndCorpusQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("cq", "textType=Abhandlung & corpusSigle=GOE").queryParam("corpusQuery", "textType=Autobiographie & corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithCqAndCorpusQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
+ .queryParam("corpusQuery",
+ "textType=Autobiographie & corpusSigle=GOE")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -48,8 +55,11 @@
}
@Test
- public void testStatisticsWithCorpusQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", "textType=Autobiographie & corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithCorpusQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery",
+ "textType=Autobiographie & corpusSigle=GOE")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -58,12 +68,14 @@
assertEquals(19387, node.at("/sentences").asInt());
assertEquals(514, node.at("/paragraphs").asInt());
assertEquals(StatusCodes.DEPRECATED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/1").asText(), "Parameter corpusQuery is deprecated in favor of cq.");
+ assertEquals(node.at("/warnings/0/1").asText(),
+ "Parameter corpusQuery is deprecated in favor of cq.");
}
@Test
- public void testEmptyStatistics() throws KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", "").request().method("GET");
+ public void testEmptyStatistics () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery", "").request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -71,7 +83,8 @@
assertEquals(665842, node.at("/tokens").asInt());
assertEquals(25074, node.at("/sentences").asInt());
assertEquals(772, node.at("/paragraphs").asInt());
- response = target().path(API_VERSION).path("statistics").request().method("GET");
+ response = target().path(API_VERSION).path("statistics").request()
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
query = response.readEntity(String.class);
node = JsonUtils.readTree(query);
@@ -82,11 +95,19 @@
}
@Test
- public void testGetStatisticsWithKoralQuery() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).post(Entity.json("{ \"collection\" : {\"@type\": " + "\"koral:doc\", \"key\": \"availability\", \"match\": " + "\"match:eq\", \"type\": \"type:regex\", \"value\": " + "\"CC-BY.*\"} }"));
+ public void testGetStatisticsWithKoralQuery ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request()
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .post(Entity.json("{ \"collection\" : {\"@type\": "
+ + "\"koral:doc\", \"key\": \"availability\", \"match\": "
+ + "\"match:eq\", \"type\": \"type:regex\", \"value\": "
+ + "\"CC-BY.*\"} }"));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
- assertEquals(response.getHeaders().getFirst("X-Index-Revision"), "Wes8Bd4h1OypPqbWF5njeQ==");
+ assertEquals(response.getHeaders().getFirst("X-Index-Revision"),
+ "Wes8Bd4h1OypPqbWF5njeQ==");
JsonNode node = JsonUtils.readTree(ent);
assertEquals(2, node.at("/documents").asInt());
assertEquals(72770, node.at("/tokens").asInt());
@@ -95,28 +116,42 @@
}
@Test
- public void testGetStatisticsWithEmptyCollection() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).post(Entity.json("{}"));
+ public void testGetStatisticsWithEmptyCollection ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request()
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .post(Entity.json("{}"));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(node.at("/errors/0/0").asInt(), de.ids_mannheim.korap.util.StatusCodes.MISSING_COLLECTION);
- assertEquals(node.at("/errors/0/1").asText(), "Collection is not found");
+ assertEquals(node.at("/errors/0/0").asInt(),
+ de.ids_mannheim.korap.util.StatusCodes.MISSING_COLLECTION);
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Collection is not found");
}
@Test
- public void testGetStatisticsWithIncorrectJson() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).post(Entity.json("{ \"collection\" : }"));
+ public void testGetStatisticsWithIncorrectJson ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request()
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .post(Entity.json("{ \"collection\" : }"));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(StatusCodes.DESERIALIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Failed deserializing json object: { \"collection\" : }");
+ assertEquals(StatusCodes.DESERIALIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Failed deserializing json object: { \"collection\" : }");
}
@Test
- public void testGetStatisticsWithoutKoralQuery() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().post(Entity.json(""));
+ public void testGetStatisticsWithoutKoralQuery ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request().post(Entity.json(""));
String ent = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/SearchNetworkEndpointTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/SearchNetworkEndpointTest.java
index fa72cee..81c2430 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/SearchNetworkEndpointTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/SearchNetworkEndpointTest.java
@@ -42,26 +42,41 @@
private String endpointURL = "http://localhost:" + port + "/searchEndpoint";
- public SearchNetworkEndpointTest() throws IOException {
- searchResult = IOUtils.toString(ClassLoader.getSystemResourceAsStream("network-output/search-result.jsonld"), StandardCharsets.UTF_8);
+ public SearchNetworkEndpointTest () throws IOException {
+ searchResult = IOUtils.toString(
+ ClassLoader.getSystemResourceAsStream(
+ "network-output/search-result.jsonld"),
+ StandardCharsets.UTF_8);
}
@BeforeEach
- public void startMockServer() {
+ public void startMockServer () {
mockServer = startClientAndServer(port);
mockClient = new MockServerClient("localhost", mockServer.getPort());
}
@AfterEach
- public void stopMockServer() {
+ public void stopMockServer () {
mockServer.stop();
}
@Test
- public void testSearchNetwork() throws IOException, KustvaktException, URISyntaxException {
+ public void testSearchNetwork ()
+ throws IOException, KustvaktException, URISyntaxException {
config.setNetworkEndpointURL(endpointURL);
- mockClient.reset().when(request().withMethod("POST").withPath("/searchEndpoint").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(searchResult).withStatusCode(200));
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("engine", "network").request().get();
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/searchEndpoint")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(searchResult).withStatusCode(200));
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("engine", "network").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -69,22 +84,29 @@
}
@Test
- public void testSearchWithUnknownURL() throws IOException, KustvaktException {
+ public void testSearchWithUnknownURL ()
+ throws IOException, KustvaktException {
config.setNetworkEndpointURL("http://localhost:1040/search");
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("engine", "network").request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("engine", "network").request().get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED,
+ node.at("/errors/0/0").asInt());
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testSearchWithUnknownHost() throws KustvaktException {
+ public void testSearchWithUnknownHost () throws KustvaktException {
config.setNetworkEndpointURL("http://search.com");
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("engine", "network").request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("engine", "network").request().get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED,
+ node.at("/errors/0/0").asInt());
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
}