Search in sources :

Example 1 with Preference

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
    }
}
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 2 with Preference

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);
}
Also used : UserPreferencesImpl(org.apache.qpid.server.model.preferences.UserPreferencesImpl) Preference(org.apache.qpid.server.model.preferences.Preference) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore) Before(org.junit.Before)

Example 3 with Preference

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

Example 4 with Preference

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

Example 5 with Preference

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);
}
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)

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