Author: kwall
Date: Thu Jun 28 14:27:04 2012
New Revision: 1355024

URL: http://svn.apache.org/viewvc?rev=1355024&view=rev
Log:
NO-JIRA: Bolster QueueMBean and VirtualHostManagerMBean system and unit tests.

Added:
    
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/MBeanUtils.java
    
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java
Modified:
    
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java
    
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java
    
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java
    
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java
    
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java
    
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java

Added: 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/MBeanUtils.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/MBeanUtils.java?rev=1355024&view=auto
==============================================================================
--- 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/MBeanUtils.java
 (added)
+++ 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/MBeanUtils.java
 Thu Jun 28 14:27:04 2012
@@ -0,0 +1,57 @@
+/*
+ *
+ * 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.jmx.mbeans;
+
+import javax.management.OperationsException;
+
+import org.apache.qpid.server.model.ConfiguredObjectFinder;
+import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.VirtualHost;
+
+public class MBeanUtils
+{
+    public static Queue findQueueFromQueueName(VirtualHost virtualHost, String 
queueName) throws OperationsException
+    {
+        Queue queue = 
ConfiguredObjectFinder.findConfiguredObjectByName(virtualHost.getQueues(), 
queueName);
+        if (queue == null)
+        {
+            throw new OperationsException("No such queue \""+queueName+"\"");
+        }
+        else
+        {
+            return queue;
+        }
+    }
+
+    public static  Exchange findExchangeFromExchangeName(VirtualHost 
virtualHost, String exchangeName) throws OperationsException
+    {
+        Exchange exchange = 
ConfiguredObjectFinder.findConfiguredObjectByName(virtualHost.getExchanges(), 
exchangeName);
+        if (exchange == null)
+        {
+            throw new OperationsException("No such exchange 
\""+exchangeName+"\"");
+        }
+        else
+        {
+            return exchange;
+        }
+    }
+}

Modified: 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java?rev=1355024&r1=1355023&r2=1355024&view=diff
==============================================================================
--- 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java
 (original)
+++ 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java
 Thu Jun 28 14:27:04 2012
@@ -48,7 +48,6 @@ import org.apache.qpid.server.jmx.AMQMan
 import org.apache.qpid.server.jmx.ManagedObject;
 import org.apache.qpid.server.message.AMQMessageHeader;
 import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.model.ConfiguredObjectFinder;
 import org.apache.qpid.server.model.Exchange;
 import org.apache.qpid.server.model.LifetimePolicy;
 import org.apache.qpid.server.model.Queue;
@@ -143,18 +142,11 @@ public class QueueMBean extends AMQManag
         return _queue.getName();
     }
 
-
     public Integer getMessageCount()
     {
         return getStatisticValue(Queue.QUEUE_DEPTH_MESSAGES).intValue();
     }
 
-    private Number getStatisticValue(String name)
-    {
-        final Number statistic = (Number) 
_queue.getStatistics().getStatistic(name);
-        return statistic == null ? Integer.valueOf(0) : statistic;
-    }
-
     public Integer getMaximumDeliveryCount()
     {
         return (Integer) _queue.getAttribute(Queue.MAXIMUM_DELIVERY_ATTEMPTS);
@@ -285,7 +277,7 @@ public class QueueMBean extends AMQManag
         else
         {
             VirtualHost virtualHost = _queue.getParent(VirtualHost.class);
-            Exchange exchange = findExchangeFromExchangeName(virtualHost, 
exchangeName);
+            Exchange exchange = 
MBeanUtils.findExchangeFromExchangeName(virtualHost, exchangeName);
 
             _queue.setAttribute(Queue.ALTERNATE_EXCHANGE, 
getAlternateExchange(), exchange);
         }
@@ -409,9 +401,8 @@ public class QueueMBean extends AMQManag
         GetMessageVisitor visitor = new GetMessageVisitor(messageId);
         _queue.visit(visitor);
         return visitor.getEntry();
-
     }
-    
+
     public void deleteMessageFromTop() throws IOException, JMException
     {
         VirtualHost vhost = _queue.getParent(VirtualHost.class);
@@ -477,7 +468,7 @@ public class QueueMBean extends AMQManag
         }
 
         VirtualHost vhost = _queue.getParent(VirtualHost.class);
-        final Queue destinationQueue = findQueueFromQueueName(vhost, toQueue);
+        final Queue destinationQueue = 
MBeanUtils.findQueueFromQueueName(vhost, toQueue);
 
         vhost.executeTransaction(new VirtualHost.TransactionalOperation()
         {
@@ -549,7 +540,7 @@ public class QueueMBean extends AMQManag
         }
 
         VirtualHost vhost = _queue.getParent(VirtualHost.class);
-        final Queue destinationQueue = findQueueFromQueueName(vhost, toQueue);
+        final Queue destinationQueue = 
MBeanUtils.findQueueFromQueueName(vhost, toQueue);
 
         vhost.executeTransaction(new VirtualHost.TransactionalOperation()
         {
@@ -664,29 +655,9 @@ public class QueueMBean extends AMQManag
         _queue.setAttribute(Queue.DESCRIPTION, getDescription(), description);
     }
 
-    private Queue findQueueFromQueueName(VirtualHost virtualHost, String 
queueName) throws OperationsException
-    {
-        Queue queue = 
ConfiguredObjectFinder.findConfiguredObjectByName(virtualHost.getQueues(), 
queueName);
-        if (queue == null)
-        {
-            throw new OperationsException("No such queue \""+queueName+"\"");
-        }
-        else
-        {
-            return queue;
-        }
-    }
-
-    private Exchange findExchangeFromExchangeName(VirtualHost virtualHost, 
String exchangeName) throws OperationsException
+    private Number getStatisticValue(String name)
     {
-        Exchange exchange = 
ConfiguredObjectFinder.findConfiguredObjectByName(virtualHost.getExchanges(), 
exchangeName);
-        if (exchange == null)
-        {
-            throw new OperationsException("No such exchange 
\""+exchangeName+"\"");
-        }
-        else
-        {
-            return exchange;
-        }
+        final Number statistic = (Number) 
_queue.getStatistics().getStatistic(name);
+        return statistic == null ? Integer.valueOf(0) : statistic;
     }
 }

Modified: 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java?rev=1355024&r1=1355023&r2=1355024&view=diff
==============================================================================
--- 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java
 (original)
+++ 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java
 Thu Jun 28 14:27:04 2012
@@ -33,8 +33,11 @@ import javax.management.JMException;
 import javax.management.MBeanException;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
+import javax.management.OperationsException;
 
 import org.apache.log4j.Logger;
+import org.apache.qpid.AMQInvalidArgumentException;
+import org.apache.qpid.AMQUnknownExchangeType;
 import org.apache.qpid.management.common.mbeans.ManagedBroker;
 import org.apache.qpid.management.common.mbeans.ManagedQueue;
 import org.apache.qpid.management.common.mbeans.annotations.MBeanConstructor;
@@ -66,6 +69,7 @@ public class VirtualHostManagerMBean ext
     }
 
 
+    @Override
     public String getObjectInstanceName()
     {
         return ObjectName.quote(_virtualHostMBean.getName());
@@ -77,17 +81,20 @@ public class VirtualHostManagerMBean ext
         return _virtualHostMBean;
     }
 
+    @Override
     public String[] getExchangeTypes() throws IOException
     {
         Collection<String> exchangeTypes = 
_virtualHostMBean.getVirtualHost().getExchangeTypes();
         return exchangeTypes.toArray(new String[exchangeTypes.size()]);
     }
 
+    @Override
     public List<String> retrieveQueueAttributeNames() throws IOException
     {
         return ManagedQueue.QUEUE_ATTRIBUTES;
     }
 
+    @Override
     public List<List<Object>> retrieveQueueAttributeValues(
             @MBeanOperationParameter(name = "attributes", description = 
"Attributes to retrieve") String[] attributes)
             throws IOException
@@ -125,46 +132,52 @@ public class VirtualHostManagerMBean ext
 
     }
 
+    @Override
     public void createNewExchange(String name, String type, boolean durable)
             throws IOException, JMException, MBeanException
     {
-        getConfiguredObject().createExchange(name, State.ACTIVE, durable,
-                                        LifetimePolicy.PERMANENT, 0l, type, 
Collections.EMPTY_MAP);
+        if (!getConfiguredObject().getExchangeTypes().contains(type))
+        {
+            throw new OperationsException("No such exchange type 
\""+type+"\"");
+        }
+
+        try
+        {
+            getConfiguredObject().createExchange(name, State.ACTIVE, durable,
+                                            LifetimePolicy.PERMANENT, 0l, 
type, Collections.EMPTY_MAP);
+        }
+        catch (IllegalArgumentException iae)
+        {
+            JMException jme = new JMException(iae.toString());
+            throw new MBeanException(jme, "Error in creating exchange " + 
name);
+        }
 
     }
 
+    @Override
     public void unregisterExchange(String exchangeName)
             throws IOException, JMException, MBeanException
     {
-        Exchange theExchange = null;
-        for(Exchange exchange : 
_virtualHostMBean.getVirtualHost().getExchanges())
+        Exchange theExchange = 
MBeanUtils.findExchangeFromExchangeName(_virtualHostMBean.getVirtualHost(), 
exchangeName);
+        try
         {
-            if(exchange.getName().equals(exchangeName))
-            {
-                theExchange = exchange;
-                break;
-            }
+            theExchange.delete();
         }
-        if(theExchange != null)
+        catch (IllegalStateException ex)
         {
-            try
-            {
-                theExchange.delete();
-            }
-            catch (IllegalStateException ex)
-            {
-                final JMException jme = new JMException(ex.toString());
-                throw new MBeanException(jme, "Error in unregistering exchange 
" + exchangeName);
-            }
+            final JMException jme = new JMException(ex.toString());
+            throw new MBeanException(jme, "Error in unregistering exchange " + 
exchangeName);
         }
     }
 
+    @Override
     public void createNewQueue(String queueName, String owner, boolean durable)
             throws IOException, JMException, MBeanException
     {
         createNewQueue(queueName, owner, durable, Collections.EMPTY_MAP);
     }
 
+    @Override
     public void createNewQueue(String queueName, String owner, boolean 
durable, Map<String, Object> originalArguments)
             throws IOException, JMException
     {
@@ -203,33 +216,21 @@ public class VirtualHostManagerMBean ext
         return argumentsCopy;
     }
 
+    @Override
     public void deleteQueue(
             @MBeanOperationParameter(name = ManagedQueue.TYPE, description = 
"Queue Name") String queueName)
             throws IOException, JMException, MBeanException
     {
-        Queue theQueue = null;
-        for(Queue queue : _virtualHostMBean.getVirtualHost().getQueues())
-        {
-            if(queue.getName().equals(queueName))
-            {
-                theQueue = queue;
-                break;
-            }
-        }
-        if(theQueue != null)
-        {
-            theQueue.delete();
-        }
+        Queue theQueue = 
MBeanUtils.findQueueFromQueueName(_virtualHostMBean.getVirtualHost(), 
queueName);
+        theQueue.delete();
     }
 
-
     @Override
     public ObjectName getObjectName() throws MalformedObjectNameException
     {
         return getObjectNameForSingleInstanceMBean();
     }
 
-
     public synchronized boolean isStatisticsEnabled()
     {
         updateStats();

Modified: 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java?rev=1355024&r1=1355023&r2=1355024&view=diff
==============================================================================
--- 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java
 (original)
+++ 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java
 Thu Jun 28 14:27:04 2012
@@ -31,7 +31,6 @@ import javax.management.openmbean.Tabula
 
 import junit.framework.TestCase;
 
-import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.qpid.management.common.mbeans.ManagedConnection;
 import org.apache.qpid.server.jmx.ManagedObject;
 import org.apache.qpid.server.jmx.ManagedObjectRegistry;
@@ -206,9 +205,7 @@ public class ConnectionMBeanTest extends
     private void assertAttribute(String jmxAttributeName, Object 
expectedValue, String underlyingAttributeName) throws Exception
     {
         
when(_mockConnection.getAttribute(underlyingAttributeName)).thenReturn(expectedValue);
-
-        Object actualValue = PropertyUtils.getSimpleProperty(_connectionMBean, 
jmxAttributeName);
-        assertEquals("Unexpected " + jmxAttributeName, expectedValue, 
actualValue);
+        MBeanTestUtils.assertMBeanAttribute(_connectionMBean, 
jmxAttributeName, expectedValue);
     }
 
     private void assertChannelRow(final CompositeData row, int channelId, int 
unacknowledgedMessages, boolean isTransactional, boolean flowBlocked)

Added: 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java?rev=1355024&view=auto
==============================================================================
--- 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java
 (added)
+++ 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java
 Thu Jun 28 14:27:04 2012
@@ -0,0 +1,40 @@
+/*
+ * 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.jmx.mbeans;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.qpid.server.jmx.DefaultManagedObject;
+
+public class MBeanTestUtils
+{
+
+    public static void assertMBeanAttribute(DefaultManagedObject 
managedObject, String jmxAttributeName, Object expectedValue) throws Exception
+    {
+        Object actualValue = PropertyUtils.getSimpleProperty(managedObject, 
jmxAttributeName);
+        TestCase.assertEquals("Attribute " + jmxAttributeName  + " has 
unexpected value", expectedValue, actualValue);
+    }
+
+    public static void setMBeanAttribute(DefaultManagedObject managedObject, 
String jmxAttributeName, Object newValue) throws Exception
+    {
+        PropertyUtils.setSimpleProperty(managedObject, jmxAttributeName, 
newValue);
+    }
+}

Modified: 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java?rev=1355024&r1=1355023&r2=1355024&view=diff
==============================================================================
--- 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java
 (original)
+++ 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java
 Thu Jun 28 14:27:04 2012
@@ -34,7 +34,9 @@ import javax.management.OperationsExcept
 
 import org.apache.qpid.server.jmx.ManagedObjectRegistry;
 import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.LifetimePolicy;
 import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.Statistics;
 import org.apache.qpid.server.model.VirtualHost;
 import org.apache.qpid.server.queue.NotificationCheck;
 import org.mockito.ArgumentMatcher;
@@ -49,6 +51,7 @@ public class QueueMBeanTest extends Test
     private static final String QUEUE_ALTERNATE_EXCHANGE = 
"QUEUE_ALTERNATE_EXCHANGE";
 
     private Queue _mockQueue;
+    private Statistics _mockQueueStatistics;
     private VirtualHostMBean _mockVirtualHostMBean;
     private ManagedObjectRegistry _mockManagedObjectRegistry;
     private QueueMBean _queueMBean;
@@ -57,7 +60,9 @@ public class QueueMBeanTest extends Test
     protected void setUp() throws Exception
     {
         _mockQueue = mock(Queue.class);
+        _mockQueueStatistics = mock(Statistics.class);
         when(_mockQueue.getName()).thenReturn(QUEUE_NAME);
+        when(_mockQueue.getStatistics()).thenReturn(_mockQueueStatistics);
         _mockVirtualHostMBean = mock(VirtualHostMBean.class);
 
         _mockManagedObjectRegistry = mock(ManagedObjectRegistry.class);
@@ -71,26 +76,161 @@ public class QueueMBeanTest extends Test
         assertEquals(QUEUE_NAME, _queueMBean.getName());
     }
 
-    public void testGetQueueDescription()
+    /**********  Statistics **********/
+
+    public void testGetMessageCount() throws Exception
+    {
+        assertStatistic("messageCount", 1000, Queue.QUEUE_DEPTH_MESSAGES);
+    }
+
+    public void testGetReceivedMessageCount() throws Exception
+    {
+        assertStatistic("receivedMessageCount", 1000l, 
Queue.TOTAL_ENQUEUED_MESSAGES);
+    }
+
+    public void testQueueDepth() throws Exception
+    {
+        assertStatistic("queueDepth", 4096l, Queue.QUEUE_DEPTH_BYTES);
+    }
+
+    public void testActiveConsumerCount() throws Exception
+    {
+        assertStatistic("activeConsumerCount", 3, 
Queue.CONSUMER_COUNT_WITH_CREDIT);
+    }
+
+    public void testConsumerCount() throws Exception
+    {
+        assertStatistic("consumerCount", 3, Queue.CONSUMER_COUNT);
+    }
+
+    /**********  Simple Attributes **********/
+
+    public void testGetQueueDescription() throws Exception
+    {
+        assertAttribute("description", QUEUE_DESCRIPTION, Queue.DESCRIPTION);
+    }
+
+    public void testSetQueueDescription() throws Exception
     {
-        
when(_mockQueue.getAttribute(Queue.DESCRIPTION)).thenReturn(QUEUE_DESCRIPTION);
+        testSetAttribute("description", Queue.DESCRIPTION, "descriptionold", 
"descriptionnew");
+    }
 
