View Javadoc

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