use of org.springframework.integration.scripting.ScriptExecutor in project spring-integration-samples by spring-projects.
the class ScriptTests method testRuby.
@Test
public void testRuby() {
ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor("ruby");
Order order = new Order(0);
order.addItem(DrinkType.LATTE, 2, false);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("payload", order.getItems().get(0));
variables.put("timeToPrepare", 1L);
Object obj = executor.executeScript(new ResourceScriptSource(new FileSystemResource("scripts/ruby/barista.rb")), variables);
assertNotNull(obj);
assertTrue(obj instanceof Drink);
}
use of org.springframework.integration.scripting.ScriptExecutor in project spring-integration-samples by spring-projects.
the class ScriptTests method testPython.
@Test
@Ignore
public void testPython() {
ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor("python");
Order order = new Order(0);
order.addItem(DrinkType.LATTE, 2, false);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("payload", order.getItems().get(0));
variables.put("timeToPrepare", "1");
Object obj = executor.executeScript(new ResourceScriptSource(new FileSystemResource("scripts/python/barista.py")), variables);
assertNotNull(obj);
assertTrue(obj instanceof Drink);
}
use of org.springframework.integration.scripting.ScriptExecutor in project spring-integration by spring-projects.
the class Jsr223ScriptExecutorTests method test.
@Test
public void test() {
ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor("jruby");
executor.executeScript(new StaticScriptSource("'hello, world'"));
executor.executeScript(new StaticScriptSource("'hello, again'"));
Map<String, Object> variables = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("one", 1);
headers.put("two", "two");
headers.put("three", 3);
variables.put("payload", "payload");
variables.put("headers", headers);
Resource resource = new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb");
String result = (String) executor.executeScript(new ResourceScriptSource(resource), variables);
assertEquals("payload modified", result.substring(0, "payload modified".length()));
}
use of org.springframework.integration.scripting.ScriptExecutor 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());
}
use of org.springframework.integration.scripting.ScriptExecutor 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);
}
Aggregations