use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testProhibitDuplicateId.
@Test
public void testProhibitDuplicateId() throws Exception {
final String prefType = "X-testType";
final String prefName = "prop1";
final Preference testUserPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, prefType, prefName, null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(_testSubject, testUserPreference);
Subject user2Subject = TestPrincipalUtils.createTestSubject(TEST_USERNAME2);
final Preference testUserPreference2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, testUserPreference.getId(), prefType, prefName, "new preference", TEST_PRINCIPAL2_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
try {
updateOrAppendAs(user2Subject, testUserPreference2);
fail("duplicate id should be prohibited");
} catch (IllegalArgumentException e) {
// pass
}
try {
Subject.doAs(user2Subject, new PrivilegedAction<Void>() {
@Override
public Void run() {
awaitPreferenceFuture(_testObject.getUserPreferences().replace(Arrays.asList(testUserPreference2)));
return null;
}
});
fail("duplicate id should be prohibited");
} catch (IllegalArgumentException e) {
// pass
}
try {
Subject.doAs(user2Subject, new PrivilegedAction<Void>() {
@Override
public Void run() {
awaitPreferenceFuture(_testObject.getUserPreferences().replaceByType(testUserPreference.getType(), Arrays.asList(testUserPreference2)));
return null;
}
});
fail("duplicate id should be prohibited");
} catch (IllegalArgumentException e) {
// pass
}
try {
Subject.doAs(user2Subject, new PrivilegedAction<Void>() {
@Override
public Void run() {
awaitPreferenceFuture(_testObject.getUserPreferences().replaceByTypeAndName(testUserPreference.getType(), testUserPreference.getName(), testUserPreference2));
return null;
}
});
fail("duplicate id should be prohibited");
} catch (IllegalArgumentException e) {
// pass
}
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method setUp.
@Before
public void setUp() throws Exception {
final String objectName = getTestName();
_testObject = _model.getObjectFactory().create(TestSingleton.class, Collections.<String, Object>singletonMap(ConfiguredObject.NAME, objectName), null);
_preferenceTaskExecutor = new CurrentThreadTaskExecutor();
_preferenceTaskExecutor.start();
PreferenceStore preferenceStore = mock(PreferenceStore.class);
_testObject.setUserPreferences(new UserPreferencesImpl(_preferenceTaskExecutor, _testObject, preferenceStore, Collections.<Preference>emptySet()));
_testSubject = TestPrincipalUtils.createTestSubject(TEST_USERNAME);
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testDeleteByTypeAndName.
@Test
public void testDeleteByTypeAndName() 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, null));
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 testDeleteById.
@Test
public void testDeleteById() 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()));
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, "propName", 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(null, null, 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 testOverrideContradictingOwner.
@Test
public void testOverrideContradictingOwner() {
Subject testSubject2 = TestPrincipalUtils.createTestSubject(TEST_USERNAME2);
final Preference p = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "prop1", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
updateOrAppendAs(testSubject2, p);
assertPreferences(testSubject2, p);
assertPreferences(_testSubject);
}
Aggregations