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