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