View Javadoc

1   /*
2    * $Id: JSR250LifecycleTrackerComponentFunctionalTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.test.integration.components;
12  
13  import org.mule.lifecycle.JSR250LifecycleTrackerComponent;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.FunctionalTestCase;
16  
17  public class JSR250LifecycleTrackerComponentFunctionalTestCase extends FunctionalTestCase
18  {
19  
20      @Override
21      protected String getConfigResources()
22      {
23          return "org/mule/test/integration/components/jsr250-component-lifecycle-config.xml";
24      }
25  
26      /**
27       * ASSERT:
28       * - Mule lifecycle methods invoked
29       * - Service and muleContext injected (Component implements ServiceAware/MuleContextAware)
30       * @throws Exception
31       */
32      public void testSingletonServiceLifecycle() throws Exception
33      {
34          testComponentLifecycle("MuleSingletonService",
35              "[setProperty, setService, setMuleContext, jsr250 initialise, start, stop, jsr250 dispose]");
36      }
37  
38      /**
39       * ASSERT:
40       * - Mule lifecycle methods invoked
41       * - Service and muleContext injected (Component implements ServiceAware/MuleContextAware)
42       * @throws Exception
43       */
44      public void testMulePrototypeServiceLifecycle() throws Exception
45      {
46          testComponentLifecycle("MulePrototypeService",
47              "[setProperty, setService, setMuleContext, jsr250 initialise, start, stop, jsr250 dispose]");
48      }
49  
50      /**
51       * ASSERT:
52       * - Mule lifecycle methods invoked
53       * - Service and muleContext injected (Component implements ServiceAware/MuleContextAware)
54       * @throws Exception
55       */
56      public void testMulePooledPrototypeServiceLifecycle() throws Exception
57      {
58          testComponentLifecycle("MulePooledPrototypeService", "[setProperty, setService, setMuleContext, jsr250 initialise, start, stop, jsr250 dispose]");
59      }
60      
61      /**
62       * ASSERT:
63       * - Mule lifecycle methods invoked each time singleton is used to create new object in pool
64       * - Service and muleContext injected each time singleton is used to create new object in pool (Component implements ServiceAware/MuleContextAware)
65       * @throws Exception
66       */
67      public void testMulePooledSingletonServiceLifecycle() throws Exception
68      {
69          testComponentLifecycle("MulePooledSingletonService", "[setProperty, setService, setMuleContext, jsr250 initialise, jsr250 initialise, jsr250 initialise, start, start, start, stop, stop, stop, jsr250 dispose, jsr250 dispose, jsr250 dispose]");
70      }
71  
72      private void testComponentLifecycle(final String serviceName, final String expectedLifeCycle)
73          throws Exception
74      {
75  
76          final JSR250LifecycleTrackerComponent tracker = exerciseComponent(serviceName);
77  
78          muleContext.dispose();
79  
80          assertEquals(serviceName, expectedLifeCycle, tracker.getTracker().toString());
81      }
82  
83      private JSR250LifecycleTrackerComponent exerciseComponent(final String serviceName) throws Exception
84      {
85          MuleClient muleClient = new MuleClient(muleContext);
86          final JSR250LifecycleTrackerComponent ltc = (JSR250LifecycleTrackerComponent) muleClient.send(
87              "vm://" + serviceName + ".In", null, null).getPayload();
88  
89          assertNotNull(ltc);
90  
91          return ltc;
92      }
93  }