1
2
3
4
5
6
7 package org.mule.module.cxf;
8
9 import org.mule.api.MessagingException;
10 import org.mule.api.endpoint.InboundEndpoint;
11 import org.mule.module.client.MuleClient;
12 import org.mule.module.cxf.testmodels.CustomFault;
13 import org.mule.module.cxf.testmodels.CxfEnabledFaultMessage;
14 import org.mule.tck.junit4.FunctionalTestCase;
15 import org.mule.tck.junit4.rule.DynamicPort;
16
17 import org.apache.cxf.interceptor.Fault;
18 import org.junit.Ignore;
19 import org.junit.Rule;
20 import org.junit.Test;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26
27 public class CxfComponentExceptionStrategyTestCase extends FunctionalTestCase
28 {
29
30 @Rule
31 public DynamicPort dynamicPort = new DynamicPort("port1");
32
33 @Override
34 protected String getConfigResources()
35 {
36 return "exception-strategy-conf.xml";
37 }
38
39 @Test
40 public void testDefaultComponentExceptionStrategy() throws Exception
41 {
42 MuleClient client = new MuleClient(muleContext);
43 try
44 {
45 client.send("cxf:" + ((InboundEndpoint) client.getMuleContext().getRegistry()
46 .lookupObject("cxfDefaultInbound")).getAddress() + "?method=testCxfException", "TEST", null);
47 fail("Exception expected");
48 }
49 catch (MessagingException e)
50 {
51 assertTrue(e.getCause().getCause() instanceof CxfEnabledFaultMessage);
52 }
53 }
54
55 @Test
56 @Ignore("This doesn't work because of a bug in the CXF client code :-(")
57 public void testHandledException() throws Exception
58 {
59 MuleClient client = new MuleClient(muleContext);
60
61 try
62 {
63 client.send("cxf:" + ((InboundEndpoint) client.getMuleContext().getRegistry()
64 .lookupObject("cxfExceptionStrategyInbound")).getAddress() + "?method=testCxfException", "TEST", null);
65 fail("Exception expected");
66 }
67 catch (MessagingException e)
68 {
69 Throwable t = e.getCause().getCause();
70 assertTrue(t instanceof CxfEnabledFaultMessage);
71 CustomFault fault = ((CxfEnabledFaultMessage) t).getFaultInfo();
72 assertNotNull(fault);
73 assertEquals("Custom Exception Message", fault.getDescription());
74 }
75 }
76
77 @Test
78 public void testUnhandledException() throws Exception
79 {
80 MuleClient client = new MuleClient(muleContext);
81 try
82 {
83 client.send("cxf:" + ((InboundEndpoint) client.getMuleContext().getRegistry()
84 .lookupObject("cxfExceptionStrategyInbound")).getAddress() + "?method=testNonCxfException", "TEST", null);
85 fail("Exception expected");
86 }
87 catch (MessagingException e)
88 {
89 assertTrue(e.getCause() instanceof Fault);
90 }
91 }
92
93 }