View Javadoc

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