blob: 03bcb5c169813e44d8b2923fa38161f58e786ca3 [file] [log] [blame]
margaretha46e2c952024-05-23 09:09:54 +02001package de.ids_mannheim.korap.scenario;
2
3import static org.junit.jupiter.api.Assertions.assertEquals;
4
5import org.junit.jupiter.api.AfterAll;
6import org.junit.jupiter.api.Test;
7import org.springframework.test.context.ContextConfiguration;
8
9import com.fasterxml.jackson.databind.JsonNode;
10
11import de.ids_mannheim.korap.config.SpringJerseyTest;
12import de.ids_mannheim.korap.exceptions.KustvaktException;
13import de.ids_mannheim.korap.util.KrillProperties;
14import de.ids_mannheim.korap.utils.JsonUtils;
15import jakarta.ws.rs.core.Response;
16import jakarta.ws.rs.core.Response.Status;
17
margaretha335abd92025-05-02 10:11:29 +020018@ContextConfiguration(
19 locations = "classpath:test-config-dnb.xml",
20 inheritLocations = false
21)
margaretha46e2c952024-05-23 09:09:54 +020022public class DNBTest extends SpringJerseyTest {
23
24 public final static String API_VERSION = "v1.0";
25
26 private JsonNode sendQuery (String query) throws KustvaktException {
27 Response r = target().path(API_VERSION).path("search")
28 .queryParam("q", query).queryParam("ql", "poliqarp")
29 .queryParam("show-tokens", true).request().get();
30 assertEquals(Status.OK.getStatusCode(), r.getStatus());
31 String entity = r.readEntity(String.class);
32 JsonNode node = JsonUtils.readTree(entity);
33
34 return node;
35
36 }
37
38 @AfterAll
39 public static void resetKrillProperties() {
40 KrillProperties.loadProperties("kustvakt-test.conf");
41 }
42
43 @Test
44 public void testTokenMatchSize () throws KustvaktException {
45 assertEquals(1, KrillProperties.maxTokenMatchSize);
46 assertEquals(25, KrillProperties.maxTokenContextSize);
47
48 JsonNode node = sendQuery("[orth=das]");
49 assertEquals(KrillProperties.maxTokenMatchSize,
50 node.at("/matches/0/tokens/match").size());
51
52 node = sendQuery("[orth=das][orth=Glück]");
53 assertEquals(KrillProperties.maxTokenMatchSize,
54 node.at("/matches/0/tokens/match").size());
55 }
56
57 @Test
58 public void testTokenContextMatchSize () throws KustvaktException {
59 Response r = target().path(API_VERSION).path("search")
60 .queryParam("q", "[orth=das][orth=Glück]")
61 .queryParam("ql", "poliqarp").queryParam("show-tokens", true)
62 .queryParam("context", "30-token,30-token").request().get();
63 assertEquals(Status.OK.getStatusCode(), r.getStatus());
64 String entity = r.readEntity(String.class);
65 JsonNode node = JsonUtils.readTree(entity);
66
67 assertEquals(KrillProperties.maxTokenContextSize,
68 node.at("/meta/context/left/1").asInt());
69 assertEquals(KrillProperties.maxTokenContextSize,
70 node.at("/meta/context/right/1").asInt());
71
72 assertEquals(KrillProperties.maxTokenContextSize,
73 node.at("/matches/0/tokens/left").size());
74
75 // There is a bug in Krill (https://github.com/KorAP/Krill/issues/141)
76 // So the following test fails
77// assertEquals(KrillProperties.maxTokenContextSize,
78// node.at("/matches/0/tokens/right").size());
79 }
80
81}