1   /*
2    * $Id: WsdlGenerationTestCase.java 11179 2008-03-05 13:46:23Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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.FunctionalTestCase;
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 FunctionalTestCase
25  {
26      /**
27       * The generated proxy names have increasing counter if run from the top-level m2
28       * build, can be e.g. $Proxy12. Check optionally for 3 digits to be on the safe
29       * side.
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();
43  
44          MuleMessage result = client.send("http://localhost:62081/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          // standalone m2 test run can produce $Proxy0, $Proxy1, $Proxy3, etc.
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:62081/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();
72  
73          MuleMessage result = client.send("http://localhost:62082/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:62082/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();
96  
97          MuleMessage result = client.send("http://localhost:62083/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         assertEquals("http://localhost:62083/services/EchoService3",
112             doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
113     }
114 }