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.integration.async;
8   
9   import static org.junit.Assert.assertFalse;
10  import static org.junit.Assert.assertNotNull;
11  import static org.junit.Assert.assertNull;
12  import static org.junit.Assert.assertTrue;
13  
14  import org.mule.api.MuleMessage;
15  import org.mule.api.client.MuleClient;
16  import org.mule.tck.junit4.FunctionalTestCase;
17  import org.mule.transport.NullPayload;
18  
19  import org.junit.Test;
20  
21  public class SedaStageWorkRejectionTestCase extends FunctionalTestCase
22  {
23      protected String getConfigResources()
24      {
25          return "org/mule/test/integration/async/seda-stage-work-rejection-config.xml";
26      }
27  
28      @Test
29      public void handleRejectedEventWithExceptionStrategy() throws Exception
30      {
31          // Send 3 messages
32          MuleClient client = muleContext.getClient();
33          int nrMessages = 3;
34          for (int i = 0; i < nrMessages; i++)
35          {
36              client.dispatch("vm://flow.in", "some data " + i, null);
37          }
38  
39          // Receive 2 messages
40          for (int i = 0; i < 2; i++)
41          {
42              MuleMessage result = client.request("vm://flow.out", RECEIVE_TIMEOUT);
43              assertNotNull(result);
44              assertNull(result.getExceptionPayload());
45              assertFalse(result.getPayload() instanceof NullPayload);
46  
47              assertTrue(result.getPayloadAsString().contains("some data"));
48          }
49  
50          // Third message doesn't arrive
51          assertNull(client.request("vm://flow.out", RECEIVE_TIMEOUT / 5));
52  
53          // Third message was router via exception strategy
54          MuleMessage result = client.request("vm://flow.exception", RECEIVE_TIMEOUT);
55          assertNotNull(result);
56      }
57  }