View Javadoc

1   /*
2    * $Id: LifecycleTrackerConnectorFunctionalTestCase.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.transport;
12  
13  import org.mule.tck.FunctionalTestCase;
14  
15  public class LifecycleTrackerConnectorFunctionalTestCase extends FunctionalTestCase
16  {
17  
18      @Override
19      protected String getConfigResources()
20      {
21          return "org/mule/test/integration/transport/connector-lifecycle-config.xml";
22      }
23  
24      /**
25       * ASSERT:
26       * - Mule stop/start lifecycle methods invoked
27       * - Mule initialize/dipose lifecycle methods NOT invoked
28       * - Spring lifecycle methods invoked
29       * - Service and muleContext injected (Component implements ServiceAware/MuleContextAware)
30       * NOTE: muleContext is injected twice, once by registry and once by lifecycleAdaptor
31       * @throws Exception
32       */
33      public void testConnectorLifecycle() throws Exception
34      {
35          testComponentLifecycle(
36              "test1",
37              "[setProperty, initialise, connect, start, stop, disconnect, dispose]");
38      }
39  
40      private void testComponentLifecycle(final String connectorName, final String expectedLifeCycle)
41          throws Exception
42      {
43  
44          final ConnectorLifecycleTracker tracker = getConnector(connectorName);
45  
46          muleContext.dispose();
47  
48          assertEquals(connectorName, expectedLifeCycle, tracker.getTracker().toString());
49      }
50  
51      private ConnectorLifecycleTracker getConnector(final String connectorName) throws Exception
52      {
53          ConnectorLifecycleTracker t = (ConnectorLifecycleTracker)muleContext.getRegistry().lookupConnector(connectorName);
54          assertNotNull(t);
55  
56          return t;
57      }
58  }