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.functional;
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.Map;
16  
17  import org.junit.Rule;
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.assertTrue;
22  
23  public class CxfContentTypeTestCase extends FunctionalTestCase
24  {
25      private static final String requestPayload =
26          "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
27              "           xmlns:hi=\"http://example.org/\">\n" +
28              "<soap:Body>\n" +
29              "<hi:sayHi>\n" +
30              "    <arg0>Hello</arg0>\n" +
31              "</hi:sayHi>\n" +
32              "</soap:Body>\n" +
33              "</soap:Envelope>";
34  
35      @Rule
36      public DynamicPort dynamicPort = new DynamicPort("port1");
37  
38      @Override
39      protected String getConfigResources()
40      {
41          return "cxf-echo-service-conf.xml";
42      }
43  
44      @Test
45      public void testCxfService() throws Exception
46      {
47          MuleMessage request = new DefaultMuleMessage(requestPayload, (Map<String,Object>)null, muleContext);
48          MuleClient client = new MuleClient(muleContext);
49          MuleMessage received = client.send("http://localhost:" + dynamicPort.getNumber() + "/hello", request);
50          String contentType = received.getInboundProperty("content-type");
51          assertNotNull(contentType);
52          assertTrue(contentType.contains("charset"));
53      }
54  
55      @Test
56      public void testCxfClient() throws Exception
57      {
58          MuleMessage request = new DefaultMuleMessage("hello", (Map<String,Object>)null, muleContext);
59          MuleClient client = new MuleClient(muleContext);
60          MuleMessage received = client.send("vm://helloClient", request);
61          String contentType = received.getInboundProperty("contentType");
62          assertNotNull(contentType);
63          assertTrue(contentType.contains("charset"));
64      }
65  
66  }