Search in sources :

Example 11 with StaticScriptSource

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

the class PythonScriptExecutorTests method testLiteral.

@Test
public void testLiteral() {
    Object obj = executor.executeScript(new StaticScriptSource("3+4"));
    assertEquals(7, obj);
    obj = executor.executeScript(new StaticScriptSource("'hello,world'"));
    assertEquals("hello,world", obj);
}
Also used : StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) Test(org.junit.Test)

Example 12 with StaticScriptSource

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

the class PythonScriptExecutorTests method test1.

@Test
public void test1() {
    Object obj = executor.executeScript(new StaticScriptSource("x=2"));
    assertEquals(2, obj);
}
Also used : StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) Test(org.junit.Test)

Example 13 with StaticScriptSource

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

the class Jsr223ScriptExecutorTests method testJs.

@Test
public void testJs() {
    ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor("js");
    Object obj = executor.executeScript(new StaticScriptSource("function js(){ return 'js';} js();"));
    assertEquals("js", obj.toString());
}
Also used : StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) ScriptExecutor(org.springframework.integration.scripting.ScriptExecutor) Test(org.junit.Test)

Example 14 with StaticScriptSource

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

the class Jsr223ScriptExecutorTests method testPython.

@Test
public void testPython() {
    ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor("python");
    Object obj = executor.executeScript(new StaticScriptSource("x=2"));
    assertEquals(2, obj);
    obj = executor.executeScript(new StaticScriptSource("def foo(y):\n\tx=y\n\treturn y\nz=foo(2)"));
    assertEquals(2, obj);
}
Also used : StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) ScriptExecutor(org.springframework.integration.scripting.ScriptExecutor) Test(org.junit.Test)

Example 15 with StaticScriptSource

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

the class GroovyScriptEvaluatorTests method testGroovyScriptFromStringUsingJsr223.

@Test
public void testGroovyScriptFromStringUsingJsr223() {
    StandardScriptEvaluator evaluator = new StandardScriptEvaluator();
    evaluator.setLanguage("Groovy");
    Object result = evaluator.evaluate(new StaticScriptSource("return 3 * 2"));
    assertThat(result).isEqualTo(6);
}
Also used : StandardScriptEvaluator(org.springframework.scripting.support.StandardScriptEvaluator) StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) 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