1   /*
2    * $Id: RemoteExceptionTestCase.java 10789 2008-02-12 20:04:43Z dfeist $
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.test.integration.client;
12  
13  import org.mule.api.ExceptionPayload;
14  import org.mule.api.DefaultMuleException;
15  import org.mule.api.MuleMessage;
16  import org.mule.api.endpoint.MalformedEndpointException;
17  import org.mule.api.transformer.TransformerException;
18  import org.mule.module.client.MuleClient;
19  import org.mule.module.client.RemoteDispatcher;
20  import org.mule.tck.FunctionalTestCase;
21  
22  import java.util.Date;
23  
24  public class RemoteExceptionTestCase extends FunctionalTestCase
25  {
26  
27      protected String getConfigResources()
28      {
29          return "org/mule/test/integration/client/remote-exception-config.xml";
30      }
31  
32      public void testClientTransformerException() throws Exception
33      {
34          MuleClient client = new MuleClient();
35          RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:5555");
36          MuleMessage result = dispatcher.sendRemote("vm://test.queue.1", new Date(), null);
37          assertNotNull(result);
38          ExceptionPayload exceptionPayload = result.getExceptionPayload();
39          assertNotNull(exceptionPayload);
40          assertTrue(exceptionPayload.getException().getCause() instanceof TransformerException);
41          assertTrue(exceptionPayload.getRootException() instanceof Exception);
42      }
43  
44      public void testClientMalformedEndpointException() throws Exception
45      {
46          MuleClient client = new MuleClient();
47          RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:5555");
48          MuleMessage result = dispatcher.sendRemote("test.queue.2", new Date(), null);
49          assertNotNull(result);
50          ExceptionPayload exceptionPayload = result.getExceptionPayload();
51          assertNotNull(exceptionPayload);
52          assertTrue(exceptionPayload.getRootException() instanceof MalformedEndpointException);
53      }
54  
55      public void testClientComponentException() throws Exception
56      {
57          MuleClient client = new MuleClient();
58          RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:5555");
59          MuleMessage result = dispatcher.sendRemote("vm://test.queue.2", new Date(), null);
60          assertNotNull(result);
61          ExceptionPayload exceptionPayload = result.getExceptionPayload();
62          assertNotNull(exceptionPayload);
63          assertTrue(exceptionPayload.getRootException() instanceof DefaultMuleException);
64          assertEquals("Functional Test Service Exception", exceptionPayload.getRootException().getMessage());
65      }
66  
67  }