View Javadoc

1   /*
2    * $Id: GroovyScriptFilterFunctionalTestCase.java 22518 2011-07-22 07:00:22Z claude.mamo $
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.module.scripting.filter;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertNull;
16  
17  import org.mule.api.MuleMessage;
18  import org.mule.module.client.MuleClient;
19  import org.mule.tck.AbstractServiceAndFlowTestCase;
20  
21  import java.util.Arrays;
22  import java.util.Collection;
23  
24  import org.junit.Test;
25  import org.junit.runners.Parameterized.Parameters;
26  
27  public class GroovyScriptFilterFunctionalTestCase extends AbstractServiceAndFlowTestCase
28  {
29  
30      public GroovyScriptFilterFunctionalTestCase(ConfigVariant variant, String configResources)
31      {
32          super(variant, configResources);
33          // Groovy really hammers the startup time since it needs to create the
34          // interpreter on every start
35          setDisposeContextPerClass(true);
36      }
37  
38      @Parameters
39      public static Collection<Object[]> parameters()
40      {
41          return Arrays.asList(new Object[][]{
42              {ConfigVariant.SERVICE, "groovy-filter-config-service.xml"},
43              {ConfigVariant.FLOW, "groovy-filter-config-flow.xml"}
44          });
45      }      
46      
47      @Test
48      public void testFilterScript() throws Exception
49      {
50          MuleClient client = new MuleClient(muleContext);
51          client.dispatch("vm://in1", "hello", null);
52          MuleMessage response = client.request("vm://out1", RECEIVE_TIMEOUT);
53          assertNotNull(response);
54          assertEquals("hello", response.getPayload());
55  
56          client.dispatch("vm://in1", "1", null);
57          response = client.request("vm://out1", RECEIVE_TIMEOUT);
58          assertNull(response);
59      }
60  }