1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.soap.axis.functional;
12
13 import org.mule.api.MuleMessage;
14 import org.mule.module.client.MuleClient;
15 import org.mule.tck.DynamicPortTestCase;
16 import org.mule.transport.http.HttpConnector;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.dom4j.Document;
22 import org.dom4j.DocumentHelper;
23
24 public class WsdlGenerationTestCase extends DynamicPortTestCase
25 {
26
27
28
29
30
31 private static final String PROXY_REGEX = "^\\$Proxy(\\d+\\d*\\d*)$";
32
33 protected String getConfigResources()
34 {
35 return "axis-wsdl-test.xml";
36 }
37
38 public void testWsdl1() throws Exception
39 {
40 Map props = new HashMap();
41 props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
42 MuleClient client = new MuleClient(muleContext);
43
44 MuleMessage result = client.send("http://localhost:" + getPorts().get(0) + "/services/EchoService1?wsdl", null, props);
45 assertNotNull(result);
46 String wsdl = result.getPayloadAsString();
47 Document doc = DocumentHelper.parseText(wsdl);
48 assertEquals("http://foo", doc.valueOf("/wsdl:definitions/@targetNamespace"));
49
50
51 assertTrue(doc.valueOf("/wsdl:definitions/wsdl:portType/@name").matches(PROXY_REGEX));
52
53 assertEquals(
54 "http://foo",
55 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
56 assertEquals(
57 "http://foo",
58 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
59
60 assertEquals("EchoService1", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
61
62 assertEquals("EchoService1", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
63 assertEquals("http://localhost:" + getPorts().get(0) + "/services/EchoService1",
64 doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
65 }
66
67 public void testWsdl2() throws Exception
68 {
69 Map props = new HashMap();
70 props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
71 MuleClient client = new MuleClient(muleContext);
72
73 MuleMessage result = client.send("http://localhost:" + getPorts().get(1) + "/services/EchoService2?wsdl", null, props);
74 assertNotNull(result);
75 String wsdl = result.getPayloadAsString();
76 Document doc = DocumentHelper.parseText(wsdl);
77 assertEquals("http://simple.component.api.mule.org", doc.valueOf("/wsdl:definitions/@targetNamespace"));
78 assertEquals("mulePortType", doc.valueOf("/wsdl:definitions/wsdl:portType/@name"));
79 assertEquals(
80 "http://simple.component.api.mule.org",
81 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
82 assertEquals(
83 "http://simple.component.api.mule.org",
84 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
85 assertEquals("muleService", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
86 assertEquals("muleServicePort", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
87 assertEquals("http://localhost:" + getPorts().get(1) + "/services/EchoService2",
88 doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
89 }
90
91 public void testWsdl3() throws Exception
92 {
93 Map props = new HashMap();
94 props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
95 MuleClient client = new MuleClient(muleContext);
96
97 MuleMessage result = client.send("http://localhost:" + getPorts().get(2) + "/services/EchoService3?wsdl", null, props);
98 assertNotNull(result);
99 String wsdl = result.getPayloadAsString();
100 Document doc = DocumentHelper.parseText(wsdl);
101 assertEquals("http://foo.com", doc.valueOf("/wsdl:definitions/@targetNamespace"));
102 assertEquals("mulePortType1", doc.valueOf("/wsdl:definitions/wsdl:portType/@name"));
103 assertEquals(
104 "http://foo.com",
105 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
106 assertEquals(
107 "http://foo.com",
108 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
109 assertEquals("muleService1", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
110 assertEquals("muleServicePort1", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
111
112 assertEquals("http://localhost:62083/services/EchoService3",
113 doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
114 }
115
116 @Override
117 protected int getNumPortsToFind()
118 {
119 return 3;
120 }
121 }