Search in sources :

Example 1 with ScriptEvaluator

use of org.springframework.scripting.ScriptEvaluator in project spring-framework by spring-projects.

the class BshScriptEvaluatorTests method testBshScriptFromString.

@Test
public void testBshScriptFromString() {
    ScriptEvaluator evaluator = new BshScriptEvaluator();
    Object result = evaluator.evaluate(new StaticScriptSource("return 3 * 2;"));
    assertEquals(6, result);
}
Also used : StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) ScriptEvaluator(org.springframework.scripting.ScriptEvaluator) Test(org.junit.Test)

Example 2 with ScriptEvaluator

use of org.springframework.scripting.ScriptEvaluator in project spring-framework by spring-projects.

the class GroovyScriptEvaluatorTests method testGroovyScriptWithArguments.

@Test
public void testGroovyScriptWithArguments() {
    ScriptEvaluator evaluator = new GroovyScriptEvaluator();
    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);
}
Also used : StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) StandardScriptEvaluator(org.springframework.scripting.support.StandardScriptEvaluator) ScriptEvaluator(org.springframework.scripting.ScriptEvaluator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with ScriptEvaluator

use of org.springframework.scripting.ScriptEvaluator in project spring-framework by spring-projects.

the class GroovyScriptEvaluatorTests method testGroovyScriptFromString.

@Test
public void testGroovyScriptFromString() {
    ScriptEvaluator evaluator = new GroovyScriptEvaluator();
    Object result = evaluator.evaluate(new StaticScriptSource("return 3 * 2"));
    assertEquals(6, result);
}
Also used : StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) StandardScriptEvaluator(org.springframework.scripting.support.StandardScriptEvaluator) ScriptEvaluator(org.springframework.scripting.ScriptEvaluator) Test(org.junit.Test)

Example 4 with ScriptEvaluator

use of org.springframework.scripting.ScriptEvaluator in project spring-framework by spring-projects.

the class GroovyScriptEvaluatorTests method testGroovyScriptFromFile.

@Test
public void testGroovyScriptFromFile() {
    ScriptEvaluator evaluator = new GroovyScriptEvaluator();
    Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.groovy", getClass())));
    assertEquals(6, result);
}
Also used : StandardScriptEvaluator(org.springframework.scripting.support.StandardScriptEvaluator) ScriptEvaluator(org.springframework.scripting.ScriptEvaluator) ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 5 with ScriptEvaluator

use of org.springframework.scripting.ScriptEvaluator in project spring-framework by spring-projects.

the class GroovyScriptEvaluatorTests method testGroovyScriptFromFileUsingJsr223.

@Test
public void testGroovyScriptFromFileUsingJsr223() {
    ScriptEvaluator evaluator = new StandardScriptEvaluator();
    Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.groovy", getClass())));
    assertEquals(6, result);
}
Also used : StandardScriptEvaluator(org.springframework.scripting.support.StandardScriptEvaluator) StandardScriptEvaluator(org.springframework.scripting.support.StandardScriptEvaluator) ScriptEvaluator(org.springframework.scripting.ScriptEvaluator) ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 ScriptEvaluator (org.springframework.scripting.ScriptEvaluator)7 StandardScriptEvaluator (org.springframework.scripting.support.StandardScriptEvaluator)4 StaticScriptSource (org.springframework.scripting.support.StaticScriptSource)4 ClassPathResource (org.springframework.core.io.ClassPathResource)3 ResourceScriptSource (org.springframework.scripting.support.ResourceScriptSource)3 HashMap (java.util.HashMap)2