1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.tcp.protocols;
12
13 import org.mule.api.MuleException;
14 import org.mule.api.MuleMessage;
15 import org.mule.module.client.MuleClient;
16 import org.mule.tck.FunctionalTestCase;
17
18 public class SafeProtocolTestCase extends FunctionalTestCase
19 {
20
21 protected static String TEST_MESSAGE = "Test TCP Request";
22
23 protected String getConfigResources()
24 {
25 return "safe-protocol-test.xml";
26 }
27
28 public void testSafeToSafe() throws MuleException
29 {
30 MuleClient client = new MuleClient();
31 assertResponseOk(client.send("tcp://localhost:65432?connector=safe", TEST_MESSAGE, null));
32 }
33
34 public void testUnsafeToSafe() throws MuleException
35 {
36 MuleClient client = new MuleClient();
37 assertResponseBad(client.send("tcp://localhost:65432?connector=unsafe", TEST_MESSAGE, null));
38 }
39
40 private void assertResponseOk(MuleMessage message)
41 {
42 assertNotNull("Null message", message);
43 Object payload = message.getPayload();
44 assertNotNull("Null payload", payload);
45 assertTrue("Payload not byte[]", payload instanceof byte[]);
46 assertEquals(TEST_MESSAGE + " Received", new String((byte[]) payload));
47 }
48
49 protected void assertResponseBad(MuleMessage message)
50 {
51 try
52 {
53 if (message.getPayloadAsString().equals(TEST_MESSAGE + " Received"))
54 {
55 fail("expected error");
56 }
57 }
58 catch (Exception e)
59 {
60
61 }
62 }
63
64 }