1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.cxf.jaxws;
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.tck.junit4.rule.DynamicPort;
17 import org.mule.transport.NullPayload;
18
19 import org.apache.commons.httpclient.HttpClient;
20 import org.apache.commons.httpclient.HttpMethod;
21 import org.apache.commons.httpclient.methods.GetMethod;
22 import org.junit.Rule;
23 import org.junit.Test;
24
25 import static org.junit.Assert.assertEquals;
26
27 public class CxfJaxWsTestCase extends FunctionalTestCase
28 {
29
30 @Rule
31 public DynamicPort dynamicPort = new DynamicPort("port1");
32
33 @Override
34 protected String getConfigResources()
35 {
36 return "jaxws-conf.xml";
37 }
38
39 @Test
40 public void testEchoService() throws Exception
41 {
42 String url = "cxf:http://localhost:" + dynamicPort.getNumber() + "/services/Echo?method=echo";
43
44 MuleClient client = new MuleClient(muleContext);
45 MuleMessage result = client.send(url, "Hello!", null);
46 assertEquals("Hello!", result.getPayload());
47 }
48
49 @Test
50 public void testOneWay() throws Exception
51 {
52 String url = "cxf:http://localhost:" + dynamicPort.getNumber() + "/services/async?method=send";
53
54 MuleClient client = new MuleClient(muleContext);
55 MuleMessage result = client.send(url, "Hello!", null);
56 assertEquals(NullPayload.getInstance(), result.getPayload());
57 }
58
59 @Test
60 public void testHttpCall() throws Exception
61 {
62 HttpClient client = new HttpClient();
63
64
65
66
67 HttpMethod httpMethod = new GetMethod("http://localhost:" + dynamicPort.getNumber() + "/services/Echo/echo/text/hello");
68
69 assertEquals(200, client.executeMethod(httpMethod));
70
71
72
73 assertEquals(
74 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
75 "<soap:Body>" +
76 "<ns2:echoResponse xmlns:ns2=\"http://testmodels.cxf.module.mule.org/\">" +
77 "<text>hello</text>" +
78 "</ns2:echoResponse>" +
79 "</soap:Body>" +
80 "</soap:Envelope>", httpMethod.getResponseBodyAsString());
81 }
82
83 @Test
84 public void testWebServiceContext() throws Exception
85 {
86 String url = "cxf:http://localhost:" + dynamicPort.getNumber() + "/services/Echo?method=ensureWebSerivceContextIsSet";
87
88 MuleClient client = new MuleClient(muleContext);
89 MuleMessage result = client.send(url, TEST_MESSAGE, null);
90 assertEquals(TEST_MESSAGE, result.getPayload());
91 }
92 }