View Javadoc

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