1   /*
2    * $Id: CxfComponentExceptionStrategyTestCase.java 11646 2008-04-25 20:28:53Z dandiep $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.transport.cxf;
12  
13  import org.mule.api.transport.DispatchException;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.transport.cxf.testmodels.CustomFault;
17  import org.mule.transport.cxf.testmodels.CxfEnabledFaultMessage;
18  
19  import org.apache.cxf.interceptor.Fault;
20  
21  public class CxfComponentExceptionStrategyTestCase extends FunctionalTestCase
22  {
23      public void testDefaultComponentExceptionStrategy() throws Exception
24      {
25          MuleClient client = new MuleClient();
26  
27          try
28          {
29              client.send("cxf:http://localhost:63181/services/CxfDefault?method=testXFireException", "TEST",
30                  null);
31          }
32          catch (DispatchException ex)
33          {
34              final Throwable t = ex.getCause();
35              assertNotNull("Cause should've been filled in.", t);
36              assertTrue(t instanceof CxfEnabledFaultMessage);
37          }
38      }
39  
40      /**
41       * This doesn't work because of a bug in the CXF client code :-(
42       * 
43       * @throws Exception
44       */
45      public void xtestHandledException() throws Exception
46      {
47          MuleClient client = new MuleClient();
48  
49          try
50          {
51              client.send(
52                  "cxf:http://localhost:63181/services/CxfWithExceptionStrategy?method=testXFireException",
53                  "TEST", null);
54          }
55          catch (DispatchException ex)
56          {
57              final Throwable t = ex.getCause();
58              t.printStackTrace();
59              assertNotNull("Cause should've been filled in.", t);
60              assertTrue(t instanceof CxfEnabledFaultMessage);
61              CxfEnabledFaultMessage cxfMsg = (CxfEnabledFaultMessage) t;
62              CustomFault fault = cxfMsg.getFaultInfo();
63              assertNotNull(fault);
64              assertEquals("Custom Exception Message", fault.getDescription());
65          }
66      }
67  
68      public void testUnhandledException() throws Exception
69      {
70          MuleClient client = new MuleClient();
71  
72          try
73          {
74              client.send(
75                  "cxf:http://localhost:63181/services/CxfWithExceptionStrategy?method=testNonXFireException",
76                  "TEST", null);
77          }
78          catch (DispatchException ex)
79          {
80              final Throwable t = ex.getCause();
81              assertNotNull("Cause should've been filled in.", t);
82              assertTrue(t instanceof Fault);
83              t.printStackTrace();
84          }
85      }
86  
87      protected String getConfigResources()
88      {
89          return "exception-strategy-conf.xml";
90      }
91  }