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.module.scripting;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  import static org.junit.Assert.assertNotNull;
17  
18  public class GroovyScriptFunctionalTestCase extends FunctionalTestCase
19  {
20      
21      public GroovyScriptFunctionalTestCase()
22      {
23          //Groovy really hammers the startup time since it needs to create the interpreter on every start
24          setDisposeContextPerClass(true);
25      }
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return "groovy-component-config.xml";
31      }
32  
33      @Test
34      public void testInlineScript() throws Exception
35      {
36          MuleClient client = new MuleClient(muleContext);
37          client.dispatch("vm://in1", "Important Message", null);
38          MuleMessage response = client.request("vm://out1", RECEIVE_TIMEOUT);
39          assertNotNull(response);
40          assertEquals("Important Message Received", response.getPayloadAsString());
41      }
42      
43      @Test
44      public void testFileBasedScript() throws Exception
45      {
46          MuleClient client = new MuleClient(muleContext);
47          client.dispatch("vm://in2", "Important Message", null);
48          MuleMessage response = client.request("vm://out2", RECEIVE_TIMEOUT);
49          assertNotNull(response);
50          assertEquals("Important Message Received", response.getPayloadAsString());
51      }
52      
53      @Test
54      public void testReferencedScript() throws Exception
55      {
56          MuleClient client = new MuleClient(muleContext);
57          client.dispatch("vm://in3", "Important Message", null);
58          MuleMessage response = client.request("vm://out3", RECEIVE_TIMEOUT);
59          assertNotNull(response);
60          assertEquals("Important Message Received", response.getPayloadAsString());
61      }    
62  
63      @Test
64      public void testScriptVariables() throws Exception
65      {
66          MuleClient client = new MuleClient(muleContext);
67          client.dispatch("vm://in4", "Important Message", null);
68          MuleMessage response = client.request("vm://out4", RECEIVE_TIMEOUT);
69          assertNotNull(response);
70          assertEquals("Important Message Received A-OK", response.getPayloadAsString());
71      }    
72  }
73  
74