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