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