View Javadoc

1   /*
2    * $Id: OutboundNotificationMessageProcessorTestCase.java 23030 2011-09-26 18:02:33Z mike.schilling $
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 java.util.concurrent.TimeUnit;
22  
23  import org.junit.Test;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertTrue;
27  
28  public class OutboundNotificationMessageProcessorTestCase extends AbstractMessageProcessorTestCase
29  {
30  
31      @Test
32      public void testDispatch() throws Exception
33      {
34          TestEndpointMessageNotificationListener listener = new TestEndpointMessageNotificationListener();
35          muleContext.registerListener(listener);
36  
37          OutboundEndpoint endpoint = createTestOutboundEndpoint(null, null, null, null, 
38              MessageExchangePattern.ONE_WAY, null);
39          MessageProcessor mp = new OutboundNotificationMessageProcessor(endpoint);
40          MuleEvent event = createTestOutboundEvent();
41          mp.process(event);
42  
43          assertTrue(listener.latch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
44          assertEquals(EndpointMessageNotification.MESSAGE_DISPATCH_END, listener.messageNotification.getAction());
45          assertEquals(endpoint.getEndpointURI().getUri().toString(),
46              listener.messageNotification.getEndpoint());
47          assertTrue(listener.messageNotification.getSource() instanceof MuleMessage);
48          assertEquals(event.getMessage().getPayload(),
49              listener.messageNotification.getSource().getPayload());
50      }
51  
52      @Test
53      public void testSend() throws Exception
54      {
55          TestEndpointMessageNotificationListener listener = new TestEndpointMessageNotificationListener();
56          muleContext.registerListener(listener);
57  
58          OutboundEndpoint endpoint = createTestOutboundEndpoint(null, null, null, null, 
59              MessageExchangePattern.REQUEST_RESPONSE, null);
60          MessageProcessor mp = new OutboundNotificationMessageProcessor(endpoint);
61          MuleEvent event = createTestOutboundEvent();
62          mp.process(event);
63  
64          assertTrue(listener.latch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
65          assertEquals(EndpointMessageNotification.MESSAGE_SEND_END, listener.messageNotification.getAction());
66          assertEquals(endpoint.getEndpointURI().getUri().toString(),
67              listener.messageNotification.getEndpoint());
68          assertTrue(listener.messageNotification.getSource() instanceof MuleMessage);
69          assertEquals(event.getMessage().getPayload(),
70              (listener.messageNotification.getSource()).getPayload());
71      }
72  
73  }