Added delete key in setting controllers

Change-Id: I82484d0a94d74cf42a68647310e37611e15a62b6
diff --git a/full/src/test/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManagerTest.java b/full/src/test/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManagerTest.java
index 7c27553..e06d9f7 100644
--- a/full/src/test/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManagerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManagerTest.java
@@ -14,7 +14,7 @@
 import de.ids_mannheim.korap.user.KorAPUser;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.user.UserDetails;
-import de.ids_mannheim.korap.user.UserSettings;
+import de.ids_mannheim.korap.user.UserSettingProcessor;
 import de.ids_mannheim.korap.user.Userdata;
 
 /**
@@ -71,7 +71,7 @@
                 .getUser((String) KustvaktConfiguration.KUSTVAKT_USER
                         .get(Attributes.USERNAME));
 
-        Userdata data = authenticationManager.getUserData(user, UserSettings.class);
+        Userdata data = authenticationManager.getUserData(user, UserSettingProcessor.class);
         assertNotNull(data);
     }
 
@@ -86,7 +86,7 @@
     @Test(expected = KustvaktException.class)
     public void testUserSettingsGetNonExistent () throws KustvaktException {
         User user = new KorAPUser(10, "random");
-        authenticationManager.getUserData(user, UserSettings.class);
+        authenticationManager.getUserData(user, UserSettingProcessor.class);
     }
 
 
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/BeanInjectTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/BeanInjectTest.java
index c5814e4..4de83e0 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/BeanInjectTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/BeanInjectTest.java
@@ -12,7 +12,7 @@
 import de.ids_mannheim.korap.handlers.UserDetailsDao;
 import de.ids_mannheim.korap.handlers.UserSettingsDao;
 import de.ids_mannheim.korap.user.UserDetails;
-import de.ids_mannheim.korap.user.UserSettings;
+import de.ids_mannheim.korap.user.UserSettingProcessor;
 
 /**
  * Created by hanl on 03.06.16.
@@ -26,7 +26,7 @@
                 .getUserDataProviders();
         assertFalse(coll.isEmpty());
         Object o = BeansFactory.getTypeFactory().getTypeInterfaceBean(coll,
-                UserSettings.class);
+                UserSettingProcessor.class);
         assertEquals(UserSettingsDao.class, AopUtils.getTargetClass(o));
 
         o = BeansFactory.getTypeFactory().getTypeInterfaceBean(coll,
diff --git a/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java b/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
index 04f8359..c97d0a5 100644
--- a/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
@@ -96,7 +96,7 @@
 
     @Test
     public void testSettingsValidation () {
-        Userdata data = new UserSettings(1);
+        Userdata data = new UserSettingProcessor(1);
         data.setField(Attributes.FILE_FORMAT_FOR_EXPORT, "export");
 
         String[] req = data.requiredFields();
@@ -118,7 +118,7 @@
 
         dao = BeansFactory.getTypeFactory().getTypeInterfaceBean(
                 helper().getContext().getUserDataProviders(),
-                UserSettings.class);
+                UserSettingProcessor.class);
         assertNotNull(dao);
         assertTrue(dao instanceof UserSettingsDao);
     }
diff --git a/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest2.java b/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest2.java
index acdd062..8364fb9 100644
--- a/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest2.java
+++ b/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest2.java
@@ -25,7 +25,7 @@
 
     @Test
     public void testReadEmptyMap () throws KustvaktException {
-        Userdata userData = new UserSettings();
+        Userdata userData = new UserSettingProcessor();
         userData.read(new HashMap<>(), false);
         String jsonSettings = userData.serialize();
         assertEquals("{}", jsonSettings);
@@ -33,7 +33,7 @@
 
     @Test
     public void testReadNullMap () throws KustvaktException {
-        Userdata userData = new UserSettings();
+        Userdata userData = new UserSettingProcessor();
         userData.read(null, false);
         String jsonSettings = userData.serialize();
         assertEquals("{}", jsonSettings);
@@ -56,7 +56,7 @@
         map.put("k1", Arrays.asList(new String[] { "a", "b", "c" }));
         map.put("k2", Arrays.asList(new Integer[] { 1, 2, 3 }));
 
-        Userdata data = new UserSettings();
+        Userdata data = new UserSettingProcessor();
         data.read(map, false);
         data.validate(new ApacheValidator());
     }
@@ -80,7 +80,7 @@
 
     @Test
     public void testUserdataDefaultFields () throws KustvaktException {
-        UserSettings settings = new UserSettings(-1);
+        UserSettingProcessor settings = new UserSettingProcessor(-1);
         Map<String, Object> m = new HashMap<>();
         m.put(Attributes.DEFAULT_REL_FOUNDRY, "rel_1");
         m.put(Attributes.DEFAULT_CONST_FOUNDRY, "const_1");
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());
     }