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