You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by lq...@apache.org on 2016/06/16 14:00:24 UTC

svn commit: r1748729 [3/3] - in /qpid/java/trunk: broker-core/src/main/java/org/apache/qpid/server/model/ broker-core/src/main/java/org/apache/qpid/server/model/preferences/ broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/ b...

Added: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandler.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandler.java?rev=1748729&view=auto
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandler.java (added)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandler.java Thu Jun 16 14:00:23 2016
@@ -0,0 +1,405 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.qpid.server.management.plugin.servlet.rest;
+
+import java.security.AccessController;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.security.auth.Subject;
+
+import com.google.common.base.Joiner;
+
+import org.apache.qpid.server.model.preferences.Preference;
+import org.apache.qpid.server.model.preferences.UserPreferences;
+
+public class RestUserPreferenceHandler
+{
+    public void handleDELETE(final UserPreferences userPreferences, final RequestInfo requestInfo)
+    {
+        final List<String> preferencesParts = requestInfo.getPreferencesParts();
+        if (preferencesParts.size() == 2)
+        {
+            String type = preferencesParts.get(0);
+            String name = preferencesParts.get(1);
+            userPreferences.replaceByTypeAndName(type, name, null);
+        }
+        else if (preferencesParts.size() == 1)
+        {
+            String type = preferencesParts.get(0);
+            userPreferences.replaceByType(type, Collections.<Preference>emptySet());
+        }
+        else if (preferencesParts.size() == 0)
+        {
+            userPreferences.replace(Collections.<Preference>emptySet());
+        }
+        else
+        {
+            throw new IllegalArgumentException(String.format("unexpected path '%s'",
+                                                             Joiner.on("/").join(preferencesParts)));
+        }
+    }
+
+    ActionTaken handlePUT(UserPreferences userPreferences, RequestInfo requestInfo, Object providedObject)
+    {
+        final List<String> preferencesParts = requestInfo.getPreferencesParts();
+
+        if (!(providedObject instanceof Map))
+        {
+            throw new IllegalArgumentException("expected object");
+        }
+        Map<String, Object> providedAttributes = (Map<String, Object>) providedObject;
+
+        if (preferencesParts.size() == 2)
+        {
+            String type = preferencesParts.get(0);
+            String name = preferencesParts.get(1);
+
+            ensureAttributeMatches(providedAttributes, "name", name);
+            ensureAttributeMatches(providedAttributes, "type", type);
+
+            String providedDescription = getProvidedAttributeAsString(providedAttributes, "description");
+            UUID providedUuid = getProvidedUuid(providedAttributes);
+
+            Set<Principal> visibilityList = getProvidedVisibilityList(providedAttributes);
+            Map<String, Object> providedValueAttributes = getProvidedValueAttributes(providedAttributes);
+
+
+            final Preference newPref = userPreferences.createPreference(providedUuid,
+                                                                        type,
+                                                                        name,
+                                                                        providedDescription,
+                                                                        visibilityList,
+                                                                        providedValueAttributes);
+            userPreferences.updateOrAppend(Collections.singleton(newPref));
+
+            return providedUuid == null ? ActionTaken.CREATED : ActionTaken.UPDATED;
+        }
+        else
+        {
+            throw new IllegalArgumentException(String.format("unexpected path '%s'",
+                                                             Joiner.on("/").join(preferencesParts)));
+        }
+    }
+
+    void handlePOST(UserPreferences userPreferences, RequestInfo requestInfo, Object providedObject)
+    {
+        final List<String> preferencesParts = requestInfo.getPreferencesParts();
+
+        if (preferencesParts.size() == 1)
+        {
+            String type = preferencesParts.get(0);
+            if (!(providedObject instanceof List))
+            {
+                throw new IllegalArgumentException("expected a list of objects");
+            }
+            List<Object> providedObjects = (List<Object>) providedObject;
+
+            Set<Preference> preferences = new HashSet<>(providedObjects.size());
+            for (Object preferenceObject : providedObjects)
+            {
+                if (!(preferenceObject instanceof Map))
+                {
+                    throw new IllegalArgumentException("expected a list of objects");
+                }
+                Map<String, Object> preferenceAttributes = (Map<String, Object>) preferenceObject;
+
+                ensureAttributeMatches(preferenceAttributes, "type", type);
+
+                String providedName = getProvidedAttributeAsString(preferenceAttributes, "name");
+                String providedDescription = getProvidedAttributeAsString(preferenceAttributes, "description");
+                UUID providedUuid = getProvidedUuid(preferenceAttributes);
+                Set<Principal> principals = getProvidedVisibilityList(preferenceAttributes);
+                Map<String, Object> providedValueAttributes = getProvidedValueAttributes(preferenceAttributes);
+
+                Preference preference = userPreferences.createPreference(providedUuid,
+                                                                         type,
+                                                                         providedName,
+                                                                         providedDescription,
+                                                                         principals,
+                                                                         providedValueAttributes);
+                preferences.add(preference);
+            }
+
+            userPreferences.updateOrAppend(preferences);
+        }
+        else if (preferencesParts.size() == 0)
+        {
+            if (!(providedObject instanceof Map))
+            {
+                throw new IllegalArgumentException("expected object");
+            }
+            Map<String, Object> providedObjectMap = (Map<String, Object>) providedObject;
+
+            Set<Preference> preferences = new HashSet<>();
+            for (String type : providedObjectMap.keySet())
+            {
+                if (!(providedObjectMap.get(type) instanceof List))
+                {
+                    final String errorMessage = String.format("expected a list of objects for attribute '%s'", type);
+                    throw new IllegalArgumentException(errorMessage);
+                }
+
+                for (Object preferenceObject : (List<Object>) providedObjectMap.get(type))
+                {
+                    if (!(preferenceObject instanceof Map))
+                    {
+                        final String errorMessage =
+                                String.format("encountered non preference object in list of type '%s'", type);
+                        throw new IllegalArgumentException(errorMessage);
+                    }
+                    Map<String, Object> preferenceAttributes = (Map<String, Object>) preferenceObject;
+
+                    ensureAttributeMatches(preferenceAttributes, "type", type);
+
+                    String providedName = getProvidedAttributeAsString(preferenceAttributes, "name");
+                    String providedDescription = getProvidedAttributeAsString(preferenceAttributes, "description");
+                    UUID providedUuid = getProvidedUuid(preferenceAttributes);
+                    Set<Principal> principals = getProvidedVisibilityList(preferenceAttributes);
+                    Map<String, Object> providedValueAttributes = getProvidedValueAttributes(preferenceAttributes);
+
+                    Preference preference = userPreferences.createPreference(providedUuid,
+                                                                             type,
+                                                                             providedName,
+                                                                             providedDescription,
+                                                                             principals,
+                                                                             providedValueAttributes);
+                    preferences.add(preference);
+                }
+            }
+
+            userPreferences.updateOrAppend(preferences);
+        }
+        else
+        {
+            throw new IllegalArgumentException(String.format("unexpected path '%s'",
+                                                             Joiner.on("/").join(preferencesParts)));
+        }
+    }
+
+    Object handleGET(UserPreferences userPreferences, RequestInfo requestInfo)
+    {
+        final List<String> preferencesParts = requestInfo.getPreferencesParts();
+        if (preferencesParts.size() == 2)
+        {
+            String type = preferencesParts.get(0);
+            String name = preferencesParts.get(1);
+
+            final Set<Preference> allPreferences = userPreferences.getPreferences();
+
+            Preference foundPreference = null;
+            for (Preference preference : allPreferences)
+            {
+                if (preference.getType().equals(type) && preference.getName().equals(name))
+                {
+                    foundPreference = preference;
+                    break;
+                }
+            }
+
+            if (foundPreference != null)
+            {
+                return foundPreference.getAttributes();
+            }
+            else
+            {
+                final String errorMessage = String.format("Preference with name '%s' of type '%s' cannot be found",
+                                                          name,
+                                                          type);
+                throw new NotFoundException(errorMessage);
+            }
+        }
+        else if (preferencesParts.size() == 1)
+        {
+            String type = preferencesParts.get(0);
+
+            final Set<Preference> allPreferences = userPreferences.getPreferences();
+
+            List<Map<String, Object>> preferences = new ArrayList<>();
+            for (Preference preference : allPreferences)
+            {
+                if (preference.getType().equals(type))
+                {
+                    preferences.add(preference.getAttributes());
+                }
+            }
+            return preferences;
+        }
+        else if (preferencesParts.size() == 0)
+        {
+            final Set<Preference> allPreferences = userPreferences.getPreferences();
+            final Map<String, List<Map<String, Object>>> preferences = new HashMap<>();
+
+            for (Preference preference : allPreferences)
+            {
+                final String type = preference.getType();
+                if (!preferences.containsKey(type))
+                {
+                    preferences.put(type, new ArrayList<Map<String, Object>>());
+                }
+                preferences.get(type).add(preference.getAttributes());
+            }
+
+            return preferences;
+        }
+        else
+        {
+            throw new IllegalArgumentException(String.format("unexpected path '%s'",
+                                                             Joiner.on("/").join(preferencesParts)));
+        }
+    }
+
+    private Map<String, Object> getProvidedValueAttributes(final Map<String, Object> preferenceAttributes)
+    {
+        Object providedValueAttributes = preferenceAttributes.get("value");
+
+        if (providedValueAttributes == null)
+        {
+            return Collections.emptyMap();
+        }
+
+        if (!(providedValueAttributes instanceof Map))
+        {
+            final String errorMessage = String.format(
+                    "Invalid preference value ('%s') found in payload, expected to be Map",
+                    providedValueAttributes);
+            throw new IllegalArgumentException(errorMessage);
+        }
+
+        for (Object key : ((Map) providedValueAttributes).keySet())
+        {
+            if (!(key instanceof String))
+            {
+                String errorMessage = String.format(
+                        "The keys of the preference value object must be of type String,  Found key (%s)", key);
+                throw new IllegalArgumentException(errorMessage);
+            }
+        }
+        return (Map<String, Object>) providedValueAttributes;
+    }
+
+    private UUID getProvidedUuid(final Map<String, Object> providedObjectMap)
+    {
+        String providedId = getProvidedAttributeAsString(providedObjectMap, "id");
+        try
+        {
+            return providedId != null ? UUID.fromString(providedId) : null;
+        }
+        catch (IllegalArgumentException iae)
+        {
+            throw new IllegalArgumentException(String.format("Invalid UUID ('%s') found in payload", providedId), iae);
+        }
+    }
+
+    private Set<Principal> getProvidedVisibilityList(final Map<String, Object> providedAttributes)
+    {
+        Object visibilityListObject = providedAttributes.get("visibilityList");
+
+        if (visibilityListObject == null)
+        {
+            return null;
+        }
+
+        if (!(visibilityListObject instanceof Collection))
+        {
+            String errorMessage = String.format("Invalid visibilityList ('%s') found in payload", visibilityListObject);
+            throw new IllegalArgumentException(errorMessage);
+        }
+
+        Subject currentSubject = Subject.getSubject(AccessController.getContext());
+        if (currentSubject == null)
+        {
+            throw new SecurityException("Current thread does not have a user");
+        }
+
+        HashMap<String, Principal> principalNameMap = new HashMap<>(currentSubject.getPrincipals().size());
+        for (Principal principal : currentSubject.getPrincipals())
+        {
+            principalNameMap.put(principal.getName(), principal);
+        }
+
+        Collection visibilityList = (Collection) visibilityListObject;
+        Set<Principal> principals = new HashSet<>(visibilityList.size());
+
+        for (Object visibilityObject : visibilityList)
+        {
+            if (!(visibilityObject instanceof String))
+            {
+                String errorMessage = String.format("Invalid visibilityList, '%s' is not a string",
+                                                    visibilityObject);
+                throw new IllegalArgumentException(errorMessage);
+            }
+
+            Principal principal = principalNameMap.get(visibilityObject);
+            if (principal == null)
+            {
+                String errorMessage = String.format("Invalid visibilityList, this user does not hold principal '%s'",
+                                                    visibilityObject);
+                throw new IllegalArgumentException(errorMessage);
+            }
+            principals.add(principal);
+        }
+        return principals;
+    }
+
+    private void ensureAttributeMatches(final Map<String, Object> preferenceAttributes,
+                                        final String attributeName,
+                                        final String expectedValue)
+    {
+        final Object providedValue = preferenceAttributes.get(attributeName);
+        if (providedValue != null && !Objects.equals(providedValue, expectedValue))
+        {
+            final String errorMessage = String.format(
+                    "The attribute '%s' within the payload ('%s') contradicts the value implied by the url ('%s')",
+                    attributeName,
+                    providedValue,
+                    expectedValue);
+            throw new IllegalArgumentException(errorMessage);
+        }
+    }
+
+    private String getProvidedAttributeAsString(final Map<String, Object> preferenceAttributes,
+                                                final String attributeName)
+    {
+        Object providedValue = preferenceAttributes.get(attributeName);
+        if (providedValue != null && !(providedValue instanceof String))
+        {
+            final String errorMessage = String.format("Attribute '%s' must be of type string. Found : '%s'",
+                                                      attributeName, providedValue);
+            throw new IllegalArgumentException(errorMessage);
+        }
+        return (String) providedValue;
+    }
+
+    enum ActionTaken
+    {
+        CREATED,
+        UPDATED
+    }
+}

