Added delete key in setting controllers

Change-Id: I82484d0a94d74cf42a68647310e37611e15a62b6
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
index d074d02..69f47df 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
@@ -1,6 +1,7 @@
 package de.ids_mannheim.korap.web.controller;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -32,8 +33,8 @@
 
     private ClientResponse sendPutRequest (String username,
             Map<String, Object> map) throws KustvaktException {
-        ClientResponse response = resource().path(API_VERSION)
-                .path(username).path("setting")
+        ClientResponse response = resource().path(API_VERSION).path(username)
+                .path("setting")
                 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
                         .createBasicAuthorizationHeaderValue(username, "pass"))
                 .type(MediaType.APPLICATION_JSON).entity(map)
@@ -47,8 +48,8 @@
         String json = "{\"foundry\":\"opennlp\",\"metadata\":\"author title "
                 + "textSigle availability\",\"resultPerPage\":25}";
 
-        ClientResponse response = resource().path(API_VERSION)
-                .path(username).path("setting")
+        ClientResponse response = resource().path(API_VERSION).path(username)
+                .path("setting")
                 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
                         .createBasicAuthorizationHeaderValue(username, "pass"))
                 .type(MediaType.APPLICATION_JSON).entity(json)
@@ -56,12 +57,17 @@
 
         assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
 
-        testRetrieveSettings(username, "opennlp", 25,
-                "author title textSigle availability");
+        int numOfResult = 25;
+        String metadata = "author title textSigle availability";
+
+        testRetrieveSettings(username, "opennlp", numOfResult, metadata);
+
+        testDeleteKey(username, numOfResult, metadata);
     }
 
     @Test
     public void testCreateSettingWithMap () throws KustvaktException {
+
         Map<String, Object> map = new HashMap<>();
         map.put("foundry", "opennlp");
         map.put("resultPerPage", 25);
@@ -81,8 +87,8 @@
         String json = "{\"foundry\":\"opennlp\",\"metadata\":\"author title "
                 + "textSigle availability\",\"resultPerPage\":25}";
 
-        ClientResponse response = resource().path(API_VERSION)
-                .path(username).path("setting")
+        ClientResponse response = resource().path(API_VERSION).path(username)
+                .path("setting")
                 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
                         .createBasicAuthorizationHeaderValue(username2, "pass"))
                 .type(MediaType.APPLICATION_JSON).entity(json)
@@ -97,8 +103,8 @@
 
     @Test
     public void testGetDifferentUsername () throws KustvaktException {
-        ClientResponse response = resource().path(API_VERSION)
-                .path(username).path("setting")
+        ClientResponse response = resource().path(API_VERSION).path(username)
+                .path("setting")
                 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
                         .createBasicAuthorizationHeaderValue(username2, "pass"))
                 .get(ClientResponse.class);
@@ -110,6 +116,34 @@
                 node.at("/errors/0/0").asInt());
     }
 
+    @Test
+    public void testDeleteKeyDifferentUsername () throws KustvaktException {
+        ClientResponse response = resource().path(API_VERSION).path(username)
+                .path("setting").path("foundry")
+                .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+                        .createBasicAuthorizationHeaderValue(username2, "pass"))
+                .delete(ClientResponse.class);
+
+        assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+        String entity = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(entity);
+        assertEquals(StatusCodes.INVALID_ARGUMENT,
+                node.at("/errors/0/0").asInt());
+    }
+
+    private void testDeleteKey (String username, int numOfResult,
+            String metadata) throws KustvaktException {
+
+        ClientResponse response = resource().path(API_VERSION).path(username)
+                .path("setting").path("foundry")
+                .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+                        .createBasicAuthorizationHeaderValue(username, "pass"))
+                .delete(ClientResponse.class);
+
+        assertEquals(Status.OK.getStatusCode(), response.getStatus());
+        testRetrieveSettings(username, null, numOfResult, metadata);
+    }
+
     private void testUpdateSetting (String username) throws KustvaktException {
         Map<String, Object> map = new HashMap<>();
         map.put("foundry", "malt");
@@ -122,10 +156,10 @@
         testRetrieveSettings(username, "malt", 15, "author title");
     }
 
-    private void testRetrieveSettings (String username, String foundry, int numOfResult,
-            String metadata) throws KustvaktException {
-        ClientResponse response = resource().path(API_VERSION)
-                .path(username).path("setting")
+    private void testRetrieveSettings (String username, String foundry,
+            int numOfResult, String metadata) throws KustvaktException {
+        ClientResponse response = resource().path(API_VERSION).path(username)
+                .path("setting")
                 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
                         .createBasicAuthorizationHeaderValue(username, "pass"))
                 .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -133,7 +167,12 @@
 
         String entity = response.getEntity(String.class);
         JsonNode node = JsonUtils.readTree(entity);
-        assertEquals(foundry, node.at("/foundry").asText());
+        if (foundry == null) {
+            assertTrue(node.at("/foundry").isMissingNode());
+        }
+        else {
+            assertEquals(foundry, node.at("/foundry").asText());
+        }
         assertEquals(numOfResult, node.at("/resultPerPage").asInt());
         assertEquals(metadata, node.at("/metadata").asText());
     }