qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1588886 [4/6] - in /qpid/trunk/qpid/java: bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/ bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/jmx/ bdbstore/src/main/java/org/apache/qpid/server/store/b...
Date Mon, 21 Apr 2014 14:28:32 GMT
Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostCreationTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostCreationTest.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostCreationTest.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostCreationTest.java Mon Apr 21 14:28:29 2014
@@ -31,7 +31,6 @@ 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.logging.EventLogger;
 import org.apache.qpid.server.model.Broker;
@@ -41,41 +40,58 @@ import org.apache.qpid.server.model.Conf
 import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl;
 import org.apache.qpid.server.model.SystemContext;
 import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.VirtualHostNode;
 import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.store.DurableConfigurationStore;
 import org.apache.qpid.server.store.MessageStore;
 import org.apache.qpid.server.store.TestMemoryMessageStore;
+import org.apache.qpid.server.virtualhost.AbstractVirtualHost;
 import org.apache.qpid.server.virtualhost.StandardVirtualHost;
 
 public class VirtualHostCreationTest extends TestCase
 {
+    private VirtualHostNode<?> _virtualHostNode;
 
-    public void testCreateVirtualHostFromStoreConfigAttributes()
+    @Override
+    public void setUp() throws Exception
     {
+        super.setUp();
+
+        EventLogger eventLogger = mock(EventLogger.class);
         SecurityManager securityManager = mock(SecurityManager.class);
-        ConfigurationEntry entry = mock(ConfigurationEntry.class);
+
         SystemContext systemContext = mock(SystemContext.class);
         ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
         when(systemContext.getObjectFactory()).thenReturn(objectFactory);
         when(systemContext.getModel()).thenReturn(objectFactory.getModel());
+        when(systemContext.getEventLogger()).thenReturn(eventLogger);
 
-        Broker parent = mock(Broker.class);
-        when(parent.getObjectFactory()).thenReturn(objectFactory);
-        when(parent.getModel()).thenReturn(objectFactory.getModel());
-        when(parent.getSecurityManager()).thenReturn(securityManager);
-        when(parent.getCategoryClass()).thenReturn(Broker.class);
-        when(systemContext.getEventLogger()).thenReturn(mock(EventLogger.class));
-        when(parent.getParent(eq(SystemContext.class))).thenReturn(systemContext);
+        Broker broker = mock(Broker.class);
+        when(broker.getObjectFactory()).thenReturn(objectFactory);
+        when(broker.getModel()).thenReturn(objectFactory.getModel());
+        when(broker.getSecurityManager()).thenReturn(securityManager);
+        when(broker.getCategoryClass()).thenReturn(Broker.class);
+        when(broker.getParent(eq(SystemContext.class))).thenReturn(systemContext);
+
+        _virtualHostNode = mock(VirtualHostNode.class);
+        when(_virtualHostNode.getParent(Broker.class)).thenReturn(broker);
+        when(_virtualHostNode.getObjectFactory()).thenReturn(objectFactory);
+        when(_virtualHostNode.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
+        when(_virtualHostNode.getModel()).thenReturn(objectFactory.getModel());
+    }
 
+    public void testCreateVirtualHostFromStoreConfigAttributes()
+    {
         Map<String, Object> attributes = new HashMap<String, Object>();
         attributes.put(VirtualHost.NAME, getName());
         attributes.put(VirtualHost.TYPE, StandardVirtualHost.TYPE);
         attributes.put(VirtualHost.ID, UUID.randomUUID());
 
         attributes.put(VirtualHost.MESSAGE_STORE_SETTINGS, Collections.singletonMap(MessageStore.STORE_TYPE, TestMemoryMessageStore.TYPE));
-        when(entry.getAttributes()).thenReturn(attributes);
 
-        VirtualHost host = new StandardVirtualHost(attributes,parent);
+        VirtualHost<?,?,?> host = new StandardVirtualHost(attributes, _virtualHostNode);
         host.open();
+
         assertNotNull("Null is returned", host);
         assertEquals("Unexpected name", getName(), host.getName());
     }
@@ -94,19 +110,6 @@ public class VirtualHostCreationTest ext
 
     public void checkMandatoryAttributesAreValidated(String[] mandatoryAttributes, Map<String, Object> attributes)
     {
-        SecurityManager securityManager = mock(SecurityManager.class);
-        SystemContext systemContext = mock(SystemContext.class);
-        ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
-        when(systemContext.getObjectFactory()).thenReturn(objectFactory);
-        when(systemContext.getModel()).thenReturn(objectFactory.getModel());
-
-        Broker parent = mock(Broker.class);
-        when(parent.getSecurityManager()).thenReturn(securityManager);
-        when(parent.getParent(eq(SystemContext.class))).thenReturn(systemContext);
-        when(systemContext.getEventLogger()).thenReturn(mock(EventLogger.class));
-        when(parent.getObjectFactory()).thenReturn(objectFactory);
-        when(parent.getModel()).thenReturn(objectFactory.getModel());
-
         for (String name : mandatoryAttributes)
         {
             Map<String, Object> copy = new HashMap<String, Object>(attributes);
@@ -114,7 +117,7 @@ public class VirtualHostCreationTest ext
             copy.put(ConfiguredObject.ID, UUID.randomUUID());
             try
             {
-                VirtualHost host = new StandardVirtualHost(copy,parent);
+                AbstractVirtualHost<StandardVirtualHost> host = new StandardVirtualHost(copy,_virtualHostNode);
                 host.open();
                 fail("Cannot create a virtual host without a mandatory attribute " + name);
             }
@@ -126,7 +129,6 @@ public class VirtualHostCreationTest ext
             {
                 // pass
             }
-
         }
     }
 }

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java Mon Apr 21 14:28:29 2014
@@ -47,6 +47,7 @@ import org.apache.qpid.server.model.Syst
 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.model.VirtualHostNode;
 import org.apache.qpid.server.model.adapter.FileSystemPreferencesProvider;
 import org.apache.qpid.server.security.FileKeyStore;
 import org.apache.qpid.server.security.FileTrustStore;
@@ -60,11 +61,11 @@ public abstract class ConfigurationEntry
     private MemoryConfigurationEntryStore _store;
 
     private UUID _brokerId;
-    private UUID _virtualHostId;
+    private UUID _virtualHostNodeId;
     protected UUID _authenticationProviderId;
 
     private Map<String, Object> _brokerAttributes;
-    private Map<String, Object> _virtualHostAttributes;
+    private Map<String, Object> _virtualHostNodeAttributes;
     private Map<String, Object> _authenticationProviderAttributes;
 
     private TaskExecutor _taskExecutor;
@@ -90,10 +91,10 @@ public abstract class ConfigurationEntry
         _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.TYPE, "STANDARD");
+        _virtualHostNodeId = UUID.randomUUID();
+        _virtualHostNodeAttributes = new HashMap<String, Object>();
+        _virtualHostNodeAttributes.put(VirtualHost.NAME, "test");
+        _virtualHostNodeAttributes.put(VirtualHost.TYPE, "JSON");
 
         _authenticationProviderId = UUID.randomUUID();
         _authenticationProviderAttributes = new HashMap<String, Object>();
@@ -101,7 +102,7 @@ public abstract class ConfigurationEntry
         _authenticationProviderAttributes.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManager.class.getSimpleName());
 
         _store = createStore(_brokerId, _brokerAttributes);
-        addConfiguration(_virtualHostId, VirtualHost.class.getSimpleName(), _virtualHostAttributes);
+        addConfiguration(_virtualHostNodeId, VirtualHostNode.class.getSimpleName(), _virtualHostNodeAttributes);
         addConfiguration(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(), _authenticationProviderAttributes);
     }
 
