Search in sources :

Example 16 with StaticScriptSource

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

the class GroovyScriptEvaluatorTests method testGroovyScriptWithCompilerConfiguration.

@Test
public void testGroovyScriptWithCompilerConfiguration() {
    GroovyScriptEvaluator evaluator = new GroovyScriptEvaluator();
    MyBytecodeProcessor processor = new MyBytecodeProcessor();
    evaluator.getCompilerConfiguration().setBytecodePostprocessor(processor);
    Object result = evaluator.evaluate(new StaticScriptSource("return 3 * 2"));
    assertThat(result).isEqualTo(6);
    assertThat(processor.processed.contains("Script1")).isTrue();
}
Also used : StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) Test(org.junit.jupiter.api.Test)

Example 17 with StaticScriptSource

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

the class GroovyScriptEvaluatorTests method testGroovyScriptWithArgumentsUsingJsr223.

@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);
    assertThat(result).isEqualTo(6);
}
Also used : StandardScriptEvaluator(org.springframework.scripting.support.StandardScriptEvaluator) StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 18 with StaticScriptSource

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

the class BshScriptEvaluatorTests method testGroovyScriptWithArguments.

@Test
public void testGroovyScriptWithArguments() {
    ScriptEvaluator evaluator = new BshScriptEvaluator();
    Map<String, Object> arguments = new HashMap<>();
    arguments.put("a", 3);
    arguments.put("b", 2);
    Object result = evaluator.evaluate(new StaticScriptSource("return a * b;"), arguments);
    assertThat(result).isEqualTo(6);
}
Also used : StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) ScriptEvaluator(org.springframework.scripting.ScriptEvaluator) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

StaticScriptSource (org.springframework.scripting.support.StaticScriptSource)18 Test (org.junit.Test)8 Test (org.junit.jupiter.api.Test)8 HashMap (java.util.HashMap)6 ScriptEvaluator (org.springframework.scripting.ScriptEvaluator)4 StandardScriptEvaluator (org.springframework.scripting.support.StandardScriptEvaluator)4 ScriptExecutor (org.springframework.integration.scripting.ScriptExecutor)3 ResourceScriptSource (org.springframework.scripting.support.ResourceScriptSource)2 GString (groovy.lang.GString)1 Script (groovy.lang.Script)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ImportCustomizer (org.codehaus.groovy.control.customizers.ImportCustomizer)1 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)1 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1 RefreshableResourceScriptSource (org.springframework.integration.scripting.RefreshableResourceScriptSource)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1