1
2
3
4
5
6
7 package org.mule.transport.jms;
8
9 import org.mule.api.endpoint.ImmutableEndpoint;
10 import org.mule.tck.junit4.FunctionalTestCase;
11
12 import com.mockobjects.dynamic.Mock;
13
14 import javax.jms.Queue;
15 import javax.jms.Topic;
16
17 import org.junit.Test;
18
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertSame;
21 import static org.junit.Assert.assertTrue;
22
23 public class DefaultJmsTopicResolverTestCase extends FunctionalTestCase
24 {
25 private JmsConnector connector;
26 private DefaultJmsTopicResolver resolver;
27
28 @Override
29 protected String getConfigResources()
30 {
31 return "jms-topic-resolver.xml";
32 }
33
34 @Override
35 protected void doSetUp() throws Exception
36 {
37 super.doSetUp();
38 connector = (JmsConnector) muleContext.getRegistry().lookupConnector("jmsConnector");
39 resolver = (DefaultJmsTopicResolver) connector.getTopicResolver();
40 }
41
42 @Test
43 public void testSameConnector()
44 {
45 assertSame(connector, resolver.getConnector());
46 }
47
48 @Test
49 public void testEndpointNotTopicWithFallback() throws Exception
50 {
51 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep1");
52 assertFalse(resolver.isTopic(endpoint));
53 }
54
55 @Test
56 public void testEndpointNotTopicWithFallback2() throws Exception
57 {
58 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep1");
59 assertFalse(resolver.isTopic(endpoint, true));
60 }
61
62 @Test
63 public void testEndpointNotTopicNoFallback() throws Exception
64 {
65 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep1");
66 assertFalse(resolver.isTopic(endpoint, false));
67 }
68
69 @Test
70 public void testEndpointTopicPropertyWithFallback() throws Exception
71 {
72 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep2");
73 assertTrue(resolver.isTopic(endpoint));
74 }
75
76 @Test
77 public void testEndpointTopicPropertyWithFallback2() throws Exception
78 {
79 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep2");
80 assertTrue(resolver.isTopic(endpoint, true));
81 }
82
83 @Test
84 public void testEndpointTopicPropertyNoFallback() throws Exception
85 {
86 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep2");
87 assertFalse(resolver.isTopic(endpoint, false));
88 }
89
90 @Test
91 public void testEndpointTopicPrefixWithFallback() throws Exception
92 {
93 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep3");
94 assertTrue(resolver.isTopic(endpoint));
95 }
96
97 @Test
98 public void testEndpointTopicPrefixWithFallback2() throws Exception
99 {
100 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep3");
101 assertTrue(resolver.isTopic(endpoint, true));
102 }
103
104 @Test
105 public void testEndpointTopicPrefixNoFallback() throws Exception
106 {
107 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep3");
108 assertTrue(resolver.isTopic(endpoint, false));
109 }
110
111 @Test
112 public void testEndpointTopicPrefixAndPropertyWithFallback() throws Exception
113 {
114 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep4");
115 assertTrue(resolver.isTopic(endpoint));
116 }
117
118 @Test
119 public void testEndpointTopicPrefixAndPropertyWithFallback2() throws Exception
120 {
121 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep4");
122 assertTrue(resolver.isTopic(endpoint, true));
123 }
124
125 @Test
126 public void testEndpointTopicPrefixAndPropertyNoFallback() throws Exception
127 {
128 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep4");
129 assertTrue(resolver.isTopic(endpoint, false));
130 }
131
132 @Test
133 public void testEndpointTopicUsesEndpointProperties() throws Exception
134 {
135 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep5");
136 assertTrue(resolver.isTopic(endpoint));
137 }
138
139 @Test
140 public void testEndpointTopicWithLeadingSlash() throws Exception
141 {
142 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep6");
143 assertTrue(resolver.isTopic(endpoint));
144 }
145
146 @Test
147 public void testEndpointTopicWithSlashes() throws Exception
148 {
149 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep7");
150 assertTrue(resolver.isTopic(endpoint));
151 }
152
153 @Test
154 public void testEndpointQueueWithSlashes() throws Exception
155 {
156 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep8");
157 assertFalse(resolver.isTopic(endpoint));
158 }
159
160 @Test
161 public void testDestinationNotTopic() throws Exception
162 {
163
164 Mock mock = new Mock(Queue.class);
165 Queue queue = (Queue) mock.proxy();
166
167 assertFalse(resolver.isTopic(queue));
168 mock.verify();
169 }
170
171 @Test
172 public void testDestinationTopic() throws Exception
173 {
174
175 Mock mock = new Mock(Topic.class);
176 Topic topic = (Topic) mock.proxy();
177
178 assertTrue(resolver.isTopic(topic));
179 mock.verify();
180 }
181
182 }