View Javadoc

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