1
2
3
4
5
6
7 package org.mule.test.integration.exceptions;
8
9 import org.mule.api.client.LocalMuleClient;
10 import org.mule.tck.junit4.FunctionalTestCase;
11 import org.mule.tck.testmodels.mule.TestExceptionStrategy;
12 import org.mule.tck.testmodels.mule.TestExceptionStrategy.ExceptionCallback;
13 import org.mule.util.concurrent.Latch;
14
15 import java.util.concurrent.atomic.AtomicInteger;
16
17 public abstract class AbstractExceptionStrategyTestCase extends FunctionalTestCase
18 {
19 public static final int LATCH_AWAIT_TIMEOUT = 3000;
20
21 protected final AtomicInteger systemExceptionCounter = new AtomicInteger();
22 protected final AtomicInteger serviceExceptionCounter = new AtomicInteger();
23 protected Latch latch;
24 protected LocalMuleClient client;
25
26 @Override
27 protected void doSetUp() throws Exception
28 {
29 super.doSetUp();
30 if (client == null)
31 {
32 client = muleContext.getClient();
33 }
34 latch = new Latch();
35 systemExceptionCounter.set(0);
36 serviceExceptionCounter.set(0);
37
38 TestExceptionStrategy systemExceptionListener = new TestExceptionStrategy();
39 systemExceptionListener.setExceptionCallback(new ExceptionCallback()
40 {
41 public void onException(Throwable t)
42 {
43 systemExceptionCounter.incrementAndGet();
44 latch.countDown();
45 }
46 });
47 muleContext.setExceptionListener(systemExceptionListener);
48
49 TestExceptionStrategy serviceExceptionListener =
50 (TestExceptionStrategy) muleContext.getRegistry().lookupModel("TestModel").getExceptionListener();
51 serviceExceptionListener.setExceptionCallback(new ExceptionCallback()
52 {
53 public void onException(Throwable t)
54 {
55 serviceExceptionCounter.incrementAndGet();
56 latch.countDown();
57 }
58 });
59 }
60
61 @Override
62 protected void doTearDown() throws Exception
63 {
64 super.doTearDown();
65 latch = null;
66 }
67 }
68
69