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