1
2
3
4
5
6
7 package org.mule.test.routing;
8
9 import org.mule.api.ExceptionPayload;
10 import org.mule.api.MessagingException;
11 import org.mule.api.MuleMessage;
12 import org.mule.api.client.MuleClient;
13 import org.mule.tck.junit4.FunctionalTestCase;
14
15 import org.junit.Test;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21 public class FirstSuccessfulTestCase extends FunctionalTestCase
22 {
23
24 @Override
25 protected String getConfigResources()
26 {
27 return "first-successful-test.xml";
28 }
29
30 @Test
31 public void testFirstSuccessful() throws Exception
32 {
33 MuleClient client = muleContext.getClient();
34 MuleMessage response = client.send("vm://input", "XYZ", null);
35 assertEquals("XYZ is a string", response.getPayloadAsString());
36
37 response = client.send("vm://input", Integer.valueOf(9), null);
38 assertEquals("9 is an integer", response.getPayloadAsString());
39
40 response = client.send("vm://input", Long.valueOf(42), null);
41 assertEquals("42 is a number", response.getPayloadAsString());
42
43 response = client.send("vm://input", Boolean.TRUE, null);
44 ExceptionPayload ep = response.getExceptionPayload();
45 assertNotNull(ep);
46 Throwable ex = ep.getException();
47 assertTrue(ex instanceof MessagingException);
48 }
49
50 @Test
51 public void testFirstSuccessfulWithExpression() throws Exception
52 {
53 MuleClient client = muleContext.getClient();
54 MuleMessage response = client.send("vm://input2", "XYZ", null);
55 assertEquals("XYZ is a string", response.getPayloadAsString());
56 }
57
58 @Test
59 public void testFirstSuccessfulWithExpressionAllFail() throws Exception
60 {
61 MuleClient client = muleContext.getClient();
62 MuleMessage response = client.send("vm://input3", "XYZ", null);
63 ExceptionPayload ep = response.getExceptionPayload();
64 assertNotNull(ep);
65 Throwable ex = ep.getException();
66 assertTrue(ex instanceof MessagingException);
67 }
68
69 @Test
70 public void testFirstSuccessfulWithOneWayEndpoints() throws Exception
71 {
72 MuleClient client = muleContext.getClient();
73 client.dispatch("vm://input4.in", TEST_MESSAGE, null);
74
75 MuleMessage response = client.request("vm://output4.out", RECEIVE_TIMEOUT);
76 assertNotNull(response);
77 assertEquals(TEST_MESSAGE, response.getPayload());
78 }
79 }