View Javadoc

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