1 17 package org.apache.activemq.usecases; 18 19 import org.apache.activemq.EmbeddedBrokerTestSupport; 20 import org.apache.activemq.command.ActiveMQDestination; 21 import org.apache.activemq.command.ActiveMQQueue; 22 23 import javax.jms.Connection ; 24 import javax.jms.Destination ; 25 import javax.jms.Session ; 26 27 import java.util.Set ; 28 29 33 public class NewConsumerCreatesDestinationTest extends EmbeddedBrokerTestSupport { 34 35 private Connection connection; 36 private ActiveMQQueue wildcard; 37 38 public void testNewConsumerCausesNewDestinationToBeAutoCreated() throws Exception { 39 connection = createConnection(); 40 41 String wildcardText = "org.*" + getDestinationString().substring("org.apache".length()); 43 wildcard = new ActiveMQQueue(wildcardText); 44 45 System.out.println("Using wildcard: " + wildcard); 46 System.out.println("on destination: " + destination); 47 48 assertDestinationCreated(destination, false); 49 assertDestinationCreated(wildcard, false); 50 51 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 52 session.createConsumer(destination); 53 54 assertDestinationCreated(destination, true); 55 assertDestinationCreated(wildcard, true); 56 } 57 58 protected void tearDown() throws Exception { 59 if (connection != null) { 60 connection.close(); 61 } 62 super.tearDown(); 63 } 64 65 protected void assertDestinationCreated(Destination destination, boolean expected) throws Exception { 66 Set answer = broker.getBroker().getDestinations((ActiveMQDestination) destination); 67 int size = expected ? 1 : 0; 68 assertEquals("Size of found destinations: " + answer, size, answer.size()); 69 } 70 } 71 | Popular Tags |