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.test.integration.exceptions;
8   
9   import org.mule.api.lifecycle.LifecycleException;
10  import org.mule.tck.testmodels.mule.TestConnector;
11  
12  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  import static org.junit.Assert.fail;
17  
18  public class SystemExceptionStrategyTestCase extends AbstractExceptionStrategyTestCase
19  {
20      
21      @Override
22      protected String getConfigResources()
23      {
24          return "org/mule/test/integration/exceptions/system-exception-strategy.xml";
25      }
26  
27      @Test
28      public void testConnectorStartup() throws Exception
29      {
30          try
31          {
32              TestConnector c = (TestConnector) muleContext.getRegistry().lookupConnector("testConnector");
33              c.setInitialStateStopped(false);
34              c.start();
35              fail("Connector should have thrown an exception");
36          }
37          catch (LifecycleException e)
38          {
39              // expected
40          }
41          latch.await(1000, TimeUnit.MILLISECONDS); 
42          assertEquals(0, serviceExceptionCounter.get());
43          assertEquals(1, systemExceptionCounter.get());
44      }
45  
46      @Test
47      public void testConnectorPolling() throws Exception
48      {
49          muleContext.getRegistry().lookupService("Polling").start();
50          Thread.sleep(3000);
51          latch.await(1000, TimeUnit.MILLISECONDS); 
52          assertEquals(0, serviceExceptionCounter.get());
53          assertEquals(1, systemExceptionCounter.get());
54      }
55  }
56  
57