You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2012/06/28 18:46:36 UTC

svn commit: r1355072 [4/16] - in /qpid/trunk/qpid/java: ./ bdbstore/ bdbstore/jmx/ bdbstore/jmx/src/ bdbstore/jmx/src/main/ bdbstore/jmx/src/main/java/ bdbstore/jmx/src/main/java/org/ bdbstore/jmx/src/main/java/org/apache/ bdbstore/jmx/src/main/java/or...

Copied: qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBeanTest.java (from r1354912, qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/management/LoggingManagementMBeanTest.java)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBeanTest.java?p2=qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBeanTest.java&p1=qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/management/LoggingManagementMBeanTest.java&r1=1354912&r2=1355072&rev=1355072&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/management/LoggingManagementMBeanTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBeanTest.java Thu Jun 28 16:46:12 2012
@@ -14,15 +14,18 @@
  *  "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.    
+ *  under the License.
+ *
  *
- * 
  */
-package org.apache.qpid.server.logging.management;
+package org.apache.qpid.server.jmx.mbeans;
+
+import static org.mockito.Mockito.*;
 
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 
+import org.apache.qpid.server.jmx.ManagedObjectRegistry;
 import org.apache.qpid.server.util.InternalBrokerBaseCase;
 
 import static org.apache.qpid.management.common.mbeans.LoggingManagement.LOGGER_LEVEL;
@@ -41,6 +44,7 @@ import java.util.Map;
 
 public class LoggingManagementMBeanTest extends InternalBrokerBaseCase
 {
+
     private static final String TEST_LOGGER = "LoggingManagementMBeanTestLogger";
     private static final String TEST_LOGGER_CHILD1 = "LoggingManagementMBeanTestLogger.child1";
     private static final String TEST_LOGGER_CHILD2 = "LoggingManagementMBeanTestLogger.child2";
@@ -53,13 +57,15 @@ public class LoggingManagementMBeanTest 
 
     private File _testConfigFile;
 
+    private ManagedObjectRegistry _registry = mock(ManagedObjectRegistry.class);
+
     @Override
     public void setUp() throws Exception
     {
         super.setUp();
         _testConfigFile = createTempTestLog4JConfig();
     }
-    
+
     @Override
     public void tearDown() throws Exception
     {
@@ -68,9 +74,9 @@ public class LoggingManagementMBeanTest 
         {
             oldTestConfigFile.delete();
         }
-        
+
         _testConfigFile.delete();
-        
+
         super.tearDown();
     }
 
@@ -89,7 +95,7 @@ public class LoggingManagementMBeanTest 
             writer.write("<!DOCTYPE log4j:configuration SYSTEM \"log4j.dtd\">"+NEWLINE);
 
             writer.write("<log4j:configuration xmlns:log4j=\"http://jakarta.apache.org/log4j/\" debug=\"null\" " +
-            		                                                                "threshold=\"null\">"+NEWLINE);
+                                                                                 "threshold=\"null\">"+NEWLINE);
 
             writer.write("  <appender class=\"org.apache.log4j.ConsoleAppender\" name=\"STDOUT\">"+NEWLINE);
             writer.write("      <layout class=\"org.apache.log4j.PatternLayout\">"+NEWLINE);
@@ -137,13 +143,13 @@ public class LoggingManagementMBeanTest 
 
 
     //******* Test Methods ******* //
-   
+
     public void testSetRuntimeLoggerLevel()
     {
         LoggingManagementMBean lm = null;
         try
         {
-            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0);
+            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0, _registry);
         }
         catch (JMException e)
         {
@@ -156,26 +162,26 @@ public class LoggingManagementMBeanTest 
 
         //create child1 test logger, check its *effective* level is the same as the parent, "info"
         Logger log1 = Logger.getLogger(TEST_LOGGER_CHILD1);
-        assertTrue("Test logger's level was not the expected value", 
+        assertTrue("Test logger's level was not the expected value",
                     log1.getEffectiveLevel().toString().equalsIgnoreCase("info"));
 
         //now change its level to "warn"
         assertTrue("Failed to set logger level", lm.setRuntimeLoggerLevel(TEST_LOGGER_CHILD1, "warn"));
 
         //check the change, see its actual level is "warn
-        assertTrue("Test logger's level was not the expected value", 
+        assertTrue("Test logger's level was not the expected value",
                     log1.getLevel().toString().equalsIgnoreCase("warn"));
 
         //try an invalid level
         assertFalse("Trying to set an invalid level succeded", lm.setRuntimeLoggerLevel(TEST_LOGGER_CHILD1, "made.up.level"));
     }
-    
+
     public void testSetRuntimeRootLoggerLevel()
     {
         LoggingManagementMBean lm = null;
         try
         {
-            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0);
+            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0, _registry);
         }
         catch (JMException e)
         {
@@ -183,27 +189,27 @@ public class LoggingManagementMBeanTest 
         }
 
         Logger log = Logger.getRootLogger();
-        
+
         //get current root logger level
         Level origLevel = log.getLevel();
-        
+
         //change level twice to ensure a new level is actually selected
-        
+
         //set root loggers level to info
         assertTrue("Failed to set root logger level", lm.setRuntimeRootLoggerLevel("debug"));
         //check it is now actually info
         Level currentLevel = log.getLevel();
         assertTrue("Logger level was not expected value", currentLevel.equals(Level.toLevel("debug")));
-        
+
         //try an invalid level
         assertFalse("Trying to set an invalid level succeded", lm.setRuntimeRootLoggerLevel("made.up.level"));
-        
+
         //set root loggers level to warn
         assertTrue("Failed to set logger level", lm.setRuntimeRootLoggerLevel("info"));
         //check it is now actually warn
         currentLevel = log.getLevel();
         assertTrue("Logger level was not expected value", currentLevel.equals(Level.toLevel("info")));
-        
+
         //restore original level
         log.setLevel(origLevel);
     }
