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