String topicName = RandomUtil.randomString();
UnitTestCase.checkNoBinding(context, topicJNDIBinding);
checkNoResource(ObjectNameBuilder.DEFAULT.getJMSTopicObjectName(topicName));
JMSServerControl control = createManagementControl();
control.createTopic(topicName, topicJNDIBinding);
checkResource(ObjectNameBuilder.DEFAULT.getJMSTopicObjectName(topicName));
Topic topic = (Topic)context.lookup(topicJNDIBinding);
assertNotNull(topic);
HornetQConnectionFactory cf = new HornetQConnectionFactory(false,
new TransportConfiguration(InVMConnectorFactory.class.getName()));
Connection connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// create a consumer will create a Core queue bound to the topic address
MessageConsumer cons = session.createConsumer(topic);
JSONArray jsonArray = new JSONArray(control.listAllConsumersAsJSON());
assertEquals(1 + getNumberOfConsumers(), jsonArray.length());
cons.close();
jsonArray = new JSONArray(control.listAllConsumersAsJSON());
assertEquals(getNumberOfConsumers(), jsonArray.length());
String topicAddress = HornetQDestination.createTopicAddressFromName(topicName).toString();
AddressControl addressControl = (AddressControl)server.getManagementService()
.getResource(ResourceNames.CORE_ADDRESS + topicAddress);
assertNotNull(addressControl);
assertTrue(addressControl.getQueueNames().length > 0);
connection.close();
control.destroyTopic(topicName);
assertNull(server.getManagementService().getResource(ResourceNames.CORE_ADDRESS + topicAddress));
UnitTestCase.checkNoBinding(context, topicJNDIBinding);
checkNoResource(ObjectNameBuilder.DEFAULT.getJMSTopicObjectName(topicName));