[jboss-cvs] JBoss Messaging SVN: r4716 - in branches/Branch_JBMESSAGING-1303: src/main/org/jboss/messaging/jms/server/management and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 23 10:15:42 EDT 2008


Author: jmesnil
Date: 2008-07-23 10:15:42 -0400 (Wed, 23 Jul 2008)
New Revision: 4716

Added:
   branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/impl/
   branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/impl/JMSQueueControlTest.java
   branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/impl/TopicControlTest.java
Modified:
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/AddressControl.java
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/jms/server/management/TopicControlMBean.java
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/jms/server/management/impl/TopicControl.java
   branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/JMSMessageInfoTest.java
   branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/SubscriberInfoTest.java
Log:
JBMESSAGING-1303: Revisit management interfaces
* added unit tests for JMSQueueControl & TopicControl

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/AddressControl.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/AddressControl.java	2008-07-23 11:27:02 UTC (rev 4715)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/AddressControl.java	2008-07-23 14:15:42 UTC (rev 4716)
@@ -91,7 +91,7 @@
          return queueNames;
       } catch (Throwable t)
       {
-         return new String[0];
+         throw new IllegalStateException(t.getMessage());
       }
    }
 

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/jms/server/management/TopicControlMBean.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/jms/server/management/TopicControlMBean.java	2008-07-23 11:27:02 UTC (rev 4715)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/jms/server/management/TopicControlMBean.java	2008-07-23 14:15:42 UTC (rev 4716)
@@ -37,11 +37,11 @@
 {
    // Attributes ----------------------------------------------------
 
-   int getSubcriptionsCount();
+   int getSubcribersCount();
 
-   int getDurableSubcriptionsCount();
+   int getDurableSubcribersCount();
 
-   int getNonDurableSubcriptionsCount();
+   int getNonDurableSubcribersCount();
 
    int getDurableMessageCount();
 

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/jms/server/management/impl/TopicControl.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/jms/server/management/impl/TopicControl.java	2008-07-23 11:27:02 UTC (rev 4715)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/jms/server/management/impl/TopicControl.java	2008-07-23 14:15:42 UTC (rev 4716)
@@ -131,17 +131,17 @@
       return getMessageCount(DurabilityType.NON_DURABLE);
    }
 
-   public int getSubcriptionsCount()
+   public int getSubcribersCount()
    {
       return getQueues(DurabilityType.ALL).size();
    }
 
-   public int getDurableSubcriptionsCount()
+   public int getDurableSubcribersCount()
    {
       return getQueues(DurabilityType.DURABLE).size();
    }
 
-   public int getNonDurableSubcriptionsCount()
+   public int getNonDurableSubcribersCount()
    {
       return getQueues(DurabilityType.NON_DURABLE).size();
    }

Modified: branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/JMSMessageInfoTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/JMSMessageInfoTest.java	2008-07-23 11:27:02 UTC (rev 4715)
+++ branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/JMSMessageInfoTest.java	2008-07-23 14:15:42 UTC (rev 4716)
@@ -42,11 +42,8 @@
 
 import junit.framework.TestCase;
 
-import org.easymock.EasyMock;
-import org.jboss.messaging.core.management.MessageInfo;
 import org.jboss.messaging.core.server.ServerMessage;
 import org.jboss.messaging.jms.server.management.JMSMessageInfo;
