1
2
3
4
5
6
7 package org.mule.module.guice;
8
9 import org.mule.module.client.MuleClient;
10 import org.mule.registry.AbstractLifecycleTracker;
11 import org.mule.tck.junit4.AbstractMuleContextTestCase;
12
13 import com.google.inject.AbstractModule;
14
15 import org.junit.Assert;
16 import org.junit.Test;
17
18 public class GuiceLifecyceTestCase extends AbstractMuleContextTestCase
19 {
20 @Override
21 protected void doSetUp() throws Exception
22 {
23 GuiceConfigurationBuilder cb = new GuiceConfigurationBuilder(new GuiceLifecycleModule());
24 cb.configure(muleContext);
25 }
26
27
28
29
30
31
32
33 @Test
34 public void testSingletonServiceLifecycle() throws Exception
35 {
36 testComponentLifecycle("MuleSingletonService",
37 "[setProperty, setMuleContext, setService, initialise, start, stop, dispose]");
38 }
39
40
41
42
43
44
45
46 @Test
47 public void testMulePrototypeServiceLifecycle() throws Exception
48 {
49 testComponentLifecycle("MulePrototypeService",
50 "[setProperty, setMuleContext, setService, initialise, start, stop, dispose]");
51 }
52
53
54
55
56
57
58
59
60
61 @Test
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 }