Added: qpid/java/trunk/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandlerTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandlerTest.java?rev=1748729&view=auto
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandlerTest.java (added)
+++ qpid/java/trunk/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandlerTest.java Thu Jun 16 14:00:23 2016
@@ -0,0 +1,369 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.qpid.server.management.plugin.servlet.rest;
+
+import static org.apache.qpid.server.management.plugin.servlet.rest.RestUserPreferenceHandler.ActionTaken;
+import static org.mockito.Mockito.mock;
+
+import java.security.Principal;
+import java.security.PrivilegedAction;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.security.auth.Subject;
+
+import com.google.common.collect.Sets;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.preferences.Preference;
+import org.apache.qpid.server.model.preferences.UserPreferences;
+import org.apache.qpid.server.model.preferences.UserPreferencesImpl;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+import org.apache.qpid.server.security.group.GroupPrincipal;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class RestUserPreferenceHandlerTest extends QpidTestCase
+{
+
+    private static final String MYGROUP = "mygroup";
+    private static final String MYUSER = "myuser";
+
+    private RestUserPreferenceHandler _handler = new RestUserPreferenceHandler();
+    private ConfiguredObject<?> _configuredObject;
+    private UserPreferences _userPreferences;
+    private Subject _subject;
+    private GroupPrincipal _groupPrincipal;
+
+    @Override
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        _configuredObject = mock(ConfiguredObject.class);
+        _userPreferences = new UserPreferencesImpl(_configuredObject,
+                                                   new HashMap<UUID, Preference>(),
+                                                   new HashMap<String, List<Preference>>());
+        _groupPrincipal = new GroupPrincipal(MYGROUP);
+        _subject = new Subject(true,
+                               Sets.newHashSet(new AuthenticatedPrincipal(MYUSER), _groupPrincipal),
+                               Collections.emptySet(),
+                               Collections.emptySet());
+    }
+
+    public void testPutWithVisibilityList_ValidGroup() throws Exception
+    {
+
+        final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+                                                                                 Arrays.asList("X-testtype",
+                                                                                               "myprefname"));
+
+        final Map<String, Object> pref = new HashMap<>();
+        pref.put("value", Collections.emptyMap());
+        pref.put("visibilityList", Collections.singletonList(MYGROUP));
+
+        Subject.doAs(_subject, new PrivilegedAction<Void>()
+                     {
+                         @Override
+                         public Void run()
+                         {
+                             final ActionTaken action =
+                                     _handler.handlePUT(_userPreferences, requestInfo, pref);
+                             assertEquals(ActionTaken.CREATED, action);
+
+                             assertEquals("Unexpected number of preferences", 1, _userPreferences.getPreferences().size());
+                             Preference prefModel = _userPreferences.getPreferences().iterator().next();
+                             final Set<Principal> visibilityList = prefModel.getVisibilityList();
+                             assertEquals("Unexpected number of principals in visibility list", 1, visibilityList.size());
+                             Principal principal = visibilityList.iterator().next();
+                             assertEquals("Unexpected member of visibility list", MYGROUP, principal.getName());
+                             return null;
+                         }
+                     }
+                    );
+    }
+
+    public void testPutWithVisibilityList_InvalidGroup() throws Exception
+    {
+
+        final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+                                                                                 Arrays.asList("X-testtype",
+                                                                                               "myprefname"));
+
+        final Map<String, Object> pref = new HashMap<>();
+        pref.put("value", Collections.emptyMap());
+        pref.put("visibilityList", Collections.singletonList("Invalid Group"));
+
+        Subject.doAs(_subject, new PrivilegedAction<Void>()
+                     {
+                         @Override
+                         public Void run()
+                         {
+                             try
+                             {
+                                 _handler.handlePUT(_userPreferences, requestInfo, pref);
+                                 fail("Expected exception not thrown");
+                             }
+                             catch (IllegalArgumentException e)
+                             {
+                                 // pass
+                             }
+                             return null;
+                         }
+                     }
+                    );
+    }
+
+    public void testPostToTypeWithVisibilityList_ValidGroup() throws Exception
+    {
+        final RequestInfo typeRequestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+                                                                                     Arrays.asList("X-testtype"));
+
+        final Map<String, Object> pref = new HashMap<>();
+        pref.put("name", "testPref");
+        pref.put("value", Collections.emptyMap());
+        pref.put("visibilityList", Collections.singletonList(MYGROUP));
+
+        Subject.doAs(_subject, new PrivilegedAction<Void>()
+                     {
+                         @Override
+                         public Void run()
+                         {
+                             _handler.handlePOST(_userPreferences, typeRequestInfo, Collections.singletonList(pref));
+
+                             assertEquals("Unexpected number of preferences", 1, _userPreferences.getPreferences().size());
+                             Preference prefModel = _userPreferences.getPreferences().iterator().next();
+                             final Set<Principal> visibilityList = prefModel.getVisibilityList();
+                             assertEquals("Unexpected number of principals in visibility list", 1, visibilityList.size());
+                             Principal principal = visibilityList.iterator().next();
+                             assertEquals("Unexpected member of visibility list", MYGROUP, principal.getName());
+                             return null;
+                         }
+                     }
+                    );
+    }
+
+    public void testPostToRootWithVisibilityList_ValidGroup() throws Exception
+    {
+        final RequestInfo rootRequestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+                                                                                     Collections.<String>emptyList());
+        final Map<String, Object> pref = new HashMap<>();
+        pref.put("name", "testPref");
+        pref.put("value", Collections.emptyMap());
+        pref.put("visibilityList", Collections.singletonList(MYGROUP));
+
+        Subject.doAs(_subject, new PrivilegedAction<Void>()
+                     {
+                         @Override
+                         public Void run()
+                         {
+                             final Map<String, List<Map<String, Object>>> payload =
+                                     Collections.singletonMap("X-testtype2", Collections.singletonList(pref));
+                             _handler.handlePOST(_userPreferences, rootRequestInfo, payload);
+
+                             assertEquals("Unexpected number of preferences", 1, _userPreferences.getPreferences().size());
+                             Preference prefModel = _userPreferences.getPreferences().iterator().next();
+                             final Set<Principal> visibilityList = prefModel.getVisibilityList();
+                             assertEquals("Unexpected number of principals in visibility list", 1, visibilityList.size());
+                             Principal principal = visibilityList.iterator().next();
+                             assertEquals("Unexpected member of visibility list", MYGROUP, principal.getName());
+
+                             return null;
+                         }
+                     }
+                    );
+    }
+
+    public void testPostToTypeWithVisibilityList_InvalidGroup() throws Exception
+    {
+        final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+                                                                                 Arrays.asList("X-testtype"));
+
+        final Map<String, Object> pref = new HashMap<>();
+        pref.put("name", "testPref");
+        pref.put("value", Collections.emptyMap());
+        pref.put("visibilityList", Collections.singletonList("Invalid Group"));
+
+        Subject.doAs(_subject, new PrivilegedAction<Void>()
+                     {
+                         @Override
+
+                         public Void run()
+                         {
+                             try
+                             {
+                                 _handler.handlePOST(_userPreferences, requestInfo, Collections.singletonList(pref));
+                                 fail("Expected exception not thrown");
+                             }
+                             catch (IllegalArgumentException e)
+                             {
+                                 // pass
+                             }
+                             return null;
+                         }
+                     }
+                    );
+    }
+
+    public void testPostToRootWithVisibilityList_InvalidGroup() throws Exception
+    {
+        final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+                                                                                 Collections.<String>emptyList());
+
+        final Map<String, Object> pref = new HashMap<>();
+        pref.put("name", "testPref");
+        pref.put("value", Collections.emptyMap());
+        pref.put("visibilityList", Collections.singletonList("Invalid Group"));
+
+        Subject.doAs(_subject, new PrivilegedAction<Void>()
+                     {
+                         @Override
+                         public Void run()
+                         {
+                             try
+                             {
+                                 final Map<String, List<Map<String, Object>>> payload =
+                                         Collections.singletonMap("X-testType", Collections.singletonList(pref));
+                                 _handler.handlePOST(_userPreferences, requestInfo, payload);
+                                 fail("Expected exception not thrown");
+                             }
+                             catch (IllegalArgumentException e)
+                             {
+                                 // pass
+                             }
+                             return null;
+                         }
+                     }
+                    );
+    }
+
+    public void testGetHasCorrectVisibilityList() throws Exception
+    {
+        final RequestInfo rootRequestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+                                                                                     Collections.<String>emptyList());
+        final Map<String, Object> pref = new HashMap<>();
+        pref.put("name", "testPref");
+        pref.put("value", Collections.emptyMap());
+        pref.put("visibilityList", Collections.singletonList(MYGROUP));
+        final String type = "X-testtype";
+
+        Subject.doAs(_subject, new PrivilegedAction<Void>()
+                     {
+                         @Override
+                         public Void run()
+                         {
+                             Preference preference = _userPreferences.createPreference(null,
+                                                                                       type,
+                                                                                       "testpref",
+                                                                                       null,
+                                                                                       Collections.<Principal>singleton(
+                                                                                               _groupPrincipal),
+                                                                                       Collections.<String, Object>emptyMap());
+                             _userPreferences.updateOrAppend(Collections.singleton(preference));
+
+                             Map<String, List<Map<String, Object>>> typeToPreferenceListMap =
+                                     (Map<String, List<Map<String, Object>>>) _handler.handleGET(_userPreferences, rootRequestInfo);
+                             assertEquals("Unexpected preference map size", 1, typeToPreferenceListMap.size());
+                             assertEquals("Unexpected type in preference map",
+                                          type,
+                                          typeToPreferenceListMap.keySet().iterator().next());
+                             List<Map<String, Object>> preferences = typeToPreferenceListMap.get(type);
+                             assertEquals("Unexpected number of preferences", 1, preferences.size());
+                             Set<String> visibilityList = (Set<String>) preferences.get(0).get("visibilityList");
+                             assertEquals("Unexpected number of principals in visibility list", 1, visibilityList.size());
+                             assertEquals("Unexpected principal in visibility list", MYGROUP, visibilityList.iterator().next());
+                             return null;
+                         }
+                     }
+                    );
+    }
+
+    public void testDeleteByTypeAndName() throws Exception
+    {
+        final String preferenceType = "X-testtype";
+        final String preferenceName = "myprefname";
+        final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+                                                                                 Arrays.asList(preferenceType,
+                                                                                               preferenceName));
+
+        final Map<String, Object> pref = new HashMap<>();
+        pref.put("value", Collections.emptyMap());
+
+        doTestDelete(preferenceType, preferenceName, requestInfo);
+    }
+
+    public void testDeleteByType() throws Exception
+    {
+        final String preferenceType = "X-testtype";
+        final String preferenceName = "myprefname";
+        final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+                                                                                 Arrays.asList(preferenceType));
+
+        final Map<String, Object> pref = new HashMap<>();
+        pref.put("value", Collections.emptyMap());
+
+        doTestDelete(preferenceType, preferenceName, requestInfo);
+    }
+
+    public void testDeleteByRoot() throws Exception
+    {
+        final String preferenceType = "X-testtype";
+        final String preferenceName = "myprefname";
+        final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+                                                                                 Collections.<String>emptyList());
+
+        final Map<String, Object> pref = new HashMap<>();
+        pref.put("value", Collections.emptyMap());
+
+        doTestDelete(preferenceType, preferenceName, requestInfo);
+    }
+
+    private void doTestDelete(final String preferenceType, final String preferenceName, final RequestInfo requestInfo)
+    {
+        Subject.doAs(_subject, new PrivilegedAction<Void>()
+                     {
+                         @Override
+                         public Void run()
+                         {
+                             Preference preference = _userPreferences.createPreference(null,
+                                                                                       preferenceType,
+                                                                                       preferenceName,
+                                                                                       null,
+                                                                                       null,
+                                                                                       Collections.<String, Object>emptyMap());
+                             _userPreferences.updateOrAppend(Collections.singleton(preference));
+                             Set<Preference> retrievedPreferences = _userPreferences.getPreferences();
+                             assertEquals("adding pref failed", 1, retrievedPreferences.size());
+
+                             _handler.handleDELETE(_userPreferences, requestInfo);
+
+                             retrievedPreferences = _userPreferences.getPreferences();
+                             assertEquals("Deletion of preference failed", 0, retrievedPreferences.size());
+
+                             // this should be a noop
+                             _handler.handleDELETE(_userPreferences, requestInfo);
+                             return null;
+                         }
+                     }
+                    );
+    }
+}

