blob: f3dfdf1284c773dcabf5815c9559f74f1c8f7b7e [file] [log] [blame]
margarethaf093afb2017-11-12 21:38:23 +01001package de.ids_mannheim.korap.web.service.full;
2
margarethafde771a2017-11-14 15:02:10 +01003import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
margarethaf093afb2017-11-12 21:38:23 +01005
6import org.eclipse.jetty.http.HttpHeaders;
margaretha74f122c2017-11-12 22:38:57 +01007import org.junit.Ignore;
margarethaf093afb2017-11-12 21:38:23 +01008import org.junit.Test;
margarethaf093afb2017-11-12 21:38:23 +01009
10import com.fasterxml.jackson.databind.JsonNode;
11import com.sun.jersey.api.client.ClientResponse;
margarethaf093afb2017-11-12 21:38:23 +010012
13import de.ids_mannheim.korap.config.Attributes;
margarethafde771a2017-11-14 15:02:10 +010014import de.ids_mannheim.korap.config.SpringJerseyTest;
margarethaf093afb2017-11-12 21:38:23 +010015import de.ids_mannheim.korap.exceptions.KustvaktException;
16import de.ids_mannheim.korap.exceptions.StatusCodes;
17import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
18import de.ids_mannheim.korap.utils.JsonUtils;
19
margarethafde771a2017-11-14 15:02:10 +010020public class VirtualCorpusServiceTest extends SpringJerseyTest{
margarethaf093afb2017-11-12 21:38:23 +010021
22 @Test
margarethafde771a2017-11-14 15:02:10 +010023 @Ignore
margarethaf093afb2017-11-12 21:38:23 +010024 public void testStoreVC () throws KustvaktException {
25 String json =
26 "{\"name\": \"new vc\",\"type\": \"PRIVATE\",\"createdBy\": "
27 + "\"test class\",\"collectionQuery\": \"corpusSigle=GOE\"}";
28
29 ClientResponse response = resource().path("vc").path("store")
30 .header(Attributes.AUTHORIZATION,
31 BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
32 .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
33 .entity(json)
34 .post(ClientResponse.class);
35 String entity = response.getEntity(String.class);
36 System.out.println(entity);
37 }
38
39 @Test
40 public void testStoreVCUnauthorized () throws KustvaktException {
41 String json =
42 "{\"name\": \"new vc\",\"type\": \"PRIVATE\",\"createdBy\": "
43 + "\"test class\",\"collectionQuery\": \"pubDate eq 1982\"}";
44
45 ClientResponse response = resource().path("vc").path("store")
46 .entity(json).post(ClientResponse.class);
47 String entity = response.getEntity(String.class);
48
49 JsonNode node = JsonUtils.readTree(entity);
50 assertEquals(StatusCodes.UNAUTHORIZED_OPERATION,
51 node.at("/errors/0/0").asInt());
52 }
53
54 @Test
55 public void testStoreVCWithWrongType () throws KustvaktException {
56 String json =
57 "{\"name\": \"new vc\",\"type\": \"PRIVAT\",\"createdBy\": "
58 + "\"test class\",\"collectionQuery\": \"pubDate eq 1982\"}";
59
60 ClientResponse response = resource().path("vc").path("store")
61 .entity(json).post(ClientResponse.class);
62 String entity = response.getEntity(String.class);
margarethafde771a2017-11-14 15:02:10 +010063 System.out.println(entity);
margarethaf093afb2017-11-12 21:38:23 +010064
65 JsonNode node = JsonUtils.readTree(entity);
66 assertEquals(StatusCodes.DESERIALIZATION_FAILED,
67 node.at("/errors/0/0").asInt());
68 assertTrue(node.at("/errors/0/1").asText().startsWith(
69 "Cannot deserialize value of type `de.ids_mannheim.korap.constant."
70 + "VirtualCorpusType` from String \"PRIVAT\": value not one of "
margarethafde771a2017-11-14 15:02:10 +010071 + "declared Enum instance names"));
margarethaf093afb2017-11-12 21:38:23 +010072 }
73}