use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testDeleteByType.
@Test
public void testDeleteByType() throws Exception {
final String deleteType = "X-type-1";
final Preference deletePreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, deleteType, "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
String unaffectedType = "X-type-2";
final Preference unaffectedPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, unaffectedType, "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(_testSubject, deletePreference, unaffectedPreference);
Subject.doAs(_testSubject, new PrivilegedAction<Void>() {
@Override
public Void run() {
awaitPreferenceFuture(_testObject.getUserPreferences().delete(deleteType, null, null));
return null;
}
});
assertPreferences(_testSubject, unaffectedPreference);
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testProhibitDuplicateNamesOfSameType.
@Test
public void testProhibitDuplicateNamesOfSameType() {
final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(_testSubject, p1);
final Preference p2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
try {
updateOrAppendAs(_testSubject, p2);
fail("Property with same name and same type should not be allowed");
} catch (IllegalArgumentException e) {
// pass
}
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testDeleteViaReplaceByTypeAndName.
@Test
public void testDeleteViaReplaceByTypeAndName() {
final String preferenceType = "X-testType";
Subject testSubject2 = TestPrincipalUtils.createTestSubject(TEST_USERNAME2);
final Preference unaffectedPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, preferenceType, "propName", null, TEST_PRINCIPAL2_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(testSubject2, unaffectedPreference);
final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, preferenceType, "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
final Preference p2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, preferenceType, "unaffectedPropName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(_testSubject, p1, p2);
Subject.doAs(_testSubject, new PrivilegedAction<Void>() {
@Override
public Void run() {
awaitPreferenceFuture(_testObject.getUserPreferences().replaceByTypeAndName(preferenceType, "propName", null));
return null;
}
});
assertPreferences(_testSubject, p2);
assertPreferences(testSubject2, unaffectedPreference);
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testLastUpdatedDateIsImmutable.
@Test
public void testLastUpdatedDateIsImmutable() throws Exception {
final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName1", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
Date lastUpdatedDate = p1.getLastUpdatedDate();
lastUpdatedDate.setTime(0);
Date lastUpdatedDate2 = p1.getLastUpdatedDate();
assertTrue("Creation date is not immutable.", lastUpdatedDate2.getTime() != 0);
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class RestUserPreferenceHandlerTest method testGetVisiblePreferencesByRoot.
@Test
public void testGetVisiblePreferencesByRoot() throws Exception {
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());
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() {
Map<String, List<Map<String, Object>>> typeToPreferenceListMap = (Map<String, List<Map<String, Object>>>) _handler.handleGET(_userPreferences, rootRequestInfo);
assertEquals("Unexpected preference map size", (long) 1, (long) typeToPreferenceListMap.size());
assertEquals("Unexpected prefType in preference map", prefType, typeToPreferenceListMap.keySet().iterator().next());
List<Map<String, Object>> preferences = typeToPreferenceListMap.get(prefType);
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;
}
});
}
Aggregations