View Javadoc

1   /*
2    * $Id: IdempotentMessageFilterTestCase.java 20320 2010-11-24 15:03:31Z 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.routing;
12  
13  import org.mule.DefaultMuleEvent;
14  import org.mule.DefaultMuleMessage;
15  import org.mule.api.MuleEvent;
16  import org.mule.api.MuleMessage;
17  import org.mule.api.MuleSession;
18  import org.mule.api.endpoint.OutboundEndpoint;
19  import org.mule.api.service.Service;
20  import org.mule.tck.AbstractMuleTestCase;
21  import org.mule.tck.MuleTestUtils;
22  
23  import com.mockobjects.dynamic.Mock;
24  
25  
26  public class IdempotentMessageFilterTestCase extends AbstractMuleTestCase
27  {
28  
29      public void testIdempotentReceiver() throws Exception
30      {
31          OutboundEndpoint endpoint1 = getTestOutboundEndpoint("Test1Provider", "test://Test1Provider?exchangePattern=one-way");
32          Mock session = MuleTestUtils.getMockSession();
33          Service service = getTestService();
34          session.matchAndReturn("getFlowConstruct", service);
35  
36  
37          IdempotentMessageFilter ir = new IdempotentMessageFilter();
38          ir.setIdExpression("#[header:id]");
39          ir.setFlowConstruct(service);
40          ir.setThrowOnUnaccepted(false);
41  
42          MuleMessage okMessage = new DefaultMuleMessage("OK", muleContext);
43          okMessage.setOutboundProperty("id", "1");
44          MuleEvent event = new DefaultMuleEvent(okMessage, endpoint1, (MuleSession) session.proxy());
45  
46          // This one will process the event on the target endpoint
47          event = ir.process(event);
48          assertNotNull(event);
49  
50           // This will not process, because the ID is a duplicate
51          okMessage = new DefaultMuleMessage("OK", muleContext);
52          okMessage.setOutboundProperty("id", "1");
53          event = new DefaultMuleEvent(okMessage, endpoint1, (MuleSession) session.proxy());
54          event = ir.process(event);
55          assertNull(event);
56      }
57  
58  }