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.api.client.LocalMuleClient;
12  import org.mule.module.cxf.example.HelloWorld;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.tck.junit4.rule.DynamicPort;
15  
16  import java.util.Map;
17  
18  import javax.jws.WebService;
19  
20  import org.junit.Rule;
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertTrue;
24  
25  public class UnwrapsComponentExceptionTestCase extends FunctionalTestCase
26  {
27  
28      public static final String ERROR_MESSAGE = "Changos!!!";
29  
30      private static final String requestPayload =
31              "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
32              "           xmlns:hi=\"http://example.cxf.module.mule.org/\">\n" +
33              "<soap:Body>\n" +
34              "<hi:sayHi>\n" +
35              "    <arg0>Hello</arg0>\n" +
36              "</hi:sayHi>\n" +
37              "</soap:Body>\n" +
38              "</soap:Envelope>";
39  
40      @Rule
41      public DynamicPort dynamicPort = new DynamicPort("port1");
42  
43      @Override
44      protected String getConfigResources()
45      {
46          return "unwraps-component-exception-config.xml";
47      }
48  
49      @Test
50      public void testReceivesComponentExceptionMessage() throws Exception
51      {
52          MuleMessage request = new DefaultMuleMessage(requestPayload, (Map<String, Object>) null, muleContext);
53          LocalMuleClient client = muleContext.getClient();
54          MuleMessage received = client.send("http://localhost:" + dynamicPort.getNumber() + "/hello", request);
55  
56          assertTrue("Component exception was not managed", received.getPayloadAsString().contains(ERROR_MESSAGE));
57      }
58  
59      @WebService(endpointInterface = "org.mule.module.cxf.example.HelloWorld", serviceName = "HelloWorld")
60      public static class HelloWorldImpl implements HelloWorld
61      {
62  
63          public String sayHi(String text)
64          {
65              throw new RuntimeException(ERROR_MESSAGE);
66          }
67      }
68  }