View Javadoc

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