View Javadoc

1   /*
2    * $Id$
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.routing.outbound;
12  
13  import org.mule.api.MuleException;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.routing.RoutePathNotFoundException;
16  import org.mule.module.client.MuleClient;
17  import org.mule.tck.FunctionalTestCase;
18  
19  public class ChoiceRouterTestCase extends FunctionalTestCase
20  {
21      private static final String WITH_DEFAULT_ROUTE_CHANNEL = "vm://with-default-route.in";
22      private static final String WITHOUT_DEFAULT_ROUTE_CHANNEL = "vm://without-default-route.in";
23  
24      private MuleClient muleClient;
25  
26      @Override
27      protected void doSetUp() throws Exception
28      {
29          super.setDisposeManagerPerSuite(true);
30          super.doSetUp();
31          muleClient = new MuleClient(muleContext);
32      }
33  
34      @Override
35      protected String getConfigResources()
36      {
37          return "org/mule/test/integration/routing/outbound/choice-router-test.xml";
38      }
39  
40      public void testNoRouteFound() throws Exception
41      {
42          final MuleMessage result = muleClient.send(WITHOUT_DEFAULT_ROUTE_CHANNEL, "bad", null);
43          assertNotNull(result);
44          assertNotNull("should have got a MuleException", result.getExceptionPayload());
45          assertNotNull(result.getExceptionPayload().getException() instanceof MuleException);
46          assertNotNull(result.getExceptionPayload().getRootException() instanceof RoutePathNotFoundException);
47      }
48  
49      public void testRoutesFound() throws Exception
50      {
51          String result = muleClient.send(WITHOUT_DEFAULT_ROUTE_CHANNEL, "apple", null).getPayloadAsString();
52          assertEquals("apple:fruit:fruit", result);
53  
54          result = muleClient.send(WITH_DEFAULT_ROUTE_CHANNEL, "apple", null).getPayloadAsString();
55          assertEquals("apple:fruit:fruit", result);
56  
57          result = muleClient.send(WITH_DEFAULT_ROUTE_CHANNEL, "turnip", null).getPayloadAsString();
58          assertEquals("turnip:veggie:veggie", result);
59      }
60  
61      public void testWhenExpressionRouteFound() throws Exception
62      {
63          final String result = muleClient.send(WITH_DEFAULT_ROUTE_CHANNEL, "blueberry", null)
64              .getPayloadAsString();
65          assertEquals("blueberry:fruit:fruit", result);
66      }
67  
68      public void testDefaultRoute() throws Exception
69      {
70          final String result = muleClient.send(WITH_DEFAULT_ROUTE_CHANNEL, "car", null).getPayloadAsString();
71          assertEquals("car:default:default", result);
72      }
73  }