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.test.integration.client;
8   
9   import org.mule.api.MuleException;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.module.cxf.SoapConstants;
13  import org.mule.tck.junit4.AbstractMuleContextTestCase;
14  import org.mule.util.ExceptionUtils;
15  import org.mule.util.StringUtils;
16  
17  import java.util.HashMap;
18  import java.util.Map;
19  
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertTrue;
24  import static org.junit.Assert.fail;
25  
26  public class MuleClientWSDLExternalTestCase extends AbstractMuleContextTestCase
27  {
28  
29      @Test
30      public void testRequestResponse() throws Throwable
31      {
32          if (isOffline("org.mule.test.integration.client.MuleClientWSDLExternalTestCase.testRequestResponse()"))
33          {
34              return;
35          }
36  
37          String input = "IBM";
38          Map properties = new HashMap();
39          properties.put(SoapConstants.SOAP_ACTION_PROPERTY, "${methodNamespace}${method}");
40          properties.put(SoapConstants.METHOD_NAMESPACE_PROPERTY, "http://www.webserviceX.NET/");
41          String url = "wsdl:http://www.webservicex.net/stockquote.asmx?WSDL&method=GetQuote";
42          MuleMessage result = null;
43          String resultPayload = StringUtils.EMPTY;
44  
45          try
46          {
47              MuleClient client = new MuleClient(muleContext);
48              result = client.send(url, input, properties);
49              resultPayload = (result != null ? result.getPayloadAsString() : StringUtils.EMPTY);
50          }
51          catch (MuleException e)
52          {
53              fail(ExceptionUtils.getStackTrace(e));
54          }
55  
56          if (result != null)
57          {
58              logger.debug("The quote for " + input + " is: " + result.getPayload());
59          }
60  
61          assertNotNull(result);
62          assertTrue(resultPayload.startsWith("<StockQuotes><Stock><Symbol>IBM</Symbol>"));
63      }
64  
65  }