1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.cxf;
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.http.HttpConnector;
17 import org.mule.transport.servlet.MuleReceiverServlet;
18 import org.mule.transport.servlet.jetty.util.EmbeddedJettyServer;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 public class ServletTestCase extends FunctionalTestCase
24 {
25
26 public static final int HTTP_PORT = 63088;
27
28 private EmbeddedJettyServer httpServer;
29
30 @Override
31 protected String getConfigResources()
32 {
33 return "servlet-conf.xml";
34 }
35
36 @Override
37 protected void doSetUp() throws Exception
38 {
39 super.doSetUp();
40
41 httpServer = new EmbeddedJettyServer(HTTP_PORT, getContextPath(), "/services/*", new MuleReceiverServlet(), muleContext);
42 httpServer.start();
43 }
44
45 protected String getContextPath()
46 {
47 return "";
48 }
49
50 @Override
51 protected void doTearDown() throws Exception
52 {
53 if (httpServer != null && httpServer.isStarted())
54 {
55 httpServer.stop();
56 }
57
58 super.doTearDown();
59 }
60
61 public void testRequestWsdlWithServlets() throws Exception
62 {
63 String request =
64 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
65 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
66 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
67 "<soap:Body>" +
68 "<ns1:echo xmlns:ns1=\"http://testmodels.cxf.module.mule.org/\">" +
69 "<text>Test String</text>" +
70 "</ns1:echo>" +
71 "</soap:Body>" +
72 "</soap:Envelope>";
73
74 MuleClient client = new MuleClient(muleContext);
75 MuleMessage result = client.send("http://localhost:" + HTTP_PORT
76 + getContextPath() + "/services/mycomponent", request, null);
77 String res = result.getPayloadAsString();
78
79 assertTrue(res.indexOf("Test String") != -1);
80 }
81
82 public void testHttpGet() throws Exception
83 {
84 MuleClient client = new MuleClient(muleContext);
85 Map<String, Object> props = new HashMap<String, Object>();
86 props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
87 MuleMessage result = client.send("http://localhost:" + HTTP_PORT
88 + getContextPath() + "/services/mycomponent/echo/text/Test String", "", props);
89 String res = result.getPayloadAsString();
90 assertTrue(res.indexOf("Test String") != -1);
91 }
92 }
93
94