1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.email.connectors;
12
13 import org.mule.api.MuleEventContext;
14 import org.mule.api.config.MuleProperties;
15 import org.mule.api.endpoint.InboundEndpoint;
16 import org.mule.api.routing.InboundRouterCollection;
17 import org.mule.api.service.Service;
18 import org.mule.routing.inbound.DefaultInboundRouterCollection;
19 import org.mule.tck.MuleTestUtils;
20 import org.mule.tck.functional.EventCallback;
21 import org.mule.tck.functional.FunctionalTestComponent;
22 import org.mule.transport.email.transformers.EmailMessageToString;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
28 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
29
30
31
32
33
34
35 public abstract class AbstractReceivingMailConnectorTestCase extends AbstractMailConnectorFunctionalTestCase
36 {
37 public static final int POLL_PERIOD_MS = 2000;
38 public static final int WAIT_PERIOD_MS = 4 * POLL_PERIOD_MS;
39
40 protected AbstractReceivingMailConnectorTestCase(String protocol, int port)
41 {
42 super(SEND_INITIAL_EMAIL, protocol, port);
43 }
44
45 public void testReceiver() 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(MuleEventContext 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().getOrginalPayload());
60 countDown.countDown();
61 }
62 catch (Exception e)
63 {
64
65 logger.error(e.getMessage(), e);
66 }
67 }
68 });
69
70 Service service = MuleTestUtils.getTestService(uniqueName("testComponent"), FunctionalTestComponent.class, props, muleContext,
71 InboundEndpoint ep =
72 muleContext.getRegistry().lookupEndpointFactory()
73 .getInboundEndpoint(getTestEndpointURI());
74 InboundRouterCollection inboundRouter = new DefaultInboundRouterCollection();
75 inboundRouter.addEndpoint(ep);
76 service.setInboundRouter(inboundRouter);
77 muleContext.getRegistry().registerService(service);
78
79 if (!muleContext.isStarted())
80 {
81 muleContext.start();
82 }
83
84 logger.debug("waiting for count down");
85 assertTrue(countDown.await(WAIT_PERIOD_MS, TimeUnit.MILLISECONDS));
86 }
87
88 protected static Map newEmailToStringServiceOverrides()
89 {
90 Map serviceOverrides = new HashMap();
91 serviceOverrides.put(MuleProperties.CONNECTOR_INBOUND_TRANSFORMER,
92 EmailMessageToString.class.getName());
93 return serviceOverrides;
94 }
95
96 }