| margaretha | 541b8cc | 2018-01-10 13:02:46 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.web.controller; |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.junit.Assert.assertNotEquals; |
| 5 | import static org.junit.Assert.assertNotNull; |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 6 | import static org.junit.Assert.assertTrue; |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 7 | |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 8 | import javax.ws.rs.core.MediaType; |
| 9 | |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 10 | import org.junit.Ignore; |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 11 | import org.junit.Test; |
| margaretha | 4b5c141 | 2017-11-15 20:55:04 +0100 | [diff] [blame] | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 13 | |
| 14 | import com.fasterxml.jackson.databind.JsonNode; |
| margaretha | 58e1863 | 2018-02-15 13:04:42 +0100 | [diff] [blame] | 15 | import com.google.common.net.HttpHeaders; |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 16 | import com.sun.jersey.api.client.ClientResponse; |
| 17 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 18 | import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler; |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 19 | import de.ids_mannheim.korap.config.Attributes; |
| margaretha | 7a25f01 | 2018-03-22 19:49:01 +0100 | [diff] [blame] | 20 | import de.ids_mannheim.korap.config.SpringJerseyTest; |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 21 | import de.ids_mannheim.korap.exceptions.KustvaktException; |
| 22 | import de.ids_mannheim.korap.query.serialize.QuerySerializer; |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 23 | import de.ids_mannheim.korap.utils.JsonUtils; |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 24 | |
| 25 | /** |
| margaretha | 7a25f01 | 2018-03-22 19:49:01 +0100 | [diff] [blame] | 26 | * @author margaretha, hanl |
| 27 | * @lastUpdate 22/03/2018 |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 28 | * |
| 29 | */ |
| margaretha | 7a25f01 | 2018-03-22 19:49:01 +0100 | [diff] [blame] | 30 | public class SearchControllerTest extends SpringJerseyTest { |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 31 | |
| margaretha | 4b5c141 | 2017-11-15 20:55:04 +0100 | [diff] [blame] | 32 | @Autowired |
| margaretha | 7a25f01 | 2018-03-22 19:49:01 +0100 | [diff] [blame] | 33 | private HttpAuthorizationHandler handler; |
| margaretha | 4b5c141 | 2017-11-15 20:55:04 +0100 | [diff] [blame] | 34 | |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 35 | |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 36 | @Test |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 37 | public void testSearchQueryPublicCorpora () throws KustvaktException{ |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 38 | ClientResponse response = resource() |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 39 | .path("search").queryParam("q", "[orth=der]") |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 40 | .queryParam("ql", "poliqarp") |
| 41 | .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); |
| margaretha | 7a25f01 | 2018-03-22 19:49:01 +0100 | [diff] [blame] | 42 | assertEquals(ClientResponse.Status.OK.getStatusCode(), |
| 43 | response.getStatus()); |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 44 | String ent = response.getEntity(String.class); |
| margaretha | 23aae22 | 2017-12-22 15:08:23 +0100 | [diff] [blame] | 45 | // System.out.println(ent); |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 46 | JsonNode node = JsonUtils.readTree(ent); |
| 47 | assertNotNull(node); |
| margaretha | d980c8f | 2017-05-22 17:20:42 +0200 | [diff] [blame] | 48 | 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()); |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 51 | assertEquals("availability(FREE)", |
| margaretha | 65b6714 | 2017-05-29 16:23:16 +0200 | [diff] [blame] | 52 | node.at("/collection/rewrites/0/scope").asText()); |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 53 | assertEquals("operation:insertion", |
| 54 | node.at("/collection/rewrites/0/operation").asText()); |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 57 | |
| 58 | @Test |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 59 | public void testSearchQueryWithMeta () throws KustvaktException{ |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 60 | ClientResponse response = resource() |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 61 | .path("search").queryParam("q", "[orth=der]") |
| 62 | .queryParam("ql", "poliqarp").queryParam("cutoff", "true") |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 63 | .queryParam("count", "5").queryParam("page", "1") |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 64 | .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()); |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 76 | assertEquals(-1, node.at("/meta/totalResults").asInt()); |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 79 | @Test |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 80 | public void testSearchQueryFreeExtern () throws KustvaktException{ |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 81 | ClientResponse response = resource() |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 82 | .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 |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 102 | public void testSearchQueryFreeIntern () throws KustvaktException{ |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 103 | ClientResponse response = resource() |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 104 | .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 | |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 124 | @Test |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 125 | public void testSearchQueryExternAuthorized () throws KustvaktException{ |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 126 | ClientResponse response = resource() |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 127 | .path("search").queryParam("q", "[orth=die]") |
| 128 | .queryParam("ql", "poliqarp") |
| 129 | .header(Attributes.AUTHORIZATION, |
| margaretha | 2afb97d | 2017-12-07 19:18:44 +0100 | [diff] [blame] | 130 | handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")) |
| margaretha | 65b6714 | 2017-05-29 16:23:16 +0200 | [diff] [blame] | 131 | .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32") |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 132 | .get(ClientResponse.class); |
| 133 | assertEquals(ClientResponse.Status.OK.getStatusCode(), |
| 134 | response.getStatus()); |
| margaretha | 61471cc | 2017-04-20 18:42:23 +0200 | [diff] [blame] | 135 | String entity = response.getEntity(String.class); |
| 136 | JsonNode node = JsonUtils.readTree(entity); |
| margaretha | cfea1ae | 2018-01-15 20:27:26 +0100 | [diff] [blame] | 137 | // System.out.println(entity); |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 138 | assertNotNull(node); |
| margaretha | 65b6714 | 2017-05-29 16:23:16 +0200 | [diff] [blame] | 139 | assertNotEquals(0, node.path("matches").size()); |
| 140 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 141 | assertEquals("CC-BY.*", |
| 142 | node.at("/collection/operands/0/value").asText()); |
| margaretha | ad618d2 | 2017-12-11 19:58:49 +0100 | [diff] [blame] | 143 | assertEquals("ACA.*", node.at("/collection/operands/1/operands/0/value").asText()); |
| 144 | assertEquals("QAO-NC", node.at("/collection/operands/1/operands/1/value").asText()); |
| margaretha | 65b6714 | 2017-05-29 16:23:16 +0200 | [diff] [blame] | 145 | assertEquals("operation:or", node.at("/collection/operation").asText()); |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 146 | assertEquals("availability(PUB)", |
| margaretha | 65b6714 | 2017-05-29 16:23:16 +0200 | [diff] [blame] | 147 | node.at("/collection/rewrites/0/scope").asText()); |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 148 | assertEquals("operation:insertion", |
| 149 | node.at("/collection/rewrites/0/operation").asText()); |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 150 | } |
| 151 | |
| margaretha | 65b6714 | 2017-05-29 16:23:16 +0200 | [diff] [blame] | 152 | @Test |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 153 | public void testSearchQueryInternAuthorized () throws KustvaktException{ |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 154 | ClientResponse response = resource() |
| margaretha | 65b6714 | 2017-05-29 16:23:16 +0200 | [diff] [blame] | 155 | .path("search").queryParam("q", "[orth=die]") |
| 156 | .queryParam("ql", "poliqarp") |
| 157 | .header(Attributes.AUTHORIZATION, |
| margaretha | 2afb97d | 2017-12-07 19:18:44 +0100 | [diff] [blame] | 158 | handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")) |
| margaretha | 65b6714 | 2017-05-29 16:23:16 +0200 | [diff] [blame] | 159 | .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()); |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 167 | //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()); |
| margaretha | 65b6714 | 2017-05-29 16:23:16 +0200 | [diff] [blame] | 179 | } |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 180 | |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 181 | // EM: shouldn't this case gets CorpusAccess.PUB ? |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 182 | @Test |
| margaretha | 9a509ed | 2017-06-27 11:08:32 +0200 | [diff] [blame] | 183 | @Ignore |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 184 | public void testSearchQueryWithCollectionQueryAuthorizedWithoutIP () throws KustvaktException{ |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 185 | ClientResponse response = resource() |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 186 | .path("search").queryParam("q", "[orth=das]") |
| 187 | .queryParam("ql", "poliqarp") |
| 188 | .queryParam("cq", "textClass=politik & corpusSigle=BRZ10") |
| 189 | .header(Attributes.AUTHORIZATION, |
| margaretha | 2afb97d | 2017-12-07 19:18:44 +0100 | [diff] [blame] | 190 | handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")) |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 191 | .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); |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 197 | 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 |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 202 | assertEquals("availability", |
| 203 | node.at("/collection/operands/0/key").asText()); |
| 204 | assertEquals("CC-BY.*", |
| 205 | node.at("/collection/operands/0/value").asText()); |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 206 | assertEquals("textClass", |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 207 | node.at("/collection/operands/1/operands/0/key").asText()); |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 208 | assertEquals("corpusSigle", |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 209 | node.at("/collection/operands/1/operands/1/key").asText()); |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 210 | } |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 211 | |
| 212 | @Test |
| margaretha | 9a509ed | 2017-06-27 11:08:32 +0200 | [diff] [blame] | 213 | @Ignore |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 214 | public void testSearchQueryAuthorizedWithoutIP () throws KustvaktException{ |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 215 | ClientResponse response = resource() |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 216 | .path("search").queryParam("q", "[orth=die]") |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 217 | .queryParam("ql", "poliqarp") |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 218 | .header(Attributes.AUTHORIZATION, |
| margaretha | 2afb97d | 2017-12-07 19:18:44 +0100 | [diff] [blame] | 219 | handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")) |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 220 | .get(ClientResponse.class); |
| 221 | assertEquals(ClientResponse.Status.OK.getStatusCode(), |
| 222 | response.getStatus()); |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 223 | String entity = response.getEntity(String.class); |
| 224 | JsonNode node = JsonUtils.readTree(entity); |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 225 | assertNotNull(node); |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 226 | 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()); |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 232 | assertEquals("availability(PUB)", |
| 233 | node.at("/collection/rewrites/0/scope").asText()); |
| 234 | } |
| margaretha | ebe869a | 2017-06-01 19:07:41 +0200 | [diff] [blame] | 235 | |
| 236 | |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 237 | |
| 238 | @Test |
| 239 | @Ignore |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 240 | public void testSearchForPublicCorpusWithStringId () throws KustvaktException { |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 241 | ClientResponse response = resource() |
| margaretha | 61471cc | 2017-04-20 18:42:23 +0200 | [diff] [blame] | 242 | .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); |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 250 | 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()); |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 260 | assertNotEquals(0, node.path("matches").size()); |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 261 | } |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 262 | |
| 263 | |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 264 | @Test |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 265 | @Ignore |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 266 | public void testSearchForVirtualCollectionWithStringId () throws KustvaktException{ |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 267 | ClientResponse response = resource() |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 268 | .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); |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 274 | JsonNode node = JsonUtils.readTree(ent); |
| 275 | assertNotNull(node); |
| margaretha | 61471cc | 2017-04-20 18:42:23 +0200 | [diff] [blame] | 276 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 277 | assertEquals("operation:and", |
| 278 | node.at("/collection/operation").asText()); |
| margaretha | 61471cc | 2017-04-20 18:42:23 +0200 | [diff] [blame] | 279 | assertNotEquals(0, node.at("/collection/operands").size()); |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 280 | assertEquals("corpusSigle", |
| 281 | node.at("/collection/operands/0/key").asText()); |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 282 | assertEquals("GOE", node.at("/collection/operands/0/value").asText()); |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 283 | 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()); |
| margaretha | 61471cc | 2017-04-20 18:42:23 +0200 | [diff] [blame] | 288 | } |
| 289 | |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 290 | @Test |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 291 | @Ignore |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 292 | public void testSearchForCorpusWithStringIdUnauthorized () throws KustvaktException { |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 293 | ClientResponse response = resource() |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 294 | .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()); |
| margaretha | 4fa94da | 2017-05-17 17:27:07 +0200 | [diff] [blame] | 302 | assertEquals("[Cannot found public Corpus with ids: [WPD15]]", |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 303 | error.get(2).asText()); |
| 304 | } |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 305 | |
| 306 | |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 307 | @Test |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 308 | @Ignore |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 309 | public void testSearchForSpecificCorpus () throws KustvaktException{ |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 310 | ClientResponse response = resource() |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 311 | .path("corpus").path("GOE").path("search") |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 312 | .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp") |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 313 | .header(Attributes.AUTHORIZATION, |
| margaretha | 2afb97d | 2017-12-07 19:18:44 +0100 | [diff] [blame] | 314 | handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")) |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 315 | .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); |
| margaretha | a89c3f9 | 2017-05-30 19:02:08 +0200 | [diff] [blame] | 321 | 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()); |
| margaretha | 15f496c | 2017-04-21 17:36:09 +0200 | [diff] [blame] | 331 | } |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 332 | |
| 333 | |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 334 | |
| margaretha | 3fc0fd4 | 2017-05-02 18:08:31 +0200 | [diff] [blame] | 335 | |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 336 | @Test |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 337 | public void testSearchSentenceMeta () throws KustvaktException{ |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 338 | ClientResponse response = resource() |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 339 | .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); |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 347 | assertEquals("base/s:s", node.at("/meta/context").asText()); |
| 348 | assertNotEquals("${project.version}", "/meta/version"); |
| 349 | } |
| 350 | |
| 351 | |
| 352 | @Test |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 353 | public void testSearchSimpleCQL () throws KustvaktException{ |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 354 | QuerySerializer s = new QuerySerializer(); |
| 355 | s.setQuery("(der) or (das)", "CQL"); |
| 356 | |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 357 | ClientResponse response = resource() |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 358 | .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()); |
| margaretha | 61471cc | 2017-04-20 18:42:23 +0200 | [diff] [blame] | 366 | // assertEquals(17027, node.at("/meta/totalResults").asInt()); |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | |
| 370 | @Test |
| margaretha | 894a7d7 | 2017-11-08 19:24:20 +0100 | [diff] [blame] | 371 | public void testSearchRawQuery () throws KustvaktException{ |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 372 | QuerySerializer s = new QuerySerializer(); |
| 373 | s.setQuery("[orth=der]", "poliqarp"); |
| 374 | s.setCollection("corpusSigle=GOE"); |
| 375 | |
| margaretha | 0209cb7 | 2017-09-28 16:20:31 +0200 | [diff] [blame] | 376 | s.setQuery("Wasser", "poliqarp"); |
| margaretha | 23aae22 | 2017-12-22 15:08:23 +0100 | [diff] [blame] | 377 | // System.out.println(s.toJSON()); |
| margaretha | 6c2a20f | 2017-07-24 15:33:01 +0200 | [diff] [blame] | 378 | ClientResponse response = resource() |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 379 | .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()); |
| margaretha | 61471cc | 2017-04-20 18:42:23 +0200 | [diff] [blame] | 388 | // assertEquals(10993, node.at("/meta/totalResults").asInt()); |
| margaretha | 0c47c65 | 2017-04-19 18:44:40 +0200 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | } |