1
2
3
4
5
6
7 package org.mule.context.notification;
8
9 import org.mule.api.client.LocalMuleClient;
10 import org.mule.api.context.notification.ExceptionNotificationListener;
11 import org.mule.api.context.notification.ServerNotification;
12 import org.mule.tck.junit4.FunctionalTestCase;
13 import org.mule.tck.probe.PollingProber;
14 import org.mule.tck.probe.Probe;
15 import org.mule.tck.probe.Prober;
16
17 import org.junit.Test;
18
19 public class FailingNotificationListenerTestCase extends FunctionalTestCase
20 {
21
22 private static int count = 0;
23 private static final Object lock = new Object();
24
25 @Override
26 protected String getConfigResources()
27 {
28 return "org/mule/test/integration/notifications/failing-notification-listener-config.xml";
29 }
30
31 @Test
32 public void testName() throws Exception
33 {
34 LocalMuleClient client = muleContext.getClient();
35 client.dispatch("vm://testInput", TEST_MESSAGE, null);
36 client.dispatch("vm://testInput", TEST_MESSAGE, null);
37
38 Prober prober = new PollingProber(1000, 10);
39 prober.check(new Probe()
40 {
41 public boolean isSatisfied()
42 {
43 return count == 2;
44 }
45
46 public String describeFailure()
47 {
48 return "Expected to received 2 notifications but received " + count;
49 }
50 });
51 }
52
53 public static class ExceptionFailingListener implements ExceptionNotificationListener
54 {
55
56 public void onNotification(ServerNotification notification)
57 {
58 synchronized (lock)
59 {
60 count = count + 1;
61 }
62
63 throw new IllegalStateException();
64 }
65
66 }
67 }