use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testProhibitDuplicateNamesOfSameTypeInSameUpdate.
@Test
public void testProhibitDuplicateNamesOfSameTypeInSameUpdate() {
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, null, "X-testType", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
try {
updateOrAppendAs(_testSubject, p1, 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 testLastUpdatedDate.
@Test
public void testLastUpdatedDate() throws Exception {
Date beforeUpdate = new Date();
Thread.sleep(1);
final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName1", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
Thread.sleep(1);
Date afterUpdate = new Date();
Date lastUpdatedDate = p1.getLastUpdatedDate();
assertTrue(String.format("LastUpdated date is too early. Expected : after %s Found : %s", beforeUpdate, lastUpdatedDate), beforeUpdate.before(lastUpdatedDate));
assertTrue(String.format("LastUpdated date is too late. Expected : before %s Found : %s", afterUpdate, lastUpdatedDate), afterUpdate.after(lastUpdatedDate));
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testCreatedDate.
@Test
public void testCreatedDate() throws Exception {
Date beforeCreation = new Date();
Thread.sleep(1);
final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName1", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
Thread.sleep(1);
Date afterCreation = new Date();
Date createdDate = p1.getCreatedDate();
assertTrue(String.format("Creation date is too early. Expected : after %s Found : %s", beforeCreation, createdDate), beforeCreation.before(createdDate));
assertTrue(String.format("Creation date is too late. Expected : before %s Found : %s", afterCreation, createdDate), afterCreation.after(createdDate));
}
use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.
the class PreferencesTest method testReplace.
@Test
public void testReplace() {
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);
final Preference p2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, preferenceType, "newPropName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
Subject.doAs(_testSubject, new PrivilegedAction<Void>() {
@Override
public Void run() {
awaitPreferenceFuture(_testObject.getUserPreferences().replace(Collections.singleton(p2)));
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 testProhibitTypeChange.
@Test
public void testProhibitTypeChange() {
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, p1.getId(), "X-differentTestType", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
try {
updateOrAppendAs(_testSubject, p2);
fail("Type change should not be allowed");
} catch (IllegalArgumentException e) {
// pass
}
}
Aggregations