Added fields to metadata controller, resolved issue #39.
Change-Id: I32e1a77767c8b680ec0b0ff3e2da25f14a547db8
diff --git a/full/Changes b/full/Changes
index a1fd961..14a3e5e 100644
--- a/full/Changes
+++ b/full/Changes
@@ -10,7 +10,9 @@
- Added metadata controller tests (margaretha)
18/02/2019
- Fixed tests (margaretha)
- - Updated handling errors from Koral (margaretha)
+ - Updated handling errors from Koral (margaretha)
+19/02/2019
+ - Added fields to metadata controller (margaretha, issue #39)
# version 0.61.5
17/12/2018
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
index 71a3fff..661cad1 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
@@ -3,6 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import org.junit.Ignore;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
@@ -19,11 +20,41 @@
public class MetadataControllerTest extends SpringJerseyTest {
@Test
+ public void testRetrieveMetadataWithField () throws KustvaktException {
+ ClientResponse response = resource().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGA").path("01784")
+ .queryParam("fields", "author").get(ClientResponse.class);
+
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ String entity = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+
+ assertEquals("author", node.at("/document/fields/0/key").asText());
+ }
+
+
+ @Test
+ public void testRetrieveMetadataWithMultipleFields () throws KustvaktException {
+ ClientResponse response = resource().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGA").path("01784")
+ .queryParam("fields", "author,title").get(ClientResponse.class);
+
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ String entity = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+
+ assertEquals("author", node.at("/document/fields/0/key").asText());
+ assertEquals("title", node.at("/document/fields/1/key").asText());
+ }
+
+ @Test
public void testFreeMetadata () throws KustvaktException {
ClientResponse response = resource().path(API_VERSION).path("corpus")
.path("GOE").path("AGA").path("01784")
- .queryParam("foundry", "*").get(ClientResponse.class);
+ .get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -34,12 +65,14 @@
}
+ // EM: currently all metadata are allowed
@Test
+ @Ignore
public void testMetadataUnauthorized () throws KustvaktException {
ClientResponse response = resource().path(API_VERSION).path("corpus")
.path("GOE").path("AGI").path("04846")
- .queryParam("foundry", "*").get(ClientResponse.class);
+ .get(ClientResponse.class);
assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
response.getStatus());
@@ -84,7 +117,9 @@
response.getStatus());
}
+ // EM: currently all metadata are allowed
@Test
+ @Ignore
public void testMetadataAvailabilityAllUnauthorized ()
throws KustvaktException {
ClientResponse response = resource().path(API_VERSION).path("corpus")
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
index fd33b90..0a62f9d 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
@@ -23,12 +23,42 @@
import de.ids_mannheim.korap.utils.JsonUtils;
/**
- * @author margaretha, hanl
- * @lastUpdate 22/03/2018
+ * @author hanl, margaretha
+ * @lastUpdate 18/02/2019
*
*/
public class SearchControllerTest extends SpringJerseyTest {
+
+ private JsonNode requestSearchWithFields(String fields) throws KustvaktException{
+ ClientResponse response = resource().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("fields", fields)
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .get(ClientResponse.class);
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ String query = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(query);
+ return node;
+ }
+
+ @Test
+ public void testSearchWithField () throws KustvaktException {
+ JsonNode node = requestSearchWithFields("author");
+ assertNotEquals(0, node.at("/matches").size());
+ assertEquals("[\"author\"]",
+ node.at("/meta/fields").toString());
+ }
+
+ @Test
+ public void testSearchWithMultipleFields () throws KustvaktException {
+ JsonNode node = requestSearchWithFields("author, title");
+ assertNotEquals(0, node.at("/matches").size());
+ assertEquals("[\"author\",\"title\"]",
+ node.at("/meta/fields").toString());
+ }
+
@Test
public void testSearchQueryPublicCorpora () throws KustvaktException {
ClientResponse response = resource().path(API_VERSION).path("search")