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