1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration.components;
12
13 import org.mule.lifecycle.JSR250LifecycleTrackerComponent;
14 import org.mule.module.client.MuleClient;
15 import org.mule.tck.FunctionalTestCase;
16
17 public class JSR250LifecycleTrackerComponentFunctionalTestCase extends FunctionalTestCase
18 {
19
20 @Override
21 protected String getConfigResources()
22 {
23 return "org/mule/test/integration/components/jsr250-component-lifecycle-config.xml";
24 }
25
26
27
28
29
30
31
32 public void testSingletonServiceLifecycle() throws Exception
33 {
34 testComponentLifecycle("MuleSingletonService",
35 "[setProperty, setService, setMuleContext, jsr250 initialise, start, stop, jsr250 dispose]");
36 }
37
38
39
40
41
42
43
44 public void testMulePrototypeServiceLifecycle() throws Exception
45 {
46 testComponentLifecycle("MulePrototypeService",
47 "[setProperty, setService, setMuleContext, jsr250 initialise, start, stop, jsr250 dispose]");
48 }
49
50
51
52
53
54
55
56 public void testMulePooledPrototypeServiceLifecycle() throws Exception
57 {
58 testComponentLifecycle("MulePooledPrototypeService", "[setProperty, setService, setMuleContext, jsr250 initialise, start, stop, jsr250 dispose]");
59 }
60
61
62
63
64
65
66
67 public void testMulePooledSingletonServiceLifecycle() throws Exception
68 {
69 testComponentLifecycle("MulePooledSingletonService", "[setProperty, setService, setMuleContext, jsr250 initialise, jsr250 initialise, jsr250 initialise, start, start, start, stop, stop, stop, jsr250 dispose, jsr250 dispose, jsr250 dispose]");
70 }
71
72 private void testComponentLifecycle(final String serviceName, final String expectedLifeCycle)
73 throws Exception
74 {
75
76 final JSR250LifecycleTrackerComponent tracker = exerciseComponent(serviceName);
77
78 muleContext.dispose();
79
80 assertEquals(serviceName, expectedLifeCycle, tracker.getTracker().toString());
81 }
82
83 private JSR250LifecycleTrackerComponent exerciseComponent(final String serviceName) throws Exception
84 {
85 MuleClient muleClient = new MuleClient(muleContext);
86 final JSR250LifecycleTrackerComponent ltc = (JSR250LifecycleTrackerComponent) muleClient.send(
87 "vm://" + serviceName + ".In", null, null).getPayload();
88
89 assertNotNull(ltc);
90
91 return ltc;
92 }
93 }