INT-1727 renamed DefaultScriptVariableSource to DefaultScriptVariableGenerator, documented the new feature in reference manual

This commit is contained in:
Oleg Zhurakousky
2011-01-31 14:06:29 -05:00
parent da227f07a9
commit ae823fdb5d
10 changed files with 69 additions and 25 deletions

View File

@@ -59,7 +59,7 @@ public class GroovyScriptExecutingMessageProcessorTests {
Message<?> message = MessageBuilder.withPayload("foo").setHeader("testHeader", "bar"+count).build();
TestResource resource = new TestResource(script, "simpleTest");
ScriptSource scriptSource = new ResourceScriptSource(resource);
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, new DefaultScriptVariableSource());
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, new DefaultScriptVariableGenerator());
Object result = processor.processMessage(message);
assertEquals("payload is foo, header is bar"+count, result.toString());
}
@@ -72,7 +72,7 @@ public class GroovyScriptExecutingMessageProcessorTests {
TestResource resource = new TestResource(script, "simpleTest");
ScriptSource scriptSource = new ResourceScriptSource(resource);
Object result = null;
class CustomScriptVariableSource implements ScriptVariablesGenerator {
class CustomScriptVariableSource implements ScriptVariableGenerator {
public Map<String, Object> generateScriptVariables(Message<?> message) {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("date", System.nanoTime());
@@ -82,7 +82,7 @@ public class GroovyScriptExecutingMessageProcessorTests {
}
}
for (int i = 0; i < 5; i++) {
ScriptVariablesGenerator scriptVariableSource = new CustomScriptVariableSource();
ScriptVariableGenerator scriptVariableSource = new CustomScriptVariableSource();
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, scriptVariableSource);
Object newResult = processor.processMessage(message);
assertFalse(newResult.equals(result)); // make sure that we get different nanotime verifying that resolveScriptVariables() is invoked
@@ -106,7 +106,7 @@ public class GroovyScriptExecutingMessageProcessorTests {
Message<?> message = MessageBuilder.withPayload("foo").setHeader("testHeader", "bar").build();
TestResource resource = new TestResource(script, "simpleTest");
ScriptSource scriptSource = new ResourceScriptSource(resource);
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, new DefaultScriptVariableSource());
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, new DefaultScriptVariableGenerator());
Thread.sleep(20L);
resource.setScript("return \"payload is $payload\"");
Object result = processor.processMessage(message);
@@ -119,7 +119,7 @@ public class GroovyScriptExecutingMessageProcessorTests {
Message<?> message = MessageBuilder.withPayload("foo").setHeader("testHeader", "bar").build();
TestResource resource = new TestResource(script, "simpleTest");
ScriptSource scriptSource = new RefreshableResourceScriptSource(resource, 1000L);
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, new DefaultScriptVariableSource());
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, new DefaultScriptVariableGenerator());
// should be the original script
Object result = processor.processMessage(message);
assertEquals("payload is foo, header is bar", result.toString());
@@ -143,7 +143,7 @@ public class GroovyScriptExecutingMessageProcessorTests {
Message<?> message = MessageBuilder.withPayload("foo").setHeader("testHeader", "bar").build();
TestResource resource = new TestResource(script, "simpleTest");
ScriptSource scriptSource = new RefreshableResourceScriptSource(resource, -1L);
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, new DefaultScriptVariableSource());
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, new DefaultScriptVariableGenerator());
// process with the first script
Object result = processor.processMessage(message);
assertEquals("payload is foo, header is bar", result.toString());
@@ -160,7 +160,7 @@ public class GroovyScriptExecutingMessageProcessorTests {
Message<?> message = MessageBuilder.withPayload("foo").setHeader("testHeader", "bar").build();
TestResource resource = new TestResource(script, "simpleTest");
ScriptSource scriptSource = new RefreshableResourceScriptSource(resource, 0);
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, new DefaultScriptVariableSource());
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, new DefaultScriptVariableGenerator());
// process with the first script
Object result = processor.processMessage(message);
assertEquals("payload is foo, header is bar", result.toString());

View File

@@ -44,14 +44,14 @@ public class GroovyScriptPayloadMessageProcessorTests {
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());
processor = new GroovyCommandMessageProcessor(new DefaultScriptVariableGenerator());
Object result = processor.processMessage(message);
assertEquals("bar", result.toString());
}
@Test
public void testDoubleExecutionWithNewScript() throws Exception {
processor = new GroovyCommandMessageProcessor(new DefaultScriptVariableSource());
processor = new GroovyCommandMessageProcessor(new DefaultScriptVariableGenerator());
Message<?> message = MessageBuilder.withPayload("headers.foo").setHeader("foo", "bar").build();
Object result = processor.processMessage(message);
assertEquals("bar", result.toString());
@@ -64,8 +64,8 @@ public class GroovyScriptPayloadMessageProcessorTests {
public void testSimpleExecutionWithContext() throws Exception {
Message<?> message = MessageBuilder.withPayload("\"spam is $spam foo is $headers.foo\"")
.setHeader("foo", "bar").build();
ScriptVariablesGenerator scriptVariableSource =
new DefaultScriptVariableSource(Collections.singletonMap("spam",(Object)"bucket"));
ScriptVariableGenerator scriptVariableSource =
new DefaultScriptVariableGenerator(Collections.singletonMap("spam",(Object)"bucket"));
MessageProcessor<Object> processor = new GroovyCommandMessageProcessor(scriptVariableSource);
Object result = processor.processMessage(message);
assertEquals("spam is bucket foo is bar", result.toString());

View File

@@ -34,7 +34,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.groovy.ScriptVariablesGenerator;
import org.springframework.integration.groovy.ScriptVariableGenerator;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -128,7 +128,7 @@ public class GroovyServiceActivatorTests {
new ClassPathXmlApplicationContext("GroovyServiceActivatorTests-fail-withsource-context.xml", this.getClass());
}
public static class SampleScriptVariSource implements ScriptVariablesGenerator{
public static class SampleScriptVariSource implements ScriptVariableGenerator{
public Map<String, Object> generateScriptVariables(Message<?> message) {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("foo", "foo");