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