Updated handling errors from Koral and fixed tests.

Change-Id: I7ff3caa35d247b4707c11315cf2e653eed9a689b
diff --git a/full/Changes b/full/Changes
index 198aa7f..a1fd961 100644
--- a/full/Changes
+++ b/full/Changes
@@ -8,6 +8,9 @@
 06/02/2019
    - Updated a user setting test using array for multiple values (margaretha)
    - Added metadata controller tests (margaretha)
+18/02/2019
+   - Fixed tests (margaretha)
+   - Updated handling errors from Koral (margaretha)  
 
 # version 0.61.5
 17/12/2018
diff --git a/full/pom.xml b/full/pom.xml
index 325dbfe..5a13cc5 100644
--- a/full/pom.xml
+++ b/full/pom.xml
@@ -206,7 +206,7 @@
 		<dependency>
 			<groupId>de.ids_mannheim.korap</groupId>
 			<artifactId>Kustvakt-core</artifactId>
-			<version>[0.61.4,)</version>
+			<version>[0.61.6,)</version>
 		</dependency>
 		<!-- LDAP -->
 		<dependency>
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 fb083bd..71a3fff 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
@@ -88,20 +88,20 @@
     public void testMetadataAvailabilityAllUnauthorized ()
             throws KustvaktException {
         ClientResponse response = resource().path(API_VERSION).path("corpus")
-                .path("GOE").path("AGI").path("00000")
+                .path("GOE").path("AGD").path("00000")
                 .header(Attributes.AUTHORIZATION,
                         HttpAuthorizationHandler
                                 .createBasicAuthorizationHeaderValue("kustvakt",
                                         "kustvakt2015"))
                 .header(HttpHeaders.X_FORWARDED_FOR, "170.27.0.32")
                 .get(ClientResponse.class);
-
+        
         JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
         assertEquals(StatusCodes.AUTHORIZATION_FAILED,
                 node.at("/errors/0/0").asInt());
         assertEquals(
                 "Retrieving resource with ID "
-                        + "GOE/AGI/00000 is not allowed.",
+                        + "GOE/AGD/00000 is not allowed.",
                 node.at("/errors/0/1").asText());
     }
 }
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
index 4ecbe72..be6c1d6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
@@ -104,9 +104,10 @@
                 .queryParam("corpusQuery", "creationDate >= 1810")
                 .get(ClientResponse.class);
 
+        String ent = response.getEntity(String.class);
         assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
                 response.getStatus());
-        String ent = response.getEntity(String.class);
+        
         JsonNode node = mapper.readTree(ent);
         assertEquals(node.at("/errors/0/0").asInt(), 305);
         assertEquals(node.at("/errors/0/1").asText(),
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
index c04aee1..ba26d0c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
@@ -59,13 +59,13 @@
         assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
 
         int numOfResult = 25;
-        String metadata = "[\"author\",\"title\",\"textSigle\","
-                + "\"availability\"]";
+        String metadata =
+                "[\"author\",\"title\",\"textSigle\"," + "\"availability\"]";
 
-        testRetrieveSettings(username, "opennlp", numOfResult, metadata);
+        testRetrieveSettings(username, "opennlp", numOfResult, metadata, true);
 
         testDeleteKeyNotExist(username);
-        testDeleteKey(username, numOfResult, metadata);
+        testDeleteKey(username, numOfResult, metadata, true);
         testDeleteSetting(username);
     }
 
@@ -81,7 +81,7 @@
         assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
 
         testRetrieveSettings(username2, "opennlp", 25,
-                "author title textSigle availability");
+                "author title textSigle availability", false);
 
         testUpdateSetting(username2);
         testputRequestInvalidKey();
@@ -146,17 +146,18 @@
                 .get(ClientResponse.class);
 
         assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
-        
+
         String entity = response.getEntity(String.class);
         JsonNode node = JsonUtils.readTree(entity);
 
         assertEquals(StatusCodes.NO_RESOURCE_FOUND,
                 node.at("/errors/0/0").asInt());
-        assertEquals("No default setting for username: " + username +" is found",
+        assertEquals(
+                "No default setting for username: " + username + " is found",
                 node.at("/errors/0/1").asText());
         assertEquals(username, node.at("/errors/0/2").asText());
     }
-    
+
     @Test
     public void testDeleteSettingNotExist () throws KustvaktException {
         String username = "tralala";
@@ -207,10 +208,12 @@
                 node.at("/errors/0/0").asInt());
         assertEquals(username, node.at("/errors/0/2").asText());
     }
-    
-    // EM: deleting a non-existing key does not throw an error, because 
+
+    // EM: deleting a non-existing key does not throw an error,
+    // because
     // the purpose of the request has been achieved.
-    private void testDeleteKeyNotExist (String username) throws KustvaktException {
+    private void testDeleteKeyNotExist (String username)
+            throws KustvaktException {
         ClientResponse response = resource().path(API_VERSION)
                 .path("~" + username).path("setting").path("lemma-foundry")
                 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
@@ -221,7 +224,7 @@
     }
 
     private void testDeleteKey (String username, int numOfResult,
-            String metadata) throws KustvaktException {
+            String metadata, boolean isMetadataArray) throws KustvaktException {
 
         ClientResponse response = resource().path(API_VERSION)
                 .path("~" + username).path("setting").path("pos-foundry")
@@ -230,7 +233,8 @@
                 .delete(ClientResponse.class);
 
         assertEquals(Status.OK.getStatusCode(), response.getStatus());
-        testRetrieveSettings(username, null, numOfResult, metadata);
+        testRetrieveSettings(username, null, numOfResult, metadata,
+                isMetadataArray);
     }
 
     private void testUpdateSetting (String username) throws KustvaktException {
@@ -242,11 +246,12 @@
         ClientResponse response = sendPutRequest(username, map);
         assertEquals(Status.OK.getStatusCode(), response.getStatus());
 
-        testRetrieveSettings(username, "malt", 15, "author title");
+        testRetrieveSettings(username, "malt", 15, "author title", false);
     }
 
     private void testRetrieveSettings (String username, String posFoundry,
-            int numOfResult, String metadata) throws KustvaktException {
+            int numOfResult, String metadata, boolean isMetadataArray)
+            throws KustvaktException {
         ClientResponse response = resource().path(API_VERSION)
                 .path("~" + username).path("setting")
                 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
@@ -255,7 +260,7 @@
                 .get(ClientResponse.class);
 
         String entity = response.getEntity(String.class);
-        System.out.println(entity);
+
         JsonNode node = JsonUtils.readTree(entity);
         if (posFoundry == null) {
             assertTrue(node.at("/pos-foundry").isMissingNode());
@@ -264,7 +269,13 @@
             assertEquals(posFoundry, node.at("/pos-foundry").asText());
         }
         assertEquals(numOfResult, node.at("/resultPerPage").asInt());
-        assertEquals(metadata, node.at("/metadata").toString());
+
+        if (isMetadataArray) {
+            assertEquals(metadata, node.at("/metadata").toString());
+        }
+        else {
+            assertEquals(metadata, node.at("/metadata").asText());
+        }
     }
 
 }