Modified: qpid/java/trunk/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java?rev=1748729&r1=1748728&r2=1748729&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java (original)
+++ qpid/java/trunk/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java Thu Jun 16 14:00:23 2016
@@ -70,6 +70,8 @@ public class RestTestHelper
     public static final String API_BASE = "/api/latest/";
 
     private static final Logger LOGGER = LoggerFactory.getLogger(RestTestHelper.class);
+    public static final String DEFAULT_USERNAME = "webadmin";
+    public static final String DEFAULT_PASSWORD = "webadmin";
 
     private int _httpPort;
 
@@ -95,7 +97,7 @@ public class RestTestHelper
     public RestTestHelper(int httpPort)
     {
         _httpPort = httpPort;
-        setUsernameAndPassword("webadmin", "webadmin");
+        setUsernameAndPassword(DEFAULT_USERNAME, DEFAULT_PASSWORD);
     }
 
     public int getHttpPort()
@@ -256,6 +258,15 @@ public class RestTestHelper
         return providedObject;
     }
 
+    public <T> T readJsonResponse(HttpURLConnection connection, Class<T> valueType) throws IOException
+    {
+        byte[] data = readConnectionInputStream(connection);
+
+        ObjectMapper mapper = new ObjectMapper();
+
+        return mapper.readValue(new ByteArrayInputStream(data), valueType);
+    }
+
     private byte[] readConnectionInputStream(HttpURLConnection connection) throws IOException
     {
         InputStream is = connection.getInputStream();
@@ -273,7 +284,7 @@ public class RestTestHelper
         return baos.toByteArray();
     }
 
