1   /*
2    * $Id: ResponseAggregatorTestCase.java 11545 2008-04-08 21:19:46Z rossmason $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.response.SingleResponseRouter;
17  import org.mule.tck.FunctionalTestCase;
18  
19  import java.util.Map;
20  
21  public class ResponseAggregatorTestCase extends FunctionalTestCase
22  {
23  
24      protected String getConfigResources()
25      {
26          return "org/mule/test/usecases/routing/response/response-router.xml";
27      }
28  
29      public void testSyncResponse() throws Exception
30      {
31          MuleClient client = new MuleClient();
32          MuleMessage message = client.send("http://localhost:28081", "request", null);
33          assertNotNull(message);
34          assertEquals("Received: request", new String(message.getPayloadAsBytes()));
35      }
36  
37      public void testResponseEventsCleanedUp() throws Exception
38      {
39          // relax access to get to the responseEvents
40          RelaxedResponseAggregator aggregator = new RelaxedResponseAggregator();
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          aggregator.setMuleContext(muleContext);
48          aggregator.initialise();
49          aggregator.process(event);
50  
51          aggregator.getResponse(message);
52  
53          Map responseEvents = aggregator.getResponseEvents();
54          assertTrue("Response events should be cleaned up.", responseEvents.isEmpty());
55      }
56  
57      /**
58       * This class opens up the access to responseEvents map for testing
59       */
60      private static final class RelaxedResponseAggregator extends SingleResponseRouter
61      {
62          public Map getResponseEvents()
63          {
64              return this.getEventCorrelator().getResponseMessages();
65          }
66      }
67  }