INT-1727 decoupled relationship between Groovy Contro Bus and generic Script Processor

This commit is contained in:
Oleg Zhurakousky
2011-01-28 08:54:38 -05:00
parent e9b85bca18
commit bda613709f
2 changed files with 7 additions and 6 deletions

View File

@@ -16,6 +16,7 @@ package org.springframework.integration.groovy;
import groovy.lang.GString;
import org.springframework.integration.Message;
import org.springframework.integration.handler.AbstractScriptExecutingMessageProcessor;
import org.springframework.scripting.ScriptSource;
import org.springframework.scripting.groovy.GroovyScriptFactory;
import org.springframework.scripting.support.StaticScriptSource;
@@ -27,14 +28,12 @@ import org.springframework.util.Assert;
* @author Oleg Zhurakousky
* @since 2.0
*/
public class GroovyCommandMessageProcessor extends GroovyScriptExecutingMessageProcessor {
public class GroovyCommandMessageProcessor extends AbstractScriptExecutingMessageProcessor<Object> {
public GroovyCommandMessageProcessor() {
super(null);
}
private final ScriptVariableSource scriptVariableSource;
public GroovyCommandMessageProcessor(ScriptVariableSource scriptVariableSource) {
super(null, scriptVariableSource);
this.scriptVariableSource = scriptVariableSource;
}
@Override

View File

@@ -37,19 +37,21 @@ public class GroovyScriptPayloadMessageProcessorTests {
private AtomicInteger countHolder = new AtomicInteger();
private GroovyCommandMessageProcessor processor = new GroovyCommandMessageProcessor();
private GroovyCommandMessageProcessor processor;
@Test
@Repeat(20)
public void testSimpleExecution() throws Exception {
int count = countHolder.getAndIncrement();
Message<?> message = MessageBuilder.withPayload("headers.foo" + count).setHeader("foo" + count, "bar").build();
processor = new GroovyCommandMessageProcessor(new DefaultScriptVariableSource());
Object result = processor.processMessage(message);
assertEquals("bar", result.toString());
}
@Test
public void testDoubleExecutionWithNewScript() throws Exception {
processor = new GroovyCommandMessageProcessor(new DefaultScriptVariableSource());
Message<?> message = MessageBuilder.withPayload("headers.foo").setHeader("foo", "bar").build();
Object result = processor.processMessage(message);
assertEquals("bar", result.toString());