Search in sources :

Example 1 with DefaultScriptVariableGenerator

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());
}
Also used : Binding(groovy.lang.Binding) ScriptVariableGenerator(org.springframework.integration.scripting.ScriptVariableGenerator) DefaultScriptVariableGenerator(org.springframework.integration.scripting.DefaultScriptVariableGenerator) MissingPropertyException(groovy.lang.MissingPropertyException) DefaultScriptVariableGenerator(org.springframework.integration.scripting.DefaultScriptVariableGenerator) Test(org.junit.Test)

Example 2 with DefaultScriptVariableGenerator

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());
}
Also used : ScriptVariableGenerator(org.springframework.integration.scripting.ScriptVariableGenerator) DefaultScriptVariableGenerator(org.springframework.integration.scripting.DefaultScriptVariableGenerator) DefaultScriptVariableGenerator(org.springframework.integration.scripting.DefaultScriptVariableGenerator) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 DefaultScriptVariableGenerator (org.springframework.integration.scripting.DefaultScriptVariableGenerator)2 ScriptVariableGenerator (org.springframework.integration.scripting.ScriptVariableGenerator)2 Binding (groovy.lang.Binding)1 MissingPropertyException (groovy.lang.MissingPropertyException)1