1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.email;
12
13 import org.mule.MuleManager;
14 import org.mule.config.builders.QuickConfigurationBuilder;
15 import org.mule.tck.functional.EventCallback;
16 import org.mule.tck.functional.FunctionalTestComponent;
17 import org.mule.umo.UMOEventContext;
18
19 import java.util.HashMap;
20
21 import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
22 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
23
24
25
26
27
28
29 public abstract class AbstractReceivingMailConnectorTestCase extends AbstractMailConnectorFunctionalTestCase
30 {
31
32 public static final int POLL_PERIOD_MS = 1000;
33 public static final int WAIT_PERIOD_MS = 3 * POLL_PERIOD_MS;
34
35 protected AbstractReceivingMailConnectorTestCase(String connectorName)
36 {
37 super(true, connectorName);
38 }
39
40 public void testReceiver() throws Exception
41 {
42 repeatTest("doTestReceiver");
43 }
44
45 public void doTestReceiver() throws Exception
46 {
47 final CountDownLatch countDown = new CountDownLatch(1);
48
49 HashMap props = new HashMap();
50 props.put("eventCallback", new EventCallback()
51 {
52 public synchronized void eventReceived(UMOEventContext context, Object component)
53 {
54 try
55 {
56 logger.debug("woot - event received");
57 logger.debug("context: " + context);
58 logger.debug("component: " + component);
59 assertMessageOk(context.getMessage().getPayload());
60 countDown.countDown();
61 }
62 catch (Exception e)
63 {
64
65 logger.error(e.getMessage(), e);
66 }
67 }
68 });
69
70 QuickConfigurationBuilder builder = new QuickConfigurationBuilder();
71 builder.getManager().registerConnector(getConnector(false));
72 builder.registerComponent(
73 FunctionalTestComponent.class.getName(), "testComponent", getTestEndpointURI(), null, props);
74
75 logger.debug("starting mule");
76 MuleManager.getInstance().start();
77
78 logger.debug("waiting for count down");
79 assertTrue(countDown.await(WAIT_PERIOD_MS, TimeUnit.MILLISECONDS));
80 }
81
82 }