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