View Javadoc

1   /*
2    * $Id: CxfExceptionHandlingTestCase.java 22728 2011-08-24 15:51:41Z pablo.kraan $
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.api.MuleMessage;
15  import org.mule.api.endpoint.InboundEndpoint;
16  import org.mule.module.client.MuleClient;
17  import org.mule.module.cxf.testmodels.CxfEnabledFaultMessage;
18  import org.mule.tck.junit4.FunctionalTestCase;
19  import org.mule.tck.junit4.rule.DynamicPort;
20  
21  import org.junit.Ignore;
22  import org.junit.Rule;
23  import org.junit.Test;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNotNull;
27  import static org.junit.Assert.assertTrue;
28  import static org.junit.Assert.fail;
29  
30  public class CxfExceptionHandlingTestCase extends FunctionalTestCase
31  {
32      @Rule
33      public DynamicPort dynamicPort = new DynamicPort("port1");
34  
35      @Override
36      protected String getConfigResources()
37      {
38          return "onexception-conf.xml";
39      }
40  
41      @Test
42      public void testDefaultComponentExceptionStrategy() throws Exception
43      {
44          MuleClient client = new MuleClient(muleContext);
45          try
46          {
47              client.send("cxf:" + ((InboundEndpoint) client.getMuleContext().getRegistry()
48                              .lookupObject("cxfDefaultInbound")).getAddress() + "?method=testCxfException", "TEST", null);
49              fail("Exception expected");
50          }
51          catch (MessagingException e)
52          {
53              assertTrue(e.getCause().getCause() instanceof CxfEnabledFaultMessage);
54          }
55      }
56  
57      @Test
58      @Ignore("Test is timing out, was working on JUnit3 but that was a bug")
59      public void testMuleExceptionStrategyHandling() throws Exception
60      {
61          MuleClient client = new MuleClient(muleContext);
62          try
63          {
64              client.send("cxf:" + ((InboundEndpoint) client.getMuleContext().getRegistry()
65                              .lookupObject("cxfMuleESInbound")).getAddress() + "?method=testCxfException", "TEST", null);
66  //            fail("Exception expected");
67          }
68  //        catch (MessagingException e)
69  //        {
70  //            assertTrue(e.getCause().getCause() instanceof SoapFault);
71  //        }
72          finally
73          {
74              MuleMessage msg = client.request("vm://fromES", 10000);
75              assertNotNull(msg);
76              assertNotNull(msg.getPayload());
77              assertEquals("EXCEPTION STRATEGY INVOKED", msg.getPayloadAsString());
78              System.out.println(msg);
79          }
80      }
81  }