-        assertEquals(QUEUE_DESCRIPTION, _queueMBean.getDescription());
+    public void testQueueType() throws Exception
+    {
+        assertAttribute("queueType", QUEUE_TYPE, Queue.TYPE);
     }
 
-    public void testSetQueueDescription()
+    public void testMaximumDeliveryCount() throws Exception
     {
-        _queueMBean.setDescription(QUEUE_DESCRIPTION);
-        verify(_mockQueue).setAttribute(Queue.DESCRIPTION, null, 
QUEUE_DESCRIPTION);
+        assertAttribute("maximumDeliveryCount", 5, 
Queue.MAXIMUM_DELIVERY_ATTEMPTS);
     }
 
-    public void testQueueType()
+    public void testOwner() throws Exception
     {
-        when(_mockQueue.getAttribute(Queue.TYPE)).thenReturn(QUEUE_TYPE);
+        assertAttribute("owner", "testOwner", Queue.OWNER);
+    }
 
-        assertEquals(QUEUE_TYPE, _queueMBean.getQueueType());
+    public void testIsDurable() throws Exception
+    {
+        when(_mockQueue.isDurable()).thenReturn(true);
+        assertTrue(_queueMBean.isDurable());
     }
 
+    public void testIsNotDurable() throws Exception
+    {
+        when(_mockQueue.isDurable()).thenReturn(false);
+        assertFalse(_queueMBean.isDurable());
+    }
+
+    public void testIsAutoDelete() throws Exception
+    {
+        
when(_mockQueue.getLifetimePolicy()).thenReturn(LifetimePolicy.AUTO_DELETE);
+        assertTrue(_queueMBean.isAutoDelete());
+    }
+
+    public void testIsNotAutoDelete() throws Exception
+    {
+        
when(_mockQueue.getLifetimePolicy()).thenReturn(LifetimePolicy.PERMANENT);
+        assertFalse(_queueMBean.isAutoDelete());
+    }
+
+    public void testGetMaximumMessageAge() throws Exception
+    {
+        assertAttribute("maximumMessageAge", 10000l, 
Queue.ALERT_THRESHOLD_MESSAGE_AGE);
+    }
+
+    public void testSetMaximumMessageAge() throws Exception
+    {
+        testSetAttribute("maximumMessageAge", 
Queue.ALERT_THRESHOLD_MESSAGE_AGE, 1000l, 10000l);
+    }
+
+    public void testGetMaximumMessageSize() throws Exception
+    {
+        assertAttribute("maximumMessageSize", 1024l, 
Queue.ALERT_THRESHOLD_MESSAGE_SIZE);
+    }
+
+    public void testSetMaximumMessageSize() throws Exception
+    {
+        testSetAttribute("maximumMessageSize", 
Queue.ALERT_THRESHOLD_MESSAGE_SIZE, 1024l, 2048l);
+    }
+
+    public void testGetMaximumMessageCount() throws Exception
+    {
+        assertAttribute("maximumMessageCount", 5000l, 
Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES);
+    }
+
+    public void testSetMaximumMessageCount() throws Exception
+    {
+        testSetAttribute("maximumMessageCount", 
Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, 4000l, 5000l);
+    }
+
+    public void testGetMaximumQueueDepth() throws Exception
+    {
+        assertAttribute("maximumQueueDepth", 1048576l, 
Queue.ALERT_THRESHOLD_QUEUE_DEPTH_BYTES);
+    }
+
+    public void testSetMaximumQueueDepth() throws Exception
+    {
+        testSetAttribute("maximumQueueDepth", 
Queue.ALERT_THRESHOLD_QUEUE_DEPTH_BYTES,1048576l , 2097152l);
+    }
+
+    public void testGetCapacity() throws Exception
+    {
+        assertAttribute("capacity", 1048576l, 
Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES);
+    }
+
+    public void testSetCapacity() throws Exception
+    {
+        testSetAttribute("capacity", 
Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES,1048576l , 2097152l);
+    }
+
+    public void testGetFlowResumeCapacity() throws Exception
+    {
+        assertAttribute("flowResumeCapacity", 1048576l, 
Queue.QUEUE_FLOW_RESUME_SIZE_BYTES);
+    }
+
+    public void testSetFlowResumeCapacity() throws Exception
+    {
+        testSetAttribute("flowResumeCapacity", 
Queue.QUEUE_FLOW_RESUME_SIZE_BYTES,1048576l , 2097152l);
+    }
+
+    public void testIsExclusive() throws Exception
+    {
+        assertAttribute("exclusive", Boolean.TRUE, Queue.EXCLUSIVE);
+    }
+
+    public void testIsNotExclusive() throws Exception
+    {
+        assertAttribute("exclusive", Boolean.FALSE, Queue.EXCLUSIVE);
+    }
+
+    public void testSetExclusive() throws Exception
+    {
+        testSetAttribute("exclusive", Queue.EXCLUSIVE, Boolean.FALSE , 
Boolean.TRUE);
+    }
+
+    /**********  Other attributes **********/
+
     public void testGetAlternateExchange()
     {
         Exchange mockAlternateExchange = mock(Exchange.class);
@@ -153,6 +293,10 @@ public class QueueMBeanTest extends Test
         verify(_mockQueue).setAttribute(Queue.ALTERNATE_EXCHANGE, null, null);
     }
 
