View Javadoc

1   /*
2    * $Id: OutboundRouterTestCase.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.routing.outbound;
12  
13  import org.mule.api.endpoint.OutboundEndpoint;
14  import org.mule.tck.AbstractMuleTestCase;
15  
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  public class OutboundRouterTestCase extends AbstractMuleTestCase
20  {
21  
22      public void testAddGoodEndpoint() throws Exception
23      {
24          AbstractOutboundRouter router=new TransformerRouter();
25          OutboundEndpoint endpoint=getTestOutboundEndpoint("test");
26          router.addRoute(endpoint);
27          assertNotNull(router.getRoutes());
28          assertTrue(router.getRoutes().contains(endpoint));
29      }
30  
31  //    public void testAddBadEndpoint2()
32  //    {
33  //        AbstractOutboundRouter router=new TransformerRouter();
34  //        try{
35  //            router.addEndpoint(new InboundEndpoint());
36  //            fail("Invalid endpoint: Exception exceptions");
37  //        }
38  //        catch(Exception e){
39  //            assertEquals(InvalidEndpointTypeException.class, e.getClass());
40  //        }
41  //    }
42  
43      public void testSetGoodEndpoints() throws Exception
44      {
45          List list= new ArrayList();
46          list.add(getTestOutboundEndpoint("test"));
47          list.add(getTestOutboundEndpoint("test"));
48          AbstractOutboundRouter router=new TransformerRouter();
49          assertNotNull(router.getRoutes());
50          assertEquals(0, router.getRoutes().size());
51          router.addRoute(getTestOutboundEndpoint("test"));
52          assertEquals(1, router.getRoutes().size());
53          router.setRoutes(list);
54          assertNotNull(router.getRoutes());
55          assertEquals(2, router.getRoutes().size());
56      }
57  
58      public void testSetBadEndpoints() throws Exception
59      {
60          List list= new ArrayList();
61          list.add(getTestInboundEndpoint("test"));
62          list.add(getTestOutboundEndpoint("test"));
63          AbstractOutboundRouter router=new TransformerRouter();
64          try{
65              router.setRoutes(list);
66              fail("Invalid endpoint: Expecting an exception");
67          }
68          catch(Exception e){
69              assertEquals(ClassCastException.class, e.getClass());
70          }
71      }
72      
73      public void testSetBad2Endpoints() throws Exception
74      {
75          List list= new ArrayList();
76          list.add(getTestOutboundEndpoint("test"));
77          list.add(getTestInboundEndpoint("test"));
78          AbstractOutboundRouter router=new TransformerRouter();
79          try{
80              router.setRoutes(list);
81              fail("Invalid endpoint: Expecting an exception");
82          }
83          catch(Exception e){
84              assertEquals(ClassCastException.class, e.getClass());
85          }
86      }
87  
88  }
89  
90