View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule;
8   
9   import org.mule.api.endpoint.OutboundEndpoint;
10  import org.mule.api.processor.MessageProcessor;
11  import org.mule.exception.AbstractExceptionListener;
12  import org.mule.exception.DefaultServiceExceptionStrategy;
13  import org.mule.tck.junit4.AbstractMuleContextTestCase;
14  
15  import java.util.ArrayList;
16  import java.util.List;
17  
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertTrue;
23  
24  public class ExceptionListenerTestCase extends AbstractMuleContextTestCase
25  {
26      @Test
27      public void testAddGoodEndpoint() throws Exception
28      {
29          AbstractExceptionListener router = new DefaultServiceExceptionStrategy(muleContext);
30          OutboundEndpoint endpoint = getTestOutboundEndpoint("test");
31          router.addEndpoint(endpoint);
32          assertNotNull(router.getMessageProcessors());
33          assertTrue(router.getMessageProcessors().contains(endpoint));
34      }
35  
36      @Test
37      public void testSetGoodEndpoints() throws Exception
38      {
39          List<MessageProcessor> list = new ArrayList<MessageProcessor>();
40          list.add(getTestOutboundEndpoint("test"));
41          list.add(getTestOutboundEndpoint("test"));
42          
43          AbstractExceptionListener router = new DefaultServiceExceptionStrategy(muleContext);
44          assertNotNull(router.getMessageProcessors());
45          assertEquals(0, router.getMessageProcessors().size());
46          
47          router.addEndpoint(getTestOutboundEndpoint("test"));
48          assertEquals(1, router.getMessageProcessors().size());
49          
50          router.setMessageProcessors(list);
51          assertNotNull(router.getMessageProcessors());
52          assertEquals(2, router.getMessageProcessors().size());
53      }
54  }