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.junit4.AbstractMuleContextTestCase;
16
17 import com.google.inject.AbstractModule;
18
19 import org.junit.Assert;
20 import org.junit.Test;
21
22 public class GuiceLifecyceTestCase extends AbstractMuleContextTestCase
23 {
24 @Override
25 protected void doSetUp() throws Exception
26 {
27 GuiceConfigurationBuilder cb = new GuiceConfigurationBuilder(new GuiceLifecycleModule());
28 cb.configure(muleContext);
29 }
30
31
32
33
34
35
36
37 @Test
38 public void testSingletonServiceLifecycle() throws Exception
39 {
40 testComponentLifecycle("MuleSingletonService",
41 "[setProperty, setMuleContext, setService, initialise, start, stop, dispose]");
42 }
43
44
45
46
47
48
49
50 @Test
51 public void testMulePrototypeServiceLifecycle() throws Exception
52 {
53 testComponentLifecycle("MulePrototypeService",
54 "[setProperty, setMuleContext, setService, initialise, start, stop, dispose]");
55 }
56
57
58
59
60
61
62
63
64
65 @Test
66 public void testMulePooledSingletonServiceLifecycle() throws Exception
67 {
68
69
70
71 testComponentLifecycle("MulePooledSingletonService",
72 "[setProperty, setMuleContext, setService, initialise, start, stop, dispose]");
73 }
74
75 private void testComponentLifecycle(final String serviceName, final String expectedLifeCycle)
76 throws Exception
77 {
78
79 final AbstractLifecycleTracker tracker = exerciseComponent(serviceName);
80
81 muleContext.dispose();
82
83 Assert.assertEquals(serviceName, expectedLifeCycle, tracker.getTracker().toString());
84 }
85
86 private AbstractLifecycleTracker exerciseComponent(final String serviceName) throws Exception
87 {
88 MuleClient muleClient = new MuleClient(muleContext);
89 final AbstractLifecycleTracker ltc = (AbstractLifecycleTracker)muleClient.send(
90 "vm://" + serviceName + ".In", null, null).getPayload();
91
92 Assert.assertNotNull(ltc);
93
94 return ltc;
95 }
96
97 public class GuiceLifecycleModule extends AbstractModule
98 {
99 @Override
100 protected void configure()
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
126
127
128 }
129 }