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   package org.mule.test.integration.client;
8   
9   import org.mule.api.ExceptionPayload;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.endpoint.MalformedEndpointException;
12  import org.mule.api.transformer.TransformerMessagingException;
13  import org.mule.module.client.MuleClient;
14  import org.mule.module.client.RemoteDispatcher;
15  import org.mule.tck.exceptions.FunctionalTestException;
16  import org.mule.tck.junit4.FunctionalTestCase;
17  
18  import java.util.Date;
19  
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertTrue;
25  
26  public class RemoteExceptionTestCase extends FunctionalTestCase
27  {
28  
29      @Override
30      protected String getConfigResources()
31      {
32          return "org/mule/test/integration/client/remote-exception-config.xml";
33      }
34  
35      @Test
36      public void testClientTransformerException() throws Exception
37      {
38          MuleClient client = new MuleClient(muleContext);
39          RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:25551");
40          MuleMessage result = dispatcher.sendRemote("vm://test.queue.1", new Date(), null);
41          assertNotNull(result);
42          ExceptionPayload exceptionPayload = result.getExceptionPayload();
43          assertNotNull(exceptionPayload);
44          assertTrue(exceptionPayload.getException() instanceof TransformerMessagingException);
45          assertTrue(exceptionPayload.getRootException() instanceof Exception);
46      }
47  
48      @Test
49      public void testClientMalformedEndpointException() throws Exception
50      {
51          MuleClient client = new MuleClient(muleContext);
52          RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:25551");
53          MuleMessage result = dispatcher.sendRemote("test.queue.2", new Date(), null);
54          assertNotNull(result);
55          ExceptionPayload exceptionPayload = result.getExceptionPayload();
56          assertNotNull(exceptionPayload);
57          assertTrue(exceptionPayload.getRootException() instanceof MalformedEndpointException);
58      }
59  
60      @Test
61      public void testClientComponentException() throws Exception
62      {
63          MuleClient client = new MuleClient(muleContext);
64          RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:25551");
65          MuleMessage result = dispatcher.sendRemote("vm://test.queue.2", new Date(), null);
66          assertNotNull(result);
67          ExceptionPayload exceptionPayload = result.getExceptionPayload();
68          assertNotNull(exceptionPayload);
69          assertTrue(exceptionPayload.getRootException().getClass().getName(), 
70                     exceptionPayload.getRootException() instanceof FunctionalTestException);
71          assertEquals("Functional Test Service Exception", exceptionPayload.getRootException().getMessage());
72      }
73  
74  }