View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.usecases.routing.response;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.routing.requestreply.AbstractAsyncRequestReplyRequester;
13  import org.mule.tck.SensingNullMessageProcessor;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  
16  import java.util.Map;
17  
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertTrue;
23  
24  public class ResponseAggregatorTestCase extends FunctionalTestCase
25  {
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return "org/mule/test/usecases/routing/response/response-router.xml";
31      }
32  
33      @Test
34      public void testSyncResponse() throws Exception
35      {
36          MuleClient client = new MuleClient(muleContext);
37          MuleMessage message = client.send("http://localhost:28081", "request", null);
38          assertNotNull(message);
39          assertEquals("Received: request", new String(message.getPayloadAsBytes()));
40      }
41  
42      @Test
43      public void testResponseEventsCleanedUp() throws Exception
44      {
45          RelaxedAsyncReplyMP mp = new RelaxedAsyncReplyMP();
46          
47          MuleEvent event = getTestEvent("message1");
48          final MuleMessage message = event.getMessage();
49          final String id = message.getUniqueId();
50          message.setCorrelationId(id);
51          message.setCorrelationGroupSize(1);
52          
53          SensingNullMessageProcessor listener = getSensingNullMessageProcessor();
54          mp.setListener(listener);
55          mp.setReplySource(listener.getMessageSource());
56          
57          mp.process(event);
58  
59          Map responseEvents = mp.getResponseEvents();
60          assertTrue("Response events should be cleaned up.", responseEvents.isEmpty());
61      }
62  
63      /**
64       * This class opens up the access to responseEvents map for testing
65       */
66      private static final class RelaxedAsyncReplyMP extends AbstractAsyncRequestReplyRequester
67      {
68          public Map getResponseEvents()
69          {
70              return responseEvents;
71          }
72      }
73  }