blob: 1692fdc6e5977b4214d793e0d35c838099c565b7 [file] [log] [blame]
margarethaed2ee242019-12-12 17:34:18 +01001package de.ids_mannheim.korap.web.controller;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
5
6import org.junit.Test;
7
8import com.fasterxml.jackson.databind.JsonNode;
9import com.sun.jersey.api.client.ClientHandlerException;
10import com.sun.jersey.api.client.ClientResponse;
11import com.sun.jersey.api.client.UniformInterfaceException;
12
13import de.ids_mannheim.korap.config.SpringJerseyTest;
14import de.ids_mannheim.korap.exceptions.KustvaktException;
15import de.ids_mannheim.korap.exceptions.StatusCodes;
16import de.ids_mannheim.korap.utils.JsonUtils;
17
18public class MultipleCorpusQueryTest extends SpringJerseyTest {
19
20 @Test
21 public void testSearchGet () throws KustvaktException {
22 ClientResponse response = resource().path(API_VERSION).path("search")
23 .queryParam("q", "das").queryParam("ql", "poliqarp")
24 .queryParam("cq", "pubPlace=München")
25 .queryParam("cq", "textSigle=\"GOE/AGA/01784\"")
26 .get(ClientResponse.class);
27 assertEquals(ClientResponse.Status.OK.getStatusCode(),
28 response.getStatus());
29 String entity = response.getEntity(String.class);
30 JsonNode node = JsonUtils.readTree(entity);
31 node = node.at("/collection/operands/1");
32 assertEquals("koral:docGroup", node.at("/@type").asText());
33 assertEquals("operation:and", node.at("/operation").asText());
34 assertEquals(2, node.at("/operands").size());
35 assertEquals("koral:doc", node.at("/operands/0/@type").asText());
36 assertEquals("match:eq", node.at("/operands/0/match").asText());
37 assertEquals("pubPlace", node.at("/operands/0/key").asText());
38 assertEquals("München", node.at("/operands/0/value").asText());
39 assertEquals("textSigle", node.at("/operands/1/key").asText());
40 assertEquals("GOE/AGA/01784", node.at("/operands/1/value").asText());
41 }
42
43 @Test
44 public void testStatisticsWithMultipleCq ()
45 throws UniformInterfaceException, ClientHandlerException,
46 KustvaktException {
47 ClientResponse response = resource().path(API_VERSION)
48 .path("statistics").queryParam("cq", "textType=Abhandlung")
49 .queryParam("cq", "corpusSigle=GOE")
50 .method("GET", ClientResponse.class);
51 assertEquals(ClientResponse.Status.OK.getStatusCode(),
52 response.getStatus());
53 String entity = response.getEntity(String.class);
54 JsonNode node = JsonUtils.readTree(entity);
55 assertEquals(2, node.at("/documents").asInt());
56 assertEquals(138180, node.at("/tokens").asInt());
57 assertEquals(5687, node.at("/sentences").asInt());
58 assertEquals(258, node.at("/paragraphs").asInt());
59
60 assertTrue(node.at("/warnings").isMissingNode());
61 }
62
63 @Test
64 public void testStatisticsWithMultipleCorpusQuery ()
65 throws UniformInterfaceException, ClientHandlerException,
66 KustvaktException {
67 ClientResponse response =
68 resource().path(API_VERSION).path("statistics")
69 .queryParam("corpusQuery", "textType=Autobiographie")
70 .queryParam("corpusQuery", "corpusSigle=GOE")
71 .method("GET", ClientResponse.class);
72 assertEquals(ClientResponse.Status.OK.getStatusCode(),
73 response.getStatus());
74 String entity = response.getEntity(String.class);
75 JsonNode node = JsonUtils.readTree(entity);
76 assertEquals(9, node.at("/documents").asInt());
77 assertEquals(527662, node.at("/tokens").asInt());
78 assertEquals(19387, node.at("/sentences").asInt());
79 assertEquals(514, node.at("/paragraphs").asInt());
80
81 assertEquals(StatusCodes.DEPRECATED_PARAMETER,
82 node.at("/warnings/0/0").asInt());
83 assertEquals("Parameter corpusQuery is deprecated in favor of cq.",
84 node.at("/warnings/0/1").asText());
85 }
86}