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