use of org.springframework.integration.scripting.DefaultScriptVariableGenerator in project spring-integration by spring-projects.
the class GroovyScriptPayloadMessageProcessorTests method testBindingOverwriteWithContext.
// INT-2567
@Test
public void testBindingOverwriteWithContext() throws Exception {
final String defaultValue = "default";
Binding binding = new Binding() {
@Override
public Object getVariable(String name) {
try {
return super.getVariable(name);
} catch (MissingPropertyException e) {
// ignore
}
return defaultValue;
}
};
ScriptVariableGenerator scriptVariableGenerator = new DefaultScriptVariableGenerator(Collections.singletonMap("spam", (Object) "bucket"));
Message<?> message = MessageBuilder.withPayload("\"spam is $spam, foo is $foo\"").build();
processor = new GroovyCommandMessageProcessor(binding, scriptVariableGenerator);
Object result = processor.processMessage(message);
assertEquals("spam is bucket, foo is default", result.toString());
}
use of org.springframework.integration.scripting.DefaultScriptVariableGenerator in project spring-integration by spring-projects.
the class GroovyScriptPayloadMessageProcessorTests method testSimpleExecutionWithContext.
@Test
public void testSimpleExecutionWithContext() throws Exception {
Message<?> message = MessageBuilder.withPayload("\"spam is $spam foo is $headers.foo\"").setHeader("foo", "bar").build();
ScriptVariableGenerator scriptVariableGenerator = new DefaultScriptVariableGenerator(Collections.singletonMap("spam", (Object) "bucket"));
MessageProcessor<Object> processor = new GroovyCommandMessageProcessor(scriptVariableGenerator);
Object result = processor.processMessage(message);
assertEquals("spam is bucket foo is bar", result.toString());
}
Aggregations