1   /*
2   * $Id: DefaultJmsTopicResolverTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3   * --------------------------------------------------------------------------------------
4   * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5   *
6   * The software in this package is published under the terms of the CPAL v1.0
7   * license, a copy of which has been included with this distribution in the
8   * LICENSE.txt file.
9   */
10  
11  package org.mule.providers.jms;
12  
13  import org.mule.impl.endpoint.MuleEndpoint;
14  import org.mule.tck.AbstractMuleTestCase;
15  import org.mule.umo.endpoint.UMOEndpoint;
16  
17  import com.mockobjects.dynamic.Mock;
18  
19  import javax.jms.Queue;
20  import javax.jms.Topic;
21  
22  public class DefaultJmsTopicResolverTestCase extends AbstractMuleTestCase
23  {
24      private JmsConnector connector;
25      private DefaultJmsTopicResolver resolver;
26  
27      protected void doSetUp () throws Exception
28      {
29          super.doSetUp();
30          connector = new JmsConnector();
31          resolver = new DefaultJmsTopicResolver(connector);
32      }
33  
34      public void testSameConnector()
35      {
36          assertSame(connector, resolver.getConnector());
37      }
38  
39      public void testEndpointNotTopicNoFallback() throws Exception
40      {
41          UMOEndpoint endpoint = new MuleEndpoint("jms://queue.NotATopic", true);
42          assertFalse(resolver.isTopic(endpoint));
43      }
44  
45      public void testEndpointTopicNoFallback() throws Exception
46      {
47          UMOEndpoint endpoint = new MuleEndpoint("jms://topic:context.ThisIsATopic", true);
48          assertTrue(resolver.isTopic(endpoint));
49      }
50  
51      public void testEndpointNotTopicWithFallback() throws Exception
52      {
53          UMOEndpoint endpoint = new MuleEndpoint("jms://context.aTopic?topic=true", true);
54          assertTrue(resolver.isTopic(endpoint, true));
55      }
56  
57      public void testEndpointTopicFallbackNotUsed() throws Exception
58      {
59          UMOEndpoint endpoint = new MuleEndpoint("jms://topic:context.ThisIsATopic?topic=false", true);
60          assertTrue(resolver.isTopic(endpoint, true));
61      }
62  
63      public void testDestinationNotTopic() throws Exception
64      {
65          // prepare the mock
66          Mock mock = new Mock(Queue.class);
67          Queue queue = (Queue) mock.proxy();
68  
69          assertFalse(resolver.isTopic(queue));
70          mock.verify();
71      }
72  
73      public void testDestinationTopic() throws Exception
74      {
75          // prepare the mock
76          Mock mock = new Mock(Topic.class);
77          Topic topic = (Topic) mock.proxy();
78  
79          assertTrue(resolver.isTopic(topic));
80          mock.verify();
81      }
82  
83  }