View Javadoc

1   /*
2    * $Id: CxfBasicTestCase.java 20109 2010-11-07 05:20:30Z mike.schilling $
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.api.MuleMessage;
14  import org.mule.config.i18n.LocaleMessageHandler;
15  import org.mule.module.client.MuleClient;
16  import org.mule.module.xml.util.XMLUtils;
17  import org.mule.tck.FunctionalTestCase;
18  import org.mule.transport.http.HttpConstants;
19  import org.mule.util.IOUtils;
20  
21  import java.io.InputStream;
22  import java.util.HashMap;
23  import java.util.Locale;
24  import java.util.Map;
25  
26  import javax.xml.transform.TransformerFactoryConfigurationError;
27  
28  import org.custommonkey.xmlunit.XMLUnit;
29  
30  public class CxfBasicTestCase extends FunctionalTestCase
31  {
32      private String echoWsdl;
33  
34      @Override
35      protected void doSetUp() throws Exception
36      {
37          super.doSetUp();
38          echoWsdl = IOUtils.getResourceAsString("cxf-echo-service.wsdl", getClass());
39          XMLUnit.setIgnoreWhitespace(true);
40          try
41          {
42              XMLUnit.getTransformerFactory();
43          }
44          catch (TransformerFactoryConfigurationError e)
45          {
46              XMLUnit.setTransformerFactory(XMLUtils.TRANSFORMER_FACTORY_JDK5);
47          }
48      }
49  
50      public void testEchoService() throws Exception
51      {
52          MuleClient client = new MuleClient(muleContext);
53          Map<String, Object> props = new HashMap<String, Object>();
54          props.put("Content-Type", "application/soap+xml");
55          InputStream xml = getClass().getResourceAsStream("/direct/direct-request.xml");
56          MuleMessage result = client.send("http://localhost:63081/services/Echo", xml, props);
57          assertTrue(result.getPayloadAsString().contains("Hello!"));
58          String ct = result.getStringProperty(HttpConstants.HEADER_CONTENT_TYPE, "");
59          assertEquals("text/xml; charset=UTF-8", ct);
60      }
61  
62      public void testEchoServiceEncoding() throws Exception
63      {
64          MuleClient client = new MuleClient(muleContext);
65          String message = LocaleMessageHandler.getString("test-data",
66              Locale.JAPAN, "CxfBasicTestCase.testEchoServiceEncoding", new Object[]{});
67          MuleMessage result = client.send("cxf:http://localhost:63081/services/Echo?method=echo", message, null);
68          String ct = result.getStringProperty(HttpConstants.HEADER_CONTENT_TYPE, "");
69  
70          assertEquals(message, result.getPayload());
71          assertEquals("text/xml; charset=UTF-8", ct);
72      }
73  
74      public void testEchoWsdl() throws Exception
75      {
76          MuleClient client = new MuleClient(muleContext);
77          MuleMessage result = client.request("http://localhost:63081/services/Echo?wsdl", 5000);
78          assertNotNull(result.getPayload());
79          XMLUnit.compareXML(echoWsdl, result.getPayloadAsString());
80      }
81  
82      protected String getConfigResources()
83      {
84          return "basic-conf.xml";
85      }
86  
87  }