@@ -213,7 +219,7 @@ public class LoggingManagementMBeanTest 
         LoggingManagementMBean lm = null;
         try
         {
-            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0);
+            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0, _registry);
         }
         catch (JMException e)
         {
@@ -221,18 +227,18 @@ public class LoggingManagementMBeanTest 
         }
 
         Logger log = Logger.getRootLogger();
-        
+
         //get current root logger level
         Level origLevel = log.getLevel();
-        
+
         //change level twice to ensure a new level is actually selected
-        
+
         //set root loggers level to debug
         log.setLevel(Level.toLevel("debug"));
         //check it is now actually debug
         assertTrue("Logger level was not expected value", lm.getRuntimeRootLoggerLevel().equalsIgnoreCase("debug"));
-        
-        
+
+
         //set root loggers level to warn
         log.setLevel(Level.toLevel("info"));
         //check it is now actually warn
@@ -241,13 +247,13 @@ public class LoggingManagementMBeanTest 
         //restore original level
         log.setLevel(origLevel);
     }
-    
+
     public void testViewEffectiveRuntimeLoggerLevels()
     {
         LoggingManagementMBean lm = null;
         try
         {
-            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0);
+            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0, _registry);
         }
         catch (JMException e)
         {
@@ -257,7 +263,7 @@ public class LoggingManagementMBeanTest 
         //(re)create a parent test logger, set its level explicitly
         Logger log = Logger.getLogger(TEST_LOGGER);
         log.setLevel(Level.toLevel("info"));
-        
+
         //retrieve the current effective runtime logger level values
         TabularDataSupport levels = (TabularDataSupport) lm.viewEffectiveRuntimeLoggerLevels();
         Collection<Object> records = levels.values();
@@ -267,13 +273,13 @@ public class LoggingManagementMBeanTest 
             CompositeData data = (CompositeData) o;
             list.put(data.get(LOGGER_NAME).toString(), data.get(LOGGER_LEVEL).toString());
         }
-        
+
         //check child2 does not exist already
         assertFalse("Did not expect this logger to exist already", list.containsKey(TEST_LOGGER_CHILD2));
 
         //create child2 test logger
         Logger log2 = Logger.getLogger(TEST_LOGGER_CHILD2);
-        
+
         //retrieve the current effective runtime logger level values
         levels = (TabularDataSupport) lm.viewEffectiveRuntimeLoggerLevels();
         records = levels.values();
@@ -287,14 +293,14 @@ public class LoggingManagementMBeanTest 
         //verify the parent and child2 loggers are present in returned values
         assertTrue(TEST_LOGGER + " logger was not in the returned list", list.containsKey(TEST_LOGGER));
         assertTrue(TEST_LOGGER_CHILD2 + " logger was not in the returned list", list.containsKey(TEST_LOGGER_CHILD2));
-        
+
         //check child2's effective level is the same as the parent, "info"
-        assertTrue("Test logger's level was not the expected value", 
+        assertTrue("Test logger's level was not the expected value",
                     list.get(TEST_LOGGER_CHILD2).equalsIgnoreCase("info"));
 
         //now change its level explicitly to "warn"
         log2.setLevel(Level.toLevel("warn"));
-        
+
         //retrieve the current effective runtime logger level values
         levels = (TabularDataSupport) lm.viewEffectiveRuntimeLoggerLevels();
         records = levels.values();
@@ -306,7 +312,7 @@ public class LoggingManagementMBeanTest 
         }
 
         //check child2's effective level is now "warn"
-        assertTrue("Test logger's level was not the expected value", 
+        assertTrue("Test logger's level was not the expected value",
                     list.get(TEST_LOGGER_CHILD2).equalsIgnoreCase("warn"));
     }
 
@@ -315,7 +321,7 @@ public class LoggingManagementMBeanTest 
         LoggingManagementMBean lm =null;
         try
         {
-            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0);
+            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0, _registry);
         }
         catch (JMException e)
         {
@@ -378,13 +384,13 @@ public class LoggingManagementMBeanTest 
         assertTrue(TEST_CATEGORY_LEVEL + " logger's level was incorrect", list.get(TEST_CATEGORY_LEVEL).equalsIgnoreCase("error"));
         assertTrue(TEST_LOGGER_LEVEL + " logger's level was incorrect", list.get(TEST_LOGGER_LEVEL).equalsIgnoreCase("trace"));
     }
