View Javadoc

1   /*
2    * $Id: ExceptionBasedRouterTestCase.java 22422 2011-07-15 08:22:16Z dirk.olmes $
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.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.AbstractServiceAndFlowTestCase;
16  
17  import java.util.ArrayList;
18  import java.util.Arrays;
19  import java.util.Collection;
20  import java.util.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.junit.Test;
25  import org.junit.runners.Parameterized.Parameters;
26  
27  import static org.junit.Assert.assertEquals;
28  import static org.junit.Assert.assertNotNull;
29  
30  public class ExceptionBasedRouterTestCase extends AbstractServiceAndFlowTestCase
31  {
32      @Parameters
33      public static Collection<Object[]> parameters()
34      {
35          return Arrays.asList(new Object[][]{{ConfigVariant.SERVICE,
36              "org/mule/test/integration/routing/outbound/exception-based-router-service.xml"},});
37      }
38  
39      public ExceptionBasedRouterTestCase(ConfigVariant variant, String configResources)
40      {
41          super(variant, configResources);
42      }
43  
44      @Test
45      public void testStaticEndpointsByName() throws Exception
46      {
47          MuleClient client = new MuleClient(muleContext);
48  
49          MuleMessage reply = client.send("vm://in1", "request", null);
50          assertNotNull(reply);
51          assertEquals("success", reply.getPayload());
52      }
53  
54      @Test
55      public void testStaticEndpointsByURI() throws Exception
56      {
57          MuleClient client = new MuleClient(muleContext);
58  
59          MuleMessage reply = client.send("vm://in2", "request", null);
60          assertNotNull(reply);
61          assertEquals("success", reply.getPayload());
62      }
63  
64      @Test
65      public void testDynamicEndpointsByName() throws Exception
66      {
67          MuleClient client = new MuleClient(muleContext);
68  
69          Map<String, Object> props = new HashMap<String, Object>();
70          props.put("recipients", "service1,service2,service3");
71          MuleMessage reply = client.send("vm://in3", "request", props);
72          assertNotNull(reply);
73          assertEquals("success", reply.getPayload());
74      }
75  
76      @Test
77      public void testDynamicEndpointsByURI() throws Exception
78      {
79          MuleClient client = new MuleClient(muleContext);
80  
81          Map<String, Object> props = new HashMap<String, Object>();
82          List<String> recipients = new ArrayList<String>();
83          recipients.add("vm://service4?responseTransformers=validateResponse&exchangePattern=request-response");
84          recipients.add("vm://service5?responseTransformers=validateResponse&exchangePattern=request-response");
85          recipients.add("vm://service6?responseTransformers=validateResponse&exchangePattern=request-response");
86          props.put("recipients", recipients);
87          MuleMessage reply = client.send("vm://in3", "request", props);
88          assertNotNull(reply);
89          assertEquals("success", reply.getPayload());
90      }
91  
92      /**
93       * Test endpoints which generate a natural exception because they don't even
94       * exist.
95       */
96      @Test
97      public void testIllegalEndpoint() throws Exception
98      {
99          MuleClient client = new MuleClient(muleContext);
100 
101         Map<String, Object> props = new HashMap<String, Object>();
102         List<String> recipients = new ArrayList<String>();
103         recipients.add("vm://service998?exchangePattern=request-response");
104         recipients.add("vm://service5?exchangePattern=request-response");
105         recipients.add("vm://service999");
106         props.put("recipients", recipients);
107         MuleMessage reply = client.send("vm://in3", "request", props);
108         assertNotNull(reply);
109         assertEquals("success", reply.getPayload());
110     }
111 }