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.issues;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.endpoint.InboundEndpoint;
12  import org.mule.module.client.MuleClient;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.tck.junit4.rule.DynamicPort;
15  
16  import java.io.ByteArrayInputStream;
17  import java.io.InputStream;
18  
19  import org.junit.Rule;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertTrue;
25  
26  public class SynchStreamingMule1687TestCase extends FunctionalTestCase
27  {
28  
29      public static final String TEST_MESSAGE = "Test TCP Request";
30  
31      @Rule
32      public DynamicPort dynamicPort = new DynamicPort("port1");
33  
34      @Override
35      protected String getConfigResources()
36      {
37          return "tcp-synch-streaming-test.xml";
38      }
39  
40      @Test
41      public void testSendAndRequest() throws Exception
42      {
43          MuleClient client = new MuleClient(muleContext);
44          ByteArrayInputStream stream = new ByteArrayInputStream(TEST_MESSAGE.getBytes());
45          MuleMessage request = new DefaultMuleMessage(stream, muleContext);
46          MuleMessage message = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("inEcho")).getAddress(), request);
47          assertNotNull(message);
48  
49          Object payload = message.getPayload();
50          assertTrue(payload instanceof InputStream);
51          assertEquals("Some value - set to make test ok", message.getPayloadAsString());
52      }
53  
54  }