summaryrefslogtreecommitdiff
path: root/java/broker/src/test/java/org/apache/qpid/server/configuration/startup
diff options
context:
space:
mode:
Diffstat (limited to 'java/broker/src/test/java/org/apache/qpid/server/configuration/startup')
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java405
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java62
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java97
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java111
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java117
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java108
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java124
7 files changed, 1024 insertions, 0 deletions
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java
new file mode 100644
index 0000000000..c1ebe26f52
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java
@@ -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;
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java
new file mode 100644
index 0000000000..c95f67beb9
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java
@@ -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);
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java
new file mode 100644
index 0000000000..6713574e4b
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java
@@ -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
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java
new file mode 100644
index 0000000000..0d7dc1bb06
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java
@@ -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
+ }
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java
new file mode 100644
index 0000000000..42fd742407
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java
@@ -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
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java
new file mode 100644
index 0000000000..3b64f45c80
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java
@@ -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
+ }
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java
new file mode 100644
index 0000000000..57d219f85f
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java
@@ -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
+ }
+ }
+ }
+}