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 org.mule.DefaultMuleEvent;
10  import org.mule.DefaultMuleMessage;
11  import org.mule.api.MuleEvent;
12  import org.mule.api.MuleMessage;
13  import org.mule.api.MuleSession;
14  import org.mule.api.endpoint.EndpointBuilder;
15  import org.mule.api.endpoint.OutboundEndpoint;
16  import org.mule.endpoint.EndpointURIEndpointBuilder;
17  import org.mule.module.client.MuleClient;
18  import org.mule.session.DefaultMuleSession;
19  import org.mule.tck.junit4.AbstractMuleContextTestCase;
20  import org.mule.transport.AbstractConnector;
21  
22  import org.custommonkey.xmlunit.XMLAssert;
23  import org.junit.Test;
24  import org.w3c.dom.Document;
25  
26  import static org.junit.Assert.assertNotNull;
27  
28  public class CxfWsdlTestCase extends AbstractMuleContextTestCase
29  {
30      public static final String TEST_URL = "wsdl-cxf:http://localhost:8080/mule-tests-external-cxf/services/TestService?WSDL&method=getTest";
31      public static final String TEST_URL_NOWSDL = "wsdl-cxf:http://localhost:8080/mule-tests-external-cxf/services/TestService?method=getTest";
32      public static final String TEST_URL_WSDL = "http://localhost:8080/mule-tests-external-cxf/services/TestService?wsdl";
33  
34      @Test
35      public void testCxfWsdlService() throws Exception
36      {
37          MuleClient client = new MuleClient(muleContext);
38  
39          MuleMessage message = new DefaultMuleMessage("test1", muleContext);
40          MuleMessage reply = client.send(TEST_URL, message);
41          assertNotNull(reply);
42  
43          Document response = (Document) reply.getPayload();
44          assertNotNull(response);
45  
46          XMLAssert.assertXpathEvaluatesTo("test1",
47              "//*[namespace-uri()='http://applications.external.tck.mule.org' and local-name()='key']",
48              response);
49      }
50  
51      /**
52       * This tests the endpoint propery of wsdlUrl which specifies an alternative WSDL
53       * location (see MULE-1368)
54       */
55      @Test
56      public void testCxfWsdlServiceWithEndpointParam() throws Exception
57      {
58          EndpointBuilder endpointBuilder = new EndpointURIEndpointBuilder(TEST_URL_NOWSDL, muleContext);
59          endpointBuilder.setProperty("wsdlUrl", TEST_URL_WSDL);
60  
61          OutboundEndpoint endpoint = 
62              muleContext.getEndpointFactory().getOutboundEndpoint(endpointBuilder);
63  
64          MuleMessage message = new DefaultMuleMessage("test1", muleContext);
65          MuleSession session = new DefaultMuleSession(message,
66              ((AbstractConnector) endpoint.getConnector()).getSessionHandler(), muleContext);
67          MuleEvent event = new DefaultMuleEvent(message, endpoint, session);
68          MuleMessage reply = endpoint.process(event).getMessage();
69  
70          assertNotNull(reply);
71  
72          Document response = (Document) reply.getPayload();
73          assertNotNull(response);
74  
75          XMLAssert.assertXpathEvaluatesTo("test1",
76              "//*[namespace-uri()='http://applications.external.tck.mule.org' and local-name()='key']",
77              response);
78      }
79  }