1   /*
2    * $Id: WSProxyTestCase.java 12128 2008-06-23 11:22:35Z 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.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.FunctionalTestCase;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  public class WSProxyTestCase extends FunctionalTestCase
22  {
23  
24      @Override
25      protected String getConfigResources()
26      {
27          return "mule-proxy-config.xml";
28      }
29  
30      public void testDirectRequest() throws Exception
31      {
32          MuleClient client = new MuleClient();
33          MuleMessage result = client.send("wsdl-cxf:http://localhost:6065/WebService?wsdl&method=echo", 
34              new DefaultMuleMessage("mule"));
35          assertEquals ("mule", result.getPayloadAsString());
36      }
37  
38  
39      public void testWsdlProxyRequest() throws Exception
40      {
41          MuleClient client = new MuleClient();
42          Map<String, String> props = new HashMap<String, String>();
43          props.put("http.method", "GET");
44          MuleMessage replyMessage = client.send("http://localhost:6070/webServiceProxy?wsdl", 
45              "/services/webServiceProxy?WSDL", props);
46          assertNotNull(replyMessage);
47          
48          String wsdl = replyMessage.getPayloadAsString();
49          assertNotNull(wsdl);
50          assertTrue(wsdl.indexOf("<wsdl:definitions") != -1);
51          assertTrue(wsdl.indexOf("<wsdl:message name=\"echoResponse\">") != -1);
52          assertTrue(wsdl.indexOf("<wsdl:message name=\"echoRequest\">") != -1);
53      }
54      
55      public void testProxyRequest() throws Exception
56      {
57          MuleClient client = new MuleClient();
58          MuleMessage result = client.send("wsdl-cxf:http://localhost:6070/webServiceProxy?wsdl&method=echo", 
59              new DefaultMuleMessage("mule"));
60          assertEquals ("mule", result.getPayloadAsString());
61      }
62      
63      public void testWsdlFileRequest() throws Exception
64      {
65          MuleClient client = new MuleClient();
66          Map<String, String> props = new HashMap<String, String>();
67          props.put("http.method", "GET");
68          MuleMessage replyMessage = client.send("http://localhost:6075/webServiceProxy?wsdl", 
69              "/services/webServiceProxy?WSDL", props);
70          assertNotNull(replyMessage);
71          
72          String wsdl = replyMessage.getPayloadAsString();
73          assertNotNull(wsdl);
74          assertTrue(wsdl.indexOf("<wsdl:definitions") != -1);
75          assertTrue(wsdl.indexOf("<wsdl:message name=\"echoResponse\">") != -1);
76          assertTrue(wsdl.indexOf("<wsdl:message name=\"echoRequest\">") != -1);
77      }
78      
79      public void testWsdlFileProxyRequest() throws Exception
80      {
81          MuleClient client = new MuleClient();
82          MuleMessage result = client.send("wsdl-cxf:http://localhost:6075/webServiceProxy?wsdl&method=echo", 
83              new DefaultMuleMessage("mule"));
84          assertEquals ("mule", result.getPayloadAsString());
85      }
86      
87  }