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.transformers;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.transformer.TransformerException;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.RequestContext;
14  import org.mule.transformer.AbstractTransformer;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  
21  public class TransformerStoppingEventFlowTestCase extends FunctionalTestCase
22  {
23  
24      @Override
25      protected String getConfigResources()
26      {
27          return "org/mule/test/transformers/transformer-stopped-processing.xml";
28      }
29  
30      @Test
31      public void testNullReturnStopsFlow() throws Exception
32      {
33          MuleClient client = new MuleClient(muleContext);
34  
35          MuleMessage msg = client.send("vm://in", TEST_MESSAGE, null);
36          assertNotNull(msg);
37          final String payload = msg.getPayloadAsString();
38          assertNotNull(payload);
39          assertEquals(TEST_MESSAGE, payload);
40      }
41  
42      public static final class StopFlowTransformer extends AbstractTransformer
43      {
44  
45  
46          protected Object doTransform(Object src, String encoding) throws TransformerException
47          {
48              RequestContext.getEventContext().setStopFurtherProcessing(true);
49              return src;
50          }
51      }
52  }