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/07/08 15:52:31 UTC
svn commit: r1751929 [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/adapter/
broker-core/src/main/java/org/apache/qpid/server/model/preferences/
broker-core/sr...
Modified: 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=1751929&r1=1751928&r2=1751929&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandler.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandler.java Fri Jul 8 15:52:31 2016
@@ -36,7 +36,9 @@ import javax.security.auth.Subject;
import com.google.common.base.Joiner;
+import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.preferences.Preference;
+import org.apache.qpid.server.model.preferences.PreferenceFactory;
import org.apache.qpid.server.model.preferences.UserPreferences;
public class RestUserPreferenceHandler
@@ -97,8 +99,9 @@ public class RestUserPreferenceHandler
}
}
- ActionTaken handlePUT(UserPreferences userPreferences, RequestInfo requestInfo, Object providedObject)
+ ActionTaken handlePUT(ConfiguredObject<?> target, RequestInfo requestInfo, Object providedObject)
{
+ UserPreferences userPreferences = target.getUserPreferences();
final List<String> preferencesParts = requestInfo.getPreferencesParts();
if (!(providedObject instanceof Map))
@@ -115,19 +118,13 @@ public class RestUserPreferenceHandler
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);
+ Preference preference = PreferenceFactory.create(target, providedAttributes);
- final Preference newPref = userPreferences.createPreference(providedUuid,
- type,
- name,
- providedDescription,
- visibilityList,
- providedValueAttributes);
- userPreferences.updateOrAppend(Collections.singleton(newPref));
+ ensureValidVisibilityList(preference.getVisibilityList());
+
+ userPreferences.updateOrAppend(Collections.singleton(preference));
return providedUuid == null ? ActionTaken.CREATED : ActionTaken.UPDATED;
}
@@ -138,8 +135,9 @@ public class RestUserPreferenceHandler
}
}
- void handlePOST(UserPreferences userPreferences, RequestInfo requestInfo, Object providedObject)
+ void handlePOST(ConfiguredObject<?> target, RequestInfo requestInfo, Object providedObject)
{
+ UserPreferences userPreferences = target.getUserPreferences();
final List<String> preferencesParts = requestInfo.getPreferencesParts();
if (preferencesParts.size() == 1)
@@ -162,18 +160,10 @@ public class RestUserPreferenceHandler
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);
+ Preference preference = PreferenceFactory.create(target, preferenceAttributes);
+
+ ensureValidVisibilityList(preference.getVisibilityList());
+
preferences.add(preference);
}
@@ -208,18 +198,10 @@ public class RestUserPreferenceHandler
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);
+ Preference preference = PreferenceFactory.create(target, preferenceAttributes);
+
+ ensureValidVisibilityList(preference.getVisibilityList());
+
preferences.add(preference);
}
}
@@ -342,7 +324,6 @@ public class RestUserPreferenceHandler
private String getIdFromQueryParameters(final Map<String, List<String>> queryParameters)
{
- final String id;
List<String> ids = queryParameters.get("id");
if (ids != null && ids.size() > 1)
{
@@ -351,35 +332,6 @@ public class RestUserPreferenceHandler
return (ids == null ? null : ids.get(0));
}
- 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");
@@ -393,55 +345,29 @@ public class RestUserPreferenceHandler
}
}
- private Set<Principal> getProvidedVisibilityList(final Map<String, Object> providedAttributes)
+ private void ensureValidVisibilityList(final Collection<Principal> visibilityList)
{
- 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());
+ HashSet<String> principalNames = new HashSet<>(currentSubject.getPrincipals().size());
for (Principal principal : currentSubject.getPrincipals())
{
- principalNameMap.put(principal.getName(), principal);
+ principalNames.add(principal.getName());
}
- Collection visibilityList = (Collection) visibilityListObject;
- Set<Principal> principals = new HashSet<>(visibilityList.size());
-
- for (Object visibilityObject : visibilityList)
+ for (Principal visibilityPrincipal : 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)
+ if (!principalNames.contains(visibilityPrincipal.getName()))
{
String errorMessage = String.format("Invalid visibilityList, this user does not hold principal '%s'",
- visibilityObject);
+ visibilityPrincipal);
throw new IllegalArgumentException(errorMessage);
}
- principals.add(principal);
}
- return principals;
}
private void ensureAttributeMatches(final Map<String, Object> preferenceAttributes,
@@ -449,14 +375,21 @@ public class RestUserPreferenceHandler
final String expectedValue)
{
final Object providedValue = preferenceAttributes.get(attributeName);
- if (providedValue != null && !Objects.equals(providedValue, expectedValue))
+ if (providedValue != null)
+ {
+ if (!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);
+ }
+ }
+ else
{
- 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);
+ preferenceAttributes.put(attributeName, expectedValue);
}
}
Modified: 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=1751929&r1=1751928&r2=1751929&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandlerTest.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandlerTest.java Fri Jul 8 15:52:31 2016
@@ -19,7 +19,9 @@
package org.apache.qpid.server.management.plugin.servlet.rest;
import static org.apache.qpid.server.management.plugin.servlet.rest.RestUserPreferenceHandler.ActionTaken;
+import static org.apache.qpid.server.model.preferences.PreferenceTestHelper.createPreferenceAttributes;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.security.Principal;
import java.security.PrivilegedAction;
@@ -38,6 +40,7 @@ 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.PreferenceFactory;
import org.apache.qpid.server.model.preferences.UserPreferences;
import org.apache.qpid.server.model.preferences.UserPreferencesImpl;
import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
@@ -65,15 +68,14 @@ public class RestUserPreferenceHandlerTe
super.setUp();
_configuredObject = mock(ConfiguredObject.class);
_preferenceStore = mock(PreferenceStore.class);
- _userPreferences = new UserPreferencesImpl(_configuredObject,
- new HashMap<UUID, Preference>(),
- new HashMap<String, List<Preference>>(),
- _preferenceStore);
+ _userPreferences =
+ new UserPreferencesImpl(_preferenceStore, Collections.<Preference>emptyList());
_groupPrincipal = new GroupPrincipal(MYGROUP);
_subject = new Subject(true,
Sets.newHashSet(new AuthenticatedPrincipal(MYUSER), _groupPrincipal),
Collections.emptySet(),
Collections.emptySet());
+ when(_configuredObject.getUserPreferences()).thenReturn(_userPreferences);
}
public void testPutWithVisibilityList_ValidGroup() throws Exception
@@ -93,7 +95,7 @@ public class RestUserPreferenceHandlerTe
public Void run()
{
final ActionTaken action =
- _handler.handlePUT(_userPreferences, requestInfo, pref);
+ _handler.handlePUT(_configuredObject, requestInfo, pref);
assertEquals(ActionTaken.CREATED, action);
assertEquals("Unexpected number of preferences", 1, _userPreferences.getPreferences().size());
@@ -126,7 +128,7 @@ public class RestUserPreferenceHandlerTe
{
try
{
- _handler.handlePUT(_userPreferences, requestInfo, pref);
+ _handler.handlePUT(_configuredObject, requestInfo, pref);
fail("Expected exception not thrown");
}
catch (IllegalArgumentException e)
@@ -154,7 +156,7 @@ public class RestUserPreferenceHandlerTe
@Override
public Void run()
{
- _handler.handlePOST(_userPreferences, typeRequestInfo, Collections.singletonList(pref));
+ _handler.handlePOST(_configuredObject, typeRequestInfo, Collections.singletonList(pref));
assertEquals("Unexpected number of preferences", 1, _userPreferences.getPreferences().size());
Preference prefModel = _userPreferences.getPreferences().iterator().next();
@@ -184,7 +186,7 @@ public class RestUserPreferenceHandlerTe
{
final Map<String, List<Map<String, Object>>> payload =
Collections.singletonMap("X-testtype2", Collections.singletonList(pref));
- _handler.handlePOST(_userPreferences, rootRequestInfo, payload);
+ _handler.handlePOST(_configuredObject, rootRequestInfo, payload);
assertEquals("Unexpected number of preferences", 1, _userPreferences.getPreferences().size());
Preference prefModel = _userPreferences.getPreferences().iterator().next();
@@ -217,7 +219,7 @@ public class RestUserPreferenceHandlerTe
{
try
{
- _handler.handlePOST(_userPreferences, requestInfo, Collections.singletonList(pref));
+ _handler.handlePOST(_configuredObject, requestInfo, Collections.singletonList(pref));
fail("Expected exception not thrown");
}
catch (IllegalArgumentException e)
@@ -249,7 +251,7 @@ public class RestUserPreferenceHandlerTe
{
final Map<String, List<Map<String, Object>>> payload =
Collections.singletonMap("X-testType", Collections.singletonList(pref));
- _handler.handlePOST(_userPreferences, requestInfo, payload);
+ _handler.handlePOST(_configuredObject, requestInfo, payload);
fail("Expected exception not thrown");
}
catch (IllegalArgumentException e)
@@ -273,13 +275,16 @@ public class RestUserPreferenceHandlerTe
@Override
public Void run()
{
- Preference preference = _userPreferences.createPreference(null,
- type,
- "testpref",
- null,
- Collections.<Principal>singleton(
- _groupPrincipal),
- Collections.<String, Object>emptyMap());
+ Map<String, Object> prefAttributes = createPreferenceAttributes(
+ null,
+ null,
+ type,
+ "testpref",
+ null,
+ MYUSER,
+ Collections.singleton(_groupPrincipal.getName()),
+ Collections.<String, Object>emptyMap());
+ Preference preference = PreferenceFactory.create(_configuredObject, prefAttributes);
_userPreferences.updateOrAppend(Collections.singleton(preference));
Map<String, List<Map<String, Object>>> typeToPreferenceListMap =
@@ -307,24 +312,34 @@ public class RestUserPreferenceHandlerTe
public Void run()
{
final String type = "X-testtype";
- Preference p1 = _userPreferences.createPreference(null,
- type,
- "testpref",
- null,
- null,
- Collections.<String, Object>emptyMap());
- Preference p2 = _userPreferences.createPreference(null,
- type,
- "testpref2",
- null,
- null,
- Collections.<String, Object>emptyMap());
+ Map<String, Object> pref1Attributes = createPreferenceAttributes(
+ null,
+ null,
+ type,
+ "testpref",
+ null,
+ MYUSER,
+ null,
+ Collections.<String, Object>emptyMap());
+ Preference p1 = PreferenceFactory.create(_configuredObject, pref1Attributes);
+ Map<String, Object> pref2Attributes = createPreferenceAttributes(
+ null,
+ null,
+ type,
+ "testpref2",
+ null,
+ MYUSER,
+ null,
+ Collections.<String, Object>emptyMap());
+ Preference p2 = PreferenceFactory.create(_configuredObject, pref2Attributes);
_userPreferences.updateOrAppend(Arrays.asList(p1, p2));
UUID id = p1.getId();
- final RequestInfo rootRequestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
- Collections.<String>emptyList(),
- Collections.singletonMap("id", Collections.singletonList(id.toString())));
+ final RequestInfo rootRequestInfo =
+ RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+ Collections.<String>emptyList(),
+ Collections.singletonMap("id",
+ Collections.singletonList(id.toString())));
Map<String, List<Map<String, Object>>> typeToPreferenceListMap =
(Map<String, List<Map<String, Object>>>) _handler.handleGET(_userPreferences, rootRequestInfo);
@@ -349,24 +364,34 @@ public class RestUserPreferenceHandlerTe
public Void run()
{
final String type = "X-testtype";
- Preference p1 = _userPreferences.createPreference(null,
- type,
- "testpref",
- null,
- null,
- Collections.<String, Object>emptyMap());
- Preference p2 = _userPreferences.createPreference(null,
- type,
- "testpref2",
- null,
- null,
- Collections.<String, Object>emptyMap());
+ Map<String, Object> pref1Attributes = createPreferenceAttributes(
+ null,
+ null,
+ type,
+ "testpref",
+ null,
+ MYUSER,
+ null,
+ Collections.<String, Object>emptyMap());
+ Preference p1 = PreferenceFactory.create(_configuredObject, pref1Attributes);
+ Map<String, Object> pref2Attributes = createPreferenceAttributes(
+ null,
+ null,
+ type,
+ "testpref2",
+ null,
+ MYUSER,
+ null,
+ Collections.<String, Object>emptyMap());
+ Preference p2 = PreferenceFactory.create(_configuredObject, pref2Attributes);
_userPreferences.updateOrAppend(Arrays.asList(p1, p2));
UUID id = p1.getId();
- final RequestInfo rootRequestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
- Collections.<String>emptyList(),
- Collections.singletonMap("id", Collections.singletonList(id.toString())));
+ final RequestInfo rootRequestInfo =
+ RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
+ Collections.<String>emptyList(),
+ Collections.singletonMap("id",
+ Collections.singletonList(id.toString())));
_handler.handleDELETE(_userPreferences, rootRequestInfo);
@@ -423,9 +448,10 @@ public class RestUserPreferenceHandlerTe
{
final String prefName = "testpref";
final String prefType = "X-testtype";
- final RequestInfo rootRequestInfo = RequestInfo.createVisiblePreferencesRequestInfo(Collections.<String>emptyList(),
- Collections.<String>emptyList(),
- Collections.<String, List<String>>emptyMap());
+ final RequestInfo rootRequestInfo =
+ RequestInfo.createVisiblePreferencesRequestInfo(Collections.<String>emptyList(),
+ Collections.<String>emptyList(),
+ Collections.<String, List<String>>emptyMap());
Subject.doAs(_subject, new PrivilegedAction<Void>()
{
@@ -433,20 +459,27 @@ public class RestUserPreferenceHandlerTe
public Void run()
{
final Set<Preference> preferences = new HashSet<>();
- Preference p1 = _userPreferences.createPreference(null,
- prefType,
- prefName,
- null,
- Collections.<Principal>singleton(
- _groupPrincipal),
- Collections.<String, Object>emptyMap());
+ Map<String, Object> pref1Attributes = createPreferenceAttributes(
+ null,
+ null,
+ prefType,
+ prefName,
+ null,
+ MYUSER,
+ Collections.singleton(_groupPrincipal.getName()),
+ Collections.<String, Object>emptyMap());
+ Preference p1 = PreferenceFactory.create(_configuredObject, pref1Attributes);
preferences.add(p1);
- Preference p2 = _userPreferences.createPreference(null,
- prefType,
- "testPref2",
- null,
- Collections.<Principal>emptySet(),
- Collections.<String, Object>emptyMap());
+ Map<String, Object> pref2Attributes = createPreferenceAttributes(
+ null,
+ null,
+ prefType,
+ "testPref2",
+ null,
+ MYUSER,
+ Collections.<String>emptySet(),
+ Collections.<String, Object>emptyMap());
+ Preference p2 = PreferenceFactory.create(_configuredObject, pref2Attributes);
preferences.add(p2);
_userPreferences.updateOrAppend(preferences);
return null;
@@ -468,7 +501,9 @@ public class RestUserPreferenceHandlerTe
typeToPreferenceListMap.keySet().iterator().next());
List<Map<String, Object>> preferences = typeToPreferenceListMap.get(prefType);
assertEquals("Unexpected number of preferences", 1, preferences.size());
- assertEquals("Unexpected name of preferences", prefName, preferences.get(0).get(Preference.NAME_ATTRIBUTE));
+ assertEquals("Unexpected name of preferences",
+ prefName,
+ preferences.get(0).get(Preference.NAME_ATTRIBUTE));
Set<String> visibilityList = (Set<String>) preferences.get(0).get(Preference.VISIBILITY_LIST_ATTRIBUTE);
assertEquals("Unexpected number of principals in visibility list", 1, visibilityList.size());
assertEquals("Unexpected principal in visibility list", MYGROUP, visibilityList.iterator().next());
@@ -483,9 +518,10 @@ public class RestUserPreferenceHandlerTe
{
final String prefName = "testpref";
final String prefType = "X-testtype";
- final RequestInfo rootRequestInfo = RequestInfo.createVisiblePreferencesRequestInfo(Collections.<String>emptyList(),
- Arrays.asList(prefType),
- Collections.<String, List<String>>emptyMap());
+ final RequestInfo rootRequestInfo =
+ RequestInfo.createVisiblePreferencesRequestInfo(Collections.<String>emptyList(),
+ Arrays.asList(prefType),
+ Collections.<String, List<String>>emptyMap());
Subject.doAs(_subject, new PrivilegedAction<Void>()
{
@@ -493,20 +529,27 @@ public class RestUserPreferenceHandlerTe
public Void run()
{
final Set<Preference> preferences = new HashSet<>();
- Preference p1 = _userPreferences.createPreference(null,
- prefType,
- prefName,
- null,
- Collections.<Principal>singleton(
- _groupPrincipal),
- Collections.<String, Object>emptyMap());
+ Map<String, Object> pref1Attributes = createPreferenceAttributes(
+ null,
+ null,
+ prefType,
+ prefName,
+ null,
+ MYUSER,
+ Collections.singleton(_groupPrincipal.getName()),
+ Collections.<String, Object>emptyMap());
+ Preference p1 = PreferenceFactory.create(_configuredObject, pref1Attributes);
preferences.add(p1);
- Preference p2 = _userPreferences.createPreference(null,
- prefType,
- "testPref2",
- null,
- Collections.<Principal>emptySet(),
- Collections.<String, Object>emptyMap());
+ Map<String, Object> pref2Attributes = createPreferenceAttributes(
+ null,
+ null,
+ prefType,
+ "testPref2",
+ null,
+ MYUSER,
+ Collections.<String>emptySet(),
+ Collections.<String, Object>emptyMap());
+ Preference p2 = PreferenceFactory.create(_configuredObject, pref2Attributes);
preferences.add(p2);
_userPreferences.updateOrAppend(preferences);
return null;
@@ -523,7 +566,9 @@ public class RestUserPreferenceHandlerTe
List<Map<String, Object>> preferences =
(List<Map<String, Object>>) _handler.handleGET(_userPreferences, rootRequestInfo);
assertEquals("Unexpected number of preferences", 1, preferences.size());
- assertEquals("Unexpected name of preferences", prefName, preferences.get(0).get(Preference.NAME_ATTRIBUTE));
+ assertEquals("Unexpected name of preferences",
+ prefName,
+ preferences.get(0).get(Preference.NAME_ATTRIBUTE));
Set<String> visibilityList = (Set<String>) preferences.get(0).get(Preference.VISIBILITY_LIST_ATTRIBUTE);
assertEquals("Unexpected number of principals in visibility list", 1, visibilityList.size());
assertEquals("Unexpected principal in visibility list", MYGROUP, visibilityList.iterator().next());
@@ -538,9 +583,10 @@ public class RestUserPreferenceHandlerTe
{
final String prefName = "testpref";
final String prefType = "X-testtype";
- final RequestInfo rootRequestInfo = RequestInfo.createVisiblePreferencesRequestInfo(Collections.<String>emptyList(),
- Arrays.asList(prefType, prefName),
- Collections.<String, List<String>>emptyMap());
+ final RequestInfo rootRequestInfo =
+ RequestInfo.createVisiblePreferencesRequestInfo(Collections.<String>emptyList(),
+ Arrays.asList(prefType, prefName),
+ Collections.<String, List<String>>emptyMap());
Subject.doAs(_subject, new PrivilegedAction<Void>()
{
@@ -548,20 +594,27 @@ public class RestUserPreferenceHandlerTe
public Void run()
{
final Set<Preference> preferences = new HashSet<>();
- Preference p1 = _userPreferences.createPreference(null,
- prefType,
- prefName,
- null,
- Collections.<Principal>singleton(
- _groupPrincipal),
- Collections.<String, Object>emptyMap());
+ Map<String, Object> pref1Attributes = createPreferenceAttributes(
+ null,
+ null,
+ prefType,
+ prefName,
+ null,
+ MYUSER,
+ Collections.singleton(_groupPrincipal.getName()),
+ Collections.<String, Object>emptyMap());
+ Preference p1 = PreferenceFactory.create(_configuredObject, pref1Attributes);
preferences.add(p1);
- Preference p2 = _userPreferences.createPreference(null,
- prefType,
- "testPref2",
- null,
- Collections.<Principal>emptySet(),
- Collections.<String, Object>emptyMap());
+ Map<String, Object> pref2Attributes = createPreferenceAttributes(
+ null,
+ null,
+ prefType,
+ "testPref2",
+ null,
+ MYUSER,
+ Collections.<String>emptySet(),
+ Collections.<String, Object>emptyMap());
+ Preference p2 = PreferenceFactory.create(_configuredObject, pref2Attributes);
preferences.add(p2);
_userPreferences.updateOrAppend(preferences);
return null;
@@ -595,12 +648,17 @@ public class RestUserPreferenceHandlerTe
@Override
public Void run()
{
- Preference preference = _userPreferences.createPreference(null,
- preferenceType,
- preferenceName,
- null,
- null,
- Collections.<String, Object>emptyMap());
+ Map<String, Object> preferenceAttributes = createPreferenceAttributes(
+ null,
+ null,
+ preferenceType,
+ preferenceName,
+ null,
+ MYUSER,
+ null,
+ Collections.<String, Object>emptyMap());
+ Preference preference = PreferenceFactory.create(_configuredObject,
+ preferenceAttributes);
_userPreferences.updateOrAppend(Collections.singleton(preference));
Set<Preference> retrievedPreferences = _userPreferences.getPreferences();
assertEquals("adding pref failed", 1, retrievedPreferences.size());
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org