use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testGetOnlyOwnedPreferences.
@Test
public void testGetOnlyOwnedPreferences() {
final Preference testUserPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "prop1", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(_testSubject, testUserPreference);
final Preference testUser2Preference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "prop2", null, TEST_PRINCIPAL2_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
Subject testSubject2 = TestPrincipalUtils.createTestSubject(TEST_USERNAME2);
updateOrAppendAs(testSubject2, testUser2Preference);
assertPreferences(testSubject2, testUser2Preference);
assertPreferences(_testSubject, testUserPreference);
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testDeleteViaReplace.
@Test
public void testDeleteViaReplace() {
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()));
updateOrAppendAs(_testSubject, p1);
Subject.doAs(_testSubject, new PrivilegedAction<Void>() {
@Override
public Void run() {
awaitPreferenceFuture(_testObject.getUserPreferences().replace(Collections.<Preference>emptySet()));
return null;
}
});
assertPreferences(_testSubject);
assertPreferences(testSubject2, unaffectedPreference);
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testDeleteByTypeAndNameAndId.
@Test
public void testDeleteByTypeAndNameAndId() throws Exception {
final String deleteType = "X-type-1";
final String deletePropertyName = "propName";
final Preference deletePreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, deleteType, deletePropertyName, null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
final Preference unaffectedPreference1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, deleteType, "propName2", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
String unaffectedType = "X-type-2";
final Preference unaffectedPreference2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, unaffectedType, deletePropertyName, null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(_testSubject, deletePreference, unaffectedPreference1, unaffectedPreference2);
Subject.doAs(_testSubject, new PrivilegedAction<Void>() {
@Override
public Void run() {
awaitPreferenceFuture(_testObject.getUserPreferences().delete(deleteType, deletePropertyName, deletePreference.getId()));
return null;
}
});
assertPreferences(_testSubject, unaffectedPreference1, unaffectedPreference2);
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testGetVisiblePreferences.
@Test
public void testGetVisiblePreferences() {
final String testGroupName = "testGroup";
Subject sharer = TestPrincipalUtils.createTestSubject(TEST_USERNAME2, testGroupName);
Subject nonSharer = TestPrincipalUtils.createTestSubject(TEST_USERNAME, testGroupName);
final Preference sharedPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName1", "shared with group", TEST_PRINCIPAL2_SERIALIZATION, Collections.singleton(TestPrincipalUtils.getTestPrincipalSerialization(testGroupName)), Collections.<String, Object>emptyMap()));
final Preference notSharedPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName2", null, TEST_PRINCIPAL2_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(sharer, sharedPreference, notSharedPreference);
final Preference nonSharersPrivatePref = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(nonSharer, nonSharersPrivatePref);
Subject.doAs(nonSharer, new PrivilegedAction<Void>() {
@Override
public Void run() {
Set<Preference> retrievedPreferences = awaitPreferenceFuture(_testObject.getUserPreferences().getVisiblePreferences());
assertEquals("Unexpected number of preferences", (long) 2, (long) retrievedPreferences.size());
Set<UUID> visibleIds = new HashSet<>(retrievedPreferences.size());
for (Preference preference : retrievedPreferences) {
visibleIds.add(preference.getId());
}
assertTrue("Owned preference not visible", visibleIds.contains(nonSharersPrivatePref.getId()));
assertTrue("Shared preference not visible", visibleIds.contains(sharedPreference.getId()));
return null;
}
});
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testDeleteViaReplaceByType.
@Test
public void testDeleteViaReplaceByType() {
final String preferenceType = "X-testType";
final String unaffectedPreferenceType = "X-unaffectedType";
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, unaffectedPreferenceType, "propName", 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().replaceByType(preferenceType, Collections.<Preference>emptySet()));
return null;
}
});
assertPreferences(_testSubject, p2);
assertPreferences(testSubject2, unaffectedPreference);
}
Aggregations