1
2
3
4
5
6
7 package org.mule.transport.tcp;
8
9 import org.mule.api.MuleMessage;
10 import org.mule.module.client.MuleClient;
11 import org.mule.tck.junit4.FunctionalTestCase;
12 import org.mule.tck.junit4.rule.DynamicPort;
13
14 import org.junit.ClassRule;
15 import org.junit.Test;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNull;
19
20 public class TcpLengthFunctionalTestCase extends FunctionalTestCase
21 {
22 protected static String TEST_MESSAGE = "Test TCP Request";
23 private int timeout = 60 * 1000 / 20;
24
25 @ClassRule
26 public static DynamicPort dynamicPort1 = new DynamicPort("port1");
27
28 @ClassRule
29 public static DynamicPort dynamicPort2 = new DynamicPort("port2");
30
31 @ClassRule
32 public static DynamicPort dynamicPort3 = new DynamicPort("port3");
33
34 public TcpLengthFunctionalTestCase()
35 {
36 setDisposeContextPerClass(true);
37 }
38
39 @Override
40 protected String getConfigResources()
41 {
42 return "tcp-length-functional-test.xml";
43 }
44
45 @Test
46 public void testSend() throws Exception
47 {
48 MuleClient client = new MuleClient(muleContext);
49 MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, null);
50 assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
51 }
52
53 @Test
54 public void testDispatchAndReplyViaStream() throws Exception
55 {
56 MuleClient client = new MuleClient(muleContext);
57 client.dispatch("asyncClientEndpoint1", TEST_MESSAGE, null);
58
59 Thread.sleep(200);
60 MuleMessage result = client.request("asyncClientEndpoint1", timeout);
61
62 assertNull(result);
63 }
64
65 @Test
66 public void testDispatchAndReply() throws Exception
67 {
68 MuleClient client = new MuleClient(muleContext);
69 client.dispatch("asyncClientEndpoint2", TEST_MESSAGE, null);
70
71 Thread.sleep(200);
72 MuleMessage result = client.request("asyncClientEndpoint2", timeout);
73
74 assertNull(result);
75 }
76
77 }