1   /*
2    * $Id: WsdlGenerationTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.providers.soap.axis.functional;
12  
13  import org.mule.extras.client.MuleClient;
14  import org.mule.providers.http.HttpConnector;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.umo.UMOMessage;
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      /**
28       * The generated proxy names have increasing counter if run from the top-level m2
29       * build, can be e.g. $Proxy12. Check optionally for 3 digits to be on the safe
30       * side.
31       */
32      private static final String PROXY_REGEX = "^\\$Proxy(\\d+\\d*\\d*)$";
33  
34      public WsdlGenerationTestCase()
35      {
36          super.setDisposeManagerPerSuite(true);
37      }
38  
39      protected String getConfigResources()
40      {
41          return "axis-wsdl-test.xml";
42      }
43  
44      public void testWsdl1() throws Exception
45      {
46          Map props = new HashMap();
47          props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
48          MuleClient client = new MuleClient();
49  
50          UMOMessage result = client.send("http://localhost:62081/services/EchoService1?wsdl", null, props);
51          assertNotNull(result);
52          String wsdl = result.getPayloadAsString();
53          Document doc = DocumentHelper.parseText(wsdl);
54          assertEquals("http://foo", doc.valueOf("/wsdl:definitions/@targetNamespace"));
55  
56          // standalone m2 test run can produce $Proxy0, $Proxy1, $Proxy3, etc.
57          assertTrue(doc.valueOf("/wsdl:definitions/wsdl:portType/@name").matches(PROXY_REGEX));
58  
59          assertEquals(
60              "http://foo",
61              doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
62          assertEquals(
63              "http://foo",
64              doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
65  
66          assertEquals("EchoService1", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
67  
68          assertEquals("EchoService1", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
69          assertEquals("http://localhost:62081/services/EchoService1",
70              doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
71  
72      }
73  
74      public void testWsdl2() throws Exception
75      {
76          Map props = new HashMap();
77          props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
78          MuleClient client = new MuleClient();
79  
80          UMOMessage result = client.send("http://localhost:62082/services/EchoService2?wsdl", null, props);
81          assertNotNull(result);
82          String wsdl = result.getPayloadAsString();
83          Document doc = DocumentHelper.parseText(wsdl);
84          assertEquals("http://simple.components.mule.org", doc.valueOf("/wsdl:definitions/@targetNamespace"));
85          assertEquals("mulePortType", doc.valueOf("/wsdl:definitions/wsdl:portType/@name"));
86          assertEquals(
87              "http://simple.components.mule.org",
88              doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
89          assertEquals(
90              "http://simple.components.mule.org",
91              doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
92          assertEquals("muleService", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
93          assertEquals("muleServicePort", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
94          assertEquals("http://localhost:62082/services/EchoService2",
95              doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
96  
97      }
98  
99      public void testWsdl3() throws Exception
100     {
101         Map props = new HashMap();
102         props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
103         MuleClient client = new MuleClient();
104 
105         UMOMessage result = client.send("http://localhost:62083/services/EchoService3?wsdl", null, props);
106         assertNotNull(result);
107         String wsdl = result.getPayloadAsString();
108         Document doc = DocumentHelper.parseText(wsdl);
109         assertEquals("http://foo.com", doc.valueOf("/wsdl:definitions/@targetNamespace"));
110         assertEquals("mulePortType1", doc.valueOf("/wsdl:definitions/wsdl:portType/@name"));
111         assertEquals(
112             "http://foo.com",
113             doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:input[@name='echoRequest']/wsdlsoap:body/@namespace"));
114         assertEquals(
115             "http://foo.com",
116             doc.valueOf("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='echo']/wsdl:output[@name='echoResponse']/wsdlsoap:body/@namespace"));
117         assertEquals("muleService1", doc.valueOf("/wsdl:definitions/wsdl:service/@name"));
118         assertEquals("muleServicePort1", doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/@name"));
119         assertEquals("http://localhost:62083/services/EchoService3",
120             doc.valueOf("/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address/@location"));
121 
122     }
123 }