-    
+
     public void testGetAndSetConfigFileRootLoggerLevel() throws Exception
     {
         LoggingManagementMBean lm =null;
         try
         {
-            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0);
+            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 0, _registry);
         }
         catch (JMException e)
         {
@@ -399,7 +405,7 @@ public class LoggingManagementMBeanTest 
 
         //try an invalid level
         assertFalse("Use of an invalid RootLogger level was successfull", lm.setConfigFileRootLoggerLevel("made.up.level"));
-        
+
         //change the level to warn
         assertTrue("Failed to set new RootLogger level", lm.setConfigFileRootLoggerLevel("warn"));
 
@@ -415,7 +421,7 @@ public class LoggingManagementMBeanTest 
         LoggingManagementMBean lm =null;
         try
         {
-            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 5000);
+            lm = new LoggingManagementMBean(_testConfigFile.getAbsolutePath(), 5000, _registry);
         }
         catch (JMException e)
         {

Copied: qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java (from r1354912, qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java?p2=qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java&p1=qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java&r1=1354912&r2=1355072&rev=1355072&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java Thu Jun 28 16:46:12 2012
@@ -1,5 +1,4 @@
 /*
- *
  * 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
@@ -18,27 +17,24 @@
  * under the License.
  *
  */
-package org.apache.qpid.server.transport;
+package org.apache.qpid.server.jmx.mbeans;
+
+import junit.framework.TestCase;
 
-import org.apache.qpid.transport.network.NetworkTransport;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.qpid.server.jmx.DefaultManagedObject;
 
-public class QpidAcceptor
+public class MBeanTestUtils
 {
-    private NetworkTransport _transport;
-    private String _protocol;
-    public QpidAcceptor(NetworkTransport transport, String protocol)
-    {
-        _transport = transport;
-        _protocol = protocol;
-    }
 
-    public NetworkTransport getNetworkTransport()
+    public static void assertMBeanAttribute(DefaultManagedObject managedObject, String jmxAttributeName, Object expectedValue) throws Exception
     {
-        return _transport;
+        Object actualValue = PropertyUtils.getSimpleProperty(managedObject, jmxAttributeName);
+        TestCase.assertEquals("Attribute " + jmxAttributeName  + " has unexpected value", expectedValue, actualValue);
     }
 
-    public String toString()
+    public static void setMBeanAttribute(DefaultManagedObject managedObject, String jmxAttributeName, Object newValue) throws Exception
     {
-        return _protocol;
-    }    
+        PropertyUtils.setSimpleProperty(managedObject, jmxAttributeName, newValue);
+    }
 }

Added: qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/QueueMBeanTest.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,368 @@
+/*
+ * 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 static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Matchers.isNull;
+import static org.mockito.Matchers.argThat;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import javax.management.ListenerNotFoundException;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.OperationsException;
+
+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;
+
+import junit.framework.TestCase;
+
+public class QueueMBeanTest extends TestCase
+{
+    private static final String QUEUE_NAME = "QUEUE_NAME";
+    private static final String QUEUE_DESCRIPTION = "QUEUE_DESCRIPTION";
+    private static final String  QUEUE_TYPE = "QUEUE_TYPE";
+    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;
+
+    @Override
+    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);
+        when(_mockVirtualHostMBean.getRegistry()).thenReturn(_mockManagedObjectRegistry);
+
+        _queueMBean = new QueueMBean(_mockQueue, _mockVirtualHostMBean);
+    }
+
+    public void testQueueName()
+    {
+        assertEquals(QUEUE_NAME, _queueMBean.getName());
+    }
+
+    /**********  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
+    {
+        testSetAttribute("description", Queue.DESCRIPTION, "descriptionold", "descriptionnew");
+    }
+
+    public void testQueueType() throws Exception
+    {
+        assertAttribute("queueType", QUEUE_TYPE, Queue.TYPE);
+    }
+
+    public void testMaximumDeliveryCount() throws Exception
+    {
+        assertAttribute("maximumDeliveryCount", 5, Queue.MAXIMUM_DELIVERY_ATTEMPTS);
+    }
+
+    public void testOwner() throws Exception
+    {
+        assertAttribute("owner", "testOwner", Queue.OWNER);
+    }
+
+    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);
+        when(mockAlternateExchange.getName()).thenReturn(QUEUE_ALTERNATE_EXCHANGE);
+
+        when(_mockQueue.getAttribute(Queue.ALTERNATE_EXCHANGE)).thenReturn(mockAlternateExchange);
+
+        assertEquals(QUEUE_ALTERNATE_EXCHANGE, _queueMBean.getAlternateExchange());
+    }
+
+    public void testGetAlternateExchangeWhenQueueHasNone()
+    {
+        when(_mockQueue.getAttribute(Queue.ALTERNATE_EXCHANGE)).thenReturn(null);
+
+        assertNull(_queueMBean.getAlternateExchange());
+    }
+
+    public void testSetAlternateExchange() throws Exception
+    {
+        Exchange mockExchange1 = mock(Exchange.class);
+        when(mockExchange1.getName()).thenReturn("exchange1");
+
+        Exchange mockExchange2 = mock(Exchange.class);
+        when(mockExchange2.getName()).thenReturn("exchange2");
+
+        Exchange mockExchange3 = mock(Exchange.class);
+        when(mockExchange3.getName()).thenReturn("exchange3");
+
+        VirtualHost mockVirtualHost = mock(VirtualHost.class);
+        when(mockVirtualHost.getExchanges()).thenReturn(Arrays.asList(new Exchange[] {mockExchange1, mockExchange2, mockExchange3}));
+        when(_mockQueue.getParent(VirtualHost.class)).thenReturn(mockVirtualHost);
+
+        _queueMBean.setAlternateExchange("exchange2");
+        verify(_mockQueue).setAttribute(Queue.ALTERNATE_EXCHANGE, null, mockExchange2);
+    }
+
+    public void testSetAlternateExchangeWithUnknownExchangeName() throws Exception
+    {
+        Exchange mockExchange = mock(Exchange.class);
+        when(mockExchange.getName()).thenReturn("exchange1");
+
+        VirtualHost mockVirtualHost = mock(VirtualHost.class);
+        when(mockVirtualHost.getExchanges()).thenReturn(Collections.singletonList(mockExchange));
+        when(_mockQueue.getParent(VirtualHost.class)).thenReturn(mockVirtualHost);
+
+        try
+        {
+            _queueMBean.setAlternateExchange("notknown");
+            fail("Exception not thrown");
+        }
+        catch(OperationsException oe)
+        {
+            // PASS
+        }
+    }
+
+    public void testRemoveAlternateExchange() throws Exception
+    {
+        _queueMBean.setAlternateExchange("");
+        verify(_mockQueue).setAttribute(Queue.ALTERNATE_EXCHANGE, null, null);
+    }
+
+    /**********  Operations **********/
+
+    /**********  Notifications **********/
+
+    public void testNotificationListenerCalled() throws Exception
+    {
+        NotificationListener listener = mock(NotificationListener.class);
+        _queueMBean.addNotificationListener(listener, null, null);
+
+        NotificationCheck notification = mock(NotificationCheck.class);
+        String notificationMsg = "Test notification message";
+
+        _queueMBean.notifyClients(notification, _mockQueue, notificationMsg);
+        verify(listener).handleNotification(isNotificationWithMessage(notificationMsg),
+                                            isNull());
+    }
+
+    public void testAddRemoveNotificationListener() throws Exception
+    {
+        NotificationListener listener1 = mock(NotificationListener.class);
+        _queueMBean.addNotificationListener(listener1, null, null);
+        _queueMBean.removeNotificationListener(listener1);
+    }
+
+    public void testRemoveUnknownNotificationListener() throws Exception
+    {
+        NotificationListener listener1 = mock(NotificationListener.class);
+        try
+        {
+            _queueMBean.removeNotificationListener(listener1);
+            fail("Exception not thrown");
+        }
+        catch (ListenerNotFoundException e)
+        {
+            // PASS
+        }
+    }
+
+    private Notification isNotificationWithMessage(final String expectedMessage)
+    {
+        return argThat( new ArgumentMatcher<Notification>()
+        {
+            @Override
+            public boolean matches(Object argument)
+            {
+                Notification actual = (Notification) argument;
+                return actual.getMessage().endsWith(expectedMessage);
+            }
+        });
+    }
+
+    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);
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/UserManagementMBeanTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/UserManagementMBeanTest.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/UserManagementMBeanTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/UserManagementMBeanTest.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,157 @@
+/*
+ *
+ * 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 static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+import javax.security.auth.login.AccountNotFoundException;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.management.common.mbeans.UserManagement;
+import org.apache.qpid.server.jmx.ManagedObjectRegistry;
+import org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider;
+
+public class UserManagementMBeanTest extends TestCase
+{
+    private UserManagementMBean _userManagement;
+    private ManagedObjectRegistry _mockRegistry;
+    private PasswordCredentialManagingAuthenticationProvider _mockProvider;
+
+    private static final String TEST_USERNAME = "testuser";
+    private static final String TEST_PASSWORD = "password";
+
+    @Override
+    public void setUp() throws Exception
+    {
+        super.setUp();
+
+        _mockProvider = mock(PasswordCredentialManagingAuthenticationProvider.class);
+        _mockRegistry = mock(ManagedObjectRegistry.class);
+        _userManagement = new UserManagementMBean(_mockProvider, _mockRegistry);
+    }
+
+    public void testMBeanRegistersItself() throws Exception
+    {
+        UserManagementMBean userManagementMBean = new UserManagementMBean(_mockProvider, _mockRegistry);
+        verify(_mockRegistry).registerObject(userManagementMBean);
+    }
+
+    public void testDeleteUser() throws Exception
+    {
+        boolean deleteSuccess = _userManagement.deleteUser(TEST_USERNAME);
+        assertTrue("Expected successful delete", deleteSuccess);
+
+        verify(_mockProvider).deleteUser(TEST_USERNAME);
+    }
+
+    public void testDeleteUserWhereUserDoesNotExist() throws Exception
+    {
+        doThrow(AccountNotFoundException.class).when(_mockProvider).deleteUser(TEST_USERNAME);
+
+        boolean deleteSuccess = _userManagement.deleteUser(TEST_USERNAME);
+        assertFalse("Expected unsuccessful delete", deleteSuccess);
+    }
+    
+    public void testCreateUser() throws Exception
+    {
+        when(_mockProvider.createUser(TEST_USERNAME, TEST_PASSWORD, null)).thenReturn(true);
+
+        boolean createSuccess = _userManagement.createUser(TEST_USERNAME, TEST_PASSWORD);
+        assertTrue(createSuccess);
+    }
+
+    public void testCreateUserWhereUserAlreadyExists()
+    {
+        when(_mockProvider.createUser(TEST_USERNAME, TEST_PASSWORD, null)).thenReturn(false);
+
+        boolean createSuccess = _userManagement.createUser(TEST_USERNAME, TEST_PASSWORD);
+        assertFalse(createSuccess);
+    }
+
+    public void testSetPassword() throws Exception
+    {
+        boolean setPasswordSuccess = _userManagement.setPassword(TEST_USERNAME, TEST_PASSWORD);
+        assertTrue(setPasswordSuccess);
+
+        assertTrue("Set password should return true to flag successful change", setPasswordSuccess);
+
+        verify(_mockProvider).setPassword(TEST_USERNAME, TEST_PASSWORD);
+    }
+
+    public void testSetPasswordWhereUserDoesNotExist() throws Exception
+    {
+        doThrow(AccountNotFoundException.class).when(_mockProvider).setPassword(TEST_USERNAME, TEST_PASSWORD);
+
+        boolean setPasswordSuccess = _userManagement.setPassword(TEST_USERNAME, TEST_PASSWORD);
+
+        assertFalse("Set password should return false to flag unsuccessful change", setPasswordSuccess);
+    }
+
+    public void testReload() throws Exception
+    {
+        boolean reloadSuccess = _userManagement.reloadData();
+
+        assertTrue("Reload should return true to flag succesful update", reloadSuccess);
+
+        verify(_mockProvider).reload();
+    }
+
+    public void testReloadFails() throws Exception
+    {
+        doThrow(IOException.class).when(_mockProvider).reload();
+
+        boolean reloadSuccess = _userManagement.reloadData();
+
+        assertFalse("Expected reload to fail", reloadSuccess);
+    }
+
+    public void testViewUsers() throws Exception
+    {
+        Map<String,String> args = Collections.emptyMap();
+        when(_mockProvider.getUsers()).thenReturn(Collections.singletonMap(TEST_USERNAME, args));
+
+        TabularData userList = _userManagement.viewUsers();
+
+        assertNotNull(userList);
+        assertEquals("Unexpected number of users in user list", 1, userList.size());
+        assertTrue(userList.containsKey(new Object[]{TEST_USERNAME}));
+        
+        // Check the deprecated read, write and admin items continue to exist but return false.
+        CompositeData userRec = userList.get(new Object[]{TEST_USERNAME});
+        assertTrue(userRec.containsKey(UserManagement.RIGHTS_READ_ONLY));
+        assertEquals(false, userRec.get(UserManagement.RIGHTS_READ_ONLY));
+        assertEquals(false, userRec.get(UserManagement.RIGHTS_READ_WRITE));
+        assertTrue(userRec.containsKey(UserManagement.RIGHTS_READ_WRITE));
+        assertTrue(userRec.containsKey(UserManagement.RIGHTS_ADMIN));
+        assertEquals(false, userRec.get(UserManagement.RIGHTS_ADMIN));
+    }
+}

Added: qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,175 @@
+/*
+ * 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 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();
+
+    private VirtualHost _mockVirtualHost;
+    private ManagedObjectRegistry _mockManagedObjectRegistry;
+    private VirtualHostManagerMBean _virtualHostManagerMBean;
+
+    @Override
+    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));
+    }
+
+    public void testCreateQueueWithNoOwner() throws Exception
+    {
+        _virtualHostManagerMBean.createNewQueue(TEST_QUEUE_NAME, null, true);
+
+        verify(_mockVirtualHost).createQueue(TEST_QUEUE_NAME, State.ACTIVE, true, false, LifetimePolicy.PERMANENT, 0, EMPTY_ARGUMENT_MAP);
+    }
+
+    /**
+     * Some users have been abusing the owner parameter as a description.  Decision has been taken to map this parameter
+     * through to the description field (if the description field is passed, the owner is discarded).
+     */
+    public void testCreateQueueWithOwnerMappedThroughToDescription() throws Exception
+    {
+        _virtualHostManagerMBean.createNewQueue(TEST_QUEUE_NAME, TEST_OWNER, true);
+
+        Map<String, Object> expectedArguments = Collections.singletonMap(AMQQueueFactory.X_QPID_DESCRIPTION, (Object)TEST_OWNER);
+        verify(_mockVirtualHost).createQueue(TEST_QUEUE_NAME, State.ACTIVE, true, false, LifetimePolicy.PERMANENT, 0, expectedArguments);
+    }
+
+    public void testCreateQueueWithOwnerAndDescriptionDiscardsOwner() throws Exception
+    {
+        Map<String, Object> arguments = Collections.singletonMap(AMQQueueFactory.X_QPID_DESCRIPTION, (Object)TEST_DESCRIPTION);
+        _virtualHostManagerMBean.createNewQueue(TEST_QUEUE_NAME, TEST_OWNER, true, arguments);
+
+        Map<String, Object> expectedArguments = Collections.singletonMap(AMQQueueFactory.X_QPID_DESCRIPTION, (Object)TEST_DESCRIPTION);
+        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();
+    }
+}

