001/** 002 * Copyright 2005-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.rule; 017 018import groovy.lang.Binding; 019import groovy.lang.GroovyShell; 020import org.junit.Assert; 021import org.junit.Test; 022 023import javax.script.ScriptEngine; 024import javax.script.ScriptEngineManager; 025 026/** 027 * Tests that Groovy can be loaded via Bean Scripting Framework 028 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031public class LoadEmbeddedGroovyTest { 032 @Test public void testNativeGroovy() { 033 Binding binding = new Binding(); 034 binding.setVariable("foo", new Integer(2)); 035 GroovyShell shell = new GroovyShell(binding); 036 037 Object value = shell.evaluate("println 'Hello World!'; x = 123; return foo * 10"); 038 Assert.assertTrue(value.equals(new Integer(20))); 039 Assert.assertTrue(binding.getVariable("x").equals(new Integer(123))); 040 } 041 042 @Test public void testJSR223Groovy() throws Exception { 043 ScriptEngineManager factory = new ScriptEngineManager(); 044 ScriptEngine engine = factory.getEngineByName("groovy"); 045 engine.eval("println 'hello embedded groovy world'"); 046 } 047 048 @Test public void testJSR223Groovy2() throws Exception { 049 ScriptEngineManager factory = new ScriptEngineManager(); 050 ScriptEngine engine = factory.getEngineByName("groovy"); 051 engine.eval("var = 0\r\ndef foo() {\r\n var++\r\n }\r\n foo()"); 052 } 053}