View Javadoc

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