-    private void writeJsonRequest(HttpURLConnection connection, Map<String, Object> data) throws IOException
+    private void writeJsonRequest(HttpURLConnection connection, Object data) throws IOException
     {
         ObjectMapper mapper = new ObjectMapper();
         mapper.writeValue(connection.getOutputStream(), data);
@@ -362,6 +373,13 @@ public class RestTestHelper
         return response;
     }
 
+    public <T> T getJson(String path, final Class<T> valueType) throws IOException
+    {
+        HttpURLConnection connection = openManagementConnection(path, "GET");
+        connection.connect();
+        return readJsonResponse(connection, valueType);
+    }
+
     public void createNewGroupMember(String groupProviderName, String groupName, String memberName, int responseCode) throws IOException
     {
         HttpURLConnection connection = openManagementConnection(
@@ -517,17 +535,17 @@ public class RestTestHelper
     }
 
 
-    public int submitRequest(String url, String method, Map<String, Object> attributes) throws IOException
+    public int submitRequest(String url, String method, Object data) throws IOException
     {
-        return submitRequest(url, method, attributes, null);
+        return submitRequest(url, method, data, null);
     }
 
-    public int submitRequest(String url, String method, Map<String, Object> attributes, Map<String, List<String>> responseHeadersToCapture) throws IOException
+    public int submitRequest(String url, String method, Object data, Map<String, List<String>> responseHeadersToCapture) throws IOException
     {
         HttpURLConnection connection = openManagementConnection(url, method);
-        if (attributes != null)
+        if (data != null)
         {
-            writeJsonRequest(connection, attributes);
+            writeJsonRequest(connection, data);
         }
         int responseCode = connection.getResponseCode();
         if (responseHeadersToCapture!= null)
@@ -543,10 +561,10 @@ public class RestTestHelper
         return submitRequest(url, method, (byte[])null);
     }
 
-    public void submitRequest(String url, String method, Map<String, Object> attributes, int expectedResponseCode) throws IOException
+    public void submitRequest(String url, String method, Object data, int expectedResponseCode) throws IOException
     {
         Map<String, List<String>> headers = new HashMap<>();
-        int responseCode = submitRequest(url, method, attributes, headers);
+        int responseCode = submitRequest(url, method, data, headers);
         Assert.assertEquals("Unexpected response code from " + method + " " + url , expectedResponseCode, responseCode);
         if (expectedResponseCode == 201)
         {

Copied: qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyPreferencesProviderRestTest.java (from r1748723, qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/PreferencesProviderRestTest.java)
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyPreferencesProviderRestTest.java?p2=qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyPreferencesProviderRestTest.java&p1=qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/PreferencesProviderRestTest.java&r1=1748723&r2=1748729&rev=1748729&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/PreferencesProviderRestTest.java (original)
+++ qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyPreferencesProviderRestTest.java Thu Jun 16 14:00:23 2016
@@ -40,7 +40,7 @@ import org.apache.qpid.server.security.a
 import org.apache.qpid.test.utils.TestBrokerConfiguration;
 import org.apache.qpid.test.utils.TestFileUtils;
 
-public class PreferencesProviderRestTest extends QpidRestTestCase
+public class LegacyPreferencesProviderRestTest extends QpidRestTestCase
 {
     private Map<String, File> _preferencesProviderFiles;
     private File _authenticationProviderFile;

Copied: qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyPreferencesRestTest.java (from r1748723, qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/PreferencesRestTest.java)
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyPreferencesRestTest.java?p2=qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyPreferencesRestTest.java&p1=qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/PreferencesRestTest.java&r1=1748723&r2=1748729&rev=1748729&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/PreferencesRestTest.java (original)
+++ qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyPreferencesRestTest.java Thu Jun 16 14:00:23 2016
@@ -29,7 +29,7 @@ import org.apache.qpid.server.model.adap
 import org.apache.qpid.test.utils.TestBrokerConfiguration;
 import org.apache.qpid.test.utils.TestFileUtils;
 
-public class PreferencesRestTest extends QpidRestTestCase
+public class LegacyPreferencesRestTest extends QpidRestTestCase
 {
     private File _preferencesProviderFile;
 

Copied: qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyUserPreferencesRestTest.java (from r1748723, qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/UserPreferencesRestTest.java)
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyUserPreferencesRestTest.java?p2=qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyUserPreferencesRestTest.java&p1=qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/UserPreferencesRestTest.java&r1=1748723&r2=1748729&rev=1748729&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/UserPreferencesRestTest.java (original)
+++ qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/LegacyUserPreferencesRestTest.java Thu Jun 16 14:00:23 2016
@@ -33,7 +33,7 @@ import org.apache.qpid.server.model.adap
 import org.apache.qpid.test.utils.TestBrokerConfiguration;
 import org.apache.qpid.test.utils.TestFileUtils;
 
-public class UserPreferencesRestTest extends QpidRestTestCase
+public class LegacyUserPreferencesRestTest extends QpidRestTestCase
 {
     private File _preferencesProviderFile;
 

Modified: qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/UserPreferencesRestTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/UserPreferencesRestTest.java?rev=1748729&r1=1748728&r2=1748729&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/UserPreferencesRestTest.java (original)
+++ qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/UserPreferencesRestTest.java Thu Jun 16 14:00:23 2016
@@ -1,5 +1,4 @@
 /*
- *
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -16,134 +15,266 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- *
  */
 
 package org.apache.qpid.systest.rest;
 
-import java.io.File;
-import java.net.URLEncoder;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
-import org.apache.qpid.server.model.PreferencesProvider;
-import org.apache.qpid.server.model.User;
-import org.apache.qpid.server.model.adapter.FileSystemPreferencesProvider;
-import org.apache.qpid.test.utils.TestBrokerConfiguration;
-import org.apache.qpid.test.utils.TestFileUtils;
+import javax.servlet.http.HttpServletResponse;
 
 public class UserPreferencesRestTest extends QpidRestTestCase
 {
-    private File _preferencesProviderFile;
 
-    public void setUp() throws Exception
+    public void testPutSinglePreferenceRoundTrip() throws Exception
     {
-        _preferencesProviderFile = TestFileUtils.createTempFile(this, ".prefs.json",
-                "{\"webadmin\":{\"language\": \"en\", \"saveTabs\":true},"
-              + " \"admin\":{\"language\": \"fr\", \"saveTabs\":false}" + "}");
-        super.setUp();
-    }
+        final String prefName = "mypref";
+        final String prefDescription = "mydesc";
+        final String prefType = "X-testtype";
+
+        Map<String, Object> prefAttributes = new HashMap<>();
+        prefAttributes.put("description", prefDescription);
+
+        Map<String, Object> prefValueAttributes = new HashMap<>();
+        prefValueAttributes.put("valueAttrName", "valueAttrValue");
+        prefAttributes.put("value", prefValueAttributes);
+
+        String fullUrl = String.format("broker/userpreferences/%s/%s", prefType, prefName);
+        getRestTestHelper().submitRequest(fullUrl, "PUT", prefAttributes, HttpServletResponse.SC_CREATED);
+
+        Map<String, Object> prefDetails = getRestTestHelper().getJsonAsMap(fullUrl);
+
+        assertEquals("Unexpected pref name", prefName, prefDetails.get("name"));
+        assertEquals("Unexpected pref description", prefDescription, prefDetails.get("description"));
+        assertEquals("Unexpected pref type", prefType, prefDetails.get("type"));
+        assertEquals("Unexpected pref value", prefValueAttributes, prefDetails.get("value"));
+        assertEquals("Unexpected pref owner", RestTestHelper.DEFAULT_USERNAME, prefDetails.get("owner"));
+
+        String typeUrl = String.format("broker/userpreferences/%s", prefType);
+        assertEquals("Unexpected preference returned from type url",
+                     prefDetails,
+                     getRestTestHelper().getJsonAsSingletonList(typeUrl));
+
+        String allUrl = "broker/userpreferences";
+        final Map<String, Object> allMap = getRestTestHelper().getJsonAsMap(allUrl);
+        assertEquals("Unexpected number of types in all url response", 1, allMap.size());
+        assertTrue("Expected type not found in all url response. Found : " + allMap.keySet(),
+                   allMap.containsKey(prefType));
+        List<Map<String, Object>> prefs = (List<Map<String, Object>>) allMap.get(prefType);
+        assertEquals("Unexpected number of preferences", 1, prefs.size());
 
-    public void tearDown() throws Exception
-    {
-        try
-        {
-            super.tearDown();
-        }
-        finally
-        {
-            if (_preferencesProviderFile != null)
-            {
-                _preferencesProviderFile.delete();
-            }
-        }
+        assertEquals("Unexpected preference returned from all url", prefDetails, prefs.get(0));
     }
 
-    @Override
-    protected void customizeConfiguration() throws Exception
-    {
-        super.customizeConfiguration();
 
-        TestBrokerConfiguration brokerConfiguration = getDefaultBrokerConfiguration();
-        Map<String, Object> attributes = new HashMap<String, Object>();
-        attributes.put(PreferencesProvider.NAME, "test");
-        attributes.put(PreferencesProvider.TYPE, FileSystemPreferencesProvider.PROVIDER_TYPE);
-        attributes.put(FileSystemPreferencesProvider.PATH, _preferencesProviderFile.getAbsolutePath());
-        brokerConfiguration.addPreferencesProviderConfiguration(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER,
-                attributes);
+    public void testPostSinglePreferenceRoundTrip() throws Exception
+    {
+        final String prefName = "mypref";
+        final String prefDescription = "mydesc";
+        final String prefType = "X-testtype";
+
+        Map<String, Object> prefAttributes = new HashMap<>();
+        prefAttributes.put("name", prefName);
+        prefAttributes.put("type", prefType);
+        prefAttributes.put("description", prefDescription);
+
+        Map<String, Object> prefValueAttributes = new HashMap<>();
+        prefValueAttributes.put("valueAttrName", "valueAttrValue");
+        prefAttributes.put("value", prefValueAttributes);
+
+        String rootUrl = "broker/userpreferences";
+        Map<String, List<Map<String, Object>>> payload =
+                Collections.singletonMap(prefType, Collections.singletonList(prefAttributes));
+        getRestTestHelper().submitRequest(rootUrl, "POST", payload, HttpServletResponse.SC_OK);
+
+        Map<String, List<Map<String, Object>>> allPrefs = (Map<String, List<Map<String, Object>>>) getRestTestHelper().getJson(rootUrl, Object.class);
+
+        Map<String, Object> prefDetails = allPrefs.get(prefType).get(0);
+        assertEquals("Unexpected pref name", prefName, prefDetails.get("name"));
+        assertEquals("Unexpected pref description", prefDescription, prefDetails.get("description"));
+        assertEquals("Unexpected pref type", prefType, prefDetails.get("type"));
+        assertEquals("Unexpected pref value", prefValueAttributes, prefDetails.get("value"));
+        assertEquals("Unexpected pref owner", RestTestHelper.DEFAULT_USERNAME, prefDetails.get("owner"));
+
+        String typeUrl = String.format("broker/userpreferences/%s", prefType);
+        assertEquals("Unexpected preference returned from type url",
+                     prefDetails,
+                     getRestTestHelper().getJsonAsSingletonList(typeUrl));
+
+        String allUrl = "broker/userpreferences";
+        final Map<String, Object> allMap = getRestTestHelper().getJsonAsMap(allUrl);
+        assertEquals("Unexpected number of types in all url response", 1, allMap.size());
+        assertTrue("Expected type not found in all url response. Found : " + allMap.keySet(),
+                   allMap.containsKey(prefType));
+        List<Map<String, Object>> prefs = (List<Map<String, Object>>) allMap.get(prefType);
+        assertEquals("Unexpected number of preferences", 1, prefs.size());
 
+        assertEquals("Unexpected preference returned from all url", prefDetails, prefs.get(0));
     }
 
-    public void testGetUserPreferences() throws Exception
+    public void testPostManyPreferences() throws Exception
     {
-        Map<String, Object> preferences = getRestTestHelper().getJsonAsMap(
-                "/service/userpreferences/" + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/webadmin");
-        assertEquals("Unexpected number of preferences", 2, preferences.size());
-        assertEquals("Unexpected language preference", "en", preferences.get("language"));
-        assertEquals("Unexpected saveTabs preference", true, preferences.get("saveTabs"));
+        final String pref1Name = "pref1";
+        final String pref2Name = "pref2Name";
+        final String pref3Name = "pref3";
+        final String prefType1 = "X-prefType1";
+        final String prefType2 = "X-prefType2";
+
+        Map<String, Object> pref1Attributes = new HashMap<>();
+        pref1Attributes.put("name", pref1Name);
+        pref1Attributes.put("type", prefType1);
+        pref1Attributes.put("value", Collections.emptyMap());
+
+        Map<String, Object> pref2Attributes = new HashMap<>();
+        pref2Attributes.put("name", pref2Name);
+        pref2Attributes.put("type", prefType2);
+        pref2Attributes.put("value", Collections.emptyMap());
+
+        Map<String, Object> payload = new HashMap<>();
+        payload.put(prefType1, Collections.singletonList(pref1Attributes));
+        payload.put(prefType2, Collections.singletonList(pref2Attributes));
+        String url = "broker/userpreferences";
+        getRestTestHelper().submitRequest(url, "POST", payload, HttpServletResponse.SC_OK);
+
+        Map<String, Object> pref3Attributes = new HashMap<>();
+        pref3Attributes.put("name", pref3Name);
+        pref3Attributes.put("type", prefType2);
+        pref3Attributes.put("value", Collections.emptyMap());
+
+        String url2 = String.format("broker/userpreferences/%s", prefType2);
+        getRestTestHelper().submitRequest(url2,
+                                          "POST",
+                                          Collections.singletonList(pref3Attributes),
+                                          HttpServletResponse.SC_OK);
+
+        String allUrl = "broker/userpreferences";
+        final Map<String, Object> allMap = getRestTestHelper().getJsonAsMap(allUrl);
+        assertEquals("Unexpected number of types in all url response", 2, allMap.size());
+        assertTrue("Expected type not found in all url response. Found : " + allMap.keySet(),
+                   allMap.containsKey(prefType1) && allMap.containsKey(prefType2));
+        List<Map<String, Object>> pref1s = (List<Map<String, Object>>) allMap.get(prefType1);
+        assertEquals("Unexpected number of preferences", 1, pref1s.size());
+        List<Map<String, Object>> pref2s = (List<Map<String, Object>>) allMap.get(prefType2);
+        assertEquals("Unexpected number of preferences", 2, pref2s.size());
+
+        assertEquals("Unexpected preference returned from all url for type1. Found : " + pref1s.get(0).get("name"),
+                     pref1Name,
+                     pref1s.get(0).get("name"));
+        Set<String> pref2Names = new HashSet<>();
+        pref2Names.add((String) pref2s.get(0).get("name"));
+        pref2Names.add((String) pref2s.get(1).get("name"));
+        assertTrue("Unexpected preference returned from all url for type2. Found : " + pref2Names,
+                   pref2Names.contains(pref2Name) && pref2Names.contains(pref3Name));
     }
 
-    public void testGetUserListForAuthenticationProvider() throws Exception
+    public void testPutUpdate() throws Exception
     {
-        List<Map<String, Object>> users = getRestTestHelper().getJsonAsList(
-                "/service/userpreferences/" + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER);
-        assertEquals("Unexpected number of users", 2, users.size());
-        String[] expectedUsers = { "webadmin", "admin" };
-        for (int i = 0; i < expectedUsers.length; i++)
-        {
-            Map<String, Object> user = findUser(expectedUsers[i], users);
-            assertNotNull(String.format("User %s is not found", expectedUsers[i]), user);
-        }
-    }
+        final String prefName = "mypref";
+        final String prefDescription = "mydesc";
+        final String prefType = "X-testtype";
 
-    public void testGetUserList() throws Exception
-    {
-        List<Map<String, Object>> users = getRestTestHelper().getJsonAsList("/service/userpreferences");
-        assertEquals("Unexpected number of users", 2, users.size());
-        String[] expectedUsers = { "webadmin", "admin" };
-        for (int i = 0; i < expectedUsers.length; i++)
-        {
-            Map<String, Object> user = findUser(expectedUsers[i], users);
-            assertNotNull(String.format("User %s is not found", expectedUsers[i]), user);
-        }
+        Map<String, Object> prefAttributes = new HashMap<>();
+        prefAttributes.put("description", prefDescription);
+
+        prefAttributes.put("value", Collections.emptyMap());
+        String fullUrl = String.format("broker/userpreferences/%s/%s", prefType, prefName);
+        getRestTestHelper().submitRequest(fullUrl, "PUT", prefAttributes, HttpServletResponse.SC_CREATED);
+
+        Map<String, Object> storedPreference = getRestTestHelper().getJsonAsMap(fullUrl);
+
+        assertEquals("Unexpected pref name", prefName, storedPreference.get("name"));
+        assertEquals("Unexpected pref description", prefDescription, storedPreference.get("description"));
+
+        Map<String, Object> updatePreference = new HashMap<>(storedPreference);
+        updatePreference.put("description", "new description");
+        getRestTestHelper().submitRequest(fullUrl, "PUT", updatePreference, HttpServletResponse.SC_OK);
+
+        Map<String, Object> rereadPrefDetails = getRestTestHelper().getJsonAsMap(fullUrl);
+
+        assertEquals("Unexpected id on updated pref", storedPreference.get("id"), rereadPrefDetails.get("id"));
+        assertEquals("Unexpected description on updated pref", "new description", rereadPrefDetails.get("description"));
     }
 
-    public void testDeleteUser() throws Exception
+    public void testPostUpdate() throws Exception
     {
-        int status = getRestTestHelper().submitRequest(
-                "/service/userpreferences?user="
-                        + URLEncoder.encode(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/webadmin",
-                                "UTF-8"), "DELETE");
-        assertEquals("Unexpected status ", 200, status);
-        List<Map<String, Object>> users = getRestTestHelper().getJsonAsList("/service/userpreferences");
-        assertEquals("Unexpected number of users", 1, users.size());
-        Map<String, Object> user = findUser("admin", users);
-        assertNotNull("User admin is not found", user);
-        assertNull("User webadmin is found", findUser("webadmin", users));
-    }
-
-    public void testDeleteMultipleUser() throws Exception
-    {
-        int status = getRestTestHelper().submitRequest("/service/userpreferences?user="
-                + URLEncoder.encode(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/webadmin", "UTF-8")
-                + "&user=" + URLEncoder.encode(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/admin", "UTF-8"),
-                "DELETE");
-        assertEquals("Unexpected status ", 200, status);
-        List<Map<String, Object>> users = getRestTestHelper().getJsonAsList("/service/userpreferences");
-        assertEquals("Unexpected number of users", 0, users.size());
+        final String prefName = "mypref";
+        final String prefDescription = "mydesc";
+        final String prefType = "X-testtype";
+
+        String fullUrl = String.format("broker/userpreferences/%s/%s", prefType, prefName);
+        String typeUrl = String.format("broker/userpreferences/%s", prefType);
+        String rootUrl = "broker/userpreferences";
+
+        Map<String, Object> prefAttributes = new HashMap<>();
+        prefAttributes.put("name", prefName);
+        prefAttributes.put("description", prefDescription);
+        prefAttributes.put("value", Collections.emptyMap());
+        final List<Map<String, Object>> payloadCreate = Collections.singletonList(prefAttributes);
+        getRestTestHelper().submitRequest(typeUrl, "POST", payloadCreate, HttpServletResponse.SC_OK);
+
+        Map<String, Object> storedPreference = getRestTestHelper().getJsonAsMap(fullUrl);
+
+        assertEquals("Unexpected pref name", prefName, storedPreference.get("name"));
+        assertEquals("Unexpected pref description", prefDescription, storedPreference.get("description"));
+
+        // Update via url to type
+        Map<String, Object> updatePreference = new HashMap<>(storedPreference);
+        updatePreference.put("description", "update 1");
+        final List<Map<String, Object>> payloadUpdate1 = Collections.singletonList(updatePreference);
+        getRestTestHelper().submitRequest(typeUrl, "POST", payloadUpdate1, HttpServletResponse.SC_OK);
+
+        Map<String, Object> rereadPrefDetails = getRestTestHelper().getJsonAsMap(fullUrl);
+
+        assertEquals("Unexpected id on updated pref, update 1",
+                     storedPreference.get("id"),
+                     rereadPrefDetails.get("id"));
+        assertEquals("Unexpected description on updated pref, update 1",
+                     "update 1",
+                     rereadPrefDetails.get("description"));
+
+        // Update via url to root
+        updatePreference = new HashMap<>(rereadPrefDetails);
+        updatePreference.put("description", "update 2");
+        Map<String, List<Map<String, Object>>> payloadUpdate2 =
+                Collections.singletonMap(prefType, Collections.singletonList(updatePreference));
+        getRestTestHelper().submitRequest(rootUrl, "POST", payloadUpdate2, HttpServletResponse.SC_OK);
+
+        rereadPrefDetails = getRestTestHelper().getJsonAsMap(fullUrl);
+
+        assertEquals("Unexpected description on updated pref, update 2",
+                     "update 2",
+                     rereadPrefDetails.get("description"));
     }
 
-    private Map<String, Object> findUser(String userName, List<Map<String, Object>> users)
+    public void testDelete() throws Exception
     {
-        for (Map<String, Object> map : users)
+        final String prefName = "mypref";
+        final String prefDescription = "mydesc";
+        final String prefType = "X-testtype";
+
+        Map<String, Object> prefAttributes = new HashMap<>();
+        prefAttributes.put("description", prefDescription);
+        prefAttributes.put("value", Collections.emptyMap());
+        String fullUrl = String.format("broker/userpreferences/%s/%s", prefType, prefName);
+        getRestTestHelper().submitRequest(fullUrl, "PUT", prefAttributes, HttpServletResponse.SC_CREATED);
+
+        getRestTestHelper().getJsonAsMap(fullUrl);
+
+        getRestTestHelper().submitRequest(fullUrl, "DELETE", HttpServletResponse.SC_OK);
+
+        try
         {
-            if (userName.equals(map.get(User.NAME)))
-            {
-                return map;
-            }
+            getRestTestHelper().getJsonAsMap(fullUrl);
+            fail();
+        }
+        catch (Exception e)
+        {
+            // pass
         }
-        return null;
     }
-
 }

Copied: qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/acl/LegacyUserPreferencesRestACLTest.java (from r1748723, qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/acl/UserPreferencesRestACLTest.java)
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/acl/LegacyUserPreferencesRestACLTest.java?p2=qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/acl/LegacyUserPreferencesRestACLTest.java&p1=qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/acl/UserPreferencesRestACLTest.java&r1=1748723&r2=1748729&rev=1748729&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/acl/UserPreferencesRestACLTest.java (original)
+++ qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/acl/LegacyUserPreferencesRestACLTest.java Thu Jun 16 14:00:23 2016
@@ -34,7 +34,7 @@ import org.apache.qpid.systest.rest.Qpid
 import org.apache.qpid.test.utils.TestBrokerConfiguration;
 import org.apache.qpid.test.utils.TestFileUtils;
 
-public class UserPreferencesRestACLTest extends QpidRestTestCase
+public class LegacyUserPreferencesRestACLTest extends QpidRestTestCase
 {
 
     private static final String REST_USER_PREFERENCES_BASE_URL = "/service/userpreferences";



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org