1   /*** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * 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   **/
18  package org.codehaus.activemq.service;
19  
20  import org.codehaus.activemq.broker.BrokerClientStub;
21  import org.codehaus.activemq.message.ActiveMQMessage;
22  import org.codehaus.activemq.message.ConsumerInfo;
23  
24  import java.util.List;
25  
26  /***
27   * @version $Revision: 1.4 $
28   */
29  public class SimpleTopicBrokerTest extends BrokerTestSupport {
30  
31      protected BrokerClientStub client = new BrokerClientStub();
32      protected ConsumerInfo consumerInfo;
33  
34  
35      public void testDispatch() throws Exception {
36          // now lets dispatch a message
37          ActiveMQMessage message = createMessage(getDestination());
38  
39          List messages = client.flushMessages();
40          assertEquals("No messages received yet", 0, messages.size());
41  
42          // now lets send it
43          broker.sendMessage(client, message);
44  
45          client.waitForMessageToArrive();
46  
47          // now the message should be here
48          messages = client.flushMessages();
49          assertEquals("Expected a single message", 1, messages.size());
50  
51          System.out.println("Received message: " + messages.get(0));
52      }
53  
54      protected String getDestination() {
55          return getClass().getName() + "." + getName();
56      }
57  
58      protected void setUp() throws Exception {
59          super.setUp();
60          consumerInfo = createConsumer(getDestination());
61          broker.addMessageConsumer(client, consumerInfo);
62      }
63  
64      protected void tearDown() throws Exception {
65          if (broker != null && client != null && consumerInfo != null) {
66              broker.removeMessageConsumer(client, consumerInfo);
67          }
68          super.tearDown();
69      }
70  }