@@ -282,18 +283,18 @@ public abstract class ConfigurationEntry
 
     public void testSaveExistingVirtualHost()
     {
-        ConfigurationEntry hostEntry = _store.getEntry(_virtualHostId);
+        ConfigurationEntry hostEntry = _store.getEntry(_virtualHostNodeId);
         assertNotNull("Host configuration is not found", hostEntry);
 
         Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
         virtualHostAttributes.put(VirtualHost.NAME, "test");
         virtualHostAttributes.put(VirtualHost.TYPE, "STANDARD");
 
-        ConfigurationEntry updatedEntry = new ConfigurationEntryImpl(_virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
+        ConfigurationEntry updatedEntry = new ConfigurationEntryImpl(_virtualHostNodeId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
                 hostEntry.getChildrenIds(), _store);
         _store.save(updatedEntry);
 
-        ConfigurationEntry newHostEntry = _store.getEntry(_virtualHostId);
+        ConfigurationEntry newHostEntry = _store.getEntry(_virtualHostNodeId);
         assertEquals("Unexpected virtual host configuration", updatedEntry, newHostEntry);
         assertEquals("Unexpected type", VirtualHost.class.getSimpleName(), newHostEntry.getType());
         assertEquals("Unexpected virtual host attributes", updatedEntry.getAttributes(), newHostEntry.getAttributes());

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java Mon Apr 21 14:28:29 2014
@@ -32,9 +32,9 @@ import java.util.UUID;
 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.server.model.VirtualHostNode;
 import org.apache.qpid.server.store.ConfiguredObjectRecord;
 import org.apache.qpid.test.utils.QpidTestCase;
 
@@ -82,13 +82,13 @@ public class StoreConfigurationChangeLis
         verify(_store).update(eq(false),any(ConfiguredObjectRecord.class));
     }
 
-    public void testChildAddedForVirtualHost()
+    public void testChildAddedForVirtualHostNode()
     {
         notifyBrokerStarted();
 
-        VirtualHost object = mock(VirtualHost.class);
-        Queue queue = mock(Queue.class);
-        _listener.childAdded(object, queue);
+        VirtualHostNode<?> object = mock(VirtualHostNode.class);
+        VirtualHost<?,?,?> virtualHost = mock(VirtualHost.class);
+        _listener.childAdded(object, virtualHost);
         verifyNoMoreInteractions(_store);
     }
 

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java Mon Apr 21 14:28:29 2014
@@ -23,15 +23,13 @@ package org.apache.qpid.server.logging.a
 import org.apache.qpid.server.logging.EventLogger;
 import org.apache.qpid.server.logging.LogMessage;
 import org.apache.qpid.server.logging.LogSubject;
-import org.apache.qpid.server.logging.MessageLogger;
 import org.apache.qpid.server.logging.UnitTestMessageLogger;
 import org.apache.qpid.test.utils.QpidTestCase;
 
-public class BaseActorTestCase extends QpidTestCase
+public abstract class BaseActorTestCase extends QpidTestCase
 {
     private boolean _statusUpdatesEnabled = true;
     private UnitTestMessageLogger _rawLogger;
-    private MessageLogger _rootLogger;
     private EventLogger _eventLogger;
 
     @Override
@@ -40,7 +38,6 @@ public class BaseActorTestCase extends Q
         super.setUp();
         _rawLogger = new UnitTestMessageLogger(_statusUpdatesEnabled);
         _eventLogger = new EventLogger(_rawLogger);
-        _rootLogger = _rawLogger;
     }
 
     @Override
@@ -57,10 +54,10 @@ public class BaseActorTestCase extends Q
     {
         String message = "Test logging: " + getName();
         sendTestLogMessage(message);
-        
+
         return message;
     }
-    
+
     public void sendTestLogMessage(final String message)
     {
         getEventLogger().message(new LogSubject()

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java Mon Apr 21 14:28:29 2014
@@ -25,7 +25,7 @@ import org.apache.qpid.server.protocol.A
 import org.apache.qpid.server.util.BrokerTestHelper;
 import org.apache.qpid.server.virtualhost.VirtualHostImpl;
 
-public class BaseConnectionActorTestCase extends BaseActorTestCase
+public abstract class BaseConnectionActorTestCase extends BaseActorTestCase
 {
     private AMQConnectionModel _session;
     private VirtualHostImpl _virtualHost;

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java Mon Apr 21 14:28:29 2014
@@ -28,9 +28,8 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 
-import org.apache.qpid.server.configuration.RecovererProvider;
 import org.apache.qpid.server.configuration.updater.TaskExecutor;
-import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.store.DurableConfigurationStore;
 import org.apache.qpid.server.store.MessageStore;
 import org.apache.qpid.server.store.TestMemoryMessageStore;
 import org.apache.qpid.server.util.BrokerTestHelper;
@@ -39,11 +38,9 @@ import org.apache.qpid.test.utils.QpidTe
 
 public class VirtualHostTest extends QpidTestCase
 {
-
     private Broker _broker;
-    private StatisticsGatherer _statisticsGatherer;
-    private RecovererProvider _recovererProvider;
     private TaskExecutor _taskExecutor;
+    private VirtualHostNode<?> _virtualHostNode;
 
     @Override
     protected void setUp() throws Exception
@@ -55,8 +52,12 @@ public class VirtualHostTest extends Qpi
         _taskExecutor.start();
         when(_broker.getTaskExecutor()).thenReturn(_taskExecutor);
 
-        _recovererProvider = mock(RecovererProvider.class);
-        _statisticsGatherer = mock(StatisticsGatherer.class);
+        _virtualHostNode = mock(VirtualHostNode.class);
+        when(_virtualHostNode.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
+        when(_virtualHostNode.getParent(Broker.class)).thenReturn(_broker);
+        ConfiguredObjectFactory objectFactory = _broker.getObjectFactory();
+        when(_virtualHostNode.getModel()).thenReturn(objectFactory.getModel());
+        when(_virtualHostNode.getObjectFactory()).thenReturn(objectFactory);
     }
 
 
@@ -69,26 +70,26 @@ public class VirtualHostTest extends Qpi
 
     public void testInitialisingState()
     {
-        VirtualHost host = createHost();
+        VirtualHost<?,?,?> host = createHost();
 
         assertEquals("Unexpected state", State.INITIALISING, host.getAttribute(VirtualHost.STATE));
     }
 
     public void testActiveState()
     {
-        VirtualHost host = createHost();
+        VirtualHost<?,?,?> host = createHost();
+
 
         host.setDesiredState(State.INITIALISING, State.ACTIVE);
-        host.open();
         assertEquals("Unexpected state", State.ACTIVE, host.getAttribute(VirtualHost.STATE));
     }
 
     public void testStoppedState()
     {
-        VirtualHost host = createHost();
+        VirtualHost<?,?,?> host = createHost();
 
         assertEquals("Unexpected state", State.INITIALISING, host.getAttribute(VirtualHost.STATE));
-        host.open();
+
         host.setDesiredState(State.INITIALISING, State.ACTIVE);
         assertEquals("Unexpected state", State.ACTIVE, host.getAttribute(VirtualHost.STATE));
 
@@ -98,7 +99,7 @@ public class VirtualHostTest extends Qpi
 
     public void testDeletedState()
     {
-        VirtualHost host = createHost();
+        VirtualHost<?,?,?> host = createHost();
 
         assertEquals("Unexpected state", State.INITIALISING, host.getAttribute(VirtualHost.STATE));
 
@@ -108,8 +109,8 @@ public class VirtualHostTest extends Qpi
 
     public void testCreateQueueChildHavingMessageGroupingAttributes()
     {
-        VirtualHost host = createHost();
-        host.open();
+        VirtualHost<?,?,?> host = createHost();
+
         host.setDesiredState(State.INITIALISING, State.ACTIVE);
 
         String queueName = getTestName();
@@ -120,7 +121,7 @@ public class VirtualHostTest extends Qpi
 
         host.createChild(Queue.class, arguments);
 
-        Queue queue = (Queue) ConfiguredObjectFinder.findConfiguredObjectByName(host.getQueues(), queueName);
+        Queue<?> queue = (Queue<?>) ConfiguredObjectFinder.findConfiguredObjectByName(host.getQueues(), queueName);
         Object messageGroupKey = queue.getAttribute(Queue.MESSAGE_GROUP_KEY);
         assertEquals("Unexpected message group key attribute", "mykey", messageGroupKey);
 
@@ -129,22 +130,24 @@ public class VirtualHostTest extends Qpi
 
     }
 
-    private VirtualHost createHost()
+    private VirtualHost<?,?,?> createHost()
     {
         Map<String, Object> attributes = new HashMap<String, Object>();
         attributes.put(VirtualHost.NAME, getName());
         attributes.put(VirtualHost.TYPE, StandardVirtualHost.TYPE);
         attributes.put(VirtualHost.MESSAGE_STORE_SETTINGS, Collections.singletonMap(MessageStore.STORE_TYPE, TestMemoryMessageStore.TYPE));
 
-        VirtualHost host = createHost(attributes);
+        VirtualHost<?,?,?> host = createHost(attributes);
         return host;
     }
 
-    private VirtualHost createHost(Map<String, Object> attributes)
+    private VirtualHost<?,?,?> createHost(Map<String, Object> attributes)
     {
         attributes = new HashMap<String, Object>(attributes);
         attributes.put(VirtualHost.ID, UUID.randomUUID());
-        return new StandardVirtualHost(attributes, _broker);
+        StandardVirtualHost host= new StandardVirtualHost(attributes, _virtualHostNode);
+        host.create();
+        return host;
     }
 
 }

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java Mon Apr 21 14:28:29 2014
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.verify
 import static org.mockito.Mockito.when;
 
 import java.io.File;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -37,7 +38,6 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.ArgumentMatcher;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
-
 import org.apache.qpid.common.AMQPFilterTypes;
 import org.apache.qpid.server.binding.BindingImpl;
 import org.apache.qpid.server.exchange.ExchangeImpl;
@@ -51,6 +51,7 @@ import org.apache.qpid.server.model.Excl
 import org.apache.qpid.server.model.LifetimePolicy;
 import org.apache.qpid.server.model.Queue;
 import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.model.VirtualHost;
 import org.apache.qpid.server.plugin.ExchangeType;
 import org.apache.qpid.server.queue.AMQQueue;
 import org.apache.qpid.server.security.SecurityManager;
@@ -86,6 +87,10 @@ public abstract class AbstractDurableCon
     protected Map<String, Object> _configurationStoreSettings;
     private ConfiguredObjectFactoryImpl _factory;
 
+    private ConfiguredObject<?> _parent;
+
+    private ConfiguredObjectRecord _rootRecord;
+
     public void setUp() throws Exception
     {
         super.setUp();
@@ -108,7 +113,16 @@ public abstract class AbstractDurableCon
         String argValue = "some selector expression";
         _bindingArgs.put(argKey, argValue);
 
-        reopenStore();
+
+        _parent = mock(ConfiguredObject.class);
+        when(_parent.getName()).thenReturn("testName");
+        when(_parent.getObjectFactory()).thenReturn(_factory);
+        when(_parent.getModel()).thenReturn(_factory.getModel());
+
+        _configStore = createConfigStore();
+        _configStore.openConfigurationStore(_parent, _configurationStoreSettings);
+        _rootRecord = new ConfiguredObjectRecordImpl(UUID.randomUUID(), VirtualHost.class.getSimpleName(), Collections.<String, Object>emptyMap());
+        _configStore.create(_rootRecord);
     }
 
     public void tearDown() throws Exception
@@ -130,6 +144,8 @@ public abstract class AbstractDurableCon
         _configStore.create(exchange.asObjectRecord());
 
         reopenStore();
+        _configStore.visitConfiguredObjectRecords(_handler);
+
         verify(_handler).handle(matchesRecord(_exchangeId, EXCHANGE,
                 map( org.apache.qpid.server.model.Exchange.NAME, getName(),
                         org.apache.qpid.server.model.Exchange.TYPE, getName()+"Type",
@@ -178,6 +194,7 @@ public abstract class AbstractDurableCon
         _configStore.create(binding.asObjectRecord());
 
         reopenStore();
+        _configStore.visitConfiguredObjectRecords(_handler);
 
         Map<String,Object> map = new HashMap<String, Object>();
         map.put(Binding.NAME, ROUTING_KEY);
@@ -280,6 +297,8 @@ public abstract class AbstractDurableCon
         _configStore.create(queue.asObjectRecord());
 
         reopenStore();
+        _configStore.visitConfiguredObjectRecords(_handler);
+
         Map<String, Object> queueAttributes = new HashMap<String, Object>();
         queueAttributes.put(Queue.NAME, getName());
         queueAttributes.put(Queue.OWNER, getName()+"Owner");
@@ -297,7 +316,7 @@ public abstract class AbstractDurableCon
         _configStore.create(queue.asObjectRecord());
 
         reopenStore();
-
+        _configStore.visitConfiguredObjectRecords(_handler);
 
         Map<String,Object> queueAttributes = new HashMap<String, Object>();
 
@@ -317,6 +336,7 @@ public abstract class AbstractDurableCon
         _configStore.create(queue.asObjectRecord());
 
         reopenStore();
+        _configStore.visitConfiguredObjectRecords(_handler);
 
         Map<String, Object> queueAttributes = new HashMap<String, Object>();
         queueAttributes.put(Queue.NAME, getName());
@@ -351,6 +371,7 @@ public abstract class AbstractDurableCon
         _configStore.update(false, queue.asObjectRecord());
 
         reopenStore();
+        _configStore.visitConfiguredObjectRecords(_handler);
 
         Map<String,Object> queueAttributes = new HashMap<String, Object>();
 
@@ -377,6 +398,7 @@ public abstract class AbstractDurableCon
         _configStore.update(false, queue.asObjectRecord());
 
         reopenStore();
+        _configStore.visitConfiguredObjectRecords(_handler);
 
         Map<String,Object> queueAttributes = new HashMap<String, Object>();
 
@@ -461,6 +483,7 @@ public abstract class AbstractDurableCon
         when(objectRecord.getId()).thenReturn(_queueId);
         when(objectRecord.getType()).thenReturn(Queue.class.getSimpleName());
         when(objectRecord.getAttributes()).thenReturn(attributes);
+        when(objectRecord.getParents()).thenReturn(Collections.singletonMap(_rootRecord.getType(), _rootRecord));
         when(queue.asObjectRecord()).thenReturn(objectRecord);
         return queue;
     }
@@ -485,6 +508,7 @@ public abstract class AbstractDurableCon
         when(exchangeRecord.getId()).thenReturn(_exchangeId);
         when(exchangeRecord.getType()).thenReturn(Exchange.class.getSimpleName());
         when(exchangeRecord.getAttributes()).thenReturn(actualAttributes);
+        when(exchangeRecord.getParents()).thenReturn(Collections.singletonMap(_rootRecord.getType(), _rootRecord));
         when(exchange.asObjectRecord()).thenReturn(exchangeRecord);
         when(exchange.getExchangeType()).thenReturn(mock(ExchangeType.class));
         when(exchange.getEventLogger()).thenReturn(new EventLogger());
@@ -495,14 +519,7 @@ public abstract class AbstractDurableCon
     {
         closeConfigStore();
         _configStore = createConfigStore();
-
-        ConfiguredObject<?> parent = mock(ConfiguredObject.class);
-        when(parent.getName()).thenReturn("testName");
-
-        when(parent.getObjectFactory()).thenReturn(_factory);
-        when(parent.getModel()).thenReturn(_factory.getModel());
-        _configStore.openConfigurationStore(parent, _configurationStoreSettings);
-        _configStore.visitConfiguredObjectRecords(_handler);
+        _configStore.openConfigurationStore(_parent, _configurationStoreSettings);
     }
 
     protected abstract DurableConfigurationStore createConfigStore() throws Exception;

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/JsonFileConfigStoreTest.java Mon Apr 21 14:28:29 2014
@@ -24,7 +24,6 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.argThat;
 import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -35,9 +34,6 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 
-import org.mockito.ArgumentMatcher;
-import org.mockito.InOrder;
-
 import org.apache.qpid.server.model.BrokerModel;
 import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.server.model.ConfiguredObjectFactory;
@@ -48,29 +44,34 @@ import org.apache.qpid.server.util.Serve
 import org.apache.qpid.test.utils.QpidTestCase;
 import org.apache.qpid.test.utils.TestFileUtils;
 import org.apache.qpid.util.FileUtils;
+import org.mockito.ArgumentMatcher;
+import org.mockito.InOrder;
 
 public class JsonFileConfigStoreTest extends QpidTestCase
 {
     private JsonFileConfigStore _store;
     private HashMap<String, Object> _configurationStoreSettings;
-    private ConfiguredObject<?> _virtualHost;
+    private ConfiguredObject<?> _parent;
     private File _storeLocation;
     private ConfiguredObjectRecordHandler _handler;
 
 
     private static final UUID ANY_UUID = UUID.randomUUID();
     private static final Map<String, Object> ANY_MAP = new HashMap<String, Object>();
+    private static final String VIRTUAL_HOST_TYPE = "VirtualHost";
+    private ConfiguredObjectRecord _rootRecord;
 
     @Override
     public void setUp() throws Exception
     {
         super.setUp();
 
-        _virtualHost = mock(ConfiguredObject.class);
-        when(_virtualHost.getName()).thenReturn(getName());
         ConfiguredObjectFactory factory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
-        when(_virtualHost.getObjectFactory()).thenReturn(factory);
-        when(_virtualHost.getModel()).thenReturn(factory.getModel());
+
+        _parent = mock(ConfiguredObject.class);
+        when(_parent.getName()).thenReturn(getName());
+        when(_parent.getObjectFactory()).thenReturn(factory);
+        when(_parent.getModel()).thenReturn(factory.getModel());
         _storeLocation = TestFileUtils.createTestDirectory("json", true);
         _configurationStoreSettings = new HashMap<String, Object>();
         _configurationStoreSettings.put(JsonFileConfigStore.STORE_TYPE, JsonFileConfigStore.TYPE);
@@ -99,7 +100,7 @@ public class JsonFileConfigStoreTest ext
         _configurationStoreSettings.put(JsonFileConfigStore.STORE_PATH, null);
         try
         {
-            _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+            _store.openConfigurationStore(_parent, _configurationStoreSettings);
             fail("Store should not successfully configure if there is no path set");
         }
         catch (ServerScopedRuntimeException e)
@@ -114,7 +115,7 @@ public class JsonFileConfigStoreTest ext
         _configurationStoreSettings.put(JsonFileConfigStore.STORE_PATH, System.getProperty("file.separator"));
         try
         {
-            _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+            _store.openConfigurationStore(_parent, _configurationStoreSettings);
             fail("Store should not successfully configure if there is an invalid path set");
         }
         catch (ServerScopedRuntimeException e)
@@ -125,50 +126,76 @@ public class JsonFileConfigStoreTest ext
 
     public void testVisitEmptyStore()
     {
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
         _store.visitConfiguredObjectRecords(_handler);
 
         InOrder inorder = inOrder(_handler);
         inorder.verify(_handler).begin();
-        inorder.verify(_handler,never()).handle(any(ConfiguredObjectRecord.class));
+        inorder.verify(_handler,times(0)).handle(any(ConfiguredObjectRecord.class));
         inorder.verify(_handler).end();
+
+        _store.closeConfigurationStore();
+    }
+
+    public void testInsertAndUpdateTopLevelObject() throws Exception
+    {
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
+        createRootRecord();
+        _store.closeConfigurationStore();
+
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
+        Map<String, Object> newAttributes = new HashMap<String, Object>(_rootRecord.getAttributes());
+        newAttributes.put("attributeName", "attributeValue");
+        _store.update(false, new ConfiguredObjectRecordImpl(_rootRecord.getId(), _rootRecord.getType(), newAttributes));
+        _store.closeConfigurationStore();
+
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
+
+        _store.visitConfiguredObjectRecords(_handler);
+
+        Map<String, Object> expectedAttributes = new HashMap<String, Object>(newAttributes);
+        verify(_handler, times(1)).handle(matchesRecord(_rootRecord.getId(), _rootRecord.getType(), expectedAttributes));
         _store.closeConfigurationStore();
     }
 
     public void testCreateObject() throws Exception
     {
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
+        createRootRecord();
+
         final UUID queueId = new UUID(0, 1);
         final String queueType = Queue.class.getSimpleName();
         final Map<String,Object> queueAttr = Collections.singletonMap("name", (Object) "q1");
 
-        _store.create(new ConfiguredObjectRecordImpl(queueId, queueType, queueAttr));
+        _store.create(new ConfiguredObjectRecordImpl(queueId, queueType, queueAttr, getRootAsParentMap()));
         _store.closeConfigurationStore();
 
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
 
         _store.visitConfiguredObjectRecords(_handler);
-        verify(_handler, times(1)).handle(matchesRecord(queueId, queueType, queueAttr));
+        verify(_handler).handle(matchesRecord(queueId, queueType, queueAttr));
+        verify(_handler).handle(matchesRecord(ANY_UUID, VIRTUAL_HOST_TYPE, ANY_MAP));
         _store.closeConfigurationStore();
     }
 
     public void testCreateAndUpdateObject() throws Exception
     {
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
+        createRootRecord();
+
         final UUID queueId = new UUID(0, 1);
         final String queueType = Queue.class.getSimpleName();
         Map<String,Object> queueAttr = Collections.singletonMap("name", (Object) "q1");
 
-        _store.create(new ConfiguredObjectRecordImpl(queueId, queueType, queueAttr));
-
+        _store.create(new ConfiguredObjectRecordImpl(queueId, queueType, queueAttr, getRootAsParentMap()));
 
         queueAttr = new HashMap<String,Object>(queueAttr);
         queueAttr.put("owner", "theowner");
-        _store.update(false, new ConfiguredObjectRecordImpl(queueId, queueType, queueAttr));
+        _store.update(false, new ConfiguredObjectRecordImpl(queueId, queueType, queueAttr, getRootAsParentMap()));
 
         _store.closeConfigurationStore();
 
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
         _store.visitConfiguredObjectRecords(_handler);
         verify(_handler, times(1)).handle(matchesRecord(queueId, queueType, queueAttr));
         _store.closeConfigurationStore();
@@ -177,12 +204,14 @@ public class JsonFileConfigStoreTest ext
 
     public void testCreateAndRemoveObject() throws Exception
     {
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
+        createRootRecord();
+
         final UUID queueId = new UUID(0, 1);
         final String queueType = Queue.class.getSimpleName();
         Map<String,Object> queueAttr = Collections.singletonMap("name", (Object) "q1");
 
-        final ConfiguredObjectRecordImpl record = new ConfiguredObjectRecordImpl(queueId, queueType, queueAttr);
+        final ConfiguredObjectRecordImpl record = new ConfiguredObjectRecordImpl(queueId, queueType, queueAttr, getRootAsParentMap());
         _store.create(record);
 
 
@@ -190,18 +219,20 @@ public class JsonFileConfigStoreTest ext
 
         _store.closeConfigurationStore();
 
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
         _store.visitConfiguredObjectRecords(_handler);
-        verify(_handler, never()).handle(any(ConfiguredObjectRecord.class));
+        verify(_handler, times(1)).handle(matchesRecord(ANY_UUID, VIRTUAL_HOST_TYPE, ANY_MAP));
         _store.closeConfigurationStore();
     }
 
     public void testCreateUnknownObjectType() throws Exception
     {
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
+        createRootRecord();
+
         try
         {
-            _store.create(new ConfiguredObjectRecordImpl(UUID.randomUUID(), "wibble", Collections.<String, Object>emptyMap()));
+            _store.create(new ConfiguredObjectRecordImpl(UUID.randomUUID(), "wibble", Collections.<String, Object>emptyMap(), getRootAsParentMap()));
             fail("Should not be able to create instance of type wibble");
         }
         catch (StoreException e)
@@ -212,12 +243,14 @@ public class JsonFileConfigStoreTest ext
 
     public void testTwoObjectsWithSameId() throws Exception
     {
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
+        createRootRecord();
+
         final UUID id = UUID.randomUUID();
-        _store.create(new ConfiguredObjectRecordImpl(id, "Queue", Collections.<String, Object>emptyMap()));
+        _store.create(new ConfiguredObjectRecordImpl(id, "Queue", Collections.<String, Object>emptyMap(), getRootAsParentMap()));
         try
         {
-            _store.create(new ConfiguredObjectRecordImpl(id, "Exchange", Collections.<String, Object>emptyMap()));
+            _store.create(new ConfiguredObjectRecordImpl(id, "Exchange", Collections.<String, Object>emptyMap(), getRootAsParentMap()));
             fail("Should not be able to create two objects with same id");
         }
         catch (StoreException e)
@@ -229,15 +262,17 @@ public class JsonFileConfigStoreTest ext
 
     public void testChangeTypeOfObject() throws Exception
     {
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
+        createRootRecord();
+
         final UUID id = UUID.randomUUID();
-        _store.create(new ConfiguredObjectRecordImpl(id, "Queue", Collections.<String, Object>emptyMap()));
+        _store.create(new ConfiguredObjectRecordImpl(id, "Queue", Collections.<String, Object>emptyMap(), getRootAsParentMap()));
         _store.closeConfigurationStore();
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
 
         try
         {
-            _store.update(false, new ConfiguredObjectRecordImpl(id, "Exchange", Collections.<String, Object>emptyMap()));
+            _store.update(false, new ConfiguredObjectRecordImpl(id, "Exchange", Collections.<String, Object>emptyMap(), getRootAsParentMap()));
             fail("Should not be able to update object to different type");
         }
         catch (StoreException e)
@@ -248,13 +283,13 @@ public class JsonFileConfigStoreTest ext
 
     public void testLockFileGuaranteesExclusiveAccess() throws Exception
     {
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
 
         JsonFileConfigStore secondStore = new JsonFileConfigStore();
 
         try
         {
-            secondStore.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+            secondStore.openConfigurationStore(_parent, _configurationStoreSettings);
             fail("Should not be able to open a second store with the same path");
         }
         catch(ServerScopedRuntimeException e)
@@ -262,15 +297,16 @@ public class JsonFileConfigStoreTest ext
             // pass
         }
         _store.closeConfigurationStore();
-        secondStore.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        secondStore.openConfigurationStore(_parent, _configurationStoreSettings);
 
 
     }
 
     public void testCreatedNestedObjects() throws Exception
     {
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
+        createRootRecord();
 
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
         final UUID queueId = new UUID(0, 1);
         final UUID queue2Id = new UUID(1, 1);
 
@@ -280,11 +316,12 @@ public class JsonFileConfigStoreTest ext
         final UUID bindingId = new UUID(0, 3);
         final UUID binding2Id = new UUID(1, 3);
 
-        final ConfiguredObjectRecordImpl queueRecord = new ConfiguredObjectRecordImpl(queueId, "Queue", EMPTY_ATTR);
+        Map<String, ConfiguredObjectRecord> parents = getRootAsParentMap();
+        final ConfiguredObjectRecordImpl queueRecord = new ConfiguredObjectRecordImpl(queueId, "Queue", EMPTY_ATTR, parents);
         _store.create(queueRecord);
-        final ConfiguredObjectRecordImpl queue2Record = new ConfiguredObjectRecordImpl(queue2Id, "Queue", EMPTY_ATTR);
+        final ConfiguredObjectRecordImpl queue2Record = new ConfiguredObjectRecordImpl(queue2Id, "Queue", EMPTY_ATTR, parents);
         _store.create(queue2Record);
-        final ConfiguredObjectRecordImpl exchangeRecord = new ConfiguredObjectRecordImpl(exchangeId, "Exchange", EMPTY_ATTR);
+        final ConfiguredObjectRecordImpl exchangeRecord = new ConfiguredObjectRecordImpl(exchangeId, "Exchange", EMPTY_ATTR, parents);
         _store.create(exchangeRecord);
         Map<String,ConfiguredObjectRecord> bindingParents = new HashMap<String, ConfiguredObjectRecord>();
         bindingParents.put("Exchange", exchangeRecord);
@@ -300,7 +337,7 @@ public class JsonFileConfigStoreTest ext
                 new ConfiguredObjectRecordImpl(binding2Id, "Binding", EMPTY_ATTR, binding2Parents);
         _store.update(true, bindingRecord, binding2Record);
         _store.closeConfigurationStore();
-        _store.openConfigurationStore(_virtualHost, _configurationStoreSettings);
+        _store.openConfigurationStore(_parent, _configurationStoreSettings);
         _store.visitConfiguredObjectRecords(_handler);
         verify(_handler).handle(matchesRecord(queueId, "Queue", EMPTY_ATTR));
         verify(_handler).handle(matchesRecord(queue2Id, "Queue", EMPTY_ATTR));
@@ -311,22 +348,36 @@ public class JsonFileConfigStoreTest ext
 
     }
 
+
+    private void createRootRecord()
+    {
+        UUID rootRecordId = UUID.randomUUID();
+        _rootRecord = new ConfiguredObjectRecordImpl(rootRecordId, VIRTUAL_HOST_TYPE, Collections.<String, Object>emptyMap());
+        _store.create(_rootRecord);
+    }
+
+    private Map<String, ConfiguredObjectRecord> getRootAsParentMap()
+    {
+        return Collections.<String, ConfiguredObjectRecord>singletonMap(VIRTUAL_HOST_TYPE, _rootRecord);
+    }
+
     private ConfiguredObjectRecord matchesRecord(UUID id, String type, Map<String, Object> attributes)
     {
         return argThat(new ConfiguredObjectMatcher(id, type, attributes));
     }
 
+
     private static class ConfiguredObjectMatcher extends ArgumentMatcher<ConfiguredObjectRecord>
     {
-        private final Map<String,Object> _matchingMap;
-        private final UUID _id;
-        private final String _name;
+        private final Map<String,Object> _expectedAttributes;
+        private final UUID _expectedId;
+        private final String _expectedType;
 
         private ConfiguredObjectMatcher(final UUID id, final String type, final Map<String, Object> matchingMap)
         {
-            _id = id;
-            _name = type;
-            _matchingMap = matchingMap;
+            _expectedId = id;
+            _expectedType = type;
+            _expectedAttributes = matchingMap;
         }
 
         @Override
@@ -339,9 +390,9 @@ public class JsonFileConfigStoreTest ext
                 Map<String,Object> arg = new HashMap<String, Object>(binding.getAttributes());
                 arg.remove("createdBy");
                 arg.remove("createdTime");
-                return (_id == ANY_UUID || _id.equals(binding.getId()))
-                       && _name.equals(binding.getType())
-                       && (_matchingMap == ANY_MAP || arg.equals(_matchingMap));
+                return (_expectedId == ANY_UUID || _expectedId.equals(binding.getId()))
+                       && _expectedType.equals(binding.getType())
+                       && (_expectedAttributes == ANY_MAP || arg.equals(_expectedAttributes));
 
             }
             return false;

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMemoryMessageStoreFactory.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMemoryMessageStoreFactory.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMemoryMessageStoreFactory.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/TestMemoryMessageStoreFactory.java Mon Apr 21 14:28:29 2014
@@ -23,9 +23,10 @@ package org.apache.qpid.server.store;
 
 import java.util.Map;
 
+import org.apache.qpid.server.plugin.DurableConfigurationStoreFactory;
 import org.apache.qpid.server.plugin.MessageStoreFactory;
 
-public class TestMemoryMessageStoreFactory implements MessageStoreFactory
+public class TestMemoryMessageStoreFactory implements MessageStoreFactory, DurableConfigurationStoreFactory
 {
 
     @Override
@@ -44,4 +45,15 @@ public class TestMemoryMessageStoreFacto
     public void validateAttributes(Map<String, Object> attributes)
     {
     }
+
+    @Override
+    public DurableConfigurationStore createDurableConfigurationStore()
+    {
+        return new TestMemoryMessageStore();
+    }
+
+    @Override
+    public void validateConfigurationStoreSettings(Map<String, Object> attributes)
+    {
+    }
 }

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java Mon Apr 21 14:28:29 2014
@@ -21,7 +21,6 @@
 package org.apache.qpid.server.util;
 
 import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -50,6 +49,7 @@ import org.apache.qpid.server.model.Syst
 import org.apache.qpid.server.model.SystemContextImpl;
 import org.apache.qpid.server.model.UUIDGenerator;
 import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.VirtualHostNode;
 import org.apache.qpid.server.protocol.AMQConnectionModel;
 import org.apache.qpid.server.protocol.AMQSessionModel;
 import org.apache.qpid.server.queue.AMQQueue;
@@ -75,29 +75,31 @@ public class BrokerTestHelper
         TASK_EXECUTOR.start();
     }
 
-    public static Broker createBrokerMock()
+    public static Broker<?> createBrokerMock()
     {
         ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
-        SubjectCreator subjectCreator = mock(SubjectCreator.class);
+        EventLogger eventLogger = new EventLogger();
+
+        SystemContext systemContext = mock(SystemContext.class);
+        when(systemContext.getEventLogger()).thenReturn(eventLogger);
+        when(systemContext.getObjectFactory()).thenReturn(objectFactory);
+        when(systemContext.getModel()).thenReturn(objectFactory.getModel());
+        when(systemContext.getCategoryClass()).thenReturn(SystemContext.class);
 
+        SubjectCreator subjectCreator = mock(SubjectCreator.class);
         when(subjectCreator.getMechanisms()).thenReturn("");
+
         Broker broker = mock(Broker.class);
         when(broker.getConnection_sessionCountLimit()).thenReturn(1);
         when(broker.getConnection_closeWhenNoRoute()).thenReturn(false);
         when(broker.getId()).thenReturn(UUID.randomUUID());
         when(broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(subjectCreator);
-        when(broker.getSecurityManager()).thenReturn(new SecurityManager(mock(Broker.class), false));
+        when(broker.getSecurityManager()).thenReturn(new SecurityManager(broker, false));
         when(broker.getObjectFactory()).thenReturn(objectFactory);
         when(broker.getModel()).thenReturn(objectFactory.getModel());
-        when(broker.getEventLogger()).thenReturn(new EventLogger());
+        when(broker.getEventLogger()).thenReturn(eventLogger);
         when(broker.getCategoryClass()).thenReturn(Broker.class);
-
-        SystemContext systemContext = mock(SystemContext.class);
-        when(systemContext.getObjectFactory()).thenReturn(objectFactory);
-        when(systemContext.getModel()).thenReturn(objectFactory.getModel());
-        when(systemContext.getCategoryClass()).thenReturn(SystemContext.class);
-        when(systemContext.getEventLogger()).thenReturn(new EventLogger());
-        when(broker.getParent(eq(SystemContext.class))).thenReturn(systemContext);
+        when(broker.getParent(SystemContext.class)).thenReturn(systemContext);
 
         return broker;
     }
@@ -110,34 +112,33 @@ public class BrokerTestHelper
     {
     }
 
-    public static VirtualHostImpl createVirtualHost(Map<String, Object> attributes)
+    public static VirtualHostImpl<?,?,?> createVirtualHost(Map<String, Object> attributes)
             throws Exception
     {
 
         //VirtualHostFactory factory = new PluggableFactoryLoader<VirtualHostFactory>(VirtualHostFactory.class).get(hostType);
+        Broker<?> broker = createBrokerMock();
+        ConfiguredObjectFactory objectFactory = broker.getObjectFactory();
         SystemContext systemContext = new SystemContextImpl(TASK_EXECUTOR,
-                                                            new ConfiguredObjectFactoryImpl(BrokerModel.getInstance()),
+                                                            objectFactory,
                                                             mock(EventLogger.class),
                                                             mock(LogRecorder.class),
                                                             new BrokerOptions());
-        ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
-        Broker broker = mock(Broker.class);
-        when(broker.getParent(eq(SystemContext.class))).thenReturn(systemContext);
         when(broker.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
-        SecurityManager securityManager = new SecurityManager(broker, false);
-        when(broker.getSecurityManager()).thenReturn(securityManager);
-        when(broker.getCategoryClass()).thenReturn(Broker.class);
-        when(broker.getObjectFactory()).thenReturn(objectFactory);
-        when(broker.getModel()).thenReturn(objectFactory.getModel());
-
-        AbstractVirtualHost host = (AbstractVirtualHost) objectFactory.create(VirtualHost.class,attributes, broker);
 
+        VirtualHostNode<?> virtualHostNode = mock(VirtualHostNode.class);
+        DurableConfigurationStore dcs = mock(DurableConfigurationStore.class);
+        when(virtualHostNode.getConfigurationStore()).thenReturn(dcs);
+        when(virtualHostNode.getParent(Broker.class)).thenReturn(broker);
+        when(virtualHostNode.getModel()).thenReturn(objectFactory.getModel());
+        when(virtualHostNode.getObjectFactory()).thenReturn(objectFactory);
+        AbstractVirtualHost host = (AbstractVirtualHost) objectFactory.create(VirtualHost.class, attributes, virtualHostNode );
         host.setDesiredState(host.getState(), State.ACTIVE);
 
         return host;
     }
 
-    public static VirtualHostImpl createVirtualHost(String name) throws Exception
+    public static VirtualHostImpl<?,?,?> createVirtualHost(String name) throws Exception
     {
         Map<String,Object> attributes = new HashMap<String, Object>();
         attributes.put(org.apache.qpid.server.model.VirtualHost.TYPE, StandardVirtualHost.TYPE);
@@ -151,41 +152,40 @@ public class BrokerTestHelper
         return createVirtualHost(attributes);
     }
 
-    public static AMQSessionModel createSession(int channelId, AMQConnectionModel connection)
+    public static AMQSessionModel<?,?> createSession(int channelId, AMQConnectionModel<?,?> connection)
     {
+        @SuppressWarnings("rawtypes")
         AMQSessionModel session = mock(AMQSessionModel.class);
         when(session.getConnectionModel()).thenReturn(connection);
         when(session.getChannelId()).thenReturn(channelId);
         return session;
     }
 
-    public static AMQSessionModel createSession(int channelId) throws Exception
+    public static AMQSessionModel<?,?> createSession(int channelId) throws Exception
     {
-        AMQConnectionModel session = createConnection();
+        AMQConnectionModel<?,?> session = createConnection();
         return createSession(channelId, session);
     }
 
-    public static AMQSessionModel createSession() throws Exception
+    public static AMQSessionModel<?,?> createSession() throws Exception
     {
         return createSession(1);
     }
 
-    public static AMQConnectionModel createConnection() throws Exception
+    public static AMQConnectionModel<?,?> createConnection() throws Exception
     {
         return createConnection("test");
     }
 
-    public static AMQConnectionModel createConnection(String hostName) throws Exception
+    public static AMQConnectionModel<?,?> createConnection(String hostName) throws Exception
     {
-        VirtualHostImpl virtualHost = createVirtualHost(hostName);
-        AMQConnectionModel connection = mock(AMQConnectionModel.class);
-        return connection;
+        return mock(AMQConnectionModel.class);
     }
 
-    public static ExchangeImpl createExchange(String hostName, final boolean durable, final EventLogger eventLogger) throws Exception
+    public static ExchangeImpl<?> createExchange(String hostName, final boolean durable, final EventLogger eventLogger) throws Exception
     {
         SecurityManager securityManager = new SecurityManager(mock(Broker.class), false);
-        final VirtualHostImpl virtualHost = mock(VirtualHostImpl.class);
+        final VirtualHostImpl<?,?,?> virtualHost = mock(VirtualHostImpl.class);
         when(virtualHost.getName()).thenReturn(hostName);
         when(virtualHost.getSecurityManager()).thenReturn(securityManager);
         when(virtualHost.getEventLogger()).thenReturn(eventLogger);
@@ -210,13 +210,13 @@ public class BrokerTestHelper
 
     }
 
-    public static AMQQueue createQueue(String queueName, VirtualHostImpl virtualHost)
+    public static AMQQueue<?> createQueue(String queueName, VirtualHostImpl<?,?,?> virtualHost)
             throws QueueExistsException
     {
         Map<String,Object> attributes = new HashMap<String, Object>();
         attributes.put(Queue.ID, UUIDGenerator.generateRandomUUID());
         attributes.put(Queue.NAME, queueName);
-        AMQQueue queue = virtualHost.createQueue(attributes);
+        AMQQueue<?> queue = virtualHost.createQueue(attributes);
         return queue;
     }
 

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java Mon Apr 21 14:28:29 2014
@@ -287,12 +287,6 @@ public class MockVirtualHost implements 
     }
 
     @Override
-    public Map<String, Object> getConfigurationStoreSettings()
-    {
-        return null;
-    }
-
-    @Override
     public long getQueueCount()
     {
         return 0;
@@ -658,4 +652,11 @@ public class MockVirtualHost implements 
     {
         return false;
     }
+
+    @Override
+    public String getModelVersion()
+    {
+        return null;
+    }
+
 }

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostQueueCreationTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostQueueCreationTest.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostQueueCreationTest.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostQueueCreationTest.java Mon Apr 21 14:28:29 2014
@@ -32,42 +32,80 @@ import org.apache.qpid.exchange.Exchange
 import org.apache.qpid.server.configuration.BrokerProperties;
 import org.apache.qpid.server.configuration.updater.TaskExecutor;
 import org.apache.qpid.server.exchange.ExchangeImpl;
+import org.apache.qpid.server.logging.EventLogger;
 import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.BrokerModel;
 import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.ConfiguredObjectFactory;
+import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl;
 import org.apache.qpid.server.model.LifetimePolicy;
 import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.SystemContext;
 import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.VirtualHostNode;
 import org.apache.qpid.server.queue.AMQQueue;
 import org.apache.qpid.server.queue.PriorityQueue;
 import org.apache.qpid.server.queue.PriorityQueueImpl;
 import org.apache.qpid.server.queue.StandardQueueImpl;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.store.DurableConfigurationStore;
 import org.apache.qpid.server.store.MessageStore;
 import org.apache.qpid.server.store.TestMemoryMessageStore;
-import org.apache.qpid.server.util.BrokerTestHelper;
 import org.apache.qpid.test.utils.QpidTestCase;
 
 public class VirtualHostQueueCreationTest extends QpidTestCase
 {
-    private VirtualHostImpl _virtualHost;
-    private Broker _broker;
+    private VirtualHostImpl<?,?,?> _virtualHost;
+    private VirtualHostNode<?> _virtualHostNode;
+    private TaskExecutor _taskExecutor;
 
+    @SuppressWarnings({ "rawtypes", "unchecked" })
     @Override
     public void setUp() throws Exception
     {
         super.setUp();
 
-        _broker = BrokerTestHelper.createBrokerMock();
-        TaskExecutor taskExecutor = mock(TaskExecutor.class);
-        when(taskExecutor.isTaskExecutorThread()).thenReturn(true);
-        when(_broker.getTaskExecutor()).thenReturn(taskExecutor);
+        EventLogger eventLogger = mock(EventLogger.class);
+        SecurityManager securityManager = mock(SecurityManager.class);
+        ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
+
+        _taskExecutor = new TaskExecutor();
+        _taskExecutor.start();
+
+        SystemContext<?> context = mock(SystemContext.class);
+        when(context.getEventLogger()).thenReturn(eventLogger);
+
+        Broker broker = mock(Broker.class);
+        when(broker.getObjectFactory()).thenReturn(objectFactory);
+        when(broker.getCategoryClass()).thenReturn(Broker.class);
+        when(broker.getParent(SystemContext.class)).thenReturn(context);
+        when(broker.getSecurityManager()).thenReturn(securityManager);
+        when(broker.getModel()).thenReturn(objectFactory.getModel());
+        when(broker.getTaskExecutor()).thenReturn(_taskExecutor);
+
+        _virtualHostNode = mock(VirtualHostNode.class);
+        when(_virtualHostNode.getParent(Broker.class)).thenReturn(broker);
+        when(_virtualHostNode.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
+        when(_virtualHostNode.getObjectFactory()).thenReturn(objectFactory);
+        when(_virtualHostNode.getModel()).thenReturn(objectFactory.getModel());
 
         _virtualHost = createHost();
-        _virtualHost.open();
-
-
+    }
 
+    @Override
+    public void tearDown() throws Exception
+    {
+        try
+        {
+            _taskExecutor.stopImmediately();
+        }
+        finally
+        {
+            super.tearDown();
+        }
     }
-    private VirtualHostImpl createHost()
+    private VirtualHostImpl<?,?,?> createHost()
     {
         Map<String, Object> attributes = new HashMap<String, Object>();
         attributes.put(VirtualHost.NAME, getName());
@@ -77,13 +115,10 @@ public class VirtualHostQueueCreationTes
 
         attributes = new HashMap<String, Object>(attributes);
         attributes.put(VirtualHost.ID, UUID.randomUUID());
-        return new StandardVirtualHost(attributes, _broker);
-    }
-
-    @Override
-    public void tearDown() throws Exception
-    {
-        super.tearDown();
+        StandardVirtualHost host = new StandardVirtualHost(attributes, _virtualHostNode);
+        host.create();
+        host.setDesiredState(host.getState(), State.ACTIVE);
+        return host;
     }
 
     private void verifyRegisteredQueueCount(int count)

Added: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java?rev=1588886&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java (added)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java Mon Apr 21 14:28:29 2014
@@ -0,0 +1,170 @@
+/*
+ *
+ * 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.virtualhostnode;
+
+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.updater.TaskExecutor;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.BrokerModel;
+import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl;
+import org.apache.qpid.server.model.Model;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.SystemContext;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.VirtualHostNode;
+import org.apache.qpid.server.plugin.DurableConfigurationStoreFactory;
+import org.apache.qpid.server.store.ConfiguredObjectRecord;
+import org.apache.qpid.server.store.DurableConfigurationStore;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.NullMessageStore;
+import org.apache.qpid.server.store.StoreException;
+import org.apache.qpid.server.store.TestMemoryMessageStore;
+import org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.server.virtualhost.StandardVirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class AbstractStandardVirtualHostNodeTest extends QpidTestCase
+{
+    private static final String TEST_VIRTUAL_HOST_NODE_NAME = "testNode";
+    private static final String TEST_VIRTUAL_HOST_NAME = "testVirtualHost";
+
+    private DurableConfigurationStoreFactory _configStoreFactory = mock(DurableConfigurationStoreFactory.class);
+    private UUID _nodeId = UUID.randomUUID();
+    private Broker<?> _broker;
+    private DurableConfigurationStore _configStore;
+    private ConfiguredObjectRecord _record;
+    private TaskExecutor _taskExecutor;
+
+    @Override
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        _broker = BrokerTestHelper.createBrokerMock();
+        SystemContext<?> systemContext = _broker.getParent(SystemContext.class);
+        when(systemContext.getObjectFactory()).thenReturn(new ConfiguredObjectFactoryImpl(mock(Model.class)));
+
+        _taskExecutor = new TaskExecutor();
+        _taskExecutor.start();
+        when(_broker.getTaskExecutor()).thenReturn(_taskExecutor);
+    }
+
+    @Override
+    protected void tearDown() throws Exception
+    {
+        try
+        {
+            _taskExecutor.stopImmediately();
+        }
+        finally
+        {
+            super.tearDown();
+        }
+    }
+    public void testActivationOpensConfigStoreWithExistingVirtualHostRecord() throws Exception
+    {
+        UUID virtualHostId = UUID.randomUUID();
+        _record = createMockVirtualHostCOR(virtualHostId);
+
+        _configStore = new NullMessageStore(){
+
+            @Override
+            public void visitConfiguredObjectRecords(ConfiguredObjectRecordHandler handler) throws StoreException
+            {
+                handler.begin();
+                handler.handle(_record);
+                handler.end();
+            }
+        };
+        when(_configStoreFactory.createDurableConfigurationStore()).thenReturn(_configStore);
+
+        Map<String, Object> nodeAttributes = new HashMap<String, Object>();
+        nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
+        nodeAttributes.put(VirtualHostNode.ID, _nodeId);
+
+        VirtualHostNode<?> node = new TestVirtualHostNode(_broker, nodeAttributes, _taskExecutor, _configStore);
+        node.open();
+        node.setDesiredState(node.getState(), State.ACTIVE);
+
+        VirtualHost<?, ?, ?> virtualHost = node.getVirtualHost();
+        assertNotNull("Virtual host was not recovered", virtualHost);
+        assertTrue("Unexpected virtual host type", virtualHost instanceof StandardVirtualHost);
+        assertEquals("Unexpected virtual host name", TEST_VIRTUAL_HOST_NAME, virtualHost.getName());
+        assertEquals("Unexpected virtual host state", State.ACTIVE, virtualHost.getState());
+        assertEquals("Unexpected virtual host id", virtualHostId, virtualHost.getId());
+    }
+
+    public void testActivationOpensConfigStoreWithoutVirtualHostRecord() throws Exception
+    {
+        _configStore = new NullMessageStore() {
+
+            @Override
+            public void visitConfiguredObjectRecords(ConfiguredObjectRecordHandler handler) throws StoreException
+            {
+                handler.begin();
+                // No records
+                handler.end();
+            }
+        };
+        when(_configStoreFactory.createDurableConfigurationStore()).thenReturn(_configStore);
+
+        Map<String, Object> nodeAttributes = new HashMap<String, Object>();
+        nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
+        nodeAttributes.put(VirtualHostNode.ID, _nodeId);
+
+        VirtualHostNode<?> node = new TestVirtualHostNode(_broker, nodeAttributes, _taskExecutor, _configStore);
+        node.open();
+        node.setDesiredState(node.getState(), State.ACTIVE);
+
+        VirtualHost<?, ?, ?> virtualHost = node.getVirtualHost();
+        assertNotNull("Virtual host was not recovered", virtualHost);
+        assertTrue("Unexpected virtual host type", virtualHost instanceof StandardVirtualHost);
+
+        // Virtualhost name taken from VHN and ID is random.
+        assertEquals("Unexpected virtual host name", TEST_VIRTUAL_HOST_NODE_NAME, virtualHost.getName());
+        assertEquals("Unexpected virtual host state", State.ACTIVE, virtualHost.getState());
+        assertNotNull("Unexpected virtual host id", virtualHost.getId());
+    }
+
+    private ConfiguredObjectRecord createMockVirtualHostCOR(UUID virtualHostId)
+    {
+        Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+        virtualHostAttributes.put(VirtualHost.NAME, TEST_VIRTUAL_HOST_NAME);
+        virtualHostAttributes.put(VirtualHost.TYPE, StandardVirtualHost.TYPE);
+        virtualHostAttributes.put(VirtualHost.MODEL_VERSION, BrokerModel.MODEL_VERSION);
+        Map<String,Object> messageStoreSettings = new HashMap<String, Object>();
+        virtualHostAttributes.put(VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings);
+        messageStoreSettings.put(MessageStore.STORE_TYPE, TestMemoryMessageStore.TYPE);
+
+        ConfiguredObjectRecord record = mock(ConfiguredObjectRecord.class);
+        when(record.getId()).thenReturn(virtualHostId);
+        when(record.getAttributes()).thenReturn(virtualHostAttributes);
+        when(record.getType()).thenReturn(VirtualHost.class.getSimpleName());
+        return record;
+    }
+}

Added: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNode.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNode.java?rev=1588886&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNode.java (added)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNode.java Mon Apr 21 14:28:29 2014
@@ -0,0 +1,85 @@
+/*
+ *
+ * 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.virtualhostnode;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ManagedObject;
+import org.apache.qpid.server.plugin.DurableConfigurationStoreFactory;
+import org.apache.qpid.server.store.DurableConfigurationStore;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.TestMemoryMessageStore;
+import org.apache.qpid.server.store.TestMemoryMessageStoreFactory;
+@ManagedObject(type="TestMemory", category=false)
+public class TestVirtualHostNode extends AbstractStandardVirtualHostNode<TestVirtualHostNode>
+{
+    private final DurableConfigurationStore _store;
+
+    public TestVirtualHostNode(Broker<?> parent, Map<String, Object> attributes, TaskExecutor taskExecutor)
+    {
+        this(parent, attributes, taskExecutor, null);
+    }
+
+    public TestVirtualHostNode(Broker<?> parent, Map<String, Object> attributes, TaskExecutor taskExecutor, DurableConfigurationStore store)
+    {
+        super(parent, attributes, taskExecutor);
+        _store = store;
+    }
+
+    @Override
+    protected DurableConfigurationStoreFactory getDurableConfigurationStoreFactory()
+    {
+        if (_store != null)
+        {
+            return new DurableConfigurationStoreFactory()
+            {
+
+                @Override
+                public void validateConfigurationStoreSettings(Map<String, Object> attributes)
+                {
+                }
+
+                @Override
+                public String getType()
+                {
+                    return null;
+                }
+
+                @Override
+                public DurableConfigurationStore createDurableConfigurationStore()
+                {
+                    return _store;
+                }
+            };
+        }
+
+        return new TestMemoryMessageStoreFactory();
+    }
+
+    @Override
+    public Map<String, Object> getDefaultMessageStoreSettings()
+    {
+        return Collections.<String, Object>singletonMap(MessageStore.STORE_TYPE, TestMemoryMessageStore.TYPE);
+    }
+}
\ No newline at end of file

Copied: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNodeFactory.java (from r1588885, qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNodeFactory.java?p2=qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNodeFactory.java&p1=qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java&r1=1588885&r2=1588886&rev=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/TestVirtualHostNodeFactory.java Mon Apr 21 14:28:29 2014
@@ -18,31 +18,26 @@
  * under the License.
  *
  */
-package org.apache.qpid.server.store.berkeleydb;
+package org.apache.qpid.server.virtualhostnode;
+
+import java.util.Map;
 
 import org.apache.qpid.server.model.AbstractConfiguredObjectTypeFactory;
 import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.ConfiguredObject;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-public class BDBHAVirtualHostFactory extends AbstractConfiguredObjectTypeFactory<BDBHAVirtualHost>
+public class TestVirtualHostNodeFactory extends AbstractConfiguredObjectTypeFactory<TestVirtualHostNode>
 {
-
-    public BDBHAVirtualHostFactory()
+    public TestVirtualHostNodeFactory()
     {
-        super(BDBHAVirtualHost.class);
+        super(TestVirtualHostNode.class);
     }
 
     @Override
-    public BDBHAVirtualHost createInstance(final Map<String, Object> attributes,
-                                                 final ConfiguredObject<?>... parents)
+    public TestVirtualHostNode createInstance(Map<String, Object> attributes, ConfiguredObject<?>... parents)
     {
-        final Broker broker = getParent(Broker.class, parents);
-        return new BDBHAVirtualHost(attributes, broker);
+        Broker<?> broker = getParent(Broker.class, parents);
+        return new TestVirtualHostNode(broker, attributes, broker.getTaskExecutor());
     }
 
-
 }

Copied: qpid/trunk/qpid/java/broker-core/src/test/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory (from r1588885, qpid/trunk/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory?p2=qpid/trunk/qpid/java/broker-core/src/test/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory&p1=qpid/trunk/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory&r1=1588885&r2=1588886&rev=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory Mon Apr 21 14:28:29 2014
@@ -16,4 +16,5 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-org.apache.qpid.server.store.berkeleydb.BDBHAVirtualHostFactory
+org.apache.qpid.server.virtualhostnode.TestVirtualHostNodeFactory
+

Copied: qpid/trunk/qpid/java/broker-core/src/test/resources/META-INF/services/org.apache.qpid.server.plugin.DurableConfigurationStoreFactory (from r1588885, qpid/trunk/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/resources/META-INF/services/org.apache.qpid.server.plugin.DurableConfigurationStoreFactory?p2=qpid/trunk/qpid/java/broker-core/src/test/resources/META-INF/services/org.apache.qpid.server.plugin.DurableConfigurationStoreFactory&p1=qpid/trunk/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory&r1=1588885&r2=1588886&rev=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/resources/META-INF/services/org.apache.qpid.server.plugin.DurableConfigurationStoreFactory Mon Apr 21 14:28:29 2014
@@ -16,4 +16,4 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-org.apache.qpid.server.store.berkeleydb.BDBHAVirtualHostFactory
+org.apache.qpid.server.store.TestMemoryMessageStoreFactory

Modified: qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java?rev=1588886&r1=1588885&r2=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java Mon Apr 21 14:28:29 2014
@@ -66,8 +66,11 @@ public class DerbyMessageStoreFactory im
             }
         }
 
-        @SuppressWarnings("unchecked")
-        Map<String, Object> configurationStoreSettings = (Map<String, Object>) attributes.get(VirtualHost.CONFIGURATION_STORE_SETTINGS);
+    }
+
+    @Override
+    public void validateConfigurationStoreSettings(Map<String, Object> configurationStoreSettings)
+    {
         if(configurationStoreSettings != null && getType().equals(configurationStoreSettings.get(DurableConfigurationStore.STORE_TYPE)))
         {
             Object storePath = configurationStoreSettings.get(DurableConfigurationStore.STORE_PATH);

Added: qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNode.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNode.java?rev=1588886&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNode.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNode.java Mon Apr 21 14:28:29 2014
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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.virtualhostnode.derby;
+
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ManagedAttributeField;
+import org.apache.qpid.server.model.ManagedObject;
+import org.apache.qpid.server.plugin.DurableConfigurationStoreFactory;
+import org.apache.qpid.server.store.derby.DerbyMessageStoreFactory;
+import org.apache.qpid.server.virtualhostnode.AbstractStandardVirtualHostNode;
+import org.apache.qpid.server.virtualhostnode.FileBasedVirtualHostNode;
+
+@ManagedObject( category = false, type = "DERBY" )
+public class DerbyVirtualHostNode extends AbstractStandardVirtualHostNode<DerbyVirtualHostNode> implements FileBasedVirtualHostNode<DerbyVirtualHostNode>
+{
+    @ManagedAttributeField
+    private String _storePath;
+
+    public DerbyVirtualHostNode(Broker<?> parent, Map<String, Object> attributes, TaskExecutor taskExecutor)
+    {
+        super(parent, attributes, taskExecutor);
+    }
+
+    @Override
+    protected DurableConfigurationStoreFactory getDurableConfigurationStoreFactory()
+    {
+        return new DerbyMessageStoreFactory();
+    }
+
+    @Override
+    public String getStorePath()
+    {
+        return _storePath;
+    }
+
+    @Override
+    public String toString()
+    {
+        return getClass().getSimpleName() + " [id=" + getId() + ", name=" + getName() + ", storePath=" + getStorePath() + "]";
+    }
+}

Copied: qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNodeFactory.java (from r1588885, qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNodeFactory.java?p2=qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNodeFactory.java&p1=qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java&r1=1588885&r2=1588886&rev=1588886&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/virtualhostnode/derby/DerbyVirtualHostNodeFactory.java Mon Apr 21 14:28:29 2014
@@ -18,31 +18,28 @@
  * under the License.
  *
  */
-package org.apache.qpid.server.store.berkeleydb;
+
+package org.apache.qpid.server.virtualhostnode.derby;
+
+import java.util.Map;
 
 import org.apache.qpid.server.model.AbstractConfiguredObjectTypeFactory;
 import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.ConfiguredObject;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-public class BDBHAVirtualHostFactory extends AbstractConfiguredObjectTypeFactory<BDBHAVirtualHost>
+public class DerbyVirtualHostNodeFactory extends AbstractConfiguredObjectTypeFactory<DerbyVirtualHostNode>
 {
 
-    public BDBHAVirtualHostFactory()
+    public DerbyVirtualHostNodeFactory()
     {
-        super(BDBHAVirtualHost.class);
+        super(DerbyVirtualHostNode.class);
     }
 
     @Override
-    public BDBHAVirtualHost createInstance(final Map<String, Object> attributes,
-                                                 final ConfiguredObject<?>... parents)
+    public DerbyVirtualHostNode createInstance(Map<String, Object> attributes, ConfiguredObject<?>... parents)
     {
-        final Broker broker = getParent(Broker.class, parents);
-        return new BDBHAVirtualHost(attributes, broker);
+        Broker<?> broker = getParent(Broker.class, parents);
+        return new DerbyVirtualHostNode(broker, attributes, broker.getTaskExecutor());
     }
 
-
 }



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


Mime
View raw message