1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.tck; |
12 | |
|
13 | |
import org.mule.DefaultExceptionStrategy; |
14 | |
import org.mule.api.DefaultMuleException; |
15 | |
import org.mule.api.MuleException; |
16 | |
import org.mule.api.component.JavaComponent; |
17 | |
import org.mule.api.config.ThreadingProfile; |
18 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
19 | |
import org.mule.api.endpoint.InboundEndpoint; |
20 | |
import org.mule.api.endpoint.OutboundEndpoint; |
21 | |
import org.mule.api.routing.InboundRouter; |
22 | |
import org.mule.api.routing.InboundRouterCollection; |
23 | |
import org.mule.api.routing.NestedRouter; |
24 | |
import org.mule.api.routing.OutboundRouter; |
25 | |
import org.mule.api.routing.OutboundRouterCollection; |
26 | |
import org.mule.api.routing.filter.Filter; |
27 | |
import org.mule.api.service.Service; |
28 | |
import org.mule.api.transaction.TransactionConfig; |
29 | |
import org.mule.api.transformer.Transformer; |
30 | |
import org.mule.component.PooledJavaComponent; |
31 | |
import org.mule.config.PoolingProfile; |
32 | |
import org.mule.config.QueueProfile; |
33 | |
import org.mule.model.seda.SedaService; |
34 | |
import org.mule.routing.filters.MessagePropertyFilter; |
35 | |
import org.mule.routing.filters.PayloadTypeFilter; |
36 | |
import org.mule.routing.filters.RegExFilter; |
37 | |
import org.mule.routing.filters.logic.AndFilter; |
38 | |
import org.mule.routing.inbound.IdempotentReceiver; |
39 | |
import org.mule.routing.inbound.SelectiveConsumer; |
40 | |
import org.mule.routing.outbound.FilteringOutboundRouter; |
41 | |
import org.mule.tck.testmodels.mule.TestCatchAllStrategy; |
42 | |
import org.mule.tck.testmodels.mule.TestCompressionTransformer; |
43 | |
import org.mule.tck.testmodels.mule.TestConnector; |
44 | |
import org.mule.tck.testmodels.mule.TestExceptionStrategy; |
45 | |
import org.mule.tck.testmodels.mule.TestTransactionFactory; |
46 | |
import org.mule.transformer.TransformerUtils; |
47 | |
import org.mule.transport.AbstractConnector; |
48 | |
|
49 | |
public abstract class AbstractConfigBuilderTestCase extends AbstractScriptConfigBuilderTestCase |
50 | |
{ |
51 | |
|
52 | |
public AbstractConfigBuilderTestCase(boolean legacy) |
53 | |
{ |
54 | 104 | super(legacy); |
55 | 104 | } |
56 | |
|
57 | |
|
58 | |
|
59 | |
public void testManagerConfig() throws Exception |
60 | |
{ |
61 | 4 | super.testManagerConfig(); |
62 | |
|
63 | 4 | assertNotNull(muleContext.getTransactionManager()); |
64 | 4 | } |
65 | |
|
66 | |
|
67 | |
public void testConnectorConfig() throws Exception |
68 | |
{ |
69 | 4 | super.testConnectorConfig(); |
70 | |
|
71 | 4 | TestConnector c = (TestConnector) muleContext.getRegistry().lookupConnector("dummyConnector"); |
72 | 4 | assertNotNull(c); |
73 | 4 | assertNotNull(c.getExceptionListener()); |
74 | 4 | assertTrue(c.getExceptionListener() instanceof TestExceptionStrategy); |
75 | 4 | } |
76 | |
|
77 | |
|
78 | |
public void testGlobalEndpointConfig() throws MuleException |
79 | |
{ |
80 | 4 | super.testGlobalEndpointConfig(); |
81 | 4 | ImmutableEndpoint endpoint = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint("fruitBowlEndpoint"); |
82 | 4 | assertNotNull(endpoint); |
83 | 4 | assertEquals(endpoint.getEndpointURI().getAddress(), "fruitBowlPublishQ"); |
84 | |
|
85 | 4 | MessagePropertyFilter filter = (MessagePropertyFilter)endpoint.getFilter(); |
86 | 4 | assertNotNull(filter); |
87 | 4 | assertEquals("foo=bar", filter.getExpression()); |
88 | 4 | } |
89 | |
|
90 | |
|
91 | |
public void testEndpointConfig() throws MuleException |
92 | |
{ |
93 | 4 | super.testEndpointConfig(); |
94 | |
|
95 | |
|
96 | 4 | ImmutableEndpoint endpoint = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint("waterMelonEndpoint"); |
97 | 4 | assertNotNull(endpoint); |
98 | 4 | assertEquals("UTF-8-TEST", endpoint.getEncoding()); |
99 | 4 | assertEquals("test.queue", endpoint.getEndpointURI().getAddress()); |
100 | |
|
101 | 4 | Service service = muleContext.getRegistry().lookupService("appleComponent2"); |
102 | 4 | assertNotNull(service); |
103 | 4 | } |
104 | |
|
105 | |
public void testExceptionStrategy2() |
106 | |
{ |
107 | 4 | Service service = muleContext.getRegistry().lookupService("appleComponent"); |
108 | 4 | assertNotNull(service.getExceptionListener()); |
109 | 4 | assertTrue(DefaultExceptionStrategy.class.isAssignableFrom(service.getExceptionListener().getClass())); |
110 | 4 | } |
111 | |
|
112 | |
|
113 | |
public void testTransformerConfig() |
114 | |
{ |
115 | 4 | super.testTransformerConfig(); |
116 | |
|
117 | 4 | Transformer t = muleContext.getRegistry().lookupTransformer("TestCompressionTransformer"); |
118 | 4 | assertNotNull(t); |
119 | 4 | assertTrue(t instanceof TestCompressionTransformer); |
120 | 4 | assertEquals(t.getReturnClass(), java.lang.String.class); |
121 | 4 | assertNotNull(((TestCompressionTransformer) t).getContainerProperty()); |
122 | 4 | } |
123 | |
|
124 | |
|
125 | |
public void testModelConfig() throws Exception |
126 | |
{ |
127 | 4 | super.testModelConfig(); |
128 | 4 | assertNotNull(muleContext.getRegistry().lookupService("appleComponent")); |
129 | 4 | assertNotNull(muleContext.getRegistry().lookupService("appleComponent2")); |
130 | 4 | } |
131 | |
|
132 | |
public void testOutboundRouterConfig2() |
133 | |
{ |
134 | |
|
135 | 4 | Service service = muleContext.getRegistry().lookupService("appleComponent"); |
136 | 4 | assertNotNull(service.getOutboundRouter()); |
137 | 4 | OutboundRouterCollection router = service.getOutboundRouter(); |
138 | 4 | assertNotNull(router.getCatchAllStrategy()); |
139 | 4 | assertEquals(2, router.getRouters().size()); |
140 | |
|
141 | 4 | OutboundRouter route1 = (OutboundRouter) router.getRouters().get(0); |
142 | 4 | assertTrue(route1 instanceof FilteringOutboundRouter); |
143 | 4 | assertNotNull(((FilteringOutboundRouter) route1).getTransformers()); |
144 | 4 | assertTrue(TransformerUtils.firstOrNull(((FilteringOutboundRouter) route1).getTransformers()) |
145 | |
instanceof TestCompressionTransformer); |
146 | |
|
147 | 4 | Filter filter = ((FilteringOutboundRouter) route1).getFilter(); |
148 | 4 | assertNotNull(filter); |
149 | 4 | assertTrue(filter instanceof PayloadTypeFilter); |
150 | 4 | assertEquals(String.class, ((PayloadTypeFilter) filter).getExpectedType()); |
151 | |
|
152 | |
|
153 | 4 | OutboundRouter route2 = (OutboundRouter) router.getRouters().get(1); |
154 | 4 | assertTrue(route2 instanceof FilteringOutboundRouter); |
155 | |
|
156 | 4 | Filter filter2 = ((FilteringOutboundRouter) route2).getFilter(); |
157 | 4 | assertNotNull(filter2); |
158 | 4 | assertTrue(filter2 instanceof AndFilter); |
159 | 4 | assertEquals(2, ((AndFilter) filter2).getFilters().size()); |
160 | 4 | Filter left = (Filter) ((AndFilter) filter2).getFilters().get(0); |
161 | 4 | Filter right = (Filter) ((AndFilter) filter2).getFilters().get(1); |
162 | 4 | assertNotNull(left); |
163 | 4 | assertTrue(left instanceof RegExFilter); |
164 | 4 | assertEquals("the quick brown (.*)", ((RegExFilter) left).getPattern()); |
165 | 4 | assertNotNull(right); |
166 | 4 | assertTrue(right instanceof RegExFilter); |
167 | 4 | assertEquals("(.*) brown (.*)", ((RegExFilter) right).getPattern()); |
168 | |
|
169 | 4 | assertTrue(router.getCatchAllStrategy() instanceof TestCatchAllStrategy); |
170 | 4 | } |
171 | |
|
172 | |
|
173 | |
public void testInboundRouterConfig2() |
174 | |
{ |
175 | 4 | Service service = muleContext.getRegistry().lookupService("appleComponent"); |
176 | 4 | assertNotNull(service.getInboundRouter()); |
177 | 4 | InboundRouterCollection messageRouter = service.getInboundRouter(); |
178 | 4 | assertNotNull(messageRouter.getCatchAllStrategy()); |
179 | 4 | assertEquals(2, messageRouter.getRouters().size()); |
180 | 4 | InboundRouter router = (InboundRouter) messageRouter.getRouters().get(0); |
181 | 4 | assertTrue(router instanceof SelectiveConsumer); |
182 | 4 | SelectiveConsumer sc = (SelectiveConsumer) router; |
183 | |
|
184 | 4 | assertNotNull(sc.getFilter()); |
185 | 4 | Filter filter = sc.getFilter(); |
186 | |
|
187 | 4 | assertTrue(filter instanceof PayloadTypeFilter); |
188 | 4 | assertEquals(String.class, ((PayloadTypeFilter) filter).getExpectedType()); |
189 | |
|
190 | 4 | InboundRouter router2 = (InboundRouter) messageRouter.getRouters().get(1); |
191 | 4 | assertTrue(router2 instanceof IdempotentReceiver); |
192 | 4 | } |
193 | |
|
194 | |
public void testThreadingConfig() throws DefaultMuleException |
195 | |
{ |
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | 4 | int defaultMaxBufferSize = 42; |
201 | 4 | int defaultMaxThreadsActive = 16; |
202 | 4 | int defaultMaxThreadsIdle = 3; |
203 | |
|
204 | 4 | int defaultThreadPoolExhaustedAction = ThreadingProfile.WHEN_EXHAUSTED_WAIT; |
205 | 4 | int defaultThreadTTL = 60001; |
206 | |
|
207 | |
|
208 | 4 | int connectorMaxBufferSize = 2; |
209 | |
|
210 | |
|
211 | 4 | int componentMaxBufferSize = 6; |
212 | 4 | int componentMaxThreadsActive = 12; |
213 | 4 | int componentMaxThreadsIdle = 6; |
214 | 4 | int componentThreadPoolExhaustedAction = ThreadingProfile.WHEN_EXHAUSTED_DISCARD; |
215 | |
|
216 | |
|
217 | 4 | ThreadingProfile tp = muleContext.getDefaultThreadingProfile(); |
218 | 4 | assertEquals(defaultMaxBufferSize, tp.getMaxBufferSize()); |
219 | 4 | assertEquals(defaultMaxThreadsActive, tp.getMaxThreadsActive()); |
220 | 4 | assertEquals(defaultMaxThreadsIdle, tp.getMaxThreadsIdle()); |
221 | 4 | assertEquals(defaultThreadPoolExhaustedAction, tp.getPoolExhaustedAction()); |
222 | 4 | assertEquals(defaultThreadTTL, tp.getThreadTTL()); |
223 | |
|
224 | |
|
225 | 4 | tp = muleContext.getDefaultComponentThreadingProfile(); |
226 | 4 | assertEquals(defaultMaxBufferSize, tp.getMaxBufferSize()); |
227 | 4 | assertEquals(defaultMaxThreadsActive, tp.getMaxThreadsActive()); |
228 | 4 | assertEquals(defaultMaxThreadsIdle, tp.getMaxThreadsIdle()); |
229 | 4 | assertEquals(defaultThreadPoolExhaustedAction, tp.getPoolExhaustedAction()); |
230 | 4 | assertEquals(defaultThreadTTL, tp.getThreadTTL()); |
231 | |
|
232 | |
|
233 | 4 | AbstractConnector c = (AbstractConnector) muleContext.getRegistry().lookupConnector("dummyConnector"); |
234 | 4 | tp = c.getDispatcherThreadingProfile(); |
235 | |
|
236 | 4 | assertEquals(connectorMaxBufferSize, tp.getMaxBufferSize()); |
237 | |
|
238 | 4 | assertEquals(defaultMaxThreadsActive, tp.getMaxThreadsActive()); |
239 | 4 | assertEquals(defaultMaxThreadsIdle, tp.getMaxThreadsIdle()); |
240 | 4 | assertEquals(defaultThreadPoolExhaustedAction, tp.getPoolExhaustedAction()); |
241 | 4 | assertEquals(defaultThreadTTL, tp.getThreadTTL()); |
242 | |
|
243 | |
|
244 | 4 | Service service = muleContext.getRegistry().lookupService("appleComponent2"); |
245 | 4 | assertTrue("service must be SedaService to get threading profile", service instanceof SedaService); |
246 | 4 | tp = ((SedaService) service).getThreadingProfile(); |
247 | |
|
248 | 4 | assertEquals(componentMaxBufferSize, tp.getMaxBufferSize()); |
249 | 4 | assertEquals(componentMaxThreadsActive, tp.getMaxThreadsActive()); |
250 | 4 | assertEquals(componentMaxThreadsIdle, tp.getMaxThreadsIdle()); |
251 | 4 | assertEquals(componentThreadPoolExhaustedAction, tp.getPoolExhaustedAction()); |
252 | |
|
253 | 4 | assertEquals(defaultThreadTTL, tp.getThreadTTL()); |
254 | 4 | } |
255 | |
|
256 | |
public void testPoolingConfig() |
257 | |
{ |
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | 4 | Service service = muleContext.getRegistry().lookupService("appleComponent2"); |
269 | 4 | PoolingProfile pp = ((PooledJavaComponent)service.getComponent()).getPoolingProfile(); |
270 | |
|
271 | 4 | assertEquals(9, pp.getMaxActive()); |
272 | 4 | assertEquals(6, pp.getMaxIdle()); |
273 | 4 | assertEquals(4002, pp.getMaxWait()); |
274 | 4 | assertEquals(PoolingProfile.WHEN_EXHAUSTED_FAIL, pp.getExhaustedAction()); |
275 | 4 | assertEquals(PoolingProfile.INITIALISE_ALL, pp.getInitialisationPolicy()); |
276 | 4 | } |
277 | |
|
278 | |
public void testQueueProfileConfig() |
279 | |
{ |
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | 4 | Service service = muleContext.getRegistry().lookupService("appleComponent2"); |
288 | 4 | QueueProfile qp = ((SedaService)service).getQueueProfile(); |
289 | 4 | assertEquals(102, qp.getMaxOutstandingMessages()); |
290 | 4 | assertTrue(qp.isPersistent()); |
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | 4 | } |
298 | |
|
299 | |
public void testEndpointProperties() throws Exception |
300 | |
{ |
301 | |
|
302 | 4 | Service service = muleContext.getRegistry().lookupService("appleComponent2"); |
303 | 4 | InboundEndpoint inEndpoint = service.getInboundRouter().getEndpoint( |
304 | |
"transactedInboundEndpoint"); |
305 | 4 | assertNotNull(inEndpoint); |
306 | 4 | assertNotNull(inEndpoint.getProperties()); |
307 | 4 | assertEquals("Prop1", inEndpoint.getProperties().get("testEndpointProperty")); |
308 | 4 | } |
309 | |
|
310 | |
public void testTransactionConfig() throws Exception |
311 | |
{ |
312 | |
|
313 | 4 | Service apple = muleContext.getRegistry().lookupService("appleComponent2"); |
314 | 4 | InboundEndpoint inEndpoint = apple.getInboundRouter().getEndpoint("transactedInboundEndpoint"); |
315 | 4 | assertNotNull(inEndpoint); |
316 | 4 | assertEquals(1, apple.getOutboundRouter().getRouters().size()); |
317 | 4 | assertNotNull(inEndpoint.getTransactionConfig()); |
318 | 4 | assertEquals(TransactionConfig.ACTION_ALWAYS_BEGIN, inEndpoint.getTransactionConfig().getAction()); |
319 | 4 | assertTrue(inEndpoint.getTransactionConfig().getFactory() instanceof TestTransactionFactory); |
320 | 4 | assertNull(inEndpoint.getTransactionConfig().getConstraint()); |
321 | |
|
322 | 4 | OutboundRouter outRouter = (OutboundRouter) apple.getOutboundRouter().getRouters().get(0); |
323 | 4 | OutboundEndpoint outEndpoint = (OutboundEndpoint) outRouter.getEndpoints().get(0); |
324 | 4 | assertNotNull(outEndpoint); |
325 | 4 | } |
326 | |
|
327 | |
public void testEnvironmentProperties() |
328 | |
{ |
329 | 4 | assertEquals("true", muleContext.getRegistry().lookupObject("doCompression")); |
330 | 4 | assertEquals("this was set from the manager properties!", muleContext.getRegistry().lookupObject("beanProperty1")); |
331 | 4 | assertNotNull(muleContext.getRegistry().lookupObject("OS_Version")); |
332 | 4 | } |
333 | |
|
334 | |
|
335 | |
public void testNestedRouterProxyCreation() |
336 | |
{ |
337 | |
|
338 | 4 | Service orange = muleContext.getRegistry().lookupService("orangeComponent"); |
339 | 4 | assertNotNull(orange); |
340 | 4 | assertTrue(orange.getComponent() instanceof JavaComponent); |
341 | 4 | NestedRouter r = (NestedRouter) ((JavaComponent) orange.getComponent()).getNestedRouter().getRouters().get(0); |
342 | 4 | assertNotNull(r); |
343 | |
|
344 | |
|
345 | 4 | } |
346 | |
|
347 | |
public void testMuleConfiguration() |
348 | |
{ |
349 | 4 | assertTrue(muleContext.getConfiguration().isDefaultRemoteSync()); |
350 | 4 | assertTrue(muleContext.getConfiguration().isDefaultSynchronousEndpoints()); |
351 | 4 | } |
352 | |
|
353 | |
} |