View Javadoc

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