Copied: qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java (from r1354912, qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedBrokerMBeanTest.java)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java?p2=qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java&p1=qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedBrokerMBeanTest.java&r1=1354912&r2=1355072&rev=1355072&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedBrokerMBeanTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java Thu Jun 28 16:46:12 2012
@@ -16,38 +16,26 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.qpid.management.jmx;
+package org.apache.qpid.systest.management.jmx;
 
 import org.apache.qpid.exchange.ExchangeDefaults;
 import org.apache.qpid.management.common.mbeans.ManagedBroker;
 import org.apache.qpid.management.common.mbeans.ManagedExchange;
-import org.apache.qpid.management.common.mbeans.ManagedQueue;
-import org.apache.qpid.server.queue.AMQQueueFactory;
 import org.apache.qpid.test.utils.JMXTestUtils;
 import org.apache.qpid.test.utils.QpidBrokerTestCase;
 
 import javax.management.MBeanException;
 import javax.management.ObjectName;
-import java.util.Collections;
-import java.util.Map;
 
 /**
  * Tests the JMX API for the Managed Broker.
  *
  */
-public class ManagedBrokerMBeanTest extends QpidBrokerTestCase
+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;
@@ -86,7 +74,7 @@ public class ManagedBrokerMBeanTest exte
         _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.