+    /**********  Operations **********/
+
+    /**********  Notifications **********/
+
     public void testNotificationListenerCalled() throws Exception
     {
         NotificationListener listener = mock(NotificationListener.class);
@@ -199,4 +343,26 @@ public class QueueMBeanTest extends Test
             }
         });
     }
+
+    private void assertStatistic(String jmxAttributeName, Object 
expectedValue, String underlyingAttributeName) throws Exception
+    {
+        
when(_mockQueueStatistics.getStatistic(underlyingAttributeName)).thenReturn(expectedValue);
+        MBeanTestUtils.assertMBeanAttribute(_queueMBean, jmxAttributeName, 
expectedValue);
+    }
+
+    private void assertAttribute(String jmxAttributeName, Object 
expectedValue, String underlyingAttributeName) throws Exception
+    {
+        
when(_mockQueue.getAttribute(underlyingAttributeName)).thenReturn(expectedValue);
+        MBeanTestUtils.assertMBeanAttribute(_queueMBean, jmxAttributeName, 
expectedValue);
+    }
+
+    private void testSetAttribute(String jmxAttributeName, String 
underlyingAttributeName, Object originalAttributeValue, Object 
newAttributeValue) throws Exception
+    {
+        
when(_mockQueue.getAttribute(underlyingAttributeName)).thenReturn(originalAttributeValue);
+
+        MBeanTestUtils.setMBeanAttribute(_queueMBean, jmxAttributeName, 
newAttributeValue);
+
+        verify(_mockQueue).setAttribute(underlyingAttributeName, 
originalAttributeValue, newAttributeValue);
+    }
+
 }

