@Override public void afterPropertiesSet() throws Exception { scriptEvaluator = new StandardScriptEvaluator(); Assert.state(scriptSource != null || script != null, "Either the script source or script file must be provided"); Assert.state(scriptSource == null || script == null, "Either a script source or script file must be provided, not both"); if (scriptSource != null) { Assert.isTrue(!StringUtils.isEmpty(language), "Language must be provided when using script source"); ((StandardScriptEvaluator) scriptEvaluator).setLanguage(language); } }
@Test public void testGroovyScriptFromFileUsingJsr223() { ScriptEvaluator evaluator = new StandardScriptEvaluator(); Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.groovy", getClass()))); assertEquals(6, result); }
@Test public void testGroovyScriptWithArgumentsUsingJsr223() { StandardScriptEvaluator evaluator = new StandardScriptEvaluator(); evaluator.setLanguage("Groovy"); Map<String, Object> arguments = new HashMap<>(); arguments.put("a", 3); arguments.put("b", 2); Object result = evaluator.evaluate(new StaticScriptSource("return a * b"), arguments); assertEquals(6, result); }
@Test public void testGroovyScriptFromStringUsingJsr223() { StandardScriptEvaluator evaluator = new StandardScriptEvaluator(); evaluator.setLanguage("Groovy"); Object result = evaluator.evaluate(new StaticScriptSource("return 3 * 2")); assertEquals(6, result); }
@Override public void afterPropertiesSet() throws Exception { scriptEvaluator = new StandardScriptEvaluator(); Assert.state(scriptSource != null || script != null, "Either the script source or script file must be provided"); Assert.state(scriptSource == null || script == null, "Either a script source or script file must be provided, not both"); if (scriptSource != null) { Assert.isTrue(!StringUtils.isEmpty(language), "Language must be provided when using script source"); ((StandardScriptEvaluator) scriptEvaluator).setLanguage(language); } }