Java Source Code: org.apache.activemq.usecases.NewConsumerCreatesDestinationTest


   1: /*
   2:  * Licensed to the Apache Software Foundation (ASF) under one or more
   3:  * contributor license agreements.  See the NOTICE file distributed with
   4:  * this work for additional information regarding copyright ownership.
   5:  * The ASF licenses this file to You under the Apache License, Version 2.0
   6:  * (the "License"); you may not use this file except in compliance with
   7:  * the License.  You may obtain a copy of the License at
   8:  *
   9:  *      http://www.apache.org/licenses/LICENSE-2.0
  10:  *
  11:  * Unless required by applicable law or agreed to in writing, software
  12:  * distributed under the License is distributed on an "AS IS" BASIS,
  13:  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14:  * See the License for the specific language governing permissions and
  15:  * limitations under the License.
  16:  */
  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: /**
  30:  * 
  31:  * @version $Revision: $
  32:  */
  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:        // lets create a wildcard thats kinda like those used by Virtual Topics
  42:        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:}