1
2
3
4
5
6
7 package org.mule.endpoint.outbound;
8
9 import org.mule.MessageExchangePattern;
10 import org.mule.api.MuleEvent;
11 import org.mule.api.MuleMessage;
12 import org.mule.api.endpoint.OutboundEndpoint;
13 import org.mule.api.processor.MessageProcessor;
14 import org.mule.context.notification.EndpointMessageNotification;
15 import org.mule.endpoint.AbstractMessageProcessorTestCase;
16
17 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
18 import org.junit.Test;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22
23 public class OutboundNotificationMessageProcessorTestCase extends AbstractMessageProcessorTestCase
24 {
25
26 @Test
27 public void testDispatch() throws Exception
28 {
29 TestEndpointMessageNotificationListener listener = new TestEndpointMessageNotificationListener();
30 muleContext.registerListener(listener);
31
32 OutboundEndpoint endpoint = createTestOutboundEndpoint(null, null, null, null,
33 MessageExchangePattern.ONE_WAY, null);
34 MessageProcessor mp = new OutboundNotificationMessageProcessor(endpoint);
35 MuleEvent event = createTestOutboundEvent(endpoint);
36 mp.process(event);
37
38 assertTrue(listener.latch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
39 assertEquals(EndpointMessageNotification.MESSAGE_DISPATCHED, listener.messageNotification.getAction());
40 assertEquals(endpoint.getEndpointURI().getUri().toString(),
41 listener.messageNotification.getEndpoint());
42 assertTrue(listener.messageNotification.getSource() instanceof MuleMessage);
43 assertEquals(event.getMessage().getPayload(),
44 ((MuleMessage) listener.messageNotification.getSource()).getPayload());
45 }
46
47 @Test
48 public void testSend() throws Exception
49 {
50 TestEndpointMessageNotificationListener listener = new TestEndpointMessageNotificationListener();
51 muleContext.registerListener(listener);
52
53 OutboundEndpoint endpoint = createTestOutboundEndpoint(null, null, null, null,
54 MessageExchangePattern.REQUEST_RESPONSE, null);
55 MessageProcessor mp = new OutboundNotificationMessageProcessor(endpoint);
56 MuleEvent event = createTestOutboundEvent(endpoint);
57 mp.process(event);
58
59 assertTrue(listener.latch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
60 assertEquals(EndpointMessageNotification.MESSAGE_SENT, listener.messageNotification.getAction());
61 assertEquals(endpoint.getEndpointURI().getUri().toString(),
62 listener.messageNotification.getEndpoint());
63 assertTrue(listener.messageNotification.getSource() instanceof MuleMessage);
64 assertEquals(event.getMessage().getPayload(),
65 ((MuleMessage) listener.messageNotification.getSource()).getPayload());
66 }
67
68 }