Modified: 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java?rev=1355024&r1=1355023&r2=1355024&view=diff
==============================================================================
--- 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java
 (original)
+++ 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java
 Thu Jun 28 14:27:04 2012
@@ -21,23 +21,32 @@ package org.apache.qpid.server.jmx.mbean
 
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.when;
 
 import java.util.Collections;
 import java.util.Map;
 
+import javax.management.OperationsException;
+
 import junit.framework.TestCase;
 
 import org.apache.qpid.server.jmx.ManagedObjectRegistry;
+import org.apache.qpid.server.model.Exchange;
 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.VirtualHost;
 import org.apache.qpid.server.queue.AMQQueueFactory;
+import org.mockito.verification.VerificationMode;
 
 public class VirtualHostManagerMBeanTest extends TestCase
 {
     private static final String TEST_QUEUE_NAME = "QUEUE_NAME";
+    private static final String TEST_EXCHANGE_NAME = "EXCHANGE_NAME";
     private static final String TEST_OWNER = "OWNER";
     private static final String TEST_DESCRIPTION = "DESCRIPTION";
+    private static final String TEST_EXCHANGE_TYPE = "EXCHANGE_TYPE";
 
     private static final Map<String, Object> EMPTY_ARGUMENT_MAP = 
Collections.emptyMap();
 
@@ -49,6 +58,8 @@ public class VirtualHostManagerMBeanTest
     protected void setUp() throws Exception
     {
         _mockVirtualHost = mock(VirtualHost.class);
+        
when(_mockVirtualHost.getExchangeTypes()).thenReturn(Collections.singletonList(TEST_EXCHANGE_TYPE));
+
         _mockManagedObjectRegistry = mock(ManagedObjectRegistry.class);
 
         _virtualHostManagerMBean = new VirtualHostManagerMBean(new 
VirtualHostMBean(_mockVirtualHost, _mockManagedObjectRegistry));
@@ -82,4 +93,83 @@ public class VirtualHostManagerMBeanTest
         verify(_mockVirtualHost).createQueue(TEST_QUEUE_NAME, State.ACTIVE, 
true, false, LifetimePolicy.PERMANENT, 0, expectedArguments);
     }
 
+    public void testDeleteQueue() throws Exception
+    {
+        Queue mockQueue = mock(Queue.class);
+        when(mockQueue.getName()).thenReturn("queue1");
+        
when(_mockVirtualHost.getQueues()).thenReturn(Collections.singletonList(mockQueue));
+
+        _virtualHostManagerMBean.deleteQueue("queue1");
+        verify(mockQueue).delete();
+    }
+
+    public void testDeleteQueueWhenQueueDoesNotExist() throws Exception
+    {
+        Queue mockQueue = mock(Queue.class);
+        when(mockQueue.getName()).thenReturn("queue1");
+        
when(_mockVirtualHost.getQueues()).thenReturn(Collections.singletonList(mockQueue));
+
+        try
+        {
+            _virtualHostManagerMBean.deleteQueue("unknownqueue");
+            fail("Exception not thrown");
+        }
+        catch(OperationsException oe)
+        {
+            // PASS
+            assertEquals("No such queue \"unknownqueue\"", oe.getMessage());
+        }
+        verify(mockQueue, never()).delete();
+    }
+
+    public void testCreateNewDurableExchange() throws Exception
+    {
+        _virtualHostManagerMBean.createNewExchange(TEST_EXCHANGE_NAME, 
TEST_EXCHANGE_TYPE, true);
+        verify(_mockVirtualHost).createExchange(TEST_EXCHANGE_NAME, 
State.ACTIVE, true, LifetimePolicy.PERMANENT, 0, TEST_EXCHANGE_TYPE, 
EMPTY_ARGUMENT_MAP);
+    }
+
+    public void testCreateNewExchangeWithUnknownExchangeType() throws Exception
+    {
+        String exchangeType = "notknown";
+        try
+        {
+            _virtualHostManagerMBean.createNewExchange(TEST_EXCHANGE_NAME, 
exchangeType, true);
+            fail("Exception not thrown");
+        }
+        catch (OperationsException oe)
+        {
+            // PASS
+        }
+        verify(_mockVirtualHost, never()).createExchange(TEST_EXCHANGE_NAME, 
State.ACTIVE, true, LifetimePolicy.PERMANENT, 0, exchangeType, 
EMPTY_ARGUMENT_MAP);
+    }
+
+    public void testUnregisterExchange() throws Exception
+    {
+        Exchange mockExchange = mock(Exchange.class);
+        when(mockExchange.getName()).thenReturn("exchange1");
+        
when(_mockVirtualHost.getExchanges()).thenReturn(Collections.singletonList(mockExchange));
+
+        _virtualHostManagerMBean.unregisterExchange("exchange1");
+        verify(mockExchange).delete();
+    }
+
+    public void testUnregisterExchangeWhenExchangeDoesNotExist() throws 
Exception
+    {
+        Exchange mockExchange = mock(Exchange.class);
+        when(mockExchange.getName()).thenReturn("exchange1");
+        
when(_mockVirtualHost.getExchanges()).thenReturn(Collections.singletonList(mockExchange));
+
+        try
+        {
+            _virtualHostManagerMBean.unregisterExchange("unknownexchange");
+            fail("Exception not thrown");
+        }
+        catch(OperationsException oe)
+        {
+            // PASS
+            assertEquals("No such exchange \"unknownexchange\"", 
oe.getMessage());
+        }
+
+        verify(mockExchange, never()).delete();
+    }
 }

