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.transformer;
8   
9   import org.mule.api.transformer.Transformer;
10  import org.mule.module.scripting.component.Scriptable;
11  import org.mule.transformer.AbstractTransformerTestCase;
12  
13  import java.util.ArrayList;
14  import java.util.List;
15  
16  public class GroovyScriptTransformerTestCase extends AbstractTransformerTestCase
17  {
18      public Transformer getTransformer() throws Exception
19      {
20          Scriptable script = new Scriptable(muleContext);
21          script.setScriptEngineName("groovy");
22          script.setScriptFile("StringToList.groovy");
23          script.initialise();
24          
25          ScriptTransformer transformer = new ScriptTransformer();
26          transformer.setName("StringToList");
27          transformer.setMuleContext(muleContext);
28          transformer.setScript(script);
29          transformer.initialise();
30          return transformer;
31      }
32  
33      public Transformer getRoundTripTransformer() throws Exception
34      {
35          Scriptable script = new Scriptable(muleContext);
36          script.setScriptFile("ListToString.groovy");
37          script.initialise();
38          
39          ScriptTransformer transformer = new ScriptTransformer();
40          transformer.setName("ListToString");
41          transformer.setMuleContext(muleContext);
42          transformer.setScript(script);
43          transformer.initialise();
44          return transformer;
45      }
46  
47      public Object getTestData()
48      {
49          return "this is groovy!";
50      }
51  
52      public Object getResultData()
53      {
54          List<String> list = new ArrayList<String>(3);
55          list.add("this");
56          list.add("is");
57          list.add("groovy!");
58          return list;
59      }
60  }