View Javadoc

1   /*
2    * $Id: ResponseAggregatorTestCase.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.test.usecases.routing.response;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.routing.requestreply.AbstractAsyncRequestReplyRequester;
17  import org.mule.tck.FunctionalTestCase;
18  import org.mule.tck.SensingNullMessageProcessor;
19  
20  import java.util.Map;
21  
22  public class ResponseAggregatorTestCase extends FunctionalTestCase
23  {
24      @Override
25      protected String getConfigResources()
26      {
27          return "org/mule/test/usecases/routing/response/response-router.xml";
28      }
29  
30      public void testSyncResponse() throws Exception
31      {
32          MuleClient client = new MuleClient(muleContext);
33          MuleMessage message = client.send("http://localhost:28081", "request", null);
34          assertNotNull(message);
35          assertEquals("Received: request", new String(message.getPayloadAsBytes()));
36      }
37  
38      public void testResponseEventsCleanedUp() throws Exception
39      {
40          RelaxedAsyncReplyMP mp = new RelaxedAsyncReplyMP();
41          
42          MuleEvent event = getTestEvent("message1");
43          final MuleMessage message = event.getMessage();
44          final String id = message.getUniqueId();
45          message.setCorrelationId(id);
46          message.setCorrelationGroupSize(1);
47          
48          SensingNullMessageProcessor listener = getSensingNullMessageProcessor();
49          mp.setListener(listener);
50          mp.setReplySource(listener.getMessageSource());
51          
52          mp.process(event);
53  
54          Map responseEvents = mp.getResponseEvents();
55          assertTrue("Response events should be cleaned up.", responseEvents.isEmpty());
56      }
57  
58      /**
59       * This class opens up the access to responseEvents map for testing
60       */
61      private static final class RelaxedAsyncReplyMP extends AbstractAsyncRequestReplyRequester
62      {
63          public Map getResponseEvents()
64          {
65              return responseEvents;
66          }
67      }
68  }