View Javadoc

1   /*
2    * $Id: OutboundNotificationMessageProcessorTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.endpoint.outbound;
12  
13  import org.mule.MessageExchangePattern;
14  import org.mule.api.MuleEvent;
15  import org.mule.api.MuleMessage;
16  import org.mule.api.endpoint.OutboundEndpoint;
17  import org.mule.api.processor.MessageProcessor;
18  import org.mule.context.notification.EndpointMessageNotification;
19  import org.mule.endpoint.AbstractMessageProcessorTestCase;
20  
21  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
22  
23  public class OutboundNotificationMessageProcessorTestCase extends AbstractMessageProcessorTestCase
24  {
25  
26      public void testDispatch() throws Exception
27      {
28          TestEndpointMessageNotificationListener listener = new TestEndpointMessageNotificationListener();
29          muleContext.registerListener(listener);
30  
31          OutboundEndpoint endpoint = createTestOutboundEndpoint(null, null, null, null, 
32              MessageExchangePattern.ONE_WAY, null);
33          MessageProcessor mp = new OutboundNotificationMessageProcessor(endpoint);
34          MuleEvent event = createTestOutboundEvent(endpoint);
35          mp.process(event);
36  
37          assertTrue(listener.latch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
38          assertEquals(EndpointMessageNotification.MESSAGE_DISPATCHED, listener.messageNotification.getAction());
39          assertEquals(endpoint.getEndpointURI().getUri().toString(),
40              listener.messageNotification.getEndpoint());
41          assertTrue(listener.messageNotification.getSource() instanceof MuleMessage);
42          assertEquals(event.getMessage().getPayload(),
43              ((MuleMessage) listener.messageNotification.getSource()).getPayload());
44      }
45  
46      public void testSend() throws Exception
47      {
48          TestEndpointMessageNotificationListener listener = new TestEndpointMessageNotificationListener();
49          muleContext.registerListener(listener);
50  
51          OutboundEndpoint endpoint = createTestOutboundEndpoint(null, null, null, null, 
52              MessageExchangePattern.REQUEST_RESPONSE, null);
53          MessageProcessor mp = new OutboundNotificationMessageProcessor(endpoint);
54          MuleEvent event = createTestOutboundEvent(endpoint);
55          mp.process(event);
56  
57          assertTrue(listener.latch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
58          assertEquals(EndpointMessageNotification.MESSAGE_SENT, listener.messageNotification.getAction());
59          assertEquals(endpoint.getEndpointURI().getUri().toString(),
60              listener.messageNotification.getEndpoint());
61          assertTrue(listener.messageNotification.getSource() instanceof MuleMessage);
62          assertEquals(event.getMessage().getPayload(),
63              ((MuleMessage) listener.messageNotification.getSource()).getPayload());
64      }
65  
66  }