Modified: 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java?rev=1355024&r1=1355023&r2=1355024&view=diff
==============================================================================
--- 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
 (original)
+++ 
qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
 Thu Jun 28 14:27:04 2012
@@ -33,17 +33,9 @@ import javax.management.ObjectName;
  */
 public class BrokerManagementTest extends QpidBrokerTestCase
 {
-    /**
-     * Test virtual host
-     */
     private static final String VIRTUAL_HOST = "test";
 
     /**
-     * Test exchange type
-     */
-    private static final String EXCHANGE_TYPE = "topic";
-
-    /**
      * JMX helper.
      */
     private JMXTestUtils _jmxUtils;
@@ -82,7 +74,7 @@ public class BrokerManagementTest extend
         _managedBroker.createNewQueue(queueName, "testowner", true);
 
         // Ensure the queue exists
-        assertNotNull("Queue object name expected to exist", 
_jmxUtils.getQueueObjectName("test", queueName));
+        assertNotNull("Queue object name expected to exist", 
_jmxUtils.getQueueObjectName(VIRTUAL_HOST, queueName));
         assertNotNull("Manager queue expected to be available", 
_jmxUtils.getManagedQueue(queueName));
 
         // Now verify that the default exchange has been bound.
@@ -104,14 +96,11 @@ public class BrokerManagementTest extend
     {
         String exchangeName = getTestName();
         _managedBroker.createNewExchange(exchangeName, "topic", true);
-        String queryString = 
"org.apache.qpid:type=VirtualHost.Exchange,VirtualHost="
-                + ObjectName.quote(VIRTUAL_HOST) + ",name=" + 
ObjectName.quote(exchangeName) + ",ExchangeType="
-                + EXCHANGE_TYPE;
-        ManagedExchange exchange = 
_jmxUtils.getManagedObject(ManagedExchange.class, queryString);
+
+        ManagedExchange exchange = _jmxUtils.getManagedExchange(exchangeName);
         assertNotNull("Exchange should exist", exchange);
 
         _managedBroker.unregisterExchange(exchangeName);
-        assertFalse("Exchange should have been removed", 
_jmxUtils.isManagedObjectExist(queryString));
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to