View Javadoc

1   /*
2    * $Id: CxfComponentExceptionStrategyTestCase.java 19327 2010-09-03 13:09:47Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.cxf;
12  
13  import org.mule.api.MessagingException;
14  import org.mule.module.client.MuleClient;
15  import org.mule.module.cxf.testmodels.CustomFault;
16  import org.mule.module.cxf.testmodels.CxfEnabledFaultMessage;
17  import org.mule.tck.FunctionalTestCase;
18  
19  import org.apache.cxf.binding.soap.SoapFault;
20  import org.apache.cxf.interceptor.Fault;
21  
22  public class CxfComponentExceptionStrategyTestCase extends FunctionalTestCase
23  {
24      public void testDefaultComponentExceptionStrategy() throws Exception
25      {
26          MuleClient client = new MuleClient(muleContext);
27          try
28          {
29              client.send("cxf:http://localhost:63181/services/CxfDefault?method=testCxfException", "TEST", null);
30              fail("Exception expected");
31          }
32          catch (MessagingException e)
33          {
34              assertTrue(e.getCause().getCause() instanceof SoapFault);
35          }
36      }
37  
38      /**
39       * This doesn't work because of a bug in the CXF client code :-(
40       * 
41       * @throws Exception
42       */
43      public void xtestHandledException() throws Exception
44      {
45          MuleClient client = new MuleClient(muleContext);
46  
47          try
48          {
49              client.send("cxf:http://localhost:63181/services/CxfWithExceptionStrategy?method=testCxfException", "TEST", null);
50              fail("Exception expected");
51          }
52          catch (MessagingException e)
53          {
54              Throwable t = e.getCause().getCause();
55              assertTrue(t instanceof CxfEnabledFaultMessage);
56              CustomFault fault = ((CxfEnabledFaultMessage) t).getFaultInfo();
57              assertNotNull(fault);
58              assertEquals("Custom Exception Message", fault.getDescription());
59          }
60      }
61  
62      public void testUnhandledException() throws Exception
63      {
64          MuleClient client = new MuleClient(muleContext);
65          try
66          {
67              client.send("cxf:http://localhost:63181/services/CxfWithExceptionStrategy?method=testNonCxfException", "TEST", null);
68              fail("Exception expected");
69          }
70          catch (MessagingException e)
71          {
72              assertTrue(e.getCause().getCause() instanceof Fault);
73          }
74      }
75  
76      protected String getConfigResources()
77      {
78          return "exception-strategy-conf.xml";
79      }
80  }