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