1   /*
2    * $Id: DefaultJmsTopicResolverTestCase.java 9331 2007-10-24 14:10:01Z dfeist $
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 testEndpointNotTopicWithFallback() throws Exception
40      {
41          UMOEndpoint endpoint = new MuleEndpoint("jms://queue.NotATopic", true);
42          assertFalse(resolver.isTopic(endpoint));
43      }
44  
45      public void testEndpointNotTopicWithFallback2() throws Exception
46      {
47          UMOEndpoint endpoint = new MuleEndpoint("jms://queue.NotATopic", true);
48          assertFalse(resolver.isTopic(endpoint, true));
49      }
50  
51      public void testEndpointNotTopicNoFallback() throws Exception
52      {
53          UMOEndpoint endpoint = new MuleEndpoint("jms://queue.NotATopic", true);
54          assertFalse(resolver.isTopic(endpoint, false));
55      }
56  
57      public void testEndpointTopicPropertyWithFallback() throws Exception
58      {
59          UMOEndpoint endpoint = new MuleEndpoint("jms://context.aTopic?topic=true", true);
60          assertTrue(resolver.isTopic(endpoint));
61      }
62  
63      public void testEndpointTopicPropertyWithFallback2() throws Exception
64      {
65          UMOEndpoint endpoint = new MuleEndpoint("jms://context.aTopic?topic=true", true);
66          assertTrue(resolver.isTopic(endpoint, true));
67      }
68  
69      public void testEndpointTopicPropertyNoFallback() throws Exception
70      {
71          UMOEndpoint endpoint = new MuleEndpoint("jms://context.aTopic?topic=true", true);
72          assertFalse(resolver.isTopic(endpoint, false));
73      }
74  
75      public void testEndpointTopicPrefixWithFallback() throws Exception
76      {
77          UMOEndpoint endpoint = new MuleEndpoint("jms://topic:context.ThisIsATopic", true);
78          assertTrue(resolver.isTopic(endpoint));
79      }
80  
81      public void testEndpointTopicPrefixWithFallback2() throws Exception
82      {
83          UMOEndpoint endpoint = new MuleEndpoint("jms://topic:context.ThisIsATopic", true);
84          assertTrue(resolver.isTopic(endpoint, true));
85      }
86  
87      public void testEndpointTopicPrefixNoFallback() throws Exception
88      {
89          UMOEndpoint endpoint = new MuleEndpoint("jms://topic:context.ThisIsATopic", true);
90          assertTrue(resolver.isTopic(endpoint, false));
91      }
92  
93      public void testEndpointTopicPrefixAndPropertyWithFallback() throws Exception
94      {
95          UMOEndpoint endpoint = new MuleEndpoint("jms://topic:context.ThisIsATopic?topic=false", true);
96          assertTrue(resolver.isTopic(endpoint));
97      }
98  
99      public void testEndpointTopicPrefixAndPropertyWithFallback2() throws Exception
100     {
101         UMOEndpoint endpoint = new MuleEndpoint("jms://topic:context.ThisIsATopic?topic=false", true);
102         assertTrue(resolver.isTopic(endpoint, true));
103     }
104 
105     public void testEndpointTopicPrefixAndPropertyNoFallback() throws Exception
106     {
107         UMOEndpoint endpoint = new MuleEndpoint("jms://topic:context.ThisIsATopic?topic=false", true);
108         assertTrue(resolver.isTopic(endpoint, false));
109     }
110 
111     public void testDestinationNotTopic() throws Exception
112     {
113         // prepare the mock
114         Mock mock = new Mock(Queue.class);
115         Queue queue = (Queue) mock.proxy();
116 
117         assertFalse(resolver.isTopic(queue));
118         mock.verify();
119     }
120 
121     public void testDestinationTopic() throws Exception
122     {
123         // prepare the mock
124         Mock mock = new Mock(Topic.class);
125         Topic topic = (Topic) mock.proxy();
126 
127         assertTrue(resolver.isTopic(topic));
128         mock.verify();
129     }
130 
131 }