1
2
3
4
5
6
7 package org.mule.module.cxf;
8
9 import static org.junit.Assert.assertEquals;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertNull;
12 import static org.junit.Assert.assertTrue;
13
14 import org.mule.DefaultMuleMessage;
15 import org.mule.api.MuleMessage;
16 import org.mule.module.client.MuleClient;
17 import org.mule.tck.junit4.FunctionalTestCase;
18 import org.mule.tck.junit4.rule.DynamicPort;
19 import org.mule.transport.http.HttpConnector;
20 import org.mule.transport.http.HttpConstants;
21
22 import java.util.Map;
23
24 import org.apache.cxf.interceptor.Fault;
25 import org.junit.Rule;
26 import org.junit.Test;
27
28
29 public class CxfErrorBehaviorTestCase extends FunctionalTestCase
30 {
31 private static final String requestFaultPayload =
32 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
33 " xmlns:hi=\"http://cxf.module.mule.org/\">\n" +
34 "<soap:Body>\n" +
35 "<hi:sayHi>\n" +
36 " <arg0></arg0>\n" +
37 "</hi:sayHi>\n" +
38 "</soap:Body>\n" +
39 "</soap:Envelope>";
40
41
42 @Rule
43 public DynamicPort dynamicPort = new DynamicPort("port1");
44
45 @Override
46 protected String getConfigResources()
47 {
48 return "cxf-error-behavior-conf.xml";
49 }
50
51 @Test
52 public void testFaultInCxfService() throws Exception
53 {
54 MuleMessage request = new DefaultMuleMessage(requestFaultPayload, (Map<String,Object>)null, muleContext);
55 MuleClient client = new MuleClient(muleContext);
56 MuleMessage response = client.send("http://localhost:" + dynamicPort.getNumber() + "/testServiceWithFault", request);
57 assertNotNull(response);
58 assertTrue(response.getPayloadAsString().contains("<faultstring>"));
59 assertEquals(String.valueOf(HttpConstants.SC_INTERNAL_SERVER_ERROR), response.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY));
60 }
61
62 @Test
63 public void testClientWithSOAPFault() throws Exception
64 {
65 MuleMessage request = new DefaultMuleMessage("hello", (Map<String,Object>)null, muleContext);
66 MuleClient client = new MuleClient(muleContext);
67 MuleMessage response = client.send("vm://testClientSOAPFault", request);
68 assertNotNull(response);
69 assertNotNull(response.getExceptionPayload());
70 assertTrue(response.getExceptionPayload().getException().getCause() instanceof Fault);
71 assertNull(response.getInboundProperty("http.status"));
72
73 }
74
75 @Test
76 public void testServerClientProxyWithFault() throws Exception
77 {
78 MuleClient client = new MuleClient(muleContext);
79 MuleMessage result = client.send("http://localhost:" + dynamicPort.getNumber() + "/testProxyWithFault", requestFaultPayload, null);
80 String resString = result.getPayloadAsString();
81 assertTrue(resString.contains("<faultstring>Cxf Exception Message</faultstring>"));
82 assertEquals(String.valueOf(HttpConstants.SC_INTERNAL_SERVER_ERROR), result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY));
83 }
84
85
86 }