View Javadoc

1   /*
2    * $Id: ComponentReturningNullFlowTestCase.java 22421 2011-07-15 05:05:06Z dirk.olmes $
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.components;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.AbstractServiceAndFlowTestCase;
16  import org.mule.transport.NullPayload;
17  
18  import java.util.Arrays;
19  import java.util.Collection;
20  
21  import org.junit.Test;
22  import org.junit.runners.Parameterized.Parameters;
23  
24  import static org.junit.Assert.assertFalse;
25  import static org.junit.Assert.assertNotNull;
26  import static org.junit.Assert.assertTrue;
27  
28  public class ComponentReturningNullFlowTestCase extends AbstractServiceAndFlowTestCase
29  {
30      @Parameters
31      public static Collection<Object[]> parameters()
32      {
33          return Arrays.asList(new Object[][]{
34              {ConfigVariant.SERVICE, "org/mule/test/components/component-returned-null-service.xml"},
35              {ConfigVariant.FLOW, "org/mule/test/components/component-returned-null-flow.xml"}});
36      }
37  
38      public ComponentReturningNullFlowTestCase(ConfigVariant variant, String configResources)
39      {
40          super(variant, configResources);
41      }
42  
43      @Test
44      public void testNullReturnStopsFlow() throws Exception
45      {
46          MuleClient client = new MuleClient(muleContext);
47  
48          MuleMessage msg = client.send("vm://in", "test data", null);
49          assertNotNull(msg);
50          final String payload = msg.getPayloadAsString();
51          assertNotNull(payload);
52          assertFalse("ERROR".equals(payload));
53          assertTrue(msg.getPayload() instanceof NullPayload);
54      }
55  
56      public static final class ComponentReturningNull
57      {
58          public String process(String input)
59          {
60              return null;
61          }
62      }
63  }