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.tcp;
8   
9   import org.mule.api.transport.Connector;
10  import org.mule.tck.junit4.FunctionalTestCase;
11  import org.mule.transport.ConfigurableKeyedObjectPool;
12  import org.mule.transport.ConfigurableKeyedObjectPoolFactory;
13  import org.mule.transport.DefaultConfigurableKeyedObjectPool;
14  import org.mule.transport.DefaultConfigurableKeyedObjectPoolFactory;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertTrue;
20  
21  public class TcpDispatcherPoolFactoryTestCase extends FunctionalTestCase
22  {
23  
24      @Override
25      protected String getConfigResources()
26      {
27          return "tcp-dispatcher-pool-factory-config.xml";
28      }
29  
30      public static class StubConfigurableKeyedObjectPool extends DefaultConfigurableKeyedObjectPool
31      {
32  
33      }
34  
35      public static class StubDispatcherPoolFactory implements ConfigurableKeyedObjectPoolFactory
36      {
37  
38          public ConfigurableKeyedObjectPool createObjectPool()
39          {
40              return new StubConfigurableKeyedObjectPool();
41          }
42      }
43  
44      @Test
45      public void testConnectorUsingDefaultDispatcherPoolFactory()
46      {
47          Connector connector = muleContext.getRegistry().lookupConnector("tcpConnectorWithDefaultFactory");
48  
49          assertTrue(connector instanceof TcpConnector);
50          TcpConnector tcpConnector = (TcpConnector) connector;
51          assertEquals(DefaultConfigurableKeyedObjectPoolFactory.class, tcpConnector.getDispatcherPoolFactory().getClass());
52          assertEquals(DefaultConfigurableKeyedObjectPool.class, tcpConnector.getDispatchers().getClass());
53      }
54  
55      @Test
56      public void testConnectorUsingOverriddenDispatcherPoolFactory()
57      {
58          Connector connector = muleContext.getRegistry().lookupConnector("tcpConnectorWithOverriddenFactory");
59  
60          assertTrue(connector instanceof TcpConnector);
61          TcpConnector tcpConnector = (TcpConnector) connector;
62          assertEquals(StubDispatcherPoolFactory.class, tcpConnector.getDispatcherPoolFactory().getClass());
63          assertEquals(StubConfigurableKeyedObjectPool.class, tcpConnector.getDispatchers().getClass());
64      }
65  }