@@ -108,14 +96,11 @@ public class ManagedBrokerMBeanTest exte
     {
         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));
     }
 
     /**
@@ -140,25 +125,4 @@ public class ManagedBrokerMBeanTest exte
         assertNotNull("Exchange should exist", defaultExchange);
     }
 
-    /**
-     * Tests queue creation with {@link AMQQueueFactory#X_QPID_MAXIMUM_DELIVERY_COUNT} argument.  Also tests
-     * that the attribute is exposed correctly through {@link ManagedQueue#getMaximumDeliveryCount()}.
-     */
-    public void testCreateQueueWithMaximumDeliveryCountSet() throws Exception
-    {
-        final String queueName = getName();
-        final ManagedBroker managedBroker = _jmxUtils.getManagedBroker(VIRTUAL_HOST);
-
-        final Integer deliveryCount = 1;
-        final Map<String, Object> args = Collections.singletonMap(AMQQueueFactory.X_QPID_MAXIMUM_DELIVERY_COUNT, (Object)deliveryCount);
-        managedBroker.createNewQueue(queueName, "testowner", true, args);
-
-        // Ensure the queue exists
-        assertNotNull("Queue object name expected to exist", _jmxUtils.getQueueObjectName("test", queueName));
-        assertNotNull("Manager queue expected to be available", _jmxUtils.getManagedQueue(queueName));
-
-        final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
-        assertEquals("Unexpected maximum delivery count", deliveryCount, managedQueue.getMaximumDeliveryCount());
-    }
-
 }