-import org.jboss.messaging.tests.util.RandomUtil;
 import org.jboss.messaging.util.SimpleString;
 
 /**
@@ -63,7 +60,7 @@
 
    // Static --------------------------------------------------------
 
-   private static void assertEquals(JMSMessageInfo expected,
+   public static void assertJMSMessageInfoEquals(JMSMessageInfo expected,
          CompositeData actual)
    {
       assertTrue(actual.getCompositeType().equals(JMSMessageInfo.TYPE));
@@ -103,7 +100,7 @@
       info.putProperty(randomString(), randomString());
       CompositeData data = info.toCompositeData();
 
-      assertEquals(info, data);
+      assertJMSMessageInfoEquals(info, data);
    }
 
    public void testToTabularData() throws Exception
@@ -126,8 +123,8 @@
       CompositeData data_2 = data
             .get(new Object[] { info_2.getJMSMessageID() });
 
-      assertEquals(info_1, data_1);
-      assertEquals(info_2, data_2);
+      assertJMSMessageInfoEquals(info_1, data_1);
+      assertJMSMessageInfoEquals(info_2, data_2);
    }
 
    public void testToTabularDataWithEmptyMessages() throws Exception

Modified: branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/SubscriberInfoTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/SubscriberInfoTest.java	2008-07-23 11:27:02 UTC (rev 4715)
+++ branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/SubscriberInfoTest.java	2008-07-23 14:15:42 UTC (rev 4716)
@@ -47,7 +47,7 @@
 
    // Static --------------------------------------------------------
 
-   private static void assertEquals(SubscriberInfo expected,
+   public static void assertEquals(SubscriberInfo expected,
          CompositeData actual)
    {
       assertTrue(actual.getCompositeType().equals(SubscriberInfo.TYPE));

Added: branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/impl/JMSQueueControlTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/impl/JMSQueueControlTest.java	                        (rev 0)
+++ branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/impl/JMSQueueControlTest.java	2008-07-23 14:15:42 UTC (rev 4716)
@@ -0,0 +1,258 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.jms.server.management.impl;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.jboss.messaging.tests.util.RandomUtil.randomBoolean;
+import static org.jboss.messaging.tests.util.RandomUtil.randomByte;
+import static org.jboss.messaging.tests.util.RandomUtil.randomInt;
+import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
+import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.jms.JBossQueue;
+import org.jboss.messaging.jms.server.JMSServerManager;
+import org.jboss.messaging.jms.server.management.impl.JMSQueueControl;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class JMSQueueControlTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testGetName() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossQueue queue = new JBossQueue(name);
+      Queue coreQueue = createMock(Queue.class);
+      JMSServerManager serverManager = createMock(JMSServerManager.class);
+
+      replay(coreQueue, serverManager);
+
+      JMSQueueControl control = new JMSQueueControl(queue, coreQueue,
+            jndiBinding, serverManager);
+      assertEquals(name, control.getName());
+
+      verify(coreQueue, serverManager);
+   }
+
+   public void testGetAddress() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossQueue queue = new JBossQueue(name);
+      Queue coreQueue = createMock(Queue.class);
+      JMSServerManager serverManager = createMock(JMSServerManager.class);
+
+      replay(coreQueue, serverManager);
+
+      JMSQueueControl control = new JMSQueueControl(queue, coreQueue,
+            jndiBinding, serverManager);
+      assertEquals(queue.getAddress(), control.getAddress());
+
+      verify(coreQueue, serverManager);
+   }
+
+   public void testGetJNDIBinding() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossQueue queue = new JBossQueue(name);
+      Queue coreQueue = createMock(Queue.class);
+      JMSServerManager serverManager = createMock(JMSServerManager.class);
+
+      replay(coreQueue, serverManager);
+
+      JMSQueueControl control = new JMSQueueControl(queue, coreQueue,
+            jndiBinding, serverManager);
+      assertEquals(jndiBinding, control.getJNDIBinding());
+
+      verify(coreQueue, serverManager);
+   }
+
+   public void testIsTemporary() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossQueue queue = new JBossQueue(name);
+      Queue coreQueue = createMock(Queue.class);
+      JMSServerManager serverManager = createMock(JMSServerManager.class);
+
+      replay(coreQueue, serverManager);
+
+      JMSQueueControl control = new JMSQueueControl(queue, coreQueue,
+            jndiBinding, serverManager);
+      assertEquals(queue.isTemporary(), control.isTemporary());
+
+      verify(coreQueue, serverManager);
+   }
+
+   public void testGetMessageCount() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+      int count = randomInt();
+
+      JBossQueue queue = new JBossQueue(name);
+      Queue coreQueue = createMock(Queue.class);
+      expect(coreQueue.getMessageCount()).andReturn(count);
+      JMSServerManager serverManager = createMock(JMSServerManager.class);
+
+      replay(coreQueue, serverManager);
+
+      JMSQueueControl control = new JMSQueueControl(queue, coreQueue,
+            jndiBinding, serverManager);
+      assertEquals(count, control.getMessageCount());
+
+      verify(coreQueue, serverManager);
+   }
+
+   public void testRemoveAllMessages() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossQueue queue = new JBossQueue(name);
+      Queue coreQueue = createMock(Queue.class);
+      JMSServerManager serverManager = createMock(JMSServerManager.class);
+      serverManager.removeAllMessages(queue);
+
+      replay(coreQueue, serverManager);
+
+      JMSQueueControl control = new JMSQueueControl(queue, coreQueue,
+            jndiBinding, serverManager);
+      control.removeAllMessages();
+
+      verify(coreQueue, serverManager);
+   }
+
+   public void testListMessages() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossQueue queue = new JBossQueue(name);
+      String filterStr = "color = 'green'";
+      List<MessageReference> refs = new ArrayList<MessageReference>();
+      MessageReference ref = createMock(MessageReference.class);
+      ServerMessage message = createMock(ServerMessage.class);
+      expect(message.getProperty(new SimpleString("JMSMessageID")))
+            .andStubReturn(randomSimpleString());
+      expect(message.getProperty(new SimpleString("JMSCorrelationID")))
+            .andStubReturn(randomSimpleString());
+      expect(message.getProperty(new SimpleString("JMSType"))).andStubReturn(
+            randomSimpleString());
+      expect(message.isDurable()).andStubReturn(randomBoolean());
+      expect(message.getPriority()).andStubReturn(randomByte());
+      expect(message.getProperty(new SimpleString("JMSReplyTo")))
+            .andStubReturn(randomSimpleString());
+      expect(message.getTimestamp()).andStubReturn(randomLong());
+      expect(message.getExpiration()).andStubReturn(randomLong());
+      expect(message.getPropertyNames()).andStubReturn(
+            new HashSet<SimpleString>());
+      expect(ref.getMessage()).andReturn(message);
+      refs.add(ref);
+      Queue coreQueue = createMock(Queue.class);
+      expect(coreQueue.list(isA(Filter.class))).andReturn(refs);
+      JMSServerManager serverManager = createMock(JMSServerManager.class);
+
+      replay(coreQueue, serverManager, ref, message);
+
+      JMSQueueControl control = new JMSQueueControl(queue, coreQueue,
+            jndiBinding, serverManager);
+      TabularData data = control.listMessages(filterStr);
+      assertEquals(1, data.size());
+      CompositeData info = data.get(new Object[] { message.getProperty(
+            new SimpleString("JMSMessageID")).toString() });
+      assertNotNull(info);
+
+      verify(coreQueue, serverManager, ref, message);
+   }
+
+   public void testListMessagesThrowsException() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+      String invalidFilterStr = "this is not a valid filter";
+
+      JBossQueue queue = new JBossQueue(name);
+      Queue coreQueue = createMock(Queue.class);
+      JMSServerManager serverManager = createMock(JMSServerManager.class);
+
+      replay(coreQueue, serverManager);
+
+      JMSQueueControl control = new JMSQueueControl(queue, coreQueue,
+            jndiBinding, serverManager);
+      try
+      {
+         control.listMessages(invalidFilterStr);
+         fail("IllegalStateException");
+      } catch (IllegalStateException e)
+      {
+
+      }
+      verify(coreQueue, serverManager);
+   }
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Added: branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/impl/TopicControlTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/impl/TopicControlTest.java	                        (rev 0)
+++ branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/jms/server/management/impl/TopicControlTest.java	2008-07-23 14:15:42 UTC (rev 4716)
@@ -0,0 +1,319 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.jms.server.management.impl;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.jboss.messaging.tests.util.RandomUtil.randomBoolean;
+import static org.jboss.messaging.tests.util.RandomUtil.randomByte;
+import static org.jboss.messaging.tests.util.RandomUtil.randomInt;
+import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
+import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.management.MessagingServerManagement;
+import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.jms.JBossQueue;
+import org.jboss.messaging.jms.JBossTopic;
+import org.jboss.messaging.jms.server.JMSServerManager;
+import org.jboss.messaging.jms.server.management.SubscriberInfo;
+import org.jboss.messaging.jms.server.management.impl.JMSQueueControl;
+import org.jboss.messaging.jms.server.management.impl.TopicControl;
+import org.jboss.messaging.tests.unit.jms.server.management.SubscriberInfoTest;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class TopicControlTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testGetName() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossTopic topic = new JBossTopic(name);
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+
+      replay(server);
+
+      TopicControl control = new TopicControl(topic, server, jndiBinding);
+      assertEquals(name, control.getName());
+
+      verify(server);
+   }
+
+   public void testGetAddress() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossTopic topic = new JBossTopic(name);
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+
+      replay(server);
+
+      TopicControl control = new TopicControl(topic, server, jndiBinding);
+      assertEquals(topic.getAddress(), control.getAddress());
+
+      verify(server);
+   }
+
+   public void testGetJNDIBinding() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossTopic topic = new JBossTopic(name);
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+
+      replay(server);
+
+      TopicControl control = new TopicControl(topic, server, jndiBinding);
+      assertEquals(jndiBinding, control.getJNDIBinding());
+
+      verify(server);
+   }
+
+   public void testIsTemporary() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossTopic topic = new JBossTopic(name);
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+
+      replay(server);
+
+      TopicControl control = new TopicControl(topic, server, jndiBinding);
+      assertEquals(topic.isTemporary(), control.isTemporary());
+
+      verify(server);
+   }
+
+   public void testGetMessageCount() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      int countForNonDurableQueue = randomInt();
+      int countForDurableQueue_1 = randomInt();
+      int countForDurableQueue_2 = randomInt();
+
+      JBossTopic topic = new JBossTopic(name);
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+      Queue nonDurableQueue = createMock(Queue.class);
+      expect(nonDurableQueue.isDurable()).andStubReturn(false);
+      expect(nonDurableQueue.getMessageCount()).andStubReturn(
+            countForNonDurableQueue);
+      Queue durableQueue_1 = createMock(Queue.class);
+      expect(durableQueue_1.isDurable()).andStubReturn(true);
+      expect(durableQueue_1.getMessageCount()).andStubReturn(
+            countForDurableQueue_1);
+      Queue durableQueue_2 = createMock(Queue.class);
+      expect(durableQueue_2.isDurable()).andStubReturn(true);
+      expect(durableQueue_2.getMessageCount()).andStubReturn(
+            countForDurableQueue_2);
+      List<Queue> queues = new ArrayList<Queue>();
+      queues.add(nonDurableQueue);
+      queues.add(durableQueue_1);
+      queues.add(durableQueue_2);
+      expect(server.getQueuesForAddress(topic.getSimpleAddress()))
+            .andStubReturn(queues);
+      replay(server, nonDurableQueue, durableQueue_1, durableQueue_2);
+
+      TopicControl control = new TopicControl(topic, server, jndiBinding);
+      assertEquals(countForNonDurableQueue + countForDurableQueue_1
+            + countForDurableQueue_2, control.getMessageCount());
+      assertEquals(countForDurableQueue_1 + countForDurableQueue_2, control
+            .getDurableMessageCount());
+      assertEquals(countForNonDurableQueue, control.getNonDurableMessageCount());
+
+      verify(server, nonDurableQueue, durableQueue_1, durableQueue_2);
+   }
+
+   public void testGetSubcribersCount() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossTopic topic = new JBossTopic(name);
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+      Queue nonDurableQueue = createMock(Queue.class);
+      expect(nonDurableQueue.isDurable()).andStubReturn(false);
+      Queue durableQueue_1 = createMock(Queue.class);
+      expect(durableQueue_1.isDurable()).andStubReturn(true);
+      Queue durableQueue_2 = createMock(Queue.class);
+      expect(durableQueue_2.isDurable()).andStubReturn(true);
+      List<Queue> queues = new ArrayList<Queue>();
+      queues.add(nonDurableQueue);
+      queues.add(durableQueue_1);
+      queues.add(durableQueue_2);
+      expect(server.getQueuesForAddress(topic.getSimpleAddress()))
+            .andStubReturn(queues);
+      replay(server, nonDurableQueue, durableQueue_1, durableQueue_2);
+
+      TopicControl control = new TopicControl(topic, server, jndiBinding);
+      assertEquals(3, control.getSubcribersCount());
+      assertEquals(2, control.getDurableSubcribersCount());
+      assertEquals(1, control.getNonDurableSubcribersCount());
+
+      verify(server, nonDurableQueue, durableQueue_1, durableQueue_2);
+   }
+
+   public void testRemoveAllMessages() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossTopic topic = new JBossTopic(name);
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+      server.removeAllMessagesForAddress(topic.getSimpleAddress());
+      replay(server);
+
+      TopicControl control = new TopicControl(topic, server, jndiBinding);
+      control.removeAllMessages();
+
+      verify(server);
+   }
+
+   public void testListSubscriberInfos() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossTopic topic = new JBossTopic(name);
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+      Queue durableQueue = createMock(Queue.class);
+      expect(durableQueue.getName()).andStubReturn(
+            JBossTopic.createAddressFromName(randomString()));
+      expect(durableQueue.getFilter()).andStubReturn(null);
+      expect(durableQueue.isDurable()).andStubReturn(true);
+      expect(durableQueue.getMessageCount()).andStubReturn(randomInt());
+      expect(durableQueue.getMaxSizeBytes()).andStubReturn(randomInt());
+      Queue nonDurableQueue = createMock(Queue.class);
+      expect(nonDurableQueue.getName()).andStubReturn(
+            JBossTopic.createAddressFromName(randomString()));
+      expect(nonDurableQueue.getFilter()).andStubReturn(null);
+      expect(nonDurableQueue.isDurable()).andStubReturn(false);
+      expect(nonDurableQueue.getMessageCount()).andStubReturn(randomInt());
+      expect(nonDurableQueue.getMaxSizeBytes()).andStubReturn(randomInt());
+      List<Queue> queues = new ArrayList<Queue>();
+      queues.add(durableQueue);
+      queues.add(nonDurableQueue);
+      expect(server.getQueuesForAddress(topic.getSimpleAddress()))
+            .andStubReturn(queues);
+      replay(server, durableQueue, nonDurableQueue);
+
+      TopicControl control = new TopicControl(topic, server, jndiBinding);
+      SubscriberInfo[] infos = control.listAllSubscriberInfos();
+      assertEquals(2, infos.length);
+      infos = control.listDurableSubscriberInfos();
+      assertEquals(1, infos.length);
+      assertEquals(durableQueue.getName().toString(), infos[0].getID());
+      infos = control.listNonDurableSubscriberInfos();
+      assertEquals(1, infos.length);
+      assertEquals(nonDurableQueue.getName().toString(), infos[0].getID());
+
+      verify(server, durableQueue, nonDurableQueue);
+   }
+
+   public void testListSubscribers() throws Exception
+   {
+      String jndiBinding = randomString();
+      String name = randomString();
+
+      JBossTopic topic = new JBossTopic(name);
+      MessagingServerManagement server = createMock(MessagingServerManagement.class);
+      Queue durableQueue = createMock(Queue.class);
+      expect(durableQueue.getName()).andStubReturn(
+            JBossTopic.createAddressFromName(randomString()));
+      expect(durableQueue.getFilter()).andStubReturn(null);
+      expect(durableQueue.isDurable()).andStubReturn(true);
+      expect(durableQueue.getMessageCount()).andStubReturn(randomInt());
+      expect(durableQueue.getMaxSizeBytes()).andStubReturn(randomInt());
+      Queue nonDurableQueue = createMock(Queue.class);
+      expect(nonDurableQueue.getName()).andStubReturn(
+            JBossTopic.createAddressFromName(randomString()));
+      expect(nonDurableQueue.getFilter()).andStubReturn(null);
+      expect(nonDurableQueue.isDurable()).andStubReturn(false);
+      expect(nonDurableQueue.getMessageCount()).andStubReturn(randomInt());
+      expect(nonDurableQueue.getMaxSizeBytes()).andStubReturn(randomInt());
+      List<Queue> queues = new ArrayList<Queue>();
+      queues.add(durableQueue);
+      queues.add(nonDurableQueue);
+      expect(server.getQueuesForAddress(topic.getSimpleAddress()))
+            .andStubReturn(queues);
+      replay(server, durableQueue, nonDurableQueue);
+
+      TopicControl control = new TopicControl(topic, server, jndiBinding);
+      TabularData data = control.listAllSubscribers();
+      assertEquals(2, data.size());
+      data = control.listDurableSubscribers();
+      assertEquals(1, data.size());
+      CompositeData info = data.get(new String[] { durableQueue.getName().toString() });
+      assertNotNull(info);
+      data = control.listNonDurableSubscribers();
+      assertEquals(1, data.size());
+      info = data.get(new String[] { nonDurableQueue.getName().toString() });
+      assertNotNull(info);
+
+      verify(server, durableQueue, nonDurableQueue);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}




More information about the jboss-cvs-commits mailing list