1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.rule;
17
18 import groovy.lang.Binding;
19 import groovy.lang.GroovyShell;
20 import org.junit.Assert;
21 import org.junit.Test;
22
23 import javax.script.ScriptEngine;
24 import javax.script.ScriptEngineManager;
25
26
27
28
29
30
31 public class LoadEmbeddedGroovyTest {
32 @Test public void testNativeGroovy() {
33 Binding binding = new Binding();
34 binding.setVariable("foo", new Integer(2));
35 GroovyShell shell = new GroovyShell(binding);
36
37 Object value = shell.evaluate("println 'Hello World!'; x = 123; return foo * 10");
38 Assert.assertTrue(value.equals(new Integer(20)));
39 Assert.assertTrue(binding.getVariable("x").equals(new Integer(123)));
40 }
41
42 @Test public void testJSR223Groovy() throws Exception {
43 ScriptEngineManager factory = new ScriptEngineManager();
44 ScriptEngine engine = factory.getEngineByName("groovy");
45 engine.eval("println 'hello embedded groovy world'");
46 }
47
48 @Test public void testJSR223Groovy2() throws Exception {
49 ScriptEngineManager factory = new ScriptEngineManager();
50 ScriptEngine engine = factory.getEngineByName("groovy");
51 engine.eval("var = 0\r\ndef foo() {\r\n var++\r\n }\r\n foo()");
52 }
53 }