ServerManagement.undeployTopic("TopicSubscription");
   public void testListSubscriptionsAsText() throws Exception   {      InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());      TopicConnectionFactory cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");       ServerManagement.deployTopic("TopicSubscriptionListAsText");      Topic topic = (Topic)ic.lookup("/topic/TopicSubscriptionListAsText");      TopicConnection conn = cf.createTopicConnection();      conn.setClientID("Client1");      TopicSession s = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);      MessageProducer prod = s.createProducer(topic);      prod.setDeliveryMode(DeliveryMode.PERSISTENT);      // Create 1 durable subscription and 2 non-durable subscription      s.createDurableSubscriber(topic, "SubscriberA");            s.createSubscriber(topic);      s.createSubscriber(topic);      // There should be 3 subscriptions      ObjectName destObjectName =          new ObjectName("jboss.messaging.destination:service=Topic,name=TopicSubscriptionListAsText");      String text = (String)ServerManagement.invoke(destObjectName, "listSubscriptionsAsText", null, null);      //System.out.println("Text: \n" + text);            // Find the location of durable      int durableStart = text.indexOf("Durable");      assertTrue (durableStart != -1);      assertTrue (text.indexOf("SubscriberA", durableStart) != -1);      assertTrue (text.indexOf("Client1", durableStart) != -1);      // Find the first location of Non-durable      int nonDurableStart = text.indexOf("Non-durable");      assertTrue(nonDurableStart != -1);      // Find the 2nd Non-durable      int nonDurableSecond = text.substring(nonDurableStart).indexOf("Non-durable", 1);      assertTrue(nonDurableSecond != -1);            // Test durable subscriptions      text = (String)ServerManagement.invoke(            destObjectName,             "listSubscriptionsAsText",             new Object[] {Boolean.TRUE},            new String[] {"boolean"});      //System.out.println("Durable Text: \n" + text);            durableStart = text.indexOf("Durable");      assertTrue (durableStart != -1);      assertTrue (text.indexOf("SubscriberA", durableStart) != -1);      assertTrue (text.indexOf("Client1", durableStart) != -1);            // Test non-durable subscriptions      text = (String)ServerManagement.invoke(            destObjectName,             "listSubscriptionsAsText",             new Object[] {Boolean.FALSE},            new String[] {"boolean"});      //System.out.println("Non-durable Text: \n" + text);      nonDurableStart = text.indexOf("Non-durable");      assertTrue(nonDurableStart != -1);      // Find the 2nd Non-durable      nonDurableSecond = text.substring(nonDurableStart).indexOf("Non-durable", 1);      assertTrue(nonDurableSecond != -1);                 // Now disconnect      conn.close();            // There should be only 1 subscription totally      text = (String)ServerManagement.invoke(destObjectName, "listSubscriptionsAsText", null, null);      durableStart = text.indexOf("Durable");      assertTrue (durableStart != -1);      assertTrue (text.indexOf("SubscriberA", durableStart) != -1);      assertTrue (text.indexOf("Client1", durableStart) != -1);            // There should be 1 durable subscription      text = (String)ServerManagement.invoke(            destObjectName,             "listSubscriptionsAsText",             new Object[] {Boolean.TRUE},             new String[] {"boolean"});      durableStart = text.indexOf("Durable");      assertTrue (durableStart != -1);      assertTrue (text.indexOf("SubscriberA", durableStart) != -1);      assertTrue (text.indexOf("Client1", durableStart) != -1);             // There should be 0 non-durable subscription      text = (String)ServerManagement.invoke(            destObjectName,             "listSubscriptionsAsText",             new Object[] {Boolean.FALSE},             new String[] {"boolean"});      nonDurableStart = text.indexOf("Non-durable");      assertTrue(-1 == nonDurableStart);            ServerManagement.undeployTopic("TopicSubscriptionListAsText");   }