View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   
8   package org.mule.module.cxf.functional;
9   
10  import org.mule.DefaultMuleMessage;
11  import org.mule.api.MessagingException;
12  import org.mule.api.MuleEvent;
13  import org.mule.api.MuleException;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.transformer.TransformerException;
16  import org.mule.message.ExceptionMessage;
17  import org.mule.module.client.MuleClient;
18  import org.mule.tck.junit4.FunctionalTestCase;
19  import org.mule.tck.junit4.rule.DynamicPort;
20  import org.mule.transformer.AbstractTransformer;
21  import org.mule.api.MessagingException;
22  
23  import java.util.Map;
24  
25  import org.junit.Rule;
26  import org.junit.Test;
27  
28  import static org.junit.Assert.assertNotNull;
29  import static org.junit.Assert.assertTrue;
30  
31  public class CxfClientExceptionStrategyTestCase extends FunctionalTestCase
32  {
33      @Rule
34      public DynamicPort dynamicPort = new DynamicPort("port1");
35  
36      @Override
37      protected String getConfigResources()
38      {
39          return "cxf-client-exception-strategy-flow.xml";
40      }
41  
42      @Test
43      public void testCxfClientExceptionStrategy() throws Exception
44      {
45          MuleMessage request = new DefaultMuleMessage("hello", (Map<String,Object>)null, muleContext);
46          MuleClient client = new MuleClient(muleContext);
47          client.dispatch("vm://helloClient", request);
48  
49          MuleMessage out = client.request("vm://out", org.mule.tck.FunctionalTestCase.RECEIVE_TIMEOUT);
50  
51          assertNotNull(out);
52          assertTrue(out.getPayload() instanceof ExceptionMessage);
53          assertTrue(((ExceptionMessage) out.getPayload()).getException() instanceof MessagingException);
54          assertTrue(((ExceptionMessage) out.getPayload()).getException().getMessage().contains("Error transforming message"));
55          }
56  
57      public static class ThrowExceptionTransformer extends AbstractTransformer
58      {
59          @Override
60          public MuleEvent process(MuleEvent event) throws MuleException
61          {
62              throw new MessagingException(event, new Throwable("Error transforming message"));
63          }
64  
65          @Override
66          protected Object doTransform(Object src, String enc) throws TransformerException
67          {
68              return src;
69          }
70      }
71  
72  }