1
2
3
4
5
6
7
8
9
10
11 package org.mule.example.echo;
12
13 import org.mule.api.MuleMessage;
14 import org.mule.module.client.MuleClient;
15 import org.mule.tck.FunctionalTestCase;
16 import org.mule.transport.NullPayload;
17 import org.mule.util.IOUtils;
18
19 import java.io.IOException;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.custommonkey.xmlunit.XMLAssert;
24
25
26
27
28 public abstract class AbstractEchoTestCase extends FunctionalTestCase
29 {
30 protected String expectedGetResponse;
31 protected String expectedPostResponse;
32
33 protected void doSetUp() throws Exception
34 {
35 try
36 {
37 expectedGetResponse = IOUtils.getResourceAsString(getExpectedGetResponseResource(),
38 this.getClass());
39 expectedPostResponse = IOUtils.getResourceAsString(getExpectedPostResponseResource(),
40 this.getClass());
41 }
42 catch (IOException ioex)
43 {
44 fail(ioex.getMessage());
45 }
46 }
47
48 protected abstract String getExpectedGetResponseResource();
49
50 protected abstract String getExpectedPostResponseResource();
51
52 protected abstract String getProtocol();
53
54 public void testPostEcho() throws Exception
55 {
56 MuleClient client = new MuleClient();
57 MuleMessage result = client.send("http://localhost:65081/services/EchoUMO?method=echo", "hello", null);
58 assertNotNull(result);
59 assertNull(result.getExceptionPayload());
60 assertFalse(result.getPayload() instanceof NullPayload);
61 XMLAssert.assertXMLEqual(expectedPostResponse, result.getPayloadAsString());
62 }
63
64 public void testGetEcho() throws Exception
65 {
66 MuleClient client = new MuleClient();
67 Map<String, String> props = new HashMap<String, String>();
68 props.put("http.method", "GET");
69 MuleMessage result = client.send("http://localhost:65081/services/EchoUMO?method=echo", "hello", props);
70 assertNotNull(result);
71 assertFalse(result.getPayload() instanceof NullPayload);
72 System.out.println("GOT " + result.getPayloadAsString());
73 XMLAssert.assertXMLEqual(expectedGetResponse, result.getPayloadAsString());
74 }
75
76 public void testSoapPostEcho() throws Exception
77 {
78 MuleClient client = new MuleClient();
79 MuleMessage result = client.send(
80 getProtocol() + ":http://localhost:65082/services/EchoUMO?method=echo", "hello", null);
81 assertNotNull(result);
82 assertNull(result.getExceptionPayload());
83 assertFalse(result.getPayload() instanceof NullPayload);
84 assertEquals("hello", result.getPayload());
85 }
86 }