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.module.cxf;
8   
9   import static org.junit.Assert.assertEquals;
10  import org.mule.tck.junit4.FunctionalTestCase;
11  import org.mule.tck.junit4.rule.DynamicPort;
12  import org.mule.transport.servlet.MuleReceiverServlet;
13  import org.mule.transport.servlet.jetty.util.EmbeddedJettyServer;
14  
15  import java.io.InputStream;
16  import java.net.URL;
17  import java.util.List;
18  
19  import org.dom4j.Document;
20  import org.dom4j.Element;
21  import org.dom4j.io.SAXReader;
22  import org.junit.Rule;
23  import org.junit.Test;
24  
25  public class WsdlCallTestCase extends FunctionalTestCase
26  {
27  
28      @Rule
29      public final DynamicPort jettyPort = new DynamicPort("jettyPort");
30  
31      @Rule
32      public final DynamicPort httpPort = new DynamicPort("httpPort");
33  
34      private EmbeddedJettyServer httpServer;
35  
36      @Override
37      protected String getConfigResources()
38      {
39          return "wsdl-conf.xml";
40      }
41  
42      @Override
43      protected void doSetUp() throws Exception
44      {
45          super.doSetUp();
46  
47          httpServer = new EmbeddedJettyServer(jettyPort.getNumber(), "/", "/services/*", new MuleReceiverServlet(), muleContext);
48          httpServer.start();
49      }
50  
51      @Override
52      protected void doTearDown() throws Exception
53      {
54          if (httpServer != null && httpServer.isStarted())
55          {
56              httpServer.stop();
57          }
58  
59          super.doTearDown();
60      }
61  
62      @Test
63      public void testRequestWsdlWithServlets() throws Exception
64      {
65          InputStream wsdlStream = new URL("http://localhost:" + jettyPort.getNumber()
66              + "/services/mycomponent?wsdl").openStream();
67  
68          String location = "http://localhost:" + jettyPort.getNumber() + "/services/mycomponent";
69  
70          Document document = new SAXReader().read(wsdlStream);
71  
72          List nodes = document.selectNodes("//wsdl:definitions/wsdl:service");
73          assertEquals("Callable", ((Element) nodes.get(0)).attribute("name").getStringValue());
74          nodes = document.selectNodes("//wsdl:definitions/wsdl:service/wsdl:port/soap:address");
75          assertEquals(location, ((Element) nodes.get(0)).attribute("location").getStringValue());
76      }
77  
78      @Test
79      public void testRequestWsdlWithHttp() throws Exception
80      {
81          String location = "http://localhost:" + httpPort.getNumber() + "/cxfService";
82          InputStream wsdlStream = new URL(location + "?wsdl").openStream();
83  
84          Document document = new SAXReader().read(wsdlStream);
85          List nodes = document.selectNodes("//wsdl:definitions/wsdl:service");
86          assertEquals(((Element) nodes.get(0)).attribute("name").getStringValue(), "Callable");
87  
88          nodes = document.selectNodes("//wsdl:definitions/wsdl:service/wsdl:port/soap:address");
89          assertEquals(location, ((Element) nodes.get(0)).attribute("location").getStringValue());
90      }
91  
92  }