blob: 101da58420f4ed5c8b9b0be9f87a62efae3a6550 [file] [log] [blame]
Michael Hanl0f6ffd72015-08-27 19:23:15 +02001package de.ids_mannheim.korap.web.service;
2
Michael Hanl1e18cb42015-08-06 20:57:35 +02003import com.sun.jersey.api.client.ClientResponse;
4import de.ids_mannheim.korap.config.BeanConfiguration;
5import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor;
6import de.ids_mannheim.korap.utils.JsonUtils;
Michael Hanl482f30d2015-09-25 12:39:46 +02007import de.ids_mannheim.korap.web.service.light.LightService;
Michael Hanl1e18cb42015-08-06 20:57:35 +02008import org.junit.BeforeClass;
9import org.junit.Ignore;
10import org.junit.Test;
11
12import java.util.LinkedHashMap;
13import java.util.Map;
14
15/**
16 * @author hanl
17 * @date 26/06/2015
18 */
19public class KustvaktCoreRestTest extends FastJerseyTest {
20
21 @BeforeClass
22 public static void configure() {
23 BeanConfiguration.loadClasspathContext();
24 addClass(LightService.class);
25 }
26
27 @Test
28 public void testFieldsInSearch() {
29 ClientResponse response = resource().path(API_VERSION).path("search")
30 .queryParam("q", "[base=Wort]").queryParam("ql", "poliqarp")
31 .get(ClientResponse.class);
32 assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
33 }
34
35 @Test
36 public void testQuery() {
37 ClientResponse response = resource().path(API_VERSION).path("search")
38 .queryParam("q", "Sonne prox/unit=word/distance<=5 Erde")
39 .queryParam("ql", "CQL").get(ClientResponse.class);
40 assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
41 }
42
43 // in case no index is there, this will throw an error
44 @Ignore
45 @Test
46 public void testGetMatchInfoThrowsNoException() {
47 ClientResponse response = resource().path(API_VERSION)
48 .get(ClientResponse.class);
49 }
50
51 @Test
52 public void testGetStatsThrowsNoException() {
53 CollectionQueryProcessor pr = new CollectionQueryProcessor();
54 pr.process("corpusID=WPD & textClass=Sport");
55 Map map = new LinkedHashMap();
56 map.put("collection", pr.getRequestMap());
57 ClientResponse response = resource().path(API_VERSION).path("stats")
58 .post(ClientResponse.class, JsonUtils.toJSON(map));
59 assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
60 }
61
62 @Test
63 public void testBuildQueryThrowsNoException() {
64 ClientResponse response = resource().path(API_VERSION).path("search")
65 .queryParam("q", "[base=Haus & surface=Hauses]")
66 .queryParam("ql", "poliqarp").queryParam("cutOff", "true")
67 .queryParam("page", "1").method("TRACE", ClientResponse.class);
68 assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
69 }
70
71 @Test
72 public void testQueryByNameThrowsNoException() {
73 ClientResponse response = resource().path(API_VERSION).path("corpus")
74 .path("WPD").path("search")
75 .queryParam("q", "[base=Haus & surface=Hauses]")
76 .queryParam("ql", "poliqarp").queryParam("cutOff", "true")
77 .queryParam("page", "1").get(ClientResponse.class);
Michael Hanl482f30d2015-09-25 12:39:46 +020078 System.out.println("RESPONSE " + response.getEntity(String.class));
Michael Hanl1e18cb42015-08-06 20:57:35 +020079 }
80
81}