1
2
3
4
5
6
7 package org.mule.test.integration.components;
8
9 import org.mule.lifecycle.JSR250LifecycleTrackerComponent;
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 public class JSR250LifecycleTrackerComponentFunctionalTestCase extends FunctionalTestCase
19 {
20
21 @Override
22 protected String getConfigResources()
23 {
24 return "org/mule/test/integration/components/jsr250-component-lifecycle-config.xml";
25 }
26
27
28
29
30
31
32
33 @Test
34 public void testSingletonServiceLifecycle() throws Exception
35 {
36 testComponentLifecycle("MuleSingletonService",
37 "[setProperty, setService, setMuleContext, jsr250 initialise, start, stop, jsr250 dispose]");
38 }
39
40
41
42
43
44
45
46 @Test
47 public void testMulePrototypeServiceLifecycle() throws Exception
48 {
49 testComponentLifecycle("MulePrototypeService",
50 "[setProperty, setService, setMuleContext, jsr250 initialise, start, stop, jsr250 dispose]");
51 }
52
53
54
55
56
57
58
59 @Test
60 public void testMulePooledPrototypeServiceLifecycle() throws Exception
61 {
62 testComponentLifecycle("MulePooledPrototypeService", "[setProperty, setService, setMuleContext, jsr250 initialise, start, stop, jsr250 dispose]");
63 }
64
65
66
67
68
69
70
71 @Test
72 public void testMulePooledSingletonServiceLifecycle() throws Exception
73 {
74 testComponentLifecycle("MulePooledSingletonService", "[setProperty, setService, setMuleContext, jsr250 initialise, jsr250 initialise, jsr250 initialise, start, start, start, stop, stop, stop, jsr250 dispose, jsr250 dispose, jsr250 dispose]");
75 }
76
77 private void testComponentLifecycle(final String serviceName, final String expectedLifeCycle)
78 throws Exception
79 {
80
81 final JSR250LifecycleTrackerComponent tracker = exerciseComponent(serviceName);
82
83 muleContext.dispose();
84
85 assertEquals(serviceName, expectedLifeCycle, tracker.getTracker().toString());
86 }
87
88 private JSR250LifecycleTrackerComponent exerciseComponent(final String serviceName) throws Exception
89 {
90 MuleClient muleClient = new MuleClient(muleContext);
91 final JSR250LifecycleTrackerComponent ltc = (JSR250LifecycleTrackerComponent) muleClient.send(
92 "vm://" + serviceName + ".In", null, null).getPayload();
93
94 assertNotNull(ltc);
95
96 return ltc;
97 }
98 }