View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.integration.transport;
8   
9   import org.mule.tck.junit4.FunctionalTestCase;
10  
11  import org.junit.Test;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  public class LifecycleTrackerConnectorFunctionalTestCase extends FunctionalTestCase
17  {
18  
19      @Override
20      protected String getConfigResources()
21      {
22          return "org/mule/test/integration/transport/connector-lifecycle-config.xml";
23      }
24  
25      /**
26       * ASSERT:
27       * - Mule stop/start lifecycle methods invoked
28       * - Mule initialize/dipose lifecycle methods NOT invoked
29       * - Spring lifecycle methods invoked
30       * - Service and muleContext injected (Component implements ServiceAware/MuleContextAware)
31       * NOTE: muleContext is injected twice, once by registry and once by lifecycleAdaptor
32       * @throws Exception
33       */
34      @Test
35      public void testConnectorLifecycle() throws Exception
36      {
37          testComponentLifecycle(
38              "test1",
39              "[setProperty, initialise, connect, start, stop, disconnect, dispose]");
40      }
41  
42      private void testComponentLifecycle(final String connectorName, final String expectedLifeCycle)
43          throws Exception
44      {
45  
46          final ConnectorLifecycleTracker tracker = getConnector(connectorName);
47  
48          muleContext.dispose();
49  
50          assertEquals(connectorName, expectedLifeCycle, tracker.getTracker().toString());
51      }
52  
53      private ConnectorLifecycleTracker getConnector(final String connectorName) throws Exception
54      {
55          ConnectorLifecycleTracker t = (ConnectorLifecycleTracker)muleContext.getRegistry().lookupConnector(connectorName);
56          assertNotNull(t);
57  
58          return t;
59      }
60  }