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.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.tck.junit4.rule.DynamicPort;
14  
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import org.junit.Rule;
19  import org.junit.Test;
20  
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertTrue;
24  
25  public class WSProxyTestCase extends FunctionalTestCase
26  {
27  
28      @Rule
29      public DynamicPort dynamicPort1 = new DynamicPort("port1");
30  
31      @Rule
32      public DynamicPort dynamicPort2 = new DynamicPort("port2");
33  
34      @Rule
35      public DynamicPort dynamicPort3 = new DynamicPort("port3");
36      
37      @Override
38      protected String getConfigResources()
39      {
40          return "mule-proxy-config.xml";
41      }
42  
43      @Test
44      public void testDirectRequest() throws Exception
45      {
46          MuleClient client = new MuleClient(muleContext);
47          MuleMessage result = client.send("wsdl-cxf:http://localhost:" + dynamicPort1.getNumber() + "/WebService?wsdl&method=echo",
48              new DefaultMuleMessage("mule", muleContext));
49          assertEquals ("mule", result.getPayloadAsString());
50      }
51  
52      @Test
53      public void testWsdlProxyRequest() throws Exception
54      {
55          MuleClient client = new MuleClient(muleContext);
56          Map<String, String> props = new HashMap<String, String>();
57          props.put("http.method", "GET");
58          MuleMessage replyMessage = client.send("http://localhost:" + dynamicPort2.getNumber() + "/webServiceProxy?wsdl",
59              "/services/webServiceProxy?WSDL", props);
60          assertNotNull(replyMessage);
61          
62          String wsdl = replyMessage.getPayloadAsString();
63          assertNotNull(wsdl);
64          System.out.println(wsdl);
65          assertTrue(wsdl.indexOf("<wsdl:definitions") != -1);
66          assertTrue(wsdl.indexOf("<wsdl:message name=\"echoResponse\">") != -1);
67          assertTrue(wsdl.indexOf("<wsdl:message name=\"echo\">") != -1);
68      }
69      
70      @Test
71      public void testProxyRequest() throws Exception
72      {
73          MuleClient client = new MuleClient(muleContext);
74          MuleMessage result = client.send("wsdl-cxf:http://localhost:" + dynamicPort2.getNumber() + "/webServiceProxy?wsdl&method=echo",
75              new DefaultMuleMessage("mule", muleContext));
76          assertEquals ("mule", result.getPayloadAsString());
77      }
78      
79      @Test
80      public void testWsdlFileRequest() throws Exception
81      {
82          MuleClient client = new MuleClient(muleContext);
83          Map<String, String> props = new HashMap<String, String>();
84          props.put("http.method", "GET");
85          MuleMessage replyMessage = client.send("http://localhost:" + dynamicPort3.getNumber() + "/webServiceProxy?wsdl",
86              "/services/webServiceProxy?WSDL", props);
87          assertNotNull(replyMessage);
88          
89          String wsdl = replyMessage.getPayloadAsString();
90          assertNotNull(wsdl);
91          assertTrue(wsdl.indexOf("<wsdl:definitions") != -1);
92          assertTrue(wsdl.indexOf("<wsdl:message name=\"echoResponse\">") != -1);
93          assertTrue(wsdl.indexOf("<wsdl:message name=\"echo\">") != -1);
94      }
95      
96      @Test
97      public void testWsdlFileProxyRequest() throws Exception
98      {
99          MuleClient client = new MuleClient(muleContext);
100         MuleMessage result = client.send("wsdl-cxf:http://localhost:" + dynamicPort3.getNumber() + "/webServiceProxy?wsdl&method=echo",
101             new DefaultMuleMessage("mule", muleContext));
102         assertEquals ("mule", result.getPayloadAsString());
103     }
104     
105 }