View Javadoc

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