use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class RestUserPreferenceHandlerTest method testGetVisiblePreferencesByType.
@Test
public void testGetVisiblePreferencesByType() throws Exception {
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());
Subject.doAs(_subject, new PrivilegedAction<Void>() {
@Override
public Void run() {
final Set<Preference> preferences = new HashSet<>();
Map<String, Object> pref1Attributes = createPreferenceAttributes(null, null, prefType, prefName, null, MYUSER_SERIALIZATION, Collections.singleton(MYGROUP_SERIALIZATION), Collections.<String, Object>emptyMap());
Preference p1 = PreferenceFactory.fromAttributes(_configuredObject, pref1Attributes);
preferences.add(p1);
Map<String, Object> pref2Attributes = createPreferenceAttributes(null, null, prefType, "testPref2", null, MYUSER_SERIALIZATION, Collections.<String>emptySet(), Collections.<String, Object>emptyMap());
Preference p2 = PreferenceFactory.fromAttributes(_configuredObject, pref2Attributes);
preferences.add(p2);
awaitPreferenceFuture(_userPreferences.updateOrAppend(preferences));
return null;
}
});
Subject testSubject2 = TestPrincipalUtils.createTestSubject("testUser2", MYGROUP);
Subject.doAs(testSubject2, new PrivilegedAction<Void>() {
@Override
public Void run() {
List<Map<String, Object>> preferences = (List<Map<String, Object>>) _handler.handleGET(_userPreferences, rootRequestInfo);
assertEquals("Unexpected number of preferences", (long) 1, (long) preferences.size());
assertEquals("Unexpected name of preferences", prefName, preferences.get(0).get(Preference.NAME_ATTRIBUTE));
Set<Principal> visibilityList = (Set<Principal>) preferences.get(0).get(Preference.VISIBILITY_LIST_ATTRIBUTE);
assertEquals("Unexpected number of principals in visibility list", (long) 1, (long) visibilityList.size());
assertTrue("Unexpected principal in visibility list", GenericPrincipal.principalsEqual(_groupPrincipal, visibilityList.iterator().next()));
assertTrue("Unexpected owner", GenericPrincipal.principalsEqual(_userPrincipal, (Principal) preferences.get(0).get(Preference.OWNER_ATTRIBUTE)));
return null;
}
});
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class RestUserPreferenceHandlerTest method testReplaceViaPutByTypeAndName.
@Test
public void testReplaceViaPutByTypeAndName() throws Exception {
final String prefName = "myprefname";
final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(), Arrays.asList("X-testtype", prefName));
final Map<String, Object> pref = new HashMap<>();
pref.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
final Preference createdPreference = Subject.doAs(_subject, new PrivilegedAction<Preference>() {
@Override
public Preference run() {
_handler.handlePUT(_configuredObject, requestInfo, pref);
Set<Preference> preferences = awaitPreferenceFuture(_userPreferences.getPreferences());
assertEquals("Unexpected number of preferences", (long) 1, (long) preferences.size());
Preference prefModel = preferences.iterator().next();
assertEquals("Unexpected preference name", prefName, prefModel.getName());
return prefModel;
}
});
final Map<String, Object> replacementPref = new HashMap<>();
replacementPref.put(Preference.ID_ATTRIBUTE, createdPreference.getId().toString());
replacementPref.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
final String changedDescription = "Replace that maintains id";
replacementPref.put(Preference.DESCRIPTION_ATTRIBUTE, changedDescription);
Subject.doAs(_subject, new PrivilegedAction<Void>() {
@Override
public Void run() {
_handler.handlePUT(_configuredObject, requestInfo, replacementPref);
Set<Preference> preferences = awaitPreferenceFuture(_userPreferences.getPreferences());
assertEquals("Unexpected number of preferences after update", (long) 1, (long) preferences.size());
Preference updatedPref = preferences.iterator().next();
assertEquals("Unexpected preference id", createdPreference.getId(), updatedPref.getId());
assertEquals("Unexpected preference name", prefName, updatedPref.getName());
assertEquals("Unexpected preference description", changedDescription, updatedPref.getDescription());
return null;
}
});
replacementPref.remove(Preference.ID_ATTRIBUTE);
final String changedDescription2 = "Replace that omits id";
replacementPref.put(Preference.DESCRIPTION_ATTRIBUTE, changedDescription2);
Subject.doAs(_subject, new PrivilegedAction<Void>() {
@Override
public Void run() {
_handler.handlePUT(_configuredObject, requestInfo, replacementPref);
Set<Preference> preferences = awaitPreferenceFuture(_userPreferences.getPreferences());
assertEquals("Unexpected number of preferences after update", (long) 1, (long) preferences.size());
Preference updatedPref = preferences.iterator().next();
assertFalse("Replace without id should create new id", createdPreference.getId().equals(updatedPref.getId()));
assertEquals("Unexpected preference name", prefName, updatedPref.getName());
assertEquals("Unexpected preference description", changedDescription2, updatedPref.getDescription());
return null;
}
});
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testSimpleRoundTrip.
@Test
public void testSimpleRoundTrip() {
final Preference p = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-TestPropType", "testProp1", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(_testSubject, p);
assertPreferences(_testSubject, p);
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testUpdate.
@Test
public void testUpdate() {
final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
final Preference p2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, p1.getId(), "X-testType", "newPropName", "newDescription", TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(_testSubject, p1);
updateOrAppendAs(_testSubject, p2);
assertPreferences(_testSubject, p2);
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testReplaceByTypeAndName.
@Test
public void testReplaceByTypeAndName() {
final String replaceType = "X-replaceType";
final String unaffectedType = "X-unaffectedType";
Subject testSubject2 = TestPrincipalUtils.createTestSubject(TEST_USERNAME2);
final Preference unaffectedPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, replaceType, "propName", null, TEST_PRINCIPAL2_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(testSubject2, unaffectedPreference);
final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, replaceType, "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
final Preference p1b = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, replaceType, "unaffectedPropName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
final Preference p2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, unaffectedType, "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
final Preference p3 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, replaceType, "propName", "new description", TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(_testSubject, p1, p1b, p2);
Subject.doAs(_testSubject, new PrivilegedAction<Void>() {
@Override
public Void run() {
awaitPreferenceFuture(_testObject.getUserPreferences().replaceByTypeAndName(replaceType, "propName", p3));
return null;
}
});
assertPreferences(_testSubject, p1b, p2, p3);
assertPreferences(testSubject2, unaffectedPreference);
}
Aggregations