View Javadoc

1   /*
2    * $Id: WsdlCallTestCase.java 22449 2011-07-19 07:40:43Z justin.calleja $
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 static org.junit.Assert.assertEquals;
14  
15  import java.io.InputStream;
16  import java.net.URL;
17  import java.util.Arrays;
18  import java.util.Collection;
19  import java.util.List;
20  
21  import org.dom4j.Document;
22  import org.dom4j.Element;
23  import org.dom4j.io.SAXReader;
24  import org.junit.Test;
25  import org.junit.runners.Parameterized.Parameters;
26  import org.mule.tck.AbstractServiceAndFlowTestCase;
27  import org.mule.transport.servlet.MuleReceiverServlet;
28  import org.mule.transport.servlet.jetty.util.EmbeddedJettyServer;
29  
30  public class WsdlCallTestCase extends AbstractServiceAndFlowTestCase
31  {
32      //TODO(pablo.kraan): replace with a dynamic port
33      public static final int HTTP_PORT = 63088;
34  
35      private EmbeddedJettyServer httpServer;
36  
37      public WsdlCallTestCase(ConfigVariant variant, String configResources)
38      {
39          super(variant, configResources);
40      }
41      
42      @Parameters
43      public static Collection<Object[]> parameters()
44      {
45          return Arrays.asList(new Object[][]{
46              {ConfigVariant.SERVICE, "wsdl-conf-service.xml"},
47              {ConfigVariant.FLOW, "wsdl-conf-flow.xml"}
48          });
49      }
50  
51      @Override
52      protected void doSetUp() throws Exception
53      {
54          super.doSetUp();
55  
56          httpServer = new EmbeddedJettyServer(HTTP_PORT, "/", "/services/*", new MuleReceiverServlet(), muleContext);
57          httpServer.start();
58      }
59  
60      @Override
61      protected void doTearDown() throws Exception
62      {
63          if (httpServer != null && httpServer.isStarted())
64          {
65              httpServer.stop();
66          }
67  
68          super.doTearDown();
69      }
70  
71      @Test
72      public void testRequestWsdlWithServlets() throws Exception
73      {
74          InputStream wsdlStream = new URL("http://localhost:" + HTTP_PORT
75              + "/services/mycomponent?wsdl").openStream();
76  
77          String location = "http://localhost:" + HTTP_PORT + "/services/mycomponent";
78  
79          Document document = new SAXReader().read(wsdlStream);
80  
81          List nodes = document.selectNodes("//wsdl:definitions/wsdl:service");
82          assertEquals("Callable", ((Element) nodes.get(0)).attribute("name").getStringValue());
83          nodes = document.selectNodes("//wsdl:definitions/wsdl:service/wsdl:port/soap:address");
84          assertEquals(location, ((Element) nodes.get(0)).attribute("location").getStringValue());
85      }
86  
87      @Test
88      public void testRequestWsdlWithHttp() throws Exception
89      {
90          String location = "http://localhost:63082/cxfService";
91          InputStream wsdlStream = new URL(location + "?wsdl").openStream();
92  
93          Document document = new SAXReader().read(wsdlStream);
94          List nodes = document.selectNodes("//wsdl:definitions/wsdl:service");
95          assertEquals(((Element) nodes.get(0)).attribute("name").getStringValue(), "Callable");
96  
97          nodes = document.selectNodes("//wsdl:definitions/wsdl:service/wsdl:port/soap:address");
98          assertEquals(location, ((Element) nodes.get(0)).attribute("location").getStringValue());
99      }
100 
101 }