blob: ecede59a7d9dfb58af553b3ad89657c022b9aeab [file] [log] [blame]
margaretha541b8cc2018-01-10 13:02:46 +01001package de.ids_mannheim.korap.web.controller;
margaretha0c47c652017-04-19 18:44:40 +02002
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotEquals;
5import static org.junit.Assert.assertNotNull;
margaretha3fc0fd42017-05-02 18:08:31 +02006import static org.junit.Assert.assertTrue;
margaretha0c47c652017-04-19 18:44:40 +02007
margaretha6c2a20f2017-07-24 15:33:01 +02008import javax.ws.rs.core.MediaType;
9
margarethaa89c3f92017-05-30 19:02:08 +020010import org.junit.Ignore;
margaretha0c47c652017-04-19 18:44:40 +020011import org.junit.Test;
margaretha4b5c1412017-11-15 20:55:04 +010012import org.springframework.beans.factory.annotation.Autowired;
margaretha0c47c652017-04-19 18:44:40 +020013
14import com.fasterxml.jackson.databind.JsonNode;
margaretha58e18632018-02-15 13:04:42 +010015import com.google.common.net.HttpHeaders;
margaretha0c47c652017-04-19 18:44:40 +020016import com.sun.jersey.api.client.ClientResponse;
17
margaretha56e8e552017-12-05 16:31:21 +010018import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
margaretha0c47c652017-04-19 18:44:40 +020019import de.ids_mannheim.korap.config.Attributes;
margaretha7a25f012018-03-22 19:49:01 +010020import de.ids_mannheim.korap.config.SpringJerseyTest;
margaretha0c47c652017-04-19 18:44:40 +020021import de.ids_mannheim.korap.exceptions.KustvaktException;
22import de.ids_mannheim.korap.query.serialize.QuerySerializer;
margaretha0c47c652017-04-19 18:44:40 +020023import de.ids_mannheim.korap.utils.JsonUtils;
margaretha0c47c652017-04-19 18:44:40 +020024
25/**
margaretha7a25f012018-03-22 19:49:01 +010026 * @author margaretha, hanl
27 * @lastUpdate 22/03/2018
margaretha0c47c652017-04-19 18:44:40 +020028 *
29 */
margaretha7a25f012018-03-22 19:49:01 +010030public class SearchControllerTest extends SpringJerseyTest {
margaretha0c47c652017-04-19 18:44:40 +020031
margaretha4b5c1412017-11-15 20:55:04 +010032 @Autowired
margaretha7a25f012018-03-22 19:49:01 +010033 private HttpAuthorizationHandler handler;
margaretha4b5c1412017-11-15 20:55:04 +010034
margarethaa89c3f92017-05-30 19:02:08 +020035
margaretha0c47c652017-04-19 18:44:40 +020036 @Test
margaretha894a7d72017-11-08 19:24:20 +010037 public void testSearchQueryPublicCorpora () throws KustvaktException{
margaretha6c2a20f2017-07-24 15:33:01 +020038 ClientResponse response = resource()
margaretha0c47c652017-04-19 18:44:40 +020039 .path("search").queryParam("q", "[orth=der]")
margaretha6c2a20f2017-07-24 15:33:01 +020040 .queryParam("ql", "poliqarp")
41 .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
margaretha7a25f012018-03-22 19:49:01 +010042 assertEquals(ClientResponse.Status.OK.getStatusCode(),
43 response.getStatus());
margaretha0c47c652017-04-19 18:44:40 +020044 String ent = response.getEntity(String.class);
margaretha23aae222017-12-22 15:08:23 +010045// System.out.println(ent);
margaretha0c47c652017-04-19 18:44:40 +020046 JsonNode node = JsonUtils.readTree(ent);
47 assertNotNull(node);
margarethad980c8f2017-05-22 17:20:42 +020048 assertEquals("koral:doc", node.at("/collection/@type").asText());
49 assertEquals("availability", node.at("/collection/key").asText());
50 assertEquals("CC-BY.*", node.at("/collection/value").asText());
margarethaa89c3f92017-05-30 19:02:08 +020051 assertEquals("availability(FREE)",
margaretha65b67142017-05-29 16:23:16 +020052 node.at("/collection/rewrites/0/scope").asText());
margarethaebe869a2017-06-01 19:07:41 +020053 assertEquals("operation:insertion",
54 node.at("/collection/rewrites/0/operation").asText());
margaretha0c47c652017-04-19 18:44:40 +020055 }
56
margaretha3fc0fd42017-05-02 18:08:31 +020057
58 @Test
margaretha894a7d72017-11-08 19:24:20 +010059 public void testSearchQueryWithMeta () throws KustvaktException{
margaretha6c2a20f2017-07-24 15:33:01 +020060 ClientResponse response = resource()
margaretha3fc0fd42017-05-02 18:08:31 +020061 .path("search").queryParam("q", "[orth=der]")
62 .queryParam("ql", "poliqarp").queryParam("cutoff", "true")
margarethaa89c3f92017-05-30 19:02:08 +020063 .queryParam("count", "5").queryParam("page", "1")
margaretha3fc0fd42017-05-02 18:08:31 +020064 .queryParam("context", "40-t,30-t").get(ClientResponse.class);
65 assertEquals(ClientResponse.Status.OK.getStatusCode(),
66 response.getStatus());
67 String ent = response.getEntity(String.class);
68 JsonNode node = JsonUtils.readTree(ent);
69 assertNotNull(node);
70 assertTrue(node.at("/meta/cutOff").asBoolean());
71 assertEquals(5, node.at("/meta/count").asInt());
72 assertEquals(0, node.at("/meta/startIndex").asInt());
73 assertEquals("token", node.at("/meta/context/left/0").asText());
74 assertEquals(40, node.at("/meta/context/left/1").asInt());
75 assertEquals(30, node.at("/meta/context/right/1").asInt());
margarethaa89c3f92017-05-30 19:02:08 +020076 assertEquals(-1, node.at("/meta/totalResults").asInt());
margaretha3fc0fd42017-05-02 18:08:31 +020077 }
78
margarethaebe869a2017-06-01 19:07:41 +020079 @Test
margaretha894a7d72017-11-08 19:24:20 +010080 public void testSearchQueryFreeExtern () throws KustvaktException{
margaretha6c2a20f2017-07-24 15:33:01 +020081 ClientResponse response = resource()
margarethaebe869a2017-06-01 19:07:41 +020082 .path("search").queryParam("q", "[orth=die]")
83 .queryParam("ql", "poliqarp")
84 .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
85 .get(ClientResponse.class);
86 assertEquals(ClientResponse.Status.OK.getStatusCode(),
87 response.getStatus());
88 String entity = response.getEntity(String.class);
89 JsonNode node = JsonUtils.readTree(entity);
90 assertNotNull(node);
91 assertNotEquals(0, node.path("matches").size());
92 assertEquals("koral:doc", node.at("/collection/@type").asText());
93 assertEquals("availability", node.at("/collection/key").asText());
94 assertEquals("CC-BY.*", node.at("/collection/value").asText());
95 assertEquals("availability(FREE)",
96 node.at("/collection/rewrites/0/scope").asText());
97 assertEquals("operation:insertion",
98 node.at("/collection/rewrites/0/operation").asText());
99 }
100
101 @Test
margaretha894a7d72017-11-08 19:24:20 +0100102 public void testSearchQueryFreeIntern () throws KustvaktException{
margaretha6c2a20f2017-07-24 15:33:01 +0200103 ClientResponse response = resource()
margarethaebe869a2017-06-01 19:07:41 +0200104 .path("search").queryParam("q", "[orth=die]")
105 .queryParam("ql", "poliqarp")
106 .header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32")
107 .get(ClientResponse.class);
108 assertEquals(ClientResponse.Status.OK.getStatusCode(),
109 response.getStatus());
110 String entity = response.getEntity(String.class);
111 JsonNode node = JsonUtils.readTree(entity);
112 assertNotNull(node);
113 assertNotEquals(0, node.path("matches").size());
114 assertEquals("koral:doc", node.at("/collection/@type").asText());
115 assertEquals("availability", node.at("/collection/key").asText());
116 assertEquals("CC-BY.*", node.at("/collection/value").asText());
117 assertEquals("availability(FREE)",
118 node.at("/collection/rewrites/0/scope").asText());
119 assertEquals("operation:insertion",
120 node.at("/collection/rewrites/0/operation").asText());
121 }
122
123
margaretha0c47c652017-04-19 18:44:40 +0200124 @Test
margaretha894a7d72017-11-08 19:24:20 +0100125 public void testSearchQueryExternAuthorized () throws KustvaktException{
margaretha6c2a20f2017-07-24 15:33:01 +0200126 ClientResponse response = resource()
margaretha0c47c652017-04-19 18:44:40 +0200127 .path("search").queryParam("q", "[orth=die]")
128 .queryParam("ql", "poliqarp")
129 .header(Attributes.AUTHORIZATION,
margaretha2afb97d2017-12-07 19:18:44 +0100130 handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"))
margaretha65b67142017-05-29 16:23:16 +0200131 .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
margaretha0c47c652017-04-19 18:44:40 +0200132 .get(ClientResponse.class);
133 assertEquals(ClientResponse.Status.OK.getStatusCode(),
134 response.getStatus());
margaretha61471cc2017-04-20 18:42:23 +0200135 String entity = response.getEntity(String.class);
136 JsonNode node = JsonUtils.readTree(entity);
margarethacfea1ae2018-01-15 20:27:26 +0100137// System.out.println(entity);
margaretha0c47c652017-04-19 18:44:40 +0200138 assertNotNull(node);
margaretha65b67142017-05-29 16:23:16 +0200139 assertNotEquals(0, node.path("matches").size());
140 assertEquals("koral:docGroup", node.at("/collection/@type").asText());
margarethaa89c3f92017-05-30 19:02:08 +0200141 assertEquals("CC-BY.*",
142 node.at("/collection/operands/0/value").asText());
margarethaad618d22017-12-11 19:58:49 +0100143 assertEquals("ACA.*", node.at("/collection/operands/1/operands/0/value").asText());
144 assertEquals("QAO-NC", node.at("/collection/operands/1/operands/1/value").asText());
margaretha65b67142017-05-29 16:23:16 +0200145 assertEquals("operation:or", node.at("/collection/operation").asText());
margarethaa89c3f92017-05-30 19:02:08 +0200146 assertEquals("availability(PUB)",
margaretha65b67142017-05-29 16:23:16 +0200147 node.at("/collection/rewrites/0/scope").asText());
margarethaebe869a2017-06-01 19:07:41 +0200148 assertEquals("operation:insertion",
149 node.at("/collection/rewrites/0/operation").asText());
margaretha0c47c652017-04-19 18:44:40 +0200150 }
151
margaretha65b67142017-05-29 16:23:16 +0200152 @Test
margaretha894a7d72017-11-08 19:24:20 +0100153 public void testSearchQueryInternAuthorized () throws KustvaktException{
margaretha6c2a20f2017-07-24 15:33:01 +0200154 ClientResponse response = resource()
margaretha65b67142017-05-29 16:23:16 +0200155 .path("search").queryParam("q", "[orth=die]")
156 .queryParam("ql", "poliqarp")
157 .header(Attributes.AUTHORIZATION,
margaretha2afb97d2017-12-07 19:18:44 +0100158 handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"))
margaretha65b67142017-05-29 16:23:16 +0200159 .header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32")
160 .get(ClientResponse.class);
161 assertEquals(ClientResponse.Status.OK.getStatusCode(),
162 response.getStatus());
163 String entity = response.getEntity(String.class);
164 JsonNode node = JsonUtils.readTree(entity);
165 assertNotNull(node);
166 assertNotEquals(0, node.path("matches").size());
margarethaebe869a2017-06-01 19:07:41 +0200167 //EM: no rewrite is needed
168// assertEquals("koral:docGroup", node.at("/collection/@type").asText());
169// assertEquals("QAO.*", node.at("/collection/operands/0/value").asText());
170// assertEquals("ACA.*",
171// node.at("/collection/operands/1/operands/0/value").asText());
172// assertEquals("CC-BY.*",
173// node.at("/collection/operands/1/operands/1/value").asText());
174// assertEquals("operation:or", node.at("/collection/operation").asText());
175// assertEquals("availability(ALL)",
176// node.at("/collection/rewrites/0/scope").asText());
177// assertEquals("operation:insertion",
178// node.at("/collection/rewrites/0/operation").asText());
margaretha65b67142017-05-29 16:23:16 +0200179 }
margaretha0c47c652017-04-19 18:44:40 +0200180
margarethaebe869a2017-06-01 19:07:41 +0200181 // EM: shouldn't this case gets CorpusAccess.PUB ?
margaretha0c47c652017-04-19 18:44:40 +0200182 @Test
margaretha9a509ed2017-06-27 11:08:32 +0200183 @Ignore
margaretha894a7d72017-11-08 19:24:20 +0100184 public void testSearchQueryWithCollectionQueryAuthorizedWithoutIP () throws KustvaktException{
margaretha6c2a20f2017-07-24 15:33:01 +0200185 ClientResponse response = resource()
margaretha0c47c652017-04-19 18:44:40 +0200186 .path("search").queryParam("q", "[orth=das]")
187 .queryParam("ql", "poliqarp")
188 .queryParam("cq", "textClass=politik & corpusSigle=BRZ10")
189 .header(Attributes.AUTHORIZATION,
margaretha2afb97d2017-12-07 19:18:44 +0100190 handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"))
margaretha0c47c652017-04-19 18:44:40 +0200191 .get(ClientResponse.class);
192 assertEquals(ClientResponse.Status.OK.getStatusCode(),
193 response.getStatus());
194
195 JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
196 assertNotNull(node);
margarethaa89c3f92017-05-30 19:02:08 +0200197 assertEquals("operation:insertion",
198 node.at("/collection/rewrites/0/operation").asText());
199 assertEquals("availability(PUB)",
200 node.at("/collection/rewrites/0/scope").asText());
201 // EM: double AND operations
margarethaebe869a2017-06-01 19:07:41 +0200202 assertEquals("availability",
203 node.at("/collection/operands/0/key").asText());
204 assertEquals("CC-BY.*",
205 node.at("/collection/operands/0/value").asText());
margaretha0c47c652017-04-19 18:44:40 +0200206 assertEquals("textClass",
margarethaa89c3f92017-05-30 19:02:08 +0200207 node.at("/collection/operands/1/operands/0/key").asText());
margaretha0c47c652017-04-19 18:44:40 +0200208 assertEquals("corpusSigle",
margarethaa89c3f92017-05-30 19:02:08 +0200209 node.at("/collection/operands/1/operands/1/key").asText());
margaretha0c47c652017-04-19 18:44:40 +0200210 }
margarethaa89c3f92017-05-30 19:02:08 +0200211
212 @Test
margaretha9a509ed2017-06-27 11:08:32 +0200213 @Ignore
margaretha894a7d72017-11-08 19:24:20 +0100214 public void testSearchQueryAuthorizedWithoutIP () throws KustvaktException{
margaretha6c2a20f2017-07-24 15:33:01 +0200215 ClientResponse response = resource()
margarethaebe869a2017-06-01 19:07:41 +0200216 .path("search").queryParam("q", "[orth=die]")
margarethaa89c3f92017-05-30 19:02:08 +0200217 .queryParam("ql", "poliqarp")
margarethaa89c3f92017-05-30 19:02:08 +0200218 .header(Attributes.AUTHORIZATION,
margaretha2afb97d2017-12-07 19:18:44 +0100219 handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"))
margarethaa89c3f92017-05-30 19:02:08 +0200220 .get(ClientResponse.class);
221 assertEquals(ClientResponse.Status.OK.getStatusCode(),
222 response.getStatus());
margarethaebe869a2017-06-01 19:07:41 +0200223 String entity = response.getEntity(String.class);
224 JsonNode node = JsonUtils.readTree(entity);
margarethaa89c3f92017-05-30 19:02:08 +0200225 assertNotNull(node);
margarethaebe869a2017-06-01 19:07:41 +0200226 assertNotEquals(0, node.path("matches").size());
227 assertEquals("koral:docGroup", node.at("/collection/@type").asText());
228 assertEquals("CC-BY.*",
229 node.at("/collection/operands/0/value").asText());
230 assertEquals("ACA.*", node.at("/collection/operands/1/value").asText());
231 assertEquals("operation:or", node.at("/collection/operation").asText());
margarethaa89c3f92017-05-30 19:02:08 +0200232 assertEquals("availability(PUB)",
233 node.at("/collection/rewrites/0/scope").asText());
234 }
margarethaebe869a2017-06-01 19:07:41 +0200235
236
margarethaa89c3f92017-05-30 19:02:08 +0200237
238 @Test
239 @Ignore
margaretha894a7d72017-11-08 19:24:20 +0100240 public void testSearchForPublicCorpusWithStringId () throws KustvaktException {
margaretha6c2a20f2017-07-24 15:33:01 +0200241 ClientResponse response = resource()
margaretha61471cc2017-04-20 18:42:23 +0200242 .path("corpus").path("GOE").path("search")
243 .queryParam("q", "blau").queryParam("ql", "poliqarp")
244 .get(ClientResponse.class);
245 assertEquals(ClientResponse.Status.OK.getStatusCode(),
246 response.getStatus());
247 String ent = response.getEntity(String.class);
248 JsonNode node = JsonUtils.readTree(ent);
249 assertNotNull(node);
margarethaa89c3f92017-05-30 19:02:08 +0200250 assertEquals("koral:docGroup", node.at("/collection/@type").asText());
251 assertEquals("operation:and",
252 node.at("/collection/operation").asText());
253 assertEquals("availability",
254 node.at("/collection/operands/0/key").asText());
255 assertEquals("CC-BY.*",
256 node.at("/collection/operands/0/value").asText());
257 assertEquals("corpusSigle",
258 node.at("/collection/operands/1/key").asText());
259 assertEquals("GOE", node.at("/collection/operands/1/value").asText());
margaretha15f496c2017-04-21 17:36:09 +0200260 assertNotEquals(0, node.path("matches").size());
margaretha15f496c2017-04-21 17:36:09 +0200261 }
margaretha3fc0fd42017-05-02 18:08:31 +0200262
263
margaretha15f496c2017-04-21 17:36:09 +0200264 @Test
margarethaa89c3f92017-05-30 19:02:08 +0200265 @Ignore
margaretha894a7d72017-11-08 19:24:20 +0100266 public void testSearchForVirtualCollectionWithStringId () throws KustvaktException{
margaretha6c2a20f2017-07-24 15:33:01 +0200267 ClientResponse response = resource()
margaretha15f496c2017-04-21 17:36:09 +0200268 .path("collection").path("GOE-VC").path("search")
269 .queryParam("q", "blau").queryParam("ql", "poliqarp")
270 .get(ClientResponse.class);
271 assertEquals(ClientResponse.Status.OK.getStatusCode(),
272 response.getStatus());
273 String ent = response.getEntity(String.class);
margaretha15f496c2017-04-21 17:36:09 +0200274 JsonNode node = JsonUtils.readTree(ent);
275 assertNotNull(node);
margaretha61471cc2017-04-20 18:42:23 +0200276 assertEquals("koral:docGroup", node.at("/collection/@type").asText());
margaretha3fc0fd42017-05-02 18:08:31 +0200277 assertEquals("operation:and",
278 node.at("/collection/operation").asText());
margaretha61471cc2017-04-20 18:42:23 +0200279 assertNotEquals(0, node.at("/collection/operands").size());
margaretha15f496c2017-04-21 17:36:09 +0200280 assertEquals("corpusSigle",
281 node.at("/collection/operands/0/key").asText());
margaretha3fc0fd42017-05-02 18:08:31 +0200282 assertEquals("GOE", node.at("/collection/operands/0/value").asText());
margaretha15f496c2017-04-21 17:36:09 +0200283 assertEquals("creationDate",
284 node.at("/collection/operands/1/key").asText());
285 assertEquals("1810-01-01",
286 node.at("/collection/operands/1/value").asText());
287 assertEquals(1, node.at("/meta/totalResults").asInt());
margaretha61471cc2017-04-20 18:42:23 +0200288 }
289
margaretha15f496c2017-04-21 17:36:09 +0200290 @Test
margarethaa89c3f92017-05-30 19:02:08 +0200291 @Ignore
margaretha894a7d72017-11-08 19:24:20 +0100292 public void testSearchForCorpusWithStringIdUnauthorized () throws KustvaktException {
margaretha6c2a20f2017-07-24 15:33:01 +0200293 ClientResponse response = resource()
margaretha15f496c2017-04-21 17:36:09 +0200294 .path("corpus").path("WPD15").path("search")
295 .queryParam("q", "blau").queryParam("ql", "poliqarp")
296 .get(ClientResponse.class);
297 assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
298 response.getStatus());
299 String ent = response.getEntity(String.class);
300 JsonNode error = JsonUtils.readTree(ent).get("errors").get(0);
301 assertEquals(101, error.get(0).asInt());
margaretha4fa94da2017-05-17 17:27:07 +0200302 assertEquals("[Cannot found public Corpus with ids: [WPD15]]",
margaretha15f496c2017-04-21 17:36:09 +0200303 error.get(2).asText());
304 }
margaretha3fc0fd42017-05-02 18:08:31 +0200305
306
margaretha15f496c2017-04-21 17:36:09 +0200307 @Test
margarethaa89c3f92017-05-30 19:02:08 +0200308 @Ignore
margaretha894a7d72017-11-08 19:24:20 +0100309 public void testSearchForSpecificCorpus () throws KustvaktException{
margaretha6c2a20f2017-07-24 15:33:01 +0200310 ClientResponse response = resource()
margarethaa89c3f92017-05-30 19:02:08 +0200311 .path("corpus").path("GOE").path("search")
margaretha3fc0fd42017-05-02 18:08:31 +0200312 .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
margaretha15f496c2017-04-21 17:36:09 +0200313 .header(Attributes.AUTHORIZATION,
margaretha2afb97d2017-12-07 19:18:44 +0100314 handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"))
margaretha15f496c2017-04-21 17:36:09 +0200315 .get(ClientResponse.class);
316 assertEquals(ClientResponse.Status.OK.getStatusCode(),
317 response.getStatus());
318 String entity = response.getEntity(String.class);
319 JsonNode node = JsonUtils.readTree(entity);
320 assertNotNull(node);
margarethaa89c3f92017-05-30 19:02:08 +0200321 assertEquals("koral:docGroup", node.at("/collection/@type").asText());
322 assertEquals("operation:and",
323 node.at("/collection/operation").asText());
324 assertEquals("availability",
325 node.at("/collection/operands/0/key").asText());
326 assertEquals("CC-BY.*",
327 node.at("/collection/operands/0/value").asText());
328 assertEquals("corpusSigle",
329 node.at("/collection/operands/1/key").asText());
330 assertEquals("GOE", node.at("/collection/operands/1/value").asText());
margaretha15f496c2017-04-21 17:36:09 +0200331 }
margaretha3fc0fd42017-05-02 18:08:31 +0200332
333
margaretha0c47c652017-04-19 18:44:40 +0200334
margaretha3fc0fd42017-05-02 18:08:31 +0200335
margaretha0c47c652017-04-19 18:44:40 +0200336 @Test
margaretha894a7d72017-11-08 19:24:20 +0100337 public void testSearchSentenceMeta () throws KustvaktException{
margaretha6c2a20f2017-07-24 15:33:01 +0200338 ClientResponse response = resource()
margaretha0c47c652017-04-19 18:44:40 +0200339 .path("search").queryParam("q", "[orth=der]")
340 .queryParam("ql", "poliqarp").queryParam("context", "sentence")
341 .get(ClientResponse.class);
342 assertEquals(ClientResponse.Status.OK.getStatusCode(),
343 response.getStatus());
344 String ent = response.getEntity(String.class);
345 JsonNode node = JsonUtils.readTree(ent);
346 assertNotNull(node);
margaretha0c47c652017-04-19 18:44:40 +0200347 assertEquals("base/s:s", node.at("/meta/context").asText());
348 assertNotEquals("${project.version}", "/meta/version");
349 }
350
351
352 @Test
margaretha894a7d72017-11-08 19:24:20 +0100353 public void testSearchSimpleCQL () throws KustvaktException{
margaretha0c47c652017-04-19 18:44:40 +0200354 QuerySerializer s = new QuerySerializer();
355 s.setQuery("(der) or (das)", "CQL");
356
margaretha6c2a20f2017-07-24 15:33:01 +0200357 ClientResponse response = resource()
margaretha0c47c652017-04-19 18:44:40 +0200358 .path("search").post(ClientResponse.class, s.toJSON());
359 assertEquals(ClientResponse.Status.OK.getStatusCode(),
360 response.getStatus());
361 String ent = response.getEntity(String.class);
362
363 JsonNode node = JsonUtils.readTree(ent);
364 assertNotNull(node);
365 assertNotEquals(0, node.path("matches").size());
margaretha61471cc2017-04-20 18:42:23 +0200366 // assertEquals(17027, node.at("/meta/totalResults").asInt());
margaretha0c47c652017-04-19 18:44:40 +0200367 }
368
369
370 @Test
margaretha894a7d72017-11-08 19:24:20 +0100371 public void testSearchRawQuery () throws KustvaktException{
margaretha0c47c652017-04-19 18:44:40 +0200372 QuerySerializer s = new QuerySerializer();
373 s.setQuery("[orth=der]", "poliqarp");
374 s.setCollection("corpusSigle=GOE");
375
margaretha0209cb72017-09-28 16:20:31 +0200376 s.setQuery("Wasser", "poliqarp");
margaretha23aae222017-12-22 15:08:23 +0100377// System.out.println(s.toJSON());
margaretha6c2a20f2017-07-24 15:33:01 +0200378 ClientResponse response = resource()
margaretha0c47c652017-04-19 18:44:40 +0200379 .path("search").post(ClientResponse.class, s.toJSON());
380 assertEquals(ClientResponse.Status.OK.getStatusCode(),
381 response.getStatus());
382 String ent = response.getEntity(String.class);
383
384
385 JsonNode node = JsonUtils.readTree(ent);
386 assertNotNull(node);
387 assertNotEquals(0, node.path("matches").size());
margaretha61471cc2017-04-20 18:42:23 +0200388 // assertEquals(10993, node.at("/meta/totalResults").asInt());
margaretha0c47c652017-04-19 18:44:40 +0200389 }
390
391}