View Javadoc

1   /*
2    * $Id: OutboundResponsePropertiesMessageProcessorTestCase.java 22597 2011-08-05 20:40:24Z dfeist $
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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  import org.mule.DefaultMuleEvent;
17  import org.mule.DefaultMuleMessage;
18  import org.mule.MessageExchangePattern;
19  import org.mule.api.MuleEvent;
20  import org.mule.api.MuleException;
21  import org.mule.api.config.MuleProperties;
22  import org.mule.api.endpoint.EndpointBuilder;
23  import org.mule.api.endpoint.OutboundEndpoint;
24  import org.mule.api.processor.InterceptingMessageProcessor;
25  import org.mule.api.processor.MessageProcessor;
26  import org.mule.endpoint.AbstractEndpointBuilder;
27  import org.mule.endpoint.AbstractMessageProcessorTestCase;
28  
29  import org.junit.Test;
30  
31  public class OutboundResponsePropertiesMessageProcessorTestCase extends AbstractMessageProcessorTestCase
32  {
33  
34      private static String MY_PROPERTY_KEY = "myProperty";
35      private static String MY_PROPERTY_VAL = "myPropertyValue";
36      private static String MULE_CORRELATION_ID_VAL = "152";
37  
38      @Test
39      public void testProcess() throws Exception
40      {
41          OutboundEndpoint endpoint = createTestOutboundEndpoint(null, null);
42          InterceptingMessageProcessor mp = new OutboundResponsePropertiesMessageProcessor(endpoint);
43          mp.setListener(new MessageProcessor()
44          {
45              public MuleEvent process(MuleEvent event) throws MuleException
46              {
47                  // return event with same payload but no properties
48                  try
49                  {
50                      return new DefaultMuleEvent(new DefaultMuleMessage(event.getMessage().getPayload(),
51                          muleContext), MessageExchangePattern.REQUEST_RESPONSE, getTestSession(getTestService(),
52                          muleContext));
53                  }
54                  catch (Exception e)
55                  {
56                      throw new RuntimeException(e);
57                  }
58              }
59          });
60  
61          MuleEvent event = createTestOutboundEvent();
62          event.getMessage().setOutboundProperty(MY_PROPERTY_KEY, MY_PROPERTY_VAL);
63          event.getMessage().setOutboundProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY, MULE_CORRELATION_ID_VAL);
64          MuleEvent result = mp.process(event);
65  
66          assertNotNull(result);
67          assertEquals(TEST_MESSAGE, result.getMessageAsString());
68          assertEquals(MY_PROPERTY_VAL, result.getMessage().getOutboundProperty(MY_PROPERTY_KEY));
69          assertEquals(MULE_CORRELATION_ID_VAL,
70                       result.getMessage().getOutboundProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY));
71      }
72  
73      @Override
74      protected void customizeEndpointBuilder(EndpointBuilder endpointBuilder)
75      {
76          endpointBuilder.setProperty(AbstractEndpointBuilder.PROPERTY_RESPONSE_PROPERTIES, "myProperty");
77      }
78  }