View Javadoc

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