View Javadoc

1   /*
2    * $Id: GroovyScriptFunctionalTestCase.java 22518 2011-07-22 07:00:22Z claude.mamo $
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.module.scripting;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  import org.mule.api.MuleMessage;
17  import org.mule.module.client.MuleClient;
18  import org.mule.tck.AbstractServiceAndFlowTestCase;
19  
20  import java.util.Arrays;
21  import java.util.Collection;
22  
23  import org.junit.Test;
24  import org.junit.runners.Parameterized.Parameters;
25  
26  public class GroovyScriptFunctionalTestCase extends AbstractServiceAndFlowTestCase
27  {    
28      public GroovyScriptFunctionalTestCase(ConfigVariant variant, String configResources)
29      {
30          //Groovy really hammers the startup time since it needs to create the interpreter on every start
31          super(variant, configResources);
32          setDisposeContextPerClass(true);
33      }
34  
35      @Parameters
36      public static Collection<Object[]> parameters()
37      {
38          return Arrays.asList(new Object[][]{
39              {ConfigVariant.SERVICE, "groovy-component-config-service.xml"},
40              {ConfigVariant.FLOW, "groovy-component-config-flow.xml"}
41          });
42      }              
43  
44      @Test
45      public void testInlineScript() throws Exception
46      {
47          MuleClient client = new MuleClient(muleContext);
48          client.dispatch("vm://in1", "Important Message", null);
49          MuleMessage response = client.request("vm://out1", RECEIVE_TIMEOUT);
50          assertNotNull(response);
51          assertEquals("Important Message Received", response.getPayloadAsString());
52      }
53      
54      @Test
55      public void testFileBasedScript() throws Exception
56      {
57          MuleClient client = new MuleClient(muleContext);
58          client.dispatch("vm://in2", "Important Message", null);
59          MuleMessage response = client.request("vm://out2", RECEIVE_TIMEOUT);
60          assertNotNull(response);
61          assertEquals("Important Message Received", response.getPayloadAsString());
62      }
63      
64      @Test
65      public void testReferencedScript() throws Exception
66      {
67          MuleClient client = new MuleClient(muleContext);
68          client.dispatch("vm://in3", "Important Message", null);
69          MuleMessage response = client.request("vm://out3", RECEIVE_TIMEOUT);
70          assertNotNull(response);
71          assertEquals("Important Message Received", response.getPayloadAsString());
72      }    
73  
74      @Test
75      public void testScriptVariables() throws Exception
76      {
77          MuleClient client = new MuleClient(muleContext);
78          client.dispatch("vm://in4", "Important Message", null);
79          MuleMessage response = client.request("vm://out4", RECEIVE_TIMEOUT);
80          assertNotNull(response);
81          assertEquals("Important Message Received A-OK", response.getPayloadAsString());
82      }    
83  }
84  
85