Search in sources :

Example 6 with Preference

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
    }
}
Also used : Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 7 with Preference

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));
}
Also used : Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Date(java.util.Date) Test(org.junit.Test)

Example 8 with Preference

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));
}
Also used : Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Date(java.util.Date) Test(org.junit.Test)

Example 9 with Preference

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);
}
Also used : Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 10 with Preference

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
    }
}
Also used : Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Aggregations

Preference (org.apache.qpid.server.model.preferences.Preference)40 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)39 Test (org.junit.Test)31 Subject (javax.security.auth.Subject)16 HashMap (java.util.HashMap)11 Map (java.util.Map)9 Set (java.util.Set)9 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)5 Date (java.util.Date)4 GroupPrincipal (org.apache.qpid.server.security.group.GroupPrincipal)4 Principal (java.security.Principal)3 UUID (java.util.UUID)3 GenericPrincipal (org.apache.qpid.server.model.preferences.GenericPrincipal)3 UserPreferencesImpl (org.apache.qpid.server.model.preferences.UserPreferencesImpl)3 LinkedHashSet (java.util.LinkedHashSet)2 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)2 UserPreferences (org.apache.qpid.server.model.preferences.UserPreferences)2