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.transport;
8   
9   import org.mule.api.context.WorkManager;
10  import org.mule.api.endpoint.ImmutableEndpoint;
11  import org.mule.api.transport.Connectable;
12  import org.mule.tck.junit4.AbstractMuleContextTestCase;
13  
14  import org.junit.Test;
15  
16  import static org.junit.Assert.fail;
17  
18  public class ConnectableTestCase extends AbstractMuleContextTestCase
19  {
20  
21      /**
22       * MULE-4531
23       */
24      @Test
25      public void testDoNotConnectIfConnected() throws Exception
26      {
27          Connectable connectable = new TestConnectable(getTestInboundEndpoint("test"), true);
28          connectable.connect();
29      }
30  
31      class TestConnectable extends AbstractTransportMessageHandler
32      {
33          public TestConnectable(ImmutableEndpoint endpoint, boolean connected)
34          {
35              super(endpoint);
36              this.connected.set(connected);
37          }
38  
39          @Override
40          protected ConnectableLifecycleManager createLifecycleManager()
41          {
42              return new ConnectableLifecycleManager("test", this);
43          }
44  
45          @Override
46          protected WorkManager getWorkManager()
47          {
48              return null;
49          }
50  
51          @Override
52          protected void doConnect() throws Exception
53          {
54              if (connected.get())
55              {
56                  fail("Should not attempt connection");
57              }
58              super.doConnect();
59          }
60  
61      }
62  
63  }