View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.soap.axis.functional;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.tck.junit4.rule.DynamicPort;
13  import org.mule.transport.http.HttpConnector;
14  
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import org.dom4j.Document;
19  import org.dom4j.DocumentHelper;
20  import org.junit.Rule;
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  import static org.junit.Assert.assertTrue;
26  
27  public class WsdlGenerationTestCase extends FunctionalTestCase
28  {
29      /**
30       * The generated proxy names have increasing counter if run from the top-level m2
31       * build, can be e.g. $Proxy12. Check optionally for 3 digits to be on the safe
32       * side.
33       */
34      private static final String PROXY_REGEX = "^\\$Proxy(\\d+\\d*\\d*)$";
35  
36      @Rule
37      public DynamicPort dynamicPort1 = new DynamicPort("port1");
38      
39      @Rule
40      public DynamicPort dynamicPort2 = new DynamicPort("port2");
41  
42      @Rule
43      public DynamicPort dynamicPort3 = new DynamicPort("port3");
44  
45      @Override
46      protected String getConfigResources()
47      {
48          return "axis-wsdl-test.xml";
49      }
50  
51      @Test
52      public void testWsdl1() throws Exception
53      {
54          Map props = new HashMap();
55          props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
56          MuleClient client = new MuleClient(muleContext);
57  
58          MuleMessage result = client.send("http://localhost:" + dynamicPort1.getNumber() + "/services/EchoService1?wsdl", null, props);
59          assertNotNull(result);
60          String wsdl = result.getPayloadAsString();
61          Document doc = DocumentHelper.parseText(wsdl);
62          assertEquals("http://foo", doc.valueOf("/wsdl:definitions/@targetNamespace"));
63  
64          // standalone m2 test run can produce $Proxy0, $Proxy1, $Proxy3, etc.
65          assertTrue(doc.valueOf("/wsdl:definitions/wsdl:portType/@name").matches(PROXY_REGEX));
66  
67          assertEquals(
68              "http://foo",
69              doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
70          assertEquals(
71              "http://foo",
72              doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
73  
74          assertEquals("EchoService1", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
75  
76          assertEquals("EchoService1", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
77          assertEquals("http://localhost:" + dynamicPort1.getNumber() + "/services/EchoService1",
78              doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
79      }
80  
81      @Test
82      public void testWsdl2() throws Exception
83      {
84          Map props = new HashMap();
85          props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
86          MuleClient client = new MuleClient(muleContext);
87  
88          MuleMessage result = client.send("http://localhost:" + dynamicPort2.getNumber() + "/services/EchoService2?wsdl", null, props);
89          assertNotNull(result);
90          String wsdl = result.getPayloadAsString();
91          Document doc = DocumentHelper.parseText(wsdl);
92          assertEquals("http://simple.component.api.mule.org", doc.valueOf("/wsdl:definitions/@targetNamespace"));
93          assertEquals("mulePortType", doc.valueOf("/wsdl:definitions/wsdl:portType/@name"));
94          assertEquals(
95              "http://simple.component.api.mule.org",
96              doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
97          assertEquals(
98              "http://simple.component.api.mule.org",
99              doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
100         assertEquals("muleService", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
101         assertEquals("muleServicePort", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
102         assertEquals("http://localhost:" + dynamicPort2.getNumber() + "/services/EchoService2",
103             doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
104     }
105 
106     @Test
107     public void testWsdl3() throws Exception
108     {
109         Map props = new HashMap();
110         props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
111         MuleClient client = new MuleClient(muleContext);
112 
113         MuleMessage result = client.send("http://localhost:" + dynamicPort3.getNumber() + "/services/EchoService3?wsdl", null, props);
114         assertNotNull(result);
115         String wsdl = result.getPayloadAsString();
116         Document doc = DocumentHelper.parseText(wsdl);
117         assertEquals("http://foo.com", doc.valueOf("/wsdl:definitions/@targetNamespace"));
118         assertEquals("mulePortType1", doc.valueOf("/wsdl:definitions/wsdl:portType/@name"));
119         assertEquals(
120             "http://foo.com",
121             doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
122         assertEquals(
123             "http://foo.com",
124             doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
125         assertEquals("muleService1", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
126         assertEquals("muleServicePort1", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
127         // this port is hardcoded in the wsdl, so not the same as the actual endpoint port
128         assertEquals("http://localhost:62083/services/EchoService3",
129             doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
130     }
131 
132 }