1
2
3
4
5
6
7 package org.mule.module.cxf;
8
9 import org.mule.DefaultMuleMessage;
10 import org.mule.api.MessagingException;
11 import org.mule.api.MuleMessage;
12 import org.mule.api.context.notification.ExceptionNotificationListener;
13 import org.mule.api.context.notification.ServerNotification;
14 import org.mule.api.endpoint.InboundEndpoint;
15 import org.mule.module.client.MuleClient;
16 import org.mule.module.cxf.testmodels.CxfEnabledFaultMessage;
17 import org.mule.tck.junit4.FunctionalTestCase;
18 import org.mule.tck.junit4.rule.DynamicPort;
19
20 import java.util.Map;
21 import java.util.concurrent.CountDownLatch;
22 import java.util.concurrent.TimeUnit;
23
24 import org.junit.Ignore;
25 import org.junit.Rule;
26 import org.junit.Test;
27
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertNotNull;
30 import static org.junit.Assert.assertTrue;
31 import static org.junit.Assert.fail;
32
33 public class CxfExceptionHandlingTestCase extends FunctionalTestCase
34 {
35 private static final String requestFaultPayload =
36 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
37 " xmlns:hi=\"http://cxf.module.mule.org/\">\n" +
38 "<soap:Body>\n" +
39 "<hi:sayHi>\n" +
40 " <arg0></arg0>\n" +
41 "</hi:sayHi>\n" +
42 "</soap:Body>\n" +
43 "</soap:Envelope>";
44
45 @Rule
46 public DynamicPort dynamicPort = new DynamicPort("port1");
47 private CountDownLatch latch;
48
49 @Override
50 protected String getConfigResources()
51 {
52 return "onexception-conf.xml";
53 }
54
55
56 @Test
57 public void testFaultInCxfService() throws Exception
58 {
59 MuleMessage request = new DefaultMuleMessage(requestFaultPayload, (Map<String,Object>)null, muleContext);
60 MuleClient client = new MuleClient(muleContext);
61 MuleMessage response = client.send("http://localhost:" + dynamicPort.getNumber() + "/testServiceWithFault", request);
62 assertNotNull(response);
63 assertTrue(response.getPayloadAsString().contains("<faultstring>"));
64 }
65
66 @Test
67 public void testFaultInCxfServiceInvokeExceptionStrategy() throws Exception
68 {
69 MuleMessage request = new DefaultMuleMessage(requestFaultPayload, (Map<String,Object>)null, muleContext);
70 MuleClient client = new MuleClient(muleContext);
71 latch = new CountDownLatch(1);
72 muleContext.registerListener(new ExceptionNotificationListener() {
73 public void onNotification(ServerNotification notification)
74 {
75 latch.countDown();
76 }
77 });
78
79 MuleMessage response = client.send("http://localhost:" + dynamicPort.getNumber() + "/testServiceWithFaultInvokeStrategy", request);
80 assertNotNull(response);
81 assertNotNull(response.getExceptionPayload());
82 assertTrue(latch.await(3000, TimeUnit.MILLISECONDS));
83 }
84
85 @Test
86 public void testFaultInCxfServiceInvokeComponentExceptionStrategy() throws Exception
87 {
88 MuleMessage request = new DefaultMuleMessage(requestFaultPayload, (Map<String,Object>)null, muleContext);
89 MuleClient client = new MuleClient(muleContext);
90 latch = new CountDownLatch(1);
91 muleContext.registerListener(new ExceptionNotificationListener() {
92 public void onNotification(ServerNotification notification)
93 {
94 latch.countDown();
95 }
96 });
97 MuleMessage response = client.send("http://localhost:" + dynamicPort.getNumber() + "/testServiceWithFaultInvokeComponentStrategy", request);
98 assertNotNull(response);
99 assertNotNull(response.getExceptionPayload());
100 assertTrue(latch.await(3000, TimeUnit.MILLISECONDS));
101 }
102
103 }