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