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.junit4.FunctionalTestCase;
16 import org.mule.tck.junit4.rule.DynamicPort;
17 import org.mule.transport.http.HttpConnector;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.dom4j.Document;
23 import org.dom4j.DocumentHelper;
24 import org.junit.Rule;
25 import org.junit.Test;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
30
31 public class WsdlGenerationTestCase extends FunctionalTestCase
32 {
33
34
35
36
37
38 private static final String PROXY_REGEX = "^\\$Proxy(\\d+\\d*\\d*)$";
39
40 @Rule
41 public DynamicPort dynamicPort1 = new DynamicPort("port1");
42
43 @Rule
44 public DynamicPort dynamicPort2 = new DynamicPort("port2");
45
46 @Rule
47 public DynamicPort dynamicPort3 = new DynamicPort("port3");
48
49 @Override
50 protected String getConfigResources()
51 {
52 return "axis-wsdl-test.xml";
53 }
54
55 @Test
56 public void testWsdl1() throws Exception
57 {
58 Map props = new HashMap();
59 props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
60 MuleClient client = new MuleClient(muleContext);
61
62 MuleMessage result = client.send("http://localhost:" + dynamicPort1.getNumber() + "/services/EchoService1?wsdl", null, props);
63 assertNotNull(result);
64 String wsdl = result.getPayloadAsString();
65 Document doc = DocumentHelper.parseText(wsdl);
66 assertEquals("http://foo", doc.valueOf("/wsdl:definitions/@targetNamespace"));
67
68
69 assertTrue(doc.valueOf("/wsdl:definitions/wsdl:portType/@name").matches(PROXY_REGEX));
70
71 assertEquals(
72 "http://foo",
73 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
74 assertEquals(
75 "http://foo",
76 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
77
78 assertEquals("EchoService1", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
79
80 assertEquals("EchoService1", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
81 assertEquals("http://localhost:" + dynamicPort1.getNumber() + "/services/EchoService1",
82 doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
83 }
84
85 @Test
86 public void testWsdl2() throws Exception
87 {
88 Map props = new HashMap();
89 props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
90 MuleClient client = new MuleClient(muleContext);
91
92 MuleMessage result = client.send("http://localhost:" + dynamicPort2.getNumber() + "/services/EchoService2?wsdl", null, props);
93 assertNotNull(result);
94 String wsdl = result.getPayloadAsString();
95 Document doc = DocumentHelper.parseText(wsdl);
96 assertEquals("http://simple.component.api.mule.org", doc.valueOf("/wsdl:definitions/@targetNamespace"));
97 assertEquals("mulePortType", doc.valueOf("/wsdl:definitions/wsdl:portType/@name"));
98 assertEquals(
99 "http://simple.component.api.mule.org",
100 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
101 assertEquals(
102 "http://simple.component.api.mule.org",
103 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
104 assertEquals("muleService", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
105 assertEquals("muleServicePort", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
106 assertEquals("http://localhost:" + dynamicPort2.getNumber() + "/services/EchoService2",
107 doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
108 }
109
110 @Test
111 public void testWsdl3() throws Exception
112 {
113 Map props = new HashMap();
114 props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
115 MuleClient client = new MuleClient(muleContext);
116
117 MuleMessage result = client.send("http://localhost:" + dynamicPort3.getNumber() + "/services/EchoService3?wsdl", null, props);
118 assertNotNull(result);
119 String wsdl = result.getPayloadAsString();
120 Document doc = DocumentHelper.parseText(wsdl);
121 assertEquals("http://foo.com", doc.valueOf("/wsdl:definitions/@targetNamespace"));
122 assertEquals("mulePortType1", doc.valueOf("/wsdl:definitions/wsdl:portType/@name"));
123 assertEquals(
124 "http://foo.com",
125 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
126 assertEquals(
127 "http://foo.com",
128 doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
129 assertEquals("muleService1", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
130 assertEquals("muleServicePort1", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
131
132 assertEquals("http://localhost:62083/services/EchoService3",
133 doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
134 }
135
136 }