Added: qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ConnectionManagementTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ConnectionManagementTest.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ConnectionManagementTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ConnectionManagementTest.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,283 @@
+/*
+ * 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.systest.management.jmx;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.management.JMException;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.TabularData;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.qpid.common.QpidProperties;
+import org.apache.qpid.management.common.mbeans.ManagedConnection;
+import org.apache.qpid.management.common.mbeans.ManagedQueue;
+import org.apache.qpid.test.utils.JMXTestUtils;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+
+public class ConnectionManagementTest extends QpidBrokerTestCase
+{
+    private static final String VIRTUAL_HOST_NAME = "test";
+
+    private JMXTestUtils _jmxUtils;
+    private Connection _connection;
+
+    public void setUp() throws Exception
+    {
+        _jmxUtils = new JMXTestUtils(this);
+        _jmxUtils.setUp(); // modifies broker config therefore must be done before super.setUp()
+        super.setUp();
+        _jmxUtils.open();
+    }
+
+    public void tearDown() throws Exception
+    {
+        try
+        {
+            if (_jmxUtils != null)
+            {
+                _jmxUtils.close();
+            }
+        }
+        finally
+        {
+            super.tearDown();
+        }
+    }
+
+    public void testNumberOfManagedConnectionsMatchesNumberOfClientConnections() throws Exception
+    {
+        assertEquals("Expected no managed connections", 0, getManagedConnections().size());
+
+        _connection = getConnection();
+        assertEquals("Expected one managed connection", 1, getManagedConnections().size());
+
+        _connection.close();
+        assertEquals("Expected no managed connections after client connection closed", 0, getManagedConnections().size());
+    }
+
+    public void testGetAttributes() throws Exception
+    {
+        _connection = getConnection();
+        final ManagedConnection mBean = getConnectionMBean();
+
+        checkAuthorisedId(mBean);
+        checkClientVersion(mBean);
+        checkClientId(mBean);
+    }
+
+    public void testNonTransactedSession() throws Exception
+    {
+        _connection = getConnection();
+
+        boolean transactional = false;
+        boolean flowBlocked = false;
+
+        _connection.createSession(transactional, Session.AUTO_ACKNOWLEDGE);
+
+        final ManagedConnection mBean = getConnectionMBean();
+        final CompositeDataSupport row = getTheOneChannelRow(mBean);
+        assertChannelRowData(row, 0, transactional, flowBlocked);
+    }
+
+    public void testTransactedSessionWithUnackMessages() throws Exception
+    {
+        _connection = getConnection();
+        _connection.start();
+
+        boolean transactional = true;
+        int numberOfMessages = 2;
+        final Session session = _connection.createSession(transactional, Session.SESSION_TRANSACTED);
+        final Destination destination = session.createQueue(getTestQueueName());
+        final MessageConsumer consumer = session.createConsumer(destination);
+
+        sendMessage(session, destination, numberOfMessages);
+        receiveMessagesWithoutCommit(consumer, numberOfMessages);
+
+        final ManagedConnection mBean = getConnectionMBean();
+        final CompositeDataSupport row = getTheOneChannelRow(mBean);
+        boolean flowBlocked = false;
+        assertChannelRowData(row, numberOfMessages, transactional, flowBlocked);
+
+        // check that commit advances the lastIoTime
+        final Date initialLastIOTime = mBean.getLastIoTime();
+        session.commit();
+        assertTrue("commit should have caused last IO time to advance", mBean.getLastIoTime().after(initialLastIOTime));
+
+        // check that channels() now returns one session with no unacknowledged messages
+        final CompositeDataSupport rowAfterCommit = getTheOneChannelRow(mBean);
+        final Number unackCountAfterCommit = (Number) rowAfterCommit.get(ManagedConnection.UNACKED_COUNT);
+        assertEquals("Unexpected number of unacknowledged messages", 0, unackCountAfterCommit);
+    }
+
+
+    public void testProducerFlowBlocked() throws Exception
+    {
+        _connection = getConnection();
+        _connection.start();
+
+        String queueName = getTestQueueName();
+        Session session = _connection.createSession(true, Session.SESSION_TRANSACTED);
+        Queue queue = session.createQueue(queueName);
+        createQueueOnBroker(session, queue);
+
+        ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+        managedQueue.setFlowResumeCapacity(DEFAULT_MESSAGE_SIZE * 2l);
+        managedQueue.setCapacity(DEFAULT_MESSAGE_SIZE * 3l);
+
+        final ManagedConnection managedConnection = getConnectionMBean();
+
+        // Check that producer flow is not block before test
+        final CompositeDataSupport rowBeforeSend = getTheOneChannelRow(managedConnection);
+        assertFlowBlocked(rowBeforeSend, false);
+
+
+        // Check that producer flow does not become block too soon
+        sendMessage(session, queue, 3);
+        final CompositeDataSupport rowBeforeFull = getTheOneChannelRow(managedConnection);
+        assertFlowBlocked(rowBeforeFull, false);
+
+        // Fourth message will over-fill the queue (but as we are not sending more messages, client thread wont't block)
+        sendMessage(session, queue, 1);
+        final CompositeDataSupport rowAfterFull = getTheOneChannelRow(managedConnection);
+        assertFlowBlocked(rowAfterFull, true);
+
+        // Consume two to bring the queue down to the resume capacity
+        MessageConsumer consumer = session.createConsumer(queue);
+        assertNotNull("Could not receive first message", consumer.receive(1000));
+        assertNotNull("Could not receive second message", consumer.receive(1000));
+        session.commit();
+
+        // Check that producer flow is no longer blocked
+        final CompositeDataSupport rowAfterReceive = getTheOneChannelRow(managedConnection);
+        assertFlowBlocked(rowAfterReceive, false);
+    }
+
+    private void createQueueOnBroker(Session session, Destination destination) throws JMSException
+    {
+        session.createConsumer(destination).close(); // Create a consumer only to cause queue creation
+    }
+
+    private void assertChannelRowData(final CompositeData row, int unacknowledgedMessages, boolean isTransactional, boolean flowBlocked)
+    {
+        assertNotNull(row);
+        assertEquals("Unexpected transactional flag", isTransactional, row.get(ManagedConnection.TRANSACTIONAL));
+        assertEquals("Unexpected unacknowledged message count", unacknowledgedMessages, row.get(ManagedConnection.UNACKED_COUNT));
+        assertEquals("Unexpected flow blocked", flowBlocked, row.get(ManagedConnection.FLOW_BLOCKED));
+    }
+
+    private void assertFlowBlocked(final CompositeData row, boolean flowBlocked)
+    {
+        assertNotNull(row);
+        assertEquals("Unexpected flow blocked", flowBlocked, row.get(ManagedConnection.FLOW_BLOCKED));
+    }
+
+    private void checkAuthorisedId(ManagedConnection mBean) throws Exception
+    {
+        assertEquals("Unexpected authorized id", GUEST_USERNAME, mBean.getAuthorizedId());
+    }
+
+    private void checkClientVersion(ManagedConnection mBean) throws Exception
+    {
+        String expectedVersion = QpidProperties.getReleaseVersion();
+        assertTrue(StringUtils.isNotBlank(expectedVersion));
+
+        assertEquals("Unexpected version", expectedVersion, mBean.getVersion());
+    }
+
+    private void checkClientId(ManagedConnection mBean) throws Exception
+    {
+        String expectedClientId = _connection.getClientID();
+        assertTrue(StringUtils.isNotBlank(expectedClientId));
+
+        assertEquals("Unexpected ClientId", expectedClientId, mBean.getClientId());
+    }
+
+    private ManagedConnection getConnectionMBean()
+    {
+        List<ManagedConnection> connections = getManagedConnections();
+        assertNotNull("Connection MBean is not found", connections);
+        assertEquals("Unexpected number of connection mbeans", 1, connections.size());
+        final ManagedConnection mBean = connections.get(0);
+        assertNotNull("Connection MBean is null", mBean);
+        return mBean;
+    }
+
+    private List<ManagedConnection> getManagedConnections()
+    {
+        return _jmxUtils.getManagedConnections(VIRTUAL_HOST_NAME);
+    }
+
+    private CompositeDataSupport getTheOneChannelRow(final ManagedConnection mBean) throws Exception
+    {
+        TabularData channelsData = getChannelsDataWithRetry(mBean);
+
+        assertEquals("Unexpected number of rows in channel table", 1, channelsData.size());
+
+        @SuppressWarnings("unchecked")
+        final Iterator<CompositeDataSupport> rowItr = (Iterator<CompositeDataSupport>) channelsData.values().iterator();
+        final CompositeDataSupport row = rowItr.next();
+        return row;
+    }
+
+    private void receiveMessagesWithoutCommit(final MessageConsumer consumer, int numberOfMessages) throws Exception
+    {
+        for (int i = 0; i < numberOfMessages; i++)
+        {
+            final Message m = consumer.receive(1000l);
+            assertNotNull("Message " + i + " is not received", m);
+        }
+    }
+
+    private TabularData getChannelsDataWithRetry(final ManagedConnection mBean)
+            throws IOException, JMException
+    {
+        TabularData channelsData = mBean.channels();
+        int retries = 0;
+        while(channelsData.size() == 0 && retries < 5)
+        {
+            sleep();
+            channelsData = mBean.channels();
+            retries++;
+        }
+        return channelsData;
+    }
+
+    private void sleep()
+    {
+        try
+        {
+            Thread.sleep(50);
+        }
+        catch (InterruptedException ie)
+        {
+            Thread.currentThread().interrupt();
+        }
+    }}

Copied: qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementActorLoggingTest.java (from r1354912, qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementActorLoggingTest.java?p2=qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementActorLoggingTest.java&p1=qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java&r1=1354912&r2=1355072&rev=1355072&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementActorLoggingTest.java Thu Jun 28 16:46:12 2012
@@ -18,7 +18,7 @@
  * under the License.
  *
  */
-package org.apache.qpid.management.jmx;
+package org.apache.qpid.systest.management.jmx;
 
 import org.apache.qpid.management.common.mbeans.ManagedBroker;
 import org.apache.qpid.management.common.mbeans.ManagedConnection;

Copied: qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java (from r1354912, qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ManagementLoggingTest.java)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java?p2=qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java&p1=qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ManagementLoggingTest.java&r1=1354912&r2=1355072&rev=1355072&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ManagementLoggingTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java Thu Jun 28 16:46:12 2012
@@ -18,10 +18,11 @@
  * under the License.
  *
  */
-package org.apache.qpid.server.logging;
+package org.apache.qpid.systest.management.jmx;
 
 
 import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.logging.AbstractTestLogging;
 import org.apache.qpid.test.utils.JMXTestUtils;
 import org.apache.qpid.util.LogMonitor;
 
@@ -177,7 +178,7 @@ public class ManagementLoggingTest exten
         if (isJavaBroker())
         {
             startBrokerAndCreateMonitor(true, false);
-            
+
             List<String> results = waitAndFindMatches("MNG-1002");
             // Validation
 



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