View Javadoc

1   /*
2    * $Id: AbstractExceptionStrategyTestCase.java 19327 2010-09-03 13:09:47Z tcarlson $
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.test.integration.exceptions;
12  
13  import org.mule.api.client.LocalMuleClient;
14  import org.mule.tck.FunctionalTestCase;
15  import org.mule.tck.testmodels.mule.TestExceptionStrategy;
16  import org.mule.tck.testmodels.mule.TestExceptionStrategy.ExceptionCallback;
17  import org.mule.util.concurrent.Latch;
18  
19  import java.util.concurrent.atomic.AtomicInteger;
20  
21  public abstract class AbstractExceptionStrategyTestCase extends FunctionalTestCase
22  {
23      public static final int LATCH_AWAIT_TIMEOUT = 3000;
24      
25      protected final AtomicInteger systemExceptionCounter = new AtomicInteger();
26      protected final AtomicInteger serviceExceptionCounter = new AtomicInteger();
27      protected Latch latch;
28      protected LocalMuleClient client;
29  
30      @Override
31      protected void doSetUp() throws Exception
32      {
33          super.doSetUp();
34          if (client == null)
35          {
36              client = muleContext.getClient();
37          }
38          latch = new Latch();
39          systemExceptionCounter.set(0);
40          serviceExceptionCounter.set(0);
41  
42          TestExceptionStrategy systemExceptionListener = new TestExceptionStrategy();
43          systemExceptionListener.setExceptionCallback(new ExceptionCallback()
44          {
45              public void onException(Throwable t)
46              {
47                  systemExceptionCounter.incrementAndGet();
48                  latch.countDown();
49              }
50          });
51          muleContext.setExceptionListener(systemExceptionListener);
52  
53          TestExceptionStrategy serviceExceptionListener = 
54              (TestExceptionStrategy) muleContext.getRegistry().lookupModel("TestModel").getExceptionListener();
55          serviceExceptionListener.setExceptionCallback(new ExceptionCallback()
56          {
57              public void onException(Throwable t)
58              {
59                  serviceExceptionCounter.incrementAndGet();
60                  latch.countDown();
61              }
62          });
63  
64      }
65  
66      @Override
67      protected void doTearDown() throws Exception
68      {
69          super.doTearDown();
70          latch = null;
71      }
72  }
73  
74