View Javadoc

1   /*
2    * $Id: WsdlCallTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.module.cxf;
12  
13  import org.mule.tck.FunctionalTestCase;
14  import org.mule.transport.servlet.MuleReceiverServlet;
15  import org.mule.transport.servlet.jetty.util.EmbeddedJettyServer;
16  
17  import java.io.InputStream;
18  import java.net.URL;
19  import java.util.List;
20  
21  import org.dom4j.Document;
22  import org.dom4j.Element;
23  import org.dom4j.io.SAXReader;
24  
25  public class WsdlCallTestCase extends FunctionalTestCase
26  {
27      public static final int HTTP_PORT = 63088;
28  
29      private EmbeddedJettyServer httpServer;
30  
31      @Override
32      protected void doSetUp() throws Exception
33      {
34          super.doSetUp();
35          
36          httpServer = new EmbeddedJettyServer(HTTP_PORT, "/", "/services/*", new MuleReceiverServlet(), muleContext);
37          httpServer.start();
38      }
39  
40      @Override
41      protected void doTearDown() throws Exception
42      {
43          if (httpServer != null && httpServer.isStarted())
44          {
45              httpServer.stop();
46          }
47  
48          super.doTearDown();
49      }
50      
51      
52      public void testRequestWsdlWithServlets() throws Exception
53      {
54          InputStream wsdlStream = new URL("http://localhost:" + HTTP_PORT
55              + "/services/mycomponent?wsdl").openStream();
56          
57          String location = "http://localhost:" + HTTP_PORT + "/services/mycomponent";
58          
59          Document document = new SAXReader().read(wsdlStream);
60          
61          List nodes = document.selectNodes("//wsdl:definitions/wsdl:service");
62          assertEquals("Callable", ((Element) nodes.get(0)).attribute("name").getStringValue());
63          nodes = document.selectNodes("//wsdl:definitions/wsdl:service/wsdl:port/soap:address");
64          assertEquals(location, ((Element) nodes.get(0)).attribute("location").getStringValue());
65      }
66  
67      public void testRequestWsdlWithHttp() throws Exception
68      {
69          String location = "http://localhost:63082/cxfService";
70          InputStream wsdlStream = new URL(location + "?wsdl").openStream();
71          
72          Document document = new SAXReader().read(wsdlStream);
73          List nodes = document.selectNodes("//wsdl:definitions/wsdl:service");
74          assertEquals(((Element) nodes.get(0)).attribute("name").getStringValue(), "Callable");
75          
76          nodes = document.selectNodes("//wsdl:definitions/wsdl:service/wsdl:port/soap:address");
77          assertEquals(location, ((Element) nodes.get(0)).attribute("location").getStringValue());
78      }
79  
80      protected String getConfigResources()
81      {
82          return "wsdl-conf.xml";
83      }
84      
85  }