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