View Javadoc

1   /*
2    * $Id: TcpEchoDirectProtocolTestCase.java 22454 2011-07-19 16:06:47Z justin.calleja $
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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  import java.util.Arrays;
17  import java.util.Collection;
18  
19  import org.junit.Rule;
20  import org.junit.Test;
21  import org.junit.runners.Parameterized.Parameters;
22  import org.mule.api.MuleMessage;
23  import org.mule.api.endpoint.InboundEndpoint;
24  import org.mule.module.client.MuleClient;
25  import org.mule.tck.AbstractServiceAndFlowTestCase;
26  import org.mule.tck.junit4.rule.DynamicPort;
27  
28  public class TcpEchoDirectProtocolTestCase extends AbstractServiceAndFlowTestCase
29  {
30      protected static String TEST_MESSAGE = "Test TCP Request";
31  
32      @Rule
33      public DynamicPort dynamicPort = new DynamicPort("port1");
34  
35      public TcpEchoDirectProtocolTestCase(ConfigVariant variant, String configResources)
36      {
37          super(variant, configResources);        
38      }
39      
40      @Parameters
41      public static Collection<Object[]> parameters()
42      {
43          return Arrays.asList(new Object[][]{
44              {ConfigVariant.SERVICE, "tcp-echo-test-service.xml"},
45              {ConfigVariant.FLOW, "tcp-echo-test-flow.xml"}
46          });
47      }
48  
49      @Test
50      public void testSend() throws Exception
51      {
52          MuleClient client = new MuleClient(muleContext);
53          
54          MuleMessage response = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("inBounceTcpMMP")).getAddress(), 
55              TEST_MESSAGE, null);
56          
57          assertNotNull(response);
58          assertEquals(TEST_MESSAGE, response.getPayload());
59      }
60  
61  }