summaryrefslogtreecommitdiff
path: root/java/broker/src/test/java/org/apache/qpid/server/configuration/store
diff options
context:
space:
mode:
Diffstat (limited to 'java/broker/src/test/java/org/apache/qpid/server/configuration/store')
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java392
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java216
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java341
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java83
4 files changed, 1032 insertions, 0 deletions
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
new file mode 100644
index 0000000000..b357c0b8e9
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
@@ -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));
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
new file mode 100644
index 0000000000..7c9f4889f8
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
@@ -0,0 +1,216 @@
+package org.apache.qpid.server.configuration.store;
+
+import java.io.File;
+import java.io.IOException;
+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.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTestCase
+{
+ private File _storeFile;
+ private ObjectMapper _objectMapper;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ _objectMapper = new ObjectMapper();
+ _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ _storeFile.delete();
+ super.tearDown();
+ }
+
+ @Override
+ protected ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception
+ {
+ _storeFile = createStoreFile(brokerId, brokerAttributes);
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(_storeFile.getAbsolutePath());
+ return store;
+ }
+
+ private File createStoreFile(UUID brokerId, Map<String, Object> brokerAttributes) throws IOException,
+ JsonGenerationException, JsonMappingException
+ {
+ 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();
+
+ return TestFileUtils.createTempFile(this, ".json", brokerJson);
+ }
+
+ @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));
+ }
+
+ public void testOpenEmpty()
+ {
+ File file = TestFileUtils.createTempFile(this, ".json");
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(file.getAbsolutePath());
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ store.copyTo(file.getAbsolutePath());
+
+ JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore();
+ store2.open(file.getAbsolutePath());
+ ConfigurationEntry root2 = store.getRootEntry();
+ assertEquals("Unexpected root entry", root.getId(), root2.getId());
+ }
+
+ public void testOpenNotEmpty() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File file = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(file.getAbsolutePath());
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenInMemoryEmpty()
+ {
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(JsonConfigurationEntryStore.IN_MEMORY);
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ }
+
+ public void testOpenWithInitialStoreLocation() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ File storeFile = TestFileUtils.createTempFile(this, ".json");
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(storeFile.getAbsolutePath(), initialStoreFile.getAbsolutePath());
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenInMemoryWithInitialStoreLocation() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(JsonConfigurationEntryStore.IN_MEMORY, initialStoreFile.getAbsolutePath());
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenWithInitialStore() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore initialStore = new JsonConfigurationEntryStore();
+ initialStore.open(initialStoreFile.getAbsolutePath());
+
+ File storeFile = TestFileUtils.createTempFile(this, ".json");
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(storeFile.getAbsolutePath(), initialStore);
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenInMemoryWithInitialStore() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore initialStore = new JsonConfigurationEntryStore();
+ initialStore.open(initialStoreFile.getAbsolutePath());
+
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(JsonConfigurationEntryStore.IN_MEMORY, initialStore);
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java
new file mode 100644
index 0000000000..a67daac610
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java
@@ -0,0 +1,341 @@
+package org.apache.qpid.server.configuration.store;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.any;
+
+import java.io.File;
+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 org.apache.qpid.server.BrokerOptions;
+import org.apache.qpid.server.configuration.BrokerConfigurationStoreCreator;
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class ManagementModeStoreHandlerTest extends QpidTestCase
+{
+ private ManagementModeStoreHandler _handler;
+ private BrokerOptions _options;
+ private ConfigurationEntryStore _store;
+ private ConfigurationEntry _root;
+ private ConfigurationEntry _portEntry;
+ private UUID _rootId, _portEntryId;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _rootId = UUID.randomUUID();
+ _portEntryId = UUID.randomUUID();
+ _store = mock(ConfigurationEntryStore.class);
+ _root = mock(ConfigurationEntry.class);
+ _portEntry = mock(ConfigurationEntry.class);
+ when(_store.getRootEntry()).thenReturn(_root);
+ when(_root.getId()).thenReturn(_rootId);
+ when(_portEntry.getId()).thenReturn(_portEntryId);
+ when(_store.getEntry(_portEntryId)).thenReturn(_portEntry);
+ when(_store.getEntry(_rootId)).thenReturn(_root);
+ when(_root.getChildrenIds()).thenReturn(Collections.singleton(_portEntryId));
+ when(_portEntry.getType()).thenReturn(Port.class.getSimpleName());
+ _options = new BrokerOptions();
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ }
+
+ public void testOpenString()
+ {
+ try
+ {
+ _handler.open(TMP_FOLDER + File.separator + getTestName());
+ fail("Exception should be thrown on attempt to call open method on a handler");
+ }
+ catch (IllegalStateException e)
+ {
+ // pass
+ }
+ }
+
+ public void testOpenStringString()
+ {
+ try
+ {
+ _handler.open(TMP_FOLDER + File.separator + getTestName(),
+ BrokerConfigurationStoreCreator.DEFAULT_INITIAL_STORE_LOCATION);
+ fail("Exception should be thrown on attempt to call open method on a handler");
+ }
+ catch (IllegalStateException e)
+ {
+ // pass
+ }
+ }
+
+ public void testOpenStringConfigurationEntryStore()
+ {
+ try
+ {
+ _handler.open(TMP_FOLDER + File.separator + getTestName(), _store);
+ fail("Exception should be thrown on attempt to call open method on a handler");
+ }
+ catch (IllegalStateException e)
+ {
+ // pass
+ }
+ }
+
+ public void testGetRootEntryWithEmptyOptions()
+ {
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ assertEquals("Unexpected children", Collections.singleton(_portEntryId), root.getChildrenIds());
+ }
+
+ public void testGetRootEntryWithHttpPortOverriden()
+ {
+ _options.setManagementModeHttpPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ Collection<UUID> childrenIds = root.getChildrenIds();
+ assertEquals("Unexpected children size", 2, childrenIds.size());
+ assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId));
+ }
+
+ public void testGetRootEntryWithRmiPortOverriden()
+ {
+ _options.setManagementModeRmiPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ Collection<UUID> childrenIds = root.getChildrenIds();
+ assertEquals("Unexpected children size", 3, childrenIds.size());
+ assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId));
+ }
+
+ public void testGetRootEntryWithConnectorPortOverriden()
+ {
+ _options.setManagementModeConnectorPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ Collection<UUID> childrenIds = root.getChildrenIds();
+ assertEquals("Unexpected children size", 2, childrenIds.size());
+ assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId));
+ }
+
+ public void testGetRootEntryWithManagementPortsOverriden()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _options.setManagementModeRmiPort(2000);
+ _options.setManagementModeConnectorPort(3000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ Collection<UUID> childrenIds = root.getChildrenIds();
+ assertEquals("Unexpected children size", 4, childrenIds.size());
+ assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId));
+ }
+
+ public void testGetEntryByRootId()
+ {
+ ConfigurationEntry root = _handler.getEntry(_rootId);
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ assertEquals("Unexpected children", Collections.singleton(_portEntryId), root.getChildrenIds());
+ }
+
+ public void testGetEntryByPortId()
+ {
+ ConfigurationEntry portEntry = _handler.getEntry(_portEntryId);
+ assertEquals("Unexpected entry id", _portEntryId, portEntry.getId());
+ assertTrue("Unexpected children", portEntry.getChildrenIds().isEmpty());
+ assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE));
+ }
+
+ public void testGetEntryByCLIConnectorPortId()
+ {
+ _options.setManagementModeConnectorPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ UUID optionsPort = getOptionsPortId();
+ ConfigurationEntry portEntry = _handler.getEntry(optionsPort);
+ assertCLIPortEntry(portEntry, optionsPort, Protocol.JMX_RMI);
+ }
+
+ public void testGetEntryByCLIHttpPortId()
+ {
+ _options.setManagementModeHttpPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ UUID optionsPort = getOptionsPortId();
+ ConfigurationEntry portEntry = _handler.getEntry(optionsPort);
+ assertCLIPortEntry(portEntry, optionsPort, Protocol.HTTP);
+ }
+
+ public void testHttpPortEntryIsQuiesced()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.HTTP));
+ when(_portEntry.getAttributes()).thenReturn(attributes);
+ _options.setManagementModeHttpPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ ConfigurationEntry portEntry = _handler.getEntry(_portEntryId);
+ assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE));
+ }
+
+ public void testRmiPortEntryIsQuiesced()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.RMI));
+ when(_portEntry.getAttributes()).thenReturn(attributes);
+ _options.setManagementModeRmiPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ ConfigurationEntry portEntry = _handler.getEntry(_portEntryId);
+ assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE));
+ }
+
+ public void testConnectorPortEntryIsQuiesced()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.JMX_RMI));
+ when(_portEntry.getAttributes()).thenReturn(attributes);
+ _options.setManagementModeRmiPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ ConfigurationEntry portEntry = _handler.getEntry(_portEntryId);
+ assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE));
+ }
+
+ public void testVirtualHostEntryIsQuiesced()
+ {
+ UUID virtualHostId = UUID.randomUUID();
+ ConfigurationEntry virtualHost = mock(ConfigurationEntry.class);
+ when(virtualHost.getId()).thenReturn(virtualHostId);
+ when(virtualHost.getType()).thenReturn(VirtualHost.class.getSimpleName());
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.CONFIG_PATH, "/path/to/host.xml");
+ when(virtualHost.getAttributes()).thenReturn(attributes);
+ when(_store.getEntry(virtualHostId)).thenReturn(virtualHost);
+ when(_root.getChildrenIds()).thenReturn(new HashSet<UUID>(Arrays.asList(_portEntryId, virtualHostId)));
+
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ ConfigurationEntry hostEntry = _handler.getEntry(virtualHostId);
+ Map<String, Object> hostAttributes = hostEntry.getAttributes();
+ assertEquals("Unexpected state", State.QUIESCED, hostAttributes.get(VirtualHost.STATE));
+ hostAttributes.remove(VirtualHost.STATE);
+ assertEquals("Unexpected attributes", attributes, hostAttributes);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void assertCLIPortEntry(ConfigurationEntry portEntry, UUID optionsPort, Protocol protocol)
+ {
+ assertEquals("Unexpected entry id", optionsPort, portEntry.getId());
+ assertTrue("Unexpected children", portEntry.getChildrenIds().isEmpty());
+ Map<String, Object> attributes = portEntry.getAttributes();
+ assertEquals("Unexpected name", "MANAGEMENT-MODE-PORT-" + protocol.name(), attributes.get(Port.NAME));
+ assertEquals("Unexpected protocol", Collections.singleton(protocol), new HashSet<Protocol>(
+ (Collection<Protocol>) attributes.get(Port.PROTOCOLS)));
+ }
+
+ public void testSavePort()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _options.setManagementModeRmiPort(2000);
+ _options.setManagementModeConnectorPort(3000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.NAME, "TEST");
+ ConfigurationEntry configurationEntry = new ConfigurationEntry(_portEntryId, Port.class.getSimpleName(), attributes,
+ Collections.<UUID> emptySet(), null);
+ _handler.save(configurationEntry);
+ verify(_store).save(any(ConfigurationEntry.class));
+ }
+
+ public void testSaveRoot()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _options.setManagementModeRmiPort(2000);
+ _options.setManagementModeConnectorPort(3000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ ConfigurationEntry root = _handler.getRootEntry();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Broker.NAME, "TEST");
+ ConfigurationEntry configurationEntry = new ConfigurationEntry(_rootId, Broker.class.getSimpleName(), attributes,
+ root.getChildrenIds(), null);
+ _handler.save(configurationEntry);
+ verify(_store).save(any(ConfigurationEntry.class));
+ }
+
+ public void testSaveCLIHttpPort()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ UUID portId = getOptionsPortId();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.NAME, "TEST");
+ ConfigurationEntry configurationEntry = new ConfigurationEntry(portId, Port.class.getSimpleName(), attributes,
+ Collections.<UUID> emptySet(), null);
+ try
+ {
+ _handler.save(configurationEntry);
+ fail("Exception should be thrown on trying to save CLI port");
+ }
+ catch (IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+ public void testRemove()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ _handler.remove(_portEntryId);
+ verify(_store).remove(_portEntryId);
+ }
+
+ public void testRemoveCLIPort()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ UUID portId = getOptionsPortId();
+ try
+ {
+ _handler.remove(portId);
+ fail("Exception should be thrown on trying to remove CLI port");
+ }
+ catch (IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+ private UUID getOptionsPortId()
+ {
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ Collection<UUID> childrenIds = root.getChildrenIds();
+
+ childrenIds.remove(_portEntryId);
+ UUID optionsPort = childrenIds.iterator().next();
+ return optionsPort;
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
new file mode 100644
index 0000000000..a77a0e9fcc
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
@@ -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);
+ }
+}