You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2013/02/19 10:35:33 UTC

svn commit: r1447646 [11/16] - in /qpid/trunk/qpid/java: ./ bdbstore/ bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/ bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/ bdbstore/src/main/java/org/apache/qpid/ser...

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java?rev=1447646&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java Tue Feb 19 09:35:28 2013
@@ -0,0 +1,405 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory;
+import org.apache.qpid.server.model.adapter.PortFactory;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class BrokerRecovererTest extends TestCase
+{
+    private BrokerRecoverer _brokerRecoverer;
+    private ConfigurationEntry _brokerEntry = mock(ConfigurationEntry.class);
+
+    private UUID _brokerId = UUID.randomUUID();
+    private Map<String, Collection<ConfigurationEntry>> _brokerEntryChildren = new HashMap<String, Collection<ConfigurationEntry>>();
+    private ConfigurationEntry _authenticationProviderEntry1;
+    private AuthenticationProvider _authenticationProvider1;
+
+    @Override
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        _brokerRecoverer = new BrokerRecoverer(mock(AuthenticationProviderFactory.class), mock(PortFactory.class), mock(StatisticsGatherer.class),
+                mock(VirtualHostRegistry.class), mock(LogRecorder.class), mock(RootMessageLogger.class), mock(TaskExecutor.class));
+        when(_brokerEntry.getId()).thenReturn(_brokerId);
+        when(_brokerEntry.getChildren()).thenReturn(_brokerEntryChildren);
+
+        //Add a base AuthenticationProvider for all tests
+        _authenticationProvider1 = mock(AuthenticationProvider.class);
+        when(_authenticationProvider1.getName()).thenReturn("authenticationProvider1");
+        _authenticationProviderEntry1 = mock(ConfigurationEntry.class);
+        _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1));
+    }
+
+    public void testCreateBrokerAttributes()
+    {
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(Broker.DEFAULT_VIRTUAL_HOST, "test");
+        attributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider1");
+        attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_AGE, 9l);
+        attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_COUNT, 8l);
+        attributes.put(Broker.ALERT_THRESHOLD_QUEUE_DEPTH, 7l);
+        attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_SIZE, 6l);
+        attributes.put(Broker.ALERT_REPEAT_GAP, 5l);
+        attributes.put(Broker.FLOW_CONTROL_SIZE_BYTES, 5l);
+        attributes.put(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES, 3l);
+        attributes.put(Broker.MAXIMUM_DELIVERY_ATTEMPTS, 2);
+        attributes.put(Broker.DEAD_LETTER_QUEUE_ENABLED, true);
+        attributes.put(Broker.HOUSEKEEPING_CHECK_PERIOD, 1l);
+        attributes.put(Broker.ACL_FILE, "/path/to/acl");
+        attributes.put(Broker.SESSION_COUNT_LIMIT, 1000);
+        attributes.put(Broker.HEART_BEAT_DELAY, 2000);
+        attributes.put(Broker.STATISTICS_REPORTING_PERIOD, 4000);
+        attributes.put(Broker.STATISTICS_REPORTING_RESET_ENABLED, true);
+
+        Map<String, Object> entryAttributes = new HashMap<String, Object>();
+        for (Map.Entry<String, Object> attribute : attributes.entrySet())
+        {
+            String value = convertToString(attribute.getValue());
+            entryAttributes.put(attribute.getKey(), value);
+        }
+
+        when(_brokerEntry.getAttributes()).thenReturn(entryAttributes);
+
+        final ConfigurationEntry virtualHostEntry = mock(ConfigurationEntry.class);
+        String typeName = VirtualHost.class.getSimpleName();
+        when(virtualHostEntry.getType()).thenReturn(typeName);
+        _brokerEntryChildren.put(typeName, Arrays.asList(virtualHostEntry));
+        final VirtualHost virtualHost = mock(VirtualHost.class);
+        when(virtualHost.getName()).thenReturn("test");
+
+        RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[] { virtualHostEntry, _authenticationProviderEntry1 },
+                new ConfiguredObject[] { virtualHost, _authenticationProvider1 });
+        Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+        assertNotNull(broker);
+        assertEquals(_brokerId, broker.getId());
+
+        for (Map.Entry<String, Object> attribute : attributes.entrySet())
+        {
+            Object attributeValue = broker.getAttribute(attribute.getKey());
+            assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue);
+        }
+    }
+
+    public void testCreateBrokerWithVirtualHost()
+    {
+        final ConfigurationEntry virtualHostEntry = mock(ConfigurationEntry.class);
+
+        String typeName = VirtualHost.class.getSimpleName();
+        when(virtualHostEntry.getType()).thenReturn(typeName);
+        _brokerEntryChildren.put(typeName, Arrays.asList(virtualHostEntry));
+
+        final VirtualHost virtualHost = mock(VirtualHost.class);
+
+        RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{virtualHostEntry, _authenticationProviderEntry1},
+                                                                     new ConfiguredObject[]{virtualHost, _authenticationProvider1});
+
+        Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+        assertNotNull(broker);
+        assertEquals(_brokerId, broker.getId());
+        assertEquals(1, broker.getVirtualHosts().size());
+        assertEquals(virtualHost, broker.getVirtualHosts().iterator().next());
+    }
+
+    public void testCreateBrokerWithPorts()
+    {
+        ConfigurationEntry portEntry = mock(ConfigurationEntry.class);
+        Port port = mock(Port.class);
+        _brokerEntryChildren.put(Port.class.getSimpleName(), Arrays.asList(portEntry));
+
+        RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{portEntry, _authenticationProviderEntry1},
+                                                                     new ConfiguredObject[]{port, _authenticationProvider1});
+
+        Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+        assertNotNull(broker);
+        assertEquals(_brokerId, broker.getId());
+        assertEquals(Collections.singletonList(port), broker.getPorts());
+    }
+
+    public void testCreateBrokerWithoutAuthenticationProviderThrowsException()
+    {
+        assertNotNull("expected to remove the base entry", _brokerEntryChildren.remove(AuthenticationProvider.class.getSimpleName()));
+        assertTrue("should be empty", _brokerEntryChildren.isEmpty());
+
+        RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[0], new ConfiguredObject[0]);
+
+        try
+        {
+            _brokerRecoverer.create(recovererProvider, _brokerEntry);
+            fail("should have thrown an exception due to missing authentication provider configuration");
+        }
+        catch(IllegalConfigurationException e)
+        {
+            //expected
+        }
+    }
+
+    public void testCreateBrokerWithOneAuthenticationProvider()
+    {
+        RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{_authenticationProviderEntry1},
+                                                                     new ConfiguredObject[]{_authenticationProvider1});
+
+        Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+        assertNotNull(broker);
+        assertEquals(_brokerId, broker.getId());
+        assertEquals(Collections.singletonList(_authenticationProvider1), broker.getAuthenticationProviders());
+    }
+
+    public void testCreateBrokerWithMultipleAuthenticationProvidersAndNoDefaultThrowsException()
+    {
+        AuthenticationProvider authenticationProvider2 = mock(AuthenticationProvider.class);
+        when(authenticationProvider2.getName()).thenReturn("authenticationProvider2");
+        ConfigurationEntry authenticationProviderEntry2 = mock(ConfigurationEntry.class);
+        _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1, authenticationProviderEntry2));
+
+        Map<String,Object> emptyBrokerAttributes = new HashMap<String,Object>();
+        when(_brokerEntry.getAttributes()).thenReturn(emptyBrokerAttributes);
+
+        RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{authenticationProviderEntry2, _authenticationProviderEntry1},
+                                                                     new ConfiguredObject[]{authenticationProvider2, _authenticationProvider1});
+        try
+        {
+            _brokerRecoverer.create(recovererProvider, _brokerEntry);
+            fail("should have thrown an exception due to missing authentication provider default");
+        }
+        catch(IllegalConfigurationException e)
+        {
+            //expected
+        }
+    }
+
+    public void testCreateBrokerWithMultipleAuthenticationProvidersAndPorts()
+    {
+        //Create a second authentication provider
+        AuthenticationProvider authenticationProvider2 = mock(AuthenticationProvider.class);
+        when(authenticationProvider2.getName()).thenReturn("authenticationProvider2");
+        ConfigurationEntry authenticationProviderEntry2 = mock(ConfigurationEntry.class);
+        _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1, authenticationProviderEntry2));
+
+        //Set the default authentication provider
+        Map<String,Object> brokerAtttributes = new HashMap<String,Object>();
+        when(_brokerEntry.getAttributes()).thenReturn(brokerAtttributes);
+        brokerAtttributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider2");
+
+        //Add a couple ports, one with a defined authentication provider and
+        //one without (which should then use the default)
+        ConfigurationEntry portEntry1 = mock(ConfigurationEntry.class);
+        Port port1 = mock(Port.class);
+        when(port1.getName()).thenReturn("port1");
+        when(port1.getPort()).thenReturn(5671);
+        when(port1.getAttribute(Port.AUTHENTICATION_MANAGER)).thenReturn("authenticationProvider1");
+        ConfigurationEntry portEntry2 = mock(ConfigurationEntry.class);
+        Port port2 = mock(Port.class);
+        when(port2.getName()).thenReturn("port2");
+        when(port2.getPort()).thenReturn(5672);
+        _brokerEntryChildren.put(Port.class.getSimpleName(), Arrays.asList(portEntry1, portEntry2));
+
+        RecovererProvider recovererProvider = createRecoveryProvider(
+                new ConfigurationEntry[]{portEntry1, portEntry2, authenticationProviderEntry2, _authenticationProviderEntry1},
+                new ConfiguredObject[]{port1, port2, authenticationProvider2, _authenticationProvider1});
+
+        Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+        assertNotNull(broker);
+        assertEquals("Unexpected number of authentication providers", 2,broker.getAuthenticationProviders().size());
+
+        Collection<Port> ports = broker.getPorts();
+        assertEquals("Unexpected number of ports", 2, ports.size());
+        assertTrue(ports.contains(port1));
+        assertTrue(ports.contains(port2));
+
+        verify(port1).setAuthenticationProvider(any(AuthenticationProvider.class));
+        verify(port1).setAuthenticationProvider(_authenticationProvider1);
+
+        verify(port2).setAuthenticationProvider(any(AuthenticationProvider.class));
+        verify(port2).setAuthenticationProvider(authenticationProvider2);
+    }
+
+    public void testCreateBrokerAssignsGroupAccessorToAuthenticationProviders()
+    {
+        //Create a second authentication provider
+        AuthenticationProvider authenticationProvider2 = mock(AuthenticationProvider.class);
+        when(authenticationProvider2.getName()).thenReturn("authenticationProvider2");
+        ConfigurationEntry authenticationProviderEntry2 = mock(ConfigurationEntry.class);
+        _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1, authenticationProviderEntry2));
+
+        //Set the default authentication provider
+        Map<String,Object> brokerAtttributes = new HashMap<String,Object>();
+        when(_brokerEntry.getAttributes()).thenReturn(brokerAtttributes);
+        brokerAtttributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider2");
+
+        //Create a group provider
+        ConfigurationEntry groupProviderEntry = mock(ConfigurationEntry.class);
+        GroupProvider groupProvider = mock(GroupProvider.class);
+        _brokerEntryChildren.put(GroupProvider.class.getSimpleName(), Arrays.asList(groupProviderEntry));
+
+        RecovererProvider recovererProvider = createRecoveryProvider(
+                new ConfigurationEntry[]{groupProviderEntry, authenticationProviderEntry2, _authenticationProviderEntry1},
+                new ConfiguredObject[]{groupProvider, authenticationProvider2, _authenticationProvider1});
+
+        Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+        assertNotNull(broker);
+        assertEquals("Unexpected number of authentication providers", 2, broker.getAuthenticationProviders().size());
+
+        //verify that a GroupAcessor was added to the AuthenticationProviders
+        verify(_authenticationProvider1).setGroupAccessor(any(GroupPrincipalAccessor.class));
+        verify(authenticationProvider2).setGroupAccessor(any(GroupPrincipalAccessor.class));
+    }
+
+    public void testCreateBrokerWithGroupProvider()
+    {
+        ConfigurationEntry groupProviderEntry = mock(ConfigurationEntry.class);
+        GroupProvider groupProvider = mock(GroupProvider.class);
+        _brokerEntryChildren.put(GroupProvider.class.getSimpleName(), Arrays.asList(groupProviderEntry));
+
+        RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{groupProviderEntry, _authenticationProviderEntry1},
+                                                                     new ConfiguredObject[]{groupProvider, _authenticationProvider1});
+
+        Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+        assertNotNull(broker);
+        assertEquals(_brokerId, broker.getId());
+        assertEquals(Collections.singletonList(groupProvider), broker.getGroupProviders());
+    }
+
+    public void testCreateBrokerWithPlugins()
+    {
+        ConfigurationEntry pluginEntry = mock(ConfigurationEntry.class);
+        Plugin plugin = mock(Plugin.class);
+        _brokerEntryChildren.put(Plugin.class.getSimpleName(), Arrays.asList(pluginEntry));
+
+        RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{pluginEntry, _authenticationProviderEntry1},
+                                                                     new ConfiguredObject[]{plugin, _authenticationProvider1});
+
+        Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+        assertNotNull(broker);
+        assertEquals(_brokerId, broker.getId());
+        assertEquals(Collections.singleton(plugin), new HashSet<ConfiguredObject>(broker.getChildren(Plugin.class)));
+    }
+
+    public void testCreateBrokerWithKeyStores()
+    {
+        ConfigurationEntry pluginEntry = mock(ConfigurationEntry.class);
+        KeyStore keyStore = mock(KeyStore.class);
+        _brokerEntryChildren.put(KeyStore.class.getSimpleName(), Arrays.asList(pluginEntry));
+
+        RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{pluginEntry, _authenticationProviderEntry1},
+                                                                     new ConfiguredObject[]{keyStore, _authenticationProvider1});
+
+        Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+        assertNotNull(broker);
+        assertEquals(_brokerId, broker.getId());
+        assertEquals(Collections.singleton(keyStore), new HashSet<ConfiguredObject>(broker.getChildren(KeyStore.class)));
+    }
+
+    public void testCreateBrokerWithTrustStores()
+    {
+        ConfigurationEntry pluginEntry = mock(ConfigurationEntry.class);
+        TrustStore trustStore = mock(TrustStore.class);
+        _brokerEntryChildren.put(TrustStore.class.getSimpleName(), Arrays.asList(pluginEntry));
+
+        RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{pluginEntry, _authenticationProviderEntry1},
+                                                                     new ConfiguredObject[]{trustStore, _authenticationProvider1});
+
+        Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+        assertNotNull(broker);
+        assertEquals(_brokerId, broker.getId());
+        assertEquals(Collections.singleton(trustStore), new HashSet<ConfiguredObject>(broker.getChildren(TrustStore.class)));
+    }
+
+    private String convertToString(Object attributeValue)
+    {
+        return String.valueOf(attributeValue);
+    }
+
+    private  RecovererProvider createRecoveryProvider(final ConfigurationEntry[] entries, final ConfiguredObject[] objectsToRecoverer)
+    {
+        RecovererProvider recovererProvider = new RecovererProvider()
+        {
+            @Override
+            public ConfiguredObjectRecoverer<? extends ConfiguredObject> getRecoverer(String type)
+            {
+                @SuppressWarnings({ "unchecked", "rawtypes" })
+                final ConfiguredObjectRecoverer<?  extends ConfiguredObject> recovever = new ConfiguredObjectRecoverer()
+                {
+                    @Override
+                    public ConfiguredObject create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents)
+                    {
+                        for (int i = 0; i < entries.length; i++)
+                        {
+                            ConfigurationEntry e = entries[i];
+                            if (entry == e)
+                            {
+                                return objectsToRecoverer[i];
+                            }
+                        }
+                        return null;
+                    }
+                };
+
+                return recovever;
+            }
+        };
+        return recovererProvider;
+    }
+}

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java?rev=1447646&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java Tue Feb 19 09:35:28 2013
@@ -0,0 +1,62 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class DefaultRecovererProviderTest extends TestCase
+{
+    public void testGetRecoverer()
+    {
+        String[] supportedTypes = {Broker.class.getSimpleName(),
+                VirtualHost.class.getSimpleName(), AuthenticationProvider.class.getSimpleName(),
+                GroupProvider.class.getSimpleName(), Plugin.class.getSimpleName(), Port.class.getSimpleName()};
+
+        // mocking the required object
+        StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+        VirtualHostRegistry virtualHostRegistry = mock(VirtualHostRegistry.class);
+        LogRecorder logRecorder = mock(LogRecorder.class);
+        RootMessageLogger rootMessageLogger = mock(RootMessageLogger.class);
+        TaskExecutor taskExecutor = mock(TaskExecutor.class);
+
+        DefaultRecovererProvider provider = new DefaultRecovererProvider(statisticsGatherer, virtualHostRegistry, logRecorder, rootMessageLogger, taskExecutor);
+        for (String configuredObjectType : supportedTypes)
+        {
+            ConfiguredObjectRecoverer<?> recovever = provider.getRecoverer(configuredObjectType);
+            assertNotNull("Null recoverer for type: " + configuredObjectType, recovever);
+        }
+    }
+
+}

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java?rev=1447646&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java Tue Feb 19 09:35:28 2013
@@ -0,0 +1,97 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.configuration.startup;
+import static org.mockito.Mockito.*;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.plugin.GroupManagerFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.security.group.GroupManager;
+
+import junit.framework.TestCase;
+
+public class GroupProviderRecovererTest extends TestCase
+{
+
+    private UUID _id;
+    private Map<String, Object> _attributes;
+
+    private GroupManagerFactory _factory;
+    private QpidServiceLoader<GroupManagerFactory> _groupManagerServiceLoader;
+    private Broker _broker;
+    private ConfigurationEntry _configurationEntry;
+
+    @SuppressWarnings("unchecked")
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        _id = UUID.randomUUID();
+        _attributes = new HashMap<String, Object>();
+
+        _factory = mock(GroupManagerFactory.class);
+
+        _groupManagerServiceLoader = mock(QpidServiceLoader.class);
+        when(_groupManagerServiceLoader.instancesOf(GroupManagerFactory.class)).thenReturn(Collections.singletonList(_factory ));
+
+        _broker = mock(Broker.class);
+
+        _configurationEntry = mock(ConfigurationEntry.class);
+        when(_configurationEntry.getId()).thenReturn(_id);
+        when(_configurationEntry.getAttributes()).thenReturn(_attributes);
+    }
+
+    public void testCreate()
+    {
+        GroupManager groupManager = mock(GroupManager.class);
+        String name = groupManager.getClass().getSimpleName();
+        when(_factory.createInstance(_attributes)).thenReturn(groupManager);
+        GroupProviderRecoverer groupProviderRecoverer = new GroupProviderRecoverer(_groupManagerServiceLoader);
+        GroupProvider groupProvider = groupProviderRecoverer.create(null, _configurationEntry, _broker);
+        assertNotNull("Null group provider", groupProvider);
+        assertEquals("Unexpected name", name, groupProvider.getName());
+        assertEquals("Unexpected ID", _id, groupProvider.getId());
+    }
+
+    public void testCreateThrowsExceptionWhenNoGroupManagerIsCreated()
+    {
+        when(_factory.createInstance(_attributes)).thenReturn(null);
+
+        GroupProviderRecoverer groupProviderRecoverer = new GroupProviderRecoverer(_groupManagerServiceLoader);
+        try
+        {
+            groupProviderRecoverer.create(null, _configurationEntry, _broker);
+            fail("Configuration exception should be thrown when group manager is not created");
+        }
+        catch(IllegalConfigurationException e)
+        {
+            // pass
+        }
+    }
+
+}

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java?rev=1447646&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java Tue Feb 19 09:35:28 2013
@@ -0,0 +1,111 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.TrustStore;
+
+import junit.framework.TestCase;
+
+public class KeyStoreRecovererTest extends TestCase
+{
+
+    public void testCreateWithAllAttributesProvided()
+    {
+        Map<String, Object> attributes = getKeyStoreAttributes();
+
+        UUID id = UUID.randomUUID();
+        Broker broker = mock(Broker.class);
+        ConfigurationEntry entry = mock(ConfigurationEntry.class);
+        when(entry.getAttributes()).thenReturn(attributes);
+        when(entry.getId()).thenReturn(id);
+
+        KeyStoreRecoverer recovever = new KeyStoreRecoverer();
+
+        KeyStore KeyStore = recovever.create(null, entry, broker);
+        assertNotNull("Key store configured object is not created", KeyStore);
+        assertEquals(id, KeyStore.getId());
+        assertEquals("my-secret-password", KeyStore.getPassword());
+
+        assertNull("Password was unexpectedly returned from configured object", KeyStore.getAttribute(TrustStore.PASSWORD));
+
+        // password attribute should not be exposed by a key store configured object
+        // so, we should set password value to null in the map being used to create the key store configured object
+        attributes.put(KeyStore.PASSWORD, null);
+        for (Map.Entry<String, Object> attribute : attributes.entrySet())
+        {
+            Object attributeValue = KeyStore.getAttribute(attribute.getKey());
+            assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue);
+        }
+    }
+
+    private Map<String, Object> getKeyStoreAttributes()
+    {
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(KeyStore.NAME, getName());
+        attributes.put(KeyStore.PATH, "/path/to/KeyStore");
+        attributes.put(KeyStore.PASSWORD, "my-secret-password");
+        attributes.put(KeyStore.TYPE, "NON-JKS");
+        attributes.put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+        attributes.put(KeyStore.CERTIFICATE_ALIAS, "my-cert-alias");
+        attributes.put(KeyStore.DESCRIPTION, "description");
+        return attributes;
+    }
+
+    public void testCreateWithMissedRequiredAttributes()
+    {
+        Map<String, Object> attributes = getKeyStoreAttributes();
+
+        UUID id = UUID.randomUUID();
+        Broker broker = mock(Broker.class);
+        ConfigurationEntry entry = mock(ConfigurationEntry.class);
+        when(entry.getId()).thenReturn(id);
+
+        KeyStoreRecoverer recovever = new KeyStoreRecoverer();
+
+        String[] mandatoryProperties = {KeyStore.NAME, KeyStore.PATH, KeyStore.PASSWORD};
+        for (int i = 0; i < mandatoryProperties.length; i++)
+        {
+            Map<String, Object> properties =  new HashMap<String, Object>(attributes);
+            properties.remove(mandatoryProperties[i]);
+            when(entry.getAttributes()).thenReturn(properties);
+            try
+            {
+                recovever.create(null, entry, broker);
+                fail("Cannot create key store without a " + mandatoryProperties[i]);
+            }
+            catch(IllegalArgumentException e)
+            {
+                // pass
+            }
+        }
+    }
+
+}

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java?rev=1447646&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java Tue Feb 19 09:35:28 2013
@@ -0,0 +1,117 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+
+public class PluginRecovererTest extends TestCase
+{
+    private UUID _id;
+    private Map<String, Object> _attributes;
+
+    private PluginFactory _factory;
+    private QpidServiceLoader<PluginFactory> _pluginFactoryServiceLoader;
+    private Broker _broker;
+    private ConfigurationEntry _configurationEntry;
+
+    @SuppressWarnings("unchecked")
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        _id = UUID.randomUUID();
+        _attributes = new HashMap<String, Object>();
+
+        _factory = mock(PluginFactory.class);
+
+        _pluginFactoryServiceLoader = mock(QpidServiceLoader.class);
+        when(_pluginFactoryServiceLoader.instancesOf(PluginFactory.class)).thenReturn(Collections.singletonList(_factory ));
+
+        _broker = mock(Broker.class);
+
+        _configurationEntry = mock(ConfigurationEntry.class);
+        when(_configurationEntry.getId()).thenReturn(_id);
+        when(_configurationEntry.getAttributes()).thenReturn(_attributes);
+    }
+
+    public void testCreate()
+    {
+        Plugin pluginFromFactory = mock(Plugin.class);
+        when(pluginFromFactory.getId()).thenReturn(_id);
+        when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(pluginFromFactory);
+
+        PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+        ConfiguredObject pluginFromRecoverer = pluginRecoverer.create(null, _configurationEntry, _broker);
+        assertNotNull("Null group provider", pluginFromRecoverer);
+        assertSame("Unexpected plugin", pluginFromFactory, pluginFromRecoverer);
+        assertEquals("Unexpected ID", _id, pluginFromRecoverer.getId());
+    }
+
+    public void testCreateThrowsExceptionForUnexpectedId()
+    {
+        Plugin pluginFromFactory = mock(Plugin.class);
+        when(pluginFromFactory.getId()).thenReturn(UUID.randomUUID());
+        when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(pluginFromFactory);
+
+        PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+        try
+        {
+            pluginRecoverer.create(null, _configurationEntry, _broker);
+            fail("An exception should be thrown for incorrect id");
+        }
+        catch(IllegalStateException e)
+        {
+            //pass
+        }
+    }
+
+    public void testCreateThrowsExceptionWhenNoPluginIsCreated()
+    {
+        when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(null);
+
+        PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+        try
+        {
+            pluginRecoverer.create(null, _configurationEntry, _broker);
+            fail("Configuration exception should be thrown when plugin is not created");
+        }
+        catch(IllegalConfigurationException e)
+        {
+            // pass
+        }
+    }
+
+}

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java?rev=1447646&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java Tue Feb 19 09:35:28 2013
@@ -0,0 +1,108 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class TrustStoreRecovererTest extends QpidTestCase
+{
+    public void testCreateWithAllAttributesProvided()
+    {
+        Map<String, Object> attributes = getTrustStoreAttributes();
+
+        UUID id = UUID.randomUUID();
+        Broker broker = mock(Broker.class);
+        ConfigurationEntry entry = mock(ConfigurationEntry.class);
+        when(entry.getAttributes()).thenReturn(attributes);
+        when(entry.getId()).thenReturn(id);
+
+        TrustStoreRecoverer recovever = new TrustStoreRecoverer();
+
+        TrustStore trustStore = recovever.create(null, entry, broker);
+        assertNotNull("Trust store configured object is not created", trustStore);
+        assertEquals(id, trustStore.getId());
+        assertEquals("my-secret-password", trustStore.getPassword());
+
+        assertNull("Password was unexpectedly returned from configured object", trustStore.getAttribute(TrustStore.PASSWORD));
+
+        // password attribute should not be exposed by a trust store configured object
+        // so, we should set password value to null in the map being used to create the trust store configured object
+        attributes.put(TrustStore.PASSWORD, null);
+        for (Map.Entry<String, Object> attribute : attributes.entrySet())
+        {
+            Object attributeValue = trustStore.getAttribute(attribute.getKey());
+            assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue);
+        }
+    }
+
+    private Map<String, Object> getTrustStoreAttributes()
+    {
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(TrustStore.NAME, getName());
+        attributes.put(TrustStore.PATH, "/path/to/truststore");
+        attributes.put(TrustStore.PASSWORD, "my-secret-password");
+        attributes.put(TrustStore.TYPE, "NON-JKS");
+        attributes.put(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+        attributes.put(TrustStore.DESCRIPTION, "Description");
+        return attributes;
+    }
+
+    public void testCreateWithMissedRequiredAttributes()
+    {
+        Map<String, Object> attributes = getTrustStoreAttributes();
+
+        UUID id = UUID.randomUUID();
+        Broker broker = mock(Broker.class);
+        ConfigurationEntry entry = mock(ConfigurationEntry.class);
+        when(entry.getAttributes()).thenReturn(attributes);
+        when(entry.getId()).thenReturn(id);
+
+        TrustStoreRecoverer recovever = new TrustStoreRecoverer();
+
+        String[] mandatoryProperties = {TrustStore.NAME, TrustStore.PATH, TrustStore.PASSWORD};
+        for (int i = 0; i < mandatoryProperties.length; i++)
+        {
+            Map<String, Object> properties =  new HashMap<String, Object>(attributes);
+            properties.remove(mandatoryProperties[i]);
+            when(entry.getAttributes()).thenReturn(properties);
+            try
+            {
+                recovever.create(null, entry, broker);
+                fail("Cannot create key store without a " + mandatoryProperties[i]);
+            }
+            catch(IllegalArgumentException e)
+            {
+                // pass
+            }
+        }
+    }
+
+}

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java?rev=1447646&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java Tue Feb 19 09:35:28 2013
@@ -0,0 +1,124 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+
+public class VirtualHostRecovererTest extends TestCase
+{
+    public void testCreate()
+    {
+        StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+        SecurityManager securityManager = mock(SecurityManager.class);
+        ConfigurationEntry entry = mock(ConfigurationEntry.class);
+        Broker parent = mock(Broker.class);
+        when(parent.getSecurityManager()).thenReturn(securityManager);
+
+        VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer);
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(VirtualHost.NAME, getName());
+        attributes.put(VirtualHost.CONFIG_PATH, "/path/to/virtualhost.xml");
+        when(entry.getAttributes()).thenReturn(attributes);
+
+        VirtualHost host = recoverer.create(null, entry, parent);
+
+        assertNotNull("Null is returned", host);
+        assertEquals("Unexpected name", getName(), host.getName());
+    }
+
+    public void testCreateVirtualHostFromStoreConfigAtrributes()
+    {
+        StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+        SecurityManager securityManager = mock(SecurityManager.class);
+        ConfigurationEntry entry = mock(ConfigurationEntry.class);
+        Broker parent = mock(Broker.class);
+        when(parent.getSecurityManager()).thenReturn(securityManager);
+
+        VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer);
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(VirtualHost.NAME, getName());
+        attributes.put(VirtualHost.STORE_PATH, "/path/to/virtualhost/store");
+        attributes.put(VirtualHost.STORE_TYPE, "DERBY");
+        when(entry.getAttributes()).thenReturn(attributes);
+
+        VirtualHost host = recoverer.create(null, entry, parent);
+
+        assertNotNull("Null is returned", host);
+        assertEquals("Unexpected name", getName(), host.getName());
+    }
+
+    public void testCreateWithoutMandatoryAttributesResultsInException()
+    {
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(VirtualHost.NAME, getName());
+        attributes.put(VirtualHost.CONFIG_PATH, "/path/to/virtualhost.xml");
+        String[] mandatoryAttributes = {VirtualHost.NAME, VirtualHost.CONFIG_PATH};
+
+        checkMandatoryAttributesAreValidated(mandatoryAttributes, attributes);
+
+        attributes = new HashMap<String, Object>();
+        attributes.put(VirtualHost.NAME, getName());
+        attributes.put(VirtualHost.STORE_PATH, "/path/to/store");
+        attributes.put(VirtualHost.STORE_TYPE, "DERBY");
+        mandatoryAttributes = new String[]{VirtualHost.NAME, VirtualHost.STORE_PATH, VirtualHost.STORE_TYPE};
+
+        checkMandatoryAttributesAreValidated(mandatoryAttributes, attributes);
+    }
+
+    public void checkMandatoryAttributesAreValidated(String[] mandatoryAttributes, Map<String, Object> attributes)
+    {
+        StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+        SecurityManager securityManager = mock(SecurityManager.class);
+        ConfigurationEntry entry = mock(ConfigurationEntry.class);
+        Broker parent = mock(Broker.class);
+        when(parent.getSecurityManager()).thenReturn(securityManager);
+        VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer);
+
+        for (String name : mandatoryAttributes)
+        {
+            Map<String, Object> copy = new HashMap<String, Object>(attributes);
+            copy.remove(name);
+            when(entry.getAttributes()).thenReturn(copy);
+            try
+            {
+                recoverer.create(null, entry, parent);
+                fail("Cannot create a virtual host without a manadatory attribute " + name);
+            }
+            catch(IllegalConfigurationException e)
+            {
+                // pass
+            }
+        }
+    }
+}

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java?rev=1447646&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java Tue Feb 19 09:35:28 2013
@@ -0,0 +1,392 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.configuration.store;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManager;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public abstract class ConfigurationEntryStoreTestCase extends QpidTestCase
+{
+    private ConfigurationEntryStore _store;
+
+    private UUID _brokerId;
+    private UUID _virtualHostId;
+    private UUID _authenticationProviderId;
+
+    private Map<String, Object> _brokerAttributes;
+    private Map<String, Object> _virtualHostAttributes;
+    private Map<String, Object> _authenticationProviderAttributes;
+
+    public void setUp() throws Exception
+    {
+        super.setUp();
+
+        _brokerId = UUID.randomUUID();
+        _brokerAttributes = new HashMap<String, Object>();
+        _brokerAttributes.put(Broker.DEFAULT_VIRTUAL_HOST, "test");
+        _brokerAttributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider1");
+        _brokerAttributes.put(Broker.ALERT_THRESHOLD_MESSAGE_AGE, 9);
+        _brokerAttributes.put(Broker.ALERT_THRESHOLD_MESSAGE_COUNT, 8);
+        _brokerAttributes.put(Broker.ALERT_THRESHOLD_QUEUE_DEPTH, 7);
+        _brokerAttributes.put(Broker.ALERT_THRESHOLD_MESSAGE_SIZE, 6);
+        _brokerAttributes.put(Broker.ALERT_REPEAT_GAP, 5);
+        _brokerAttributes.put(Broker.FLOW_CONTROL_SIZE_BYTES, 5);
+        _brokerAttributes.put(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES, 3);
+        _brokerAttributes.put(Broker.MAXIMUM_DELIVERY_ATTEMPTS, 2);
+        _brokerAttributes.put(Broker.DEAD_LETTER_QUEUE_ENABLED, true);
+        _brokerAttributes.put(Broker.HOUSEKEEPING_CHECK_PERIOD, 1);
+        _brokerAttributes.put(Broker.ACL_FILE, "/path/to/acl");
+        _brokerAttributes.put(Broker.SESSION_COUNT_LIMIT, 1000);
+        _brokerAttributes.put(Broker.HEART_BEAT_DELAY, 2000);
+        _brokerAttributes.put(Broker.STATISTICS_REPORTING_PERIOD, 4000);
+        _brokerAttributes.put(Broker.STATISTICS_REPORTING_RESET_ENABLED, true);
+
+        _virtualHostId = UUID.randomUUID();
+        _virtualHostAttributes = new HashMap<String, Object>();
+        _virtualHostAttributes.put(VirtualHost.NAME, "test");
+        _virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/test");
+
+        _authenticationProviderId = UUID.randomUUID();
+        _authenticationProviderAttributes = new HashMap<String, Object>();
+        _authenticationProviderAttributes.put(AuthenticationProvider.NAME, "authenticationProvider1");
+        _authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, AnonymousAuthenticationManager.class.getSimpleName());
+
+        _store = createStore(_brokerId, _brokerAttributes);
+        addConfiguration(_virtualHostId, VirtualHost.class.getSimpleName(), _virtualHostAttributes);
+        addConfiguration(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(), _authenticationProviderAttributes);
+    }
+
+    // ??? perhaps it should not be abstract
+    protected abstract ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception;
+
+    protected abstract void addConfiguration(UUID id, String type, Map<String, Object> attributes);
+
+    protected ConfigurationEntryStore getStore()
+    {
+        return _store;
+    }
+
+    public void testGetRootEntry()
+    {
+        ConfigurationEntry brokerConfigEntry = _store.getRootEntry();
+        assertNotNull("Root entry does not exist", brokerConfigEntry);
+        assertEquals("Unexpected id", _brokerId, brokerConfigEntry.getId());
+        assertEquals("Unexpected type ", Broker.class.getSimpleName(), brokerConfigEntry.getType());
+        Map<String, Object> attributes = brokerConfigEntry.getAttributes();
+        assertNotNull("Attributes cannot be null", attributes);
+        assertEquals("Unexpected attributes", _brokerAttributes, attributes);
+    }
+
+    public void testGetEntry()
+    {
+        ConfigurationEntry authenticationProviderConfigEntry = _store.getEntry(_authenticationProviderId);
+        assertNotNull("Provider with id " + _authenticationProviderId + " should exist", authenticationProviderConfigEntry);
+        assertEquals("Unexpected id", _authenticationProviderId, authenticationProviderConfigEntry.getId());
+        assertEquals("Unexpected type ", AuthenticationProvider.class.getSimpleName(), authenticationProviderConfigEntry.getType());
+        Map<String, Object> attributes = authenticationProviderConfigEntry.getAttributes();
+        assertNotNull("Attributes cannot be null", attributes);
+        assertEquals("Unexpected attributes", _authenticationProviderAttributes, attributes);
+    }
+
+    public void testRemove()
+    {
+        Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+        virtualHostAttributes.put(VirtualHost.NAME, getName());
+        virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config");
+        UUID virtualHostId = UUID.randomUUID();
+        addConfiguration(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes);
+
+        assertNotNull("Virtual host with id " + virtualHostId + " should exist", _store.getEntry(virtualHostId));
+
+        _store.remove(virtualHostId);
+        assertNull("Authentication provider configuration should be removed", _store.getEntry(virtualHostId));
+    }
+
+    public void testRemoveMultipleEntries()
+    {
+        Map<String, Object> virtualHost1Attributes = new HashMap<String, Object>();
+        virtualHost1Attributes.put(VirtualHost.NAME, "test1");
+        virtualHost1Attributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config1");
+        UUID virtualHost1Id = UUID.randomUUID();
+        addConfiguration(virtualHost1Id, VirtualHost.class.getSimpleName(), virtualHost1Attributes);
+
+        Map<String, Object> virtualHost2Attributes = new HashMap<String, Object>();
+        virtualHost2Attributes.put(VirtualHost.NAME, "test1");
+        virtualHost2Attributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config2");
+        UUID virtualHost2Id = UUID.randomUUID();
+        addConfiguration(virtualHost2Id, VirtualHost.class.getSimpleName(), virtualHost2Attributes);
+
+        assertNotNull("Virtual host with id " + virtualHost1Id + " should exist", _store.getEntry(virtualHost1Id));
+        assertNotNull("Virtual host with id " + virtualHost2Id + " should exist", _store.getEntry(virtualHost2Id));
+
+        UUID[] deletedIds = _store.remove(virtualHost1Id, virtualHost2Id);
+        assertNotNull("Unexpected deleted ids", deletedIds);
+        assertEquals("Unexpected id of first deleted virtual host", virtualHost1Id , deletedIds[0]);
+        assertEquals("Unexpected id of second deleted virtual host", virtualHost2Id , deletedIds[1]);
+        assertNull("First virtual host configuration should be removed", _store.getEntry(virtualHost1Id));
+        assertNull("Second virtual host configuration should be removed", _store.getEntry(virtualHost2Id));
+    }
+
+    public void testSaveBroker()
+    {
+        ConfigurationEntry brokerConfigEntry = _store.getRootEntry();
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(Broker.DEFAULT_VIRTUAL_HOST, "test");
+        attributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider1");
+        attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_AGE, 19);
+        attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_COUNT, 18);
+        attributes.put(Broker.ALERT_THRESHOLD_QUEUE_DEPTH, 17);
+        attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_SIZE, 16);
+        attributes.put(Broker.ALERT_REPEAT_GAP, 15);
+        attributes.put(Broker.FLOW_CONTROL_SIZE_BYTES, 15);
+        attributes.put(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES, 13);
+        attributes.put(Broker.MAXIMUM_DELIVERY_ATTEMPTS, 12);
+        attributes.put(Broker.DEAD_LETTER_QUEUE_ENABLED, false);
+        attributes.put(Broker.HOUSEKEEPING_CHECK_PERIOD, 11);
+        attributes.put(Broker.ACL_FILE, "/path/to/acl1");
+        attributes.put(Broker.SESSION_COUNT_LIMIT, 11000);
+        attributes.put(Broker.HEART_BEAT_DELAY, 12000);
+        attributes.put(Broker.STATISTICS_REPORTING_PERIOD, 14000);
+        attributes.put(Broker.STATISTICS_REPORTING_RESET_ENABLED, false);
+        ConfigurationEntry updatedBrokerEntry = new ConfigurationEntry(_brokerId, Broker.class.getSimpleName(), attributes,
+                brokerConfigEntry.getChildrenIds(), _store);
+
+        _store.save(updatedBrokerEntry);
+
+        ConfigurationEntry newBrokerConfigEntry = _store.getRootEntry();
+        assertNotNull("Root entry does not exist", newBrokerConfigEntry);
+        assertEquals("Unexpected id", _brokerId, newBrokerConfigEntry.getId());
+        assertEquals("Unexpected type ", Broker.class.getSimpleName(), newBrokerConfigEntry.getType());
+        Map<String, Object> newBrokerattributes = newBrokerConfigEntry.getAttributes();
+        assertNotNull("Attributes cannot be null", newBrokerattributes);
+        assertEquals("Unexpected attributes", attributes, newBrokerattributes);
+    }
+
+    public void testSaveNewVirtualHost()
+    {
+        Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+        virtualHostAttributes.put(VirtualHost.NAME, "test1");
+        virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config1");
+        UUID virtualHostId = UUID.randomUUID();
+        ConfigurationEntry hostEntry = new ConfigurationEntry(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
+                Collections.<UUID> emptySet(), _store);
+
+        _store.save(hostEntry);
+
+        ConfigurationEntry configurationEntry = _store.getEntry(virtualHostId);
+        assertEquals("Unexpected virtual host configuration", hostEntry, configurationEntry);
+        assertEquals("Unexpected type", VirtualHost.class.getSimpleName(), configurationEntry.getType());
+        assertEquals("Unexpected virtual host attributes", hostEntry.getAttributes(), configurationEntry.getAttributes());
+        assertTrue("Unexpected virtual host children found", hostEntry.getChildrenIds().isEmpty());
+    }
+
+    public void testSaveExistingVirtualHost()
+    {
+        ConfigurationEntry hostEntry = _store.getEntry(_virtualHostId);
+        assertNotNull("Host configuration is not found", hostEntry);
+
+        Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+        virtualHostAttributes.put(VirtualHost.NAME, "test");
+        virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/new/phantom/test/configuration");
+
+        ConfigurationEntry updatedEntry = new ConfigurationEntry(_virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
+                hostEntry.getChildrenIds(), _store);
+        _store.save(updatedEntry);
+
+        ConfigurationEntry newHostEntry = _store.getEntry(_virtualHostId);
+        assertEquals("Unexpected virtual host configuration", updatedEntry, newHostEntry);
+        assertEquals("Unexpected type", VirtualHost.class.getSimpleName(), newHostEntry.getType());
+        assertEquals("Unexpected virtual host attributes", updatedEntry.getAttributes(), newHostEntry.getAttributes());
+        assertEquals("Unexpected virtual host children found", updatedEntry.getChildrenIds(), newHostEntry.getChildrenIds());
+    }
+
+    public void testSaveNewAuthenticationProvider()
+    {
+        UUID authenticationProviderId = UUID.randomUUID();
+        Map<String, Object> authenticationProviderAttributes = new HashMap<String, Object>();
+        authenticationProviderAttributes.put(AuthenticationProvider.NAME, "authenticationProvider1");
+        authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, ExternalAuthenticationManager.class.getSimpleName());
+        ConfigurationEntry providerEntry = new ConfigurationEntry(authenticationProviderId, AuthenticationProvider.class.getSimpleName(),
+                authenticationProviderAttributes, Collections.<UUID> emptySet(), _store);
+
+        _store.save(providerEntry);
+
+        ConfigurationEntry storeEntry = _store.getEntry(authenticationProviderId);
+        assertEquals("Unexpected provider configuration", providerEntry, storeEntry);
+        assertEquals("Unexpected type", AuthenticationProvider.class.getSimpleName(), storeEntry.getType());
+        assertEquals("Unexpected provider attributes", providerEntry.getAttributes(), storeEntry.getAttributes());
+        assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+    }
+
+    public void testSaveExistingAuthenticationProvider()
+    {
+        ConfigurationEntry providerEntry = _store.getEntry(_authenticationProviderId);
+        assertNotNull("provider configuration is not found", providerEntry);
+
+        Map<String, Object> authenticationProviderAttributes = new HashMap<String, Object>();
+        authenticationProviderAttributes.put(AuthenticationProvider.NAME, "authenticationProvider1");
+        authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, ExternalAuthenticationManager.class.getSimpleName());
+        ConfigurationEntry updatedEntry = new ConfigurationEntry(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(),
+                authenticationProviderAttributes, Collections.<UUID> emptySet(), _store);
+        _store.save(updatedEntry);
+
+        ConfigurationEntry storeEntry = _store.getEntry(_authenticationProviderId);
+        assertEquals("Unexpected provider configuration", updatedEntry, storeEntry);
+        assertEquals("Unexpected type", AuthenticationProvider.class.getSimpleName(), storeEntry.getType());
+        assertEquals("Unexpected provider attributes", updatedEntry.getAttributes(), storeEntry.getAttributes());
+        assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+    }
+
+    public void testSaveTrustStore()
+    {
+        UUID trustStoreId = UUID.randomUUID();
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(TrustStore.NAME, getName());
+        attributes.put(TrustStore.PATH, "/path/to/truststore");
+        attributes.put(TrustStore.PASSWORD, "my-secret-password");
+        attributes.put(TrustStore.TYPE, "NON-JKS");
+        attributes.put(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+        attributes.put(TrustStore.DESCRIPTION, "Description");
+
+        ConfigurationEntry trustStoreEntry = new ConfigurationEntry(trustStoreId, TrustStore.class.getSimpleName(), attributes,
+                Collections.<UUID> emptySet(), _store);
+
+        _store.save(trustStoreEntry);
+
+        ConfigurationEntry storeEntry = _store.getEntry(trustStoreId);
+        assertEquals("Unexpected trust store configuration", trustStoreEntry, storeEntry);
+        assertEquals("Unexpected type", TrustStore.class.getSimpleName(), storeEntry.getType());
+        assertEquals("Unexpected provider attributes", trustStoreEntry.getAttributes(), storeEntry.getAttributes());
+        assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+    }
+
+    public void testSaveKeyStore()
+    {
+        UUID keyStoreId = UUID.randomUUID();
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(KeyStore.NAME, getName());
+        attributes.put(KeyStore.PATH, "/path/to/truststore");
+        attributes.put(KeyStore.PASSWORD, "my-secret-password");
+        attributes.put(KeyStore.TYPE, "NON-JKS");
+        attributes.put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+        attributes.put(KeyStore.DESCRIPTION, "Description");
+        attributes.put(KeyStore.CERTIFICATE_ALIAS, "Alias");
+
+        ConfigurationEntry keyStoreEntry = new ConfigurationEntry(keyStoreId, KeyStore.class.getSimpleName(), attributes, Collections.<UUID> emptySet(),
+                _store);
+
+        _store.save(keyStoreEntry);
+
+        ConfigurationEntry storeEntry = _store.getEntry(keyStoreId);
+        assertEquals("Unexpected key store configuration", keyStoreEntry, storeEntry);
+        assertEquals("Unexpected type", KeyStore.class.getSimpleName(), storeEntry.getType());
+        assertEquals("Unexpected provider attributes", keyStoreEntry.getAttributes(), storeEntry.getAttributes());
+        assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+    }
+
+    public void testSaveGroupProvider()
+    {
+        UUID groupProviderId = UUID.randomUUID();
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(GroupProvider.NAME, getName());
+
+        ConfigurationEntry groupProviderEntry = new ConfigurationEntry(groupProviderId, GroupProvider.class.getSimpleName(), attributes,
+                Collections.<UUID> emptySet(), _store);
+
+        _store.save(groupProviderEntry);
+
+        ConfigurationEntry storeEntry = _store.getEntry(groupProviderId);
+        assertEquals("Unexpected group provider configuration", groupProviderEntry, storeEntry);
+        assertEquals("Unexpected type", GroupProvider.class.getSimpleName(), storeEntry.getType());
+        assertEquals("Unexpected group provider attributes", groupProviderEntry.getAttributes(), storeEntry.getAttributes());
+        assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+    }
+
+    public void testSavePort()
+    {
+        UUID portId = UUID.randomUUID();
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        Set<String> tcpTransportSet = Collections.singleton(Transport.TCP.name());
+        attributes.put(Port.PORT, 9999);
+        attributes.put(Port.TRANSPORTS, tcpTransportSet);
+        attributes.put(Port.TCP_NO_DELAY, true);
+        attributes.put(Port.RECEIVE_BUFFER_SIZE, 1);
+        attributes.put(Port.SEND_BUFFER_SIZE, 2);
+        attributes.put(Port.NEED_CLIENT_AUTH, true);
+        attributes.put(Port.WANT_CLIENT_AUTH, true);
+
+        ConfigurationEntry portEntry = new ConfigurationEntry(portId, Port.class.getSimpleName(), attributes, Collections.<UUID> emptySet(), _store);
+
+        _store.save(portEntry);
+
+        ConfigurationEntry storeEntry = _store.getEntry(portId);
+        assertEquals("Unexpected port configuration", portEntry, storeEntry);
+        assertEquals("Unexpected type", Port.class.getSimpleName(), storeEntry.getType());
+        assertEquals("Unexpected port attributes", portEntry.getAttributes(), storeEntry.getAttributes());
+        assertTrue("Unexpected port children found", storeEntry.getChildrenIds().isEmpty());
+    }
+
+    public void testMultipleSave()
+    {
+        UUID virtualHostId = UUID.randomUUID();
+        Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+        virtualHostAttributes.put(VirtualHost.NAME, "test1");
+        virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config1");
+        ConfigurationEntry hostEntry = new ConfigurationEntry(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
+                Collections.<UUID> emptySet(), _store);
+
+        UUID keyStoreId = UUID.randomUUID();
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(KeyStore.NAME, getName());
+        attributes.put(KeyStore.PATH, "/path/to/truststore");
+        attributes.put(KeyStore.PASSWORD, "my-secret-password");
+        attributes.put(KeyStore.TYPE, "NON-JKS");
+        attributes.put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+        attributes.put(KeyStore.DESCRIPTION, "Description");
+        attributes.put(KeyStore.CERTIFICATE_ALIAS, "Alias");
+
+        ConfigurationEntry keyStoreEntry = new ConfigurationEntry(keyStoreId, KeyStore.class.getSimpleName(), attributes, Collections.<UUID> emptySet(),
+                _store);
+
+        _store.save(hostEntry, keyStoreEntry);
+
+        assertNotNull("Virtual host is not found", _store.getEntry(virtualHostId));
+        assertNotNull("Key store is not found", _store.getEntry(keyStoreId));
+    }
+}

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java?rev=1447646&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java Tue Feb 19 09:35:28 2013
@@ -0,0 +1,77 @@
+package org.apache.qpid.server.configuration.store;
+
+import java.io.File;
+import java.io.StringWriter;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.test.utils.TestFileUtils;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTestCase
+{
+    private File _storeFile;
+    private ObjectMapper _objectMapper;
+
+    public void tearDown() throws Exception
+    {
+        _storeFile.delete();
+        super.tearDown();
+    }
+
+    @Override
+    protected ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception
+    {
+        _objectMapper = new ObjectMapper();
+        _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+
+        Map<String, Object> brokerObjectMap = new HashMap<String, Object>();
+        brokerObjectMap.put(Broker.ID, brokerId);
+        brokerObjectMap.put("@type", Broker.class.getSimpleName());
+        brokerObjectMap.putAll(brokerAttributes);
+
+        StringWriter sw = new StringWriter();
+        _objectMapper.writeValue(sw, brokerObjectMap);
+
+        String brokerJson = sw.toString();
+
+        _storeFile = TestFileUtils.createTempFile(this, ".json", brokerJson);
+
+        JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+        store.open(_storeFile.getAbsolutePath());
+        return store;
+    }
+
+    @Override
+    protected void addConfiguration(UUID id, String type, Map<String, Object> attributes)
+    {
+        ConfigurationEntryStore store = getStore();
+        store.save(new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), store));
+    }
+
+    public void testAttributeIsResolvedFromSystemProperties()
+    {
+        String aclLocation = "path/to/acl/" + getTestName();
+        setTestSystemProperty("my.test.property", aclLocation);
+
+        ConfigurationEntryStore store = getStore();
+        ConfigurationEntry brokerConfigEntry = store.getRootEntry();
+        Map<String, Object> attributes = new HashMap<String, Object>(brokerConfigEntry.getAttributes());
+        attributes.put(Broker.ACL_FILE, "${my.test.property}");
+        ConfigurationEntry updatedBrokerEntry = new ConfigurationEntry(brokerConfigEntry.getId(), Broker.class.getSimpleName(),
+                attributes, brokerConfigEntry.getChildrenIds(), store);
+        store.save(updatedBrokerEntry);
+
+        JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore();
+        store2.open(_storeFile.getAbsolutePath());
+
+        assertEquals("Unresolved ACL value", aclLocation, store2.getRootEntry().getAttributes().get(Broker.ACL_FILE));
+    }
+
+}

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java?rev=1447646&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java Tue Feb 19 09:35:28 2013
@@ -0,0 +1,83 @@
+package org.apache.qpid.server.configuration.store;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.when;
+
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class StoreConfigurationChangeListenerTest extends QpidTestCase
+{
+    private ConfigurationEntryStore _store;
+    private StoreConfigurationChangeListener _listener;
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        _store = mock(ConfigurationEntryStore.class);
+        _listener = new StoreConfigurationChangeListener(_store);
+    }
+
+    public void testStateChanged()
+    {
+        notifyBrokerStarted();
+        UUID id = UUID.randomUUID();
+        ConfiguredObject object = mock(VirtualHost.class);
+        when(object.getId()).thenReturn(id);
+        _listener.stateChanged(object, State.ACTIVE, State.DELETED);
+        verify(_store).remove(id);
+    }
+
+    public void testChildAdded()
+    {
+        notifyBrokerStarted();
+        Broker broker = mock(Broker.class);
+        VirtualHost child = mock(VirtualHost.class);
+        _listener.childAdded(broker, child);
+        verify(_store).save(any(ConfigurationEntry.class), any(ConfigurationEntry.class));
+    }
+
+    public void testChildRemoved()
+    {
+        notifyBrokerStarted();
+        Broker broker = mock(Broker.class);
+        VirtualHost child = mock(VirtualHost.class);
+        _listener.childRemoved(broker, child);
+        verify(_store).save(any(ConfigurationEntry.class));
+    }
+
+    public void testAttributeSet()
+    {
+        notifyBrokerStarted();
+        Broker broker = mock(Broker.class);
+        _listener.attributeSet(broker, Broker.FLOW_CONTROL_SIZE_BYTES, null, 1);
+        verify(_store).save(any(ConfigurationEntry.class));
+    }
+
+    public void testChildAddedForVirtualHost()
+    {
+        notifyBrokerStarted();
+
+        VirtualHost object = mock(VirtualHost.class);
+        Queue queue = mock(Queue.class);
+        _listener.childAdded(object, queue);
+        verifyNoMoreInteractions(_store);
+    }
+
+    private void notifyBrokerStarted()
+    {
+        Broker broker = mock(Broker.class);
+        _listener.stateChanged(broker, State.INITIALISING, State.ACTIVE);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org