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 TransientLifecycleTrackerComponentFunctionalTestCase 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 @Test
40 public void testSpringBeanServiceLifecycle() throws Exception
41 {
42 testComponentLifecycle("SpringBeanService",
43 "[setProperty, setMuleContext, springInitialize, setService, start, stop, springDestroy]");
44 }
45
46
47
48
49
50
51
52
53
54 @Test
55 public void testSpringBeanService2Lifecycle() throws Exception
56 {
57 testComponentLifecycle("SpringBeanService2",
58 "[setProperty, setMuleContext, setService, start, stop]");
59 }
60
61
62
63
64
65
66 @Test
67 public void testSingletonServiceLifecycle() throws Exception
68 {
69 testComponentLifecycle("MuleSingletonService",
70 "[setProperty, setService, setMuleContext, initialise, start, stop, dispose]");
71 }
72
73
74
75
76
77
78 @Test
79 public void testMulePrototypeServiceLifecycle() throws Exception
80 {
81 testComponentLifecycle("MulePrototypeService",
82 "[setProperty, setService, setMuleContext, initialise, start, stop, dispose]");
83 }
84
85
86
87
88
89
90 @Test
91 public void testMulePooledPrototypeServiceLifecycle() throws Exception
92 {
93 testComponentLifecycle("MulePooledPrototypeService",
94 "[setProperty, setService, setMuleContext, initialise, start, stop, dispose]");
95 }
96
97
98
99
100
101
102 @Test
103 public void testMulePooledSingletonServiceLifecycle() throws Exception
104 {
105 testComponentLifecycle("MulePooledSingletonService",
106 "[setProperty, setService, setMuleContext, initialise, initialise, initialise, start, start, start, stop, stop, stop, dispose, dispose, dispose]");
107 }
108
109 private void testComponentLifecycle(final String serviceName, final String expectedLifeCycle)
110 throws Exception
111 {
112 AbstractLifecycleTracker tracker = exerciseComponent(serviceName);
113
114 muleContext.dispose();
115
116 assertEquals(serviceName, expectedLifeCycle, tracker.getTracker().toString());
117 }
118
119 private AbstractLifecycleTracker exerciseComponent(final String serviceName) throws Exception
120 {
121 MuleClient muleClient = new MuleClient(muleContext);
122 final AbstractLifecycleTracker ltc = (AbstractLifecycleTracker) muleClient.send(
123 "vm://" + serviceName + ".In", null, null).getPayload();
124
125 assertNotNull(ltc);
126
127 return ltc;
128 }
129 }