View Javadoc

1   /*
2    * $Id: WSProxyTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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 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(muleContext);
33          MuleMessage result = client.send("wsdl-cxf:http://localhost:6065/WebService?wsdl&method=echo", 
34              new DefaultMuleMessage("mule", muleContext));
35          assertEquals ("mule", result.getPayloadAsString());
36      }
37  
38  
39      public void testWsdlProxyRequest() throws Exception
40      {
41          MuleClient client = new MuleClient(muleContext);
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          System.out.println(wsdl);
51          assertTrue(wsdl.indexOf("<wsdl:definitions") != -1);
52          assertTrue(wsdl.indexOf("<wsdl:message name=\"echoResponse\">") != -1);
53          assertTrue(wsdl.indexOf("<wsdl:message name=\"echo\">") != -1);
54      }
55      
56      public void testProxyRequest() throws Exception
57      {
58          MuleClient client = new MuleClient(muleContext);
59          MuleMessage result = client.send("wsdl-cxf:http://localhost:6070/webServiceProxy?wsdl&method=echo", 
60              new DefaultMuleMessage("mule", muleContext));
61          assertEquals ("mule", result.getPayloadAsString());
62      }
63      
64      public void testWsdlFileRequest() throws Exception
65      {
66          MuleClient client = new MuleClient(muleContext);
67          Map<String, String> props = new HashMap<String, String>();
68          props.put("http.method", "GET");
69          MuleMessage replyMessage = client.send("http://localhost:6075/webServiceProxy?wsdl", 
70              "/services/webServiceProxy?WSDL", props);
71          assertNotNull(replyMessage);
72          
73          String wsdl = replyMessage.getPayloadAsString();
74          assertNotNull(wsdl);
75          assertTrue(wsdl.indexOf("<wsdl:definitions") != -1);
76          assertTrue(wsdl.indexOf("<wsdl:message name=\"echoResponse\">") != -1);
77          assertTrue(wsdl.indexOf("<wsdl:message name=\"echo\">") != -1);
78      }
79      
80      public void testWsdlFileProxyRequest() throws Exception
81      {
82          MuleClient client = new MuleClient(muleContext);
83          MuleMessage result = client.send("wsdl-cxf:http://localhost:6075/webServiceProxy?wsdl&method=echo", 
84              new DefaultMuleMessage("mule", muleContext));
85          assertEquals ("mule", result.getPayloadAsString());
86      }
87      
88  }