| Michael Hanl | 0f6ffd7 | 2015-08-27 19:23:15 +0200 | [diff] [blame] | 1 | package de.ids_mannheim.korap.web.service; |
| 2 | |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 3 | import com.sun.jersey.api.client.ClientResponse; |
| 4 | import de.ids_mannheim.korap.config.BeanConfiguration; |
| 5 | import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor; |
| 6 | import de.ids_mannheim.korap.utils.JsonUtils; |
| Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 7 | import de.ids_mannheim.korap.web.service.light.LightService; |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 8 | import org.junit.BeforeClass; |
| 9 | import org.junit.Ignore; |
| 10 | import org.junit.Test; |
| 11 | |
| 12 | import java.util.LinkedHashMap; |
| 13 | import java.util.Map; |
| 14 | |
| 15 | /** |
| 16 | * @author hanl |
| 17 | * @date 26/06/2015 |
| 18 | */ |
| 19 | public 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 Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 78 | System.out.println("RESPONSE " + response.getEntity(String.class)); |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | } |