1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration.exceptions;
12
13 import org.mule.api.client.LocalMuleClient;
14 import org.mule.tck.junit4.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 @Override
66 protected void doTearDown() throws Exception
67 {
68 super.doTearDown();
69 latch = null;
70 }
71 }
72
73