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.junit4.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 import org.junit.Test;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertNull;
30 import static org.junit.Assert.fail;
31
32
33
34
35 public class CxfEchoTestCase extends FunctionalTestCase
36 {
37 private String expectedGetResponse;
38
39 @Override
40 protected String getConfigResources()
41 {
42 return "echo-cxf-config.xml";
43 }
44
45 @Override
46 protected void doSetUp() throws Exception
47 {
48 try
49 {
50 expectedGetResponse = IOUtils.getResourceAsString("echo-cxf-response.xml", getClass());
51 }
52 catch (IOException ioex)
53 {
54 fail(ioex.getMessage());
55 }
56 }
57
58 @Test
59 public void testGetEcho() throws Exception
60 {
61
62
63
64 MuleClient client = new MuleClient(muleContext);
65 Map<String, String> props = new HashMap<String, String>();
66 props.put("http.method", "GET");
67 MuleMessage result = client.send("http://localhost:65082/services/EchoUMO/echo/text/hello", "", props);
68 assertNotNull(result);
69 assertFalse(result.getPayload() instanceof NullPayload);
70 XMLAssert.assertXMLEqual(expectedGetResponse, result.getPayloadAsString());
71 }
72
73 @Test
74 public void testSoapPostEcho() throws Exception
75 {
76 MuleClient client = new MuleClient(muleContext);
77 MuleMessage result = client.send("cxf:http://localhost:65082/services/EchoUMO?method=echo",
78 "hello", null);
79 assertNotNull(result);
80 assertNull(result.getExceptionPayload());
81 assertFalse(result.getPayload() instanceof NullPayload);
82 assertEquals("hello", result.getPayload());
83 }
84 }