View Javadoc

1   /*
2    * $Id: ExceptionBasedRouterTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.FunctionalTestCase;
16  
17  import java.util.ArrayList;
18  import java.util.HashMap;
19  import java.util.List;
20  import java.util.Map;
21  
22  public class ExceptionBasedRouterTestCase extends FunctionalTestCase
23  {
24      @Override
25      protected String getConfigResources()
26      {
27          return "org/mule/test/integration/routing/outbound/exception-based-router.xml";
28      }
29  
30      public void testStaticEndpointsByName() throws Exception
31      {
32          MuleClient client = new MuleClient(muleContext);
33          
34          MuleMessage reply = client.send("vm://in1", "request", null);
35          assertNotNull(reply);
36          assertEquals("success", reply.getPayload());
37      }
38  
39      public void testStaticEndpointsByURI() throws Exception
40      {
41          MuleClient client = new MuleClient(muleContext);
42          
43          MuleMessage reply = client.send("vm://in2", "request", null);
44          assertNotNull(reply);
45          assertEquals("success", reply.getPayload());
46      }
47  
48      public void testDynamicEndpointsByName() throws Exception
49      {
50          MuleClient client = new MuleClient(muleContext);
51          
52          Map<String, Object> props = new HashMap<String, Object>();
53          props.put("recipients", "service1,service2,service3");
54          MuleMessage reply = client.send("vm://in3", "request", props);
55          assertNotNull(reply);
56          assertEquals("success", reply.getPayload());
57      }
58  
59      public void testDynamicEndpointsByURI() throws Exception
60      {
61          MuleClient client = new MuleClient(muleContext);
62          
63          Map<String, Object> props = new HashMap<String, Object>();
64          List<String> recipients = new ArrayList<String>();
65          recipients.add("vm://service4?responseTransformers=validateResponse&exchangePattern=request-response");
66          recipients.add("vm://service5?responseTransformers=validateResponse&exchangePattern=request-response");
67          recipients.add("vm://service6?responseTransformers=validateResponse&exchangePattern=request-response");
68          props.put("recipients", recipients);
69          MuleMessage reply = client.send("vm://in3", "request", props);
70          assertNotNull(reply);
71          assertEquals("success", reply.getPayload());
72      }
73  
74      /**
75       * Test endpoints which generate a natural exception because they don't even exist.
76       */
77      public void testIllegalEndpoint() 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://service998?exchangePattern=request-response");
84          recipients.add("vm://service5?exchangePattern=request-response");
85          recipients.add("vm://service999");
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