View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.routing.outbound;
8   
9   import static org.junit.Assert.assertNotNull;
10  import static org.junit.Assert.assertNull;
11  import static org.junit.Assert.assertTrue;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.routing.RoutingException;
15  import org.mule.message.ExceptionMessage;
16  import org.mule.module.client.MuleClient;
17  import org.mule.tck.junit4.FunctionalTestCase;
18  
19  import java.io.ByteArrayInputStream;
20  
21  import org.junit.Test;
22  
23  public class MulticastRouterTestCase extends FunctionalTestCase
24  {
25      @Override
26      protected String getConfigResources()
27      {
28          return "org/mule/test/integration/routing/outbound/multicasting-router-config.xml";
29      }
30  
31      @Test
32      public void testAll() throws Exception
33      {
34          ByteArrayInputStream bis = new ByteArrayInputStream("Hello, world".getBytes("UTF-8"));
35          MuleClient client = new MuleClient(muleContext);
36          client.dispatch("vm://inbound1", bis, null);
37  
38          MuleMessage response = client.request("vm://output1", 2000);
39          assertNull(response);
40  
41          MuleMessage error = client.request("vm://errors", 2000);
42          assertRoutingExceptionReceived(error);
43      }
44  
45      @Test
46      public void testFirstSuccessful() throws Exception
47      {
48          ByteArrayInputStream bis = new ByteArrayInputStream("Hello, world".getBytes("UTF-8"));
49          MuleClient client = new MuleClient(muleContext);
50          client.dispatch("vm://inbound2", bis, null);
51  
52          MuleMessage response = client.request("vm://output4", 2000);
53          assertNull(response);
54  
55          MuleMessage error = client.request("vm://errors2", 2000);
56          assertRoutingExceptionReceived(error);
57      }
58  
59      /**
60       * Asserts that a {@link RoutingException} has been received.
61       *
62       * @param message The received message.
63       */
64      private void assertRoutingExceptionReceived(MuleMessage message)
65      {
66          assertNotNull(message);
67          Object payload = message.getPayload();
68          assertNotNull(payload);
69          assertTrue(payload instanceof ExceptionMessage);
70          ExceptionMessage exceptionMessage = (ExceptionMessage) payload;
71          assertTrue(exceptionMessage.getException() instanceof RoutingException);
72      }
73  }