1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration.client;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import org.mule.api.ExceptionPayload;
18 import org.mule.api.MuleMessage;
19 import org.mule.api.endpoint.MalformedEndpointException;
20 import org.mule.api.transformer.TransformerMessagingException;
21 import org.mule.module.client.MuleClient;
22 import org.mule.module.client.RemoteDispatcher;
23 import org.mule.tck.AbstractServiceAndFlowTestCase;
24 import org.mule.tck.exceptions.FunctionalTestException;
25
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.Date;
29
30 import org.junit.Test;
31 import org.junit.runners.Parameterized.Parameters;
32
33 public class RemoteExceptionTestCase extends AbstractServiceAndFlowTestCase
34 {
35 @Parameters
36 public static Collection<Object[]> parameters()
37 {
38 return Arrays.asList(new Object[][]{
39 {ConfigVariant.SERVICE, "org/mule/test/integration/client/remote-exception-config-service.xml"},
40 {ConfigVariant.FLOW, "org/mule/test/integration/client/remote-exception-config-flow.xml"}
41 });
42 }
43
44 public RemoteExceptionTestCase(ConfigVariant variant, String configResources)
45 {
46 super(variant, configResources);
47 }
48
49 @Test
50 public void testClientTransformerException() throws Exception
51 {
52 MuleClient client = new MuleClient(muleContext);
53 RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:25551");
54 MuleMessage result = dispatcher.sendRemote("vm://test.queue.1", new Date(), null);
55 assertNotNull(result);
56 ExceptionPayload exceptionPayload = result.getExceptionPayload();
57 assertNotNull(exceptionPayload);
58 assertTrue(exceptionPayload.getException() instanceof TransformerMessagingException);
59 assertTrue(exceptionPayload.getRootException() instanceof Exception);
60 }
61
62 @Test
63 public void testClientMalformedEndpointException() throws Exception
64 {
65 MuleClient client = new MuleClient(muleContext);
66 RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:25551");
67 MuleMessage result = dispatcher.sendRemote("test.queue.2", new Date(), null);
68 assertNotNull(result);
69 ExceptionPayload exceptionPayload = result.getExceptionPayload();
70 assertNotNull(exceptionPayload);
71 assertTrue(exceptionPayload.getRootException() instanceof MalformedEndpointException);
72 }
73
74 @Test
75 public void testClientComponentException() throws Exception
76 {
77 MuleClient client = new MuleClient(muleContext);
78 RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:25551");
79 MuleMessage result = dispatcher.sendRemote("vm://test.queue.2", new Date(), null);
80 assertNotNull(result);
81 ExceptionPayload exceptionPayload = result.getExceptionPayload();
82 assertNotNull(exceptionPayload);
83 assertTrue(exceptionPayload.getRootException().getClass().getName(),
84 exceptionPayload.getRootException() instanceof FunctionalTestException);
85 assertEquals("Functional Test Service Exception", exceptionPayload.getRootException().getMessage());
86 }
87 }