INT-1381, added test for 0 value

This commit is contained in:
Oleg Zhurakousky
2010-09-02 13:22:52 +00:00
parent 2057ac2bd5
commit 9c701c4e34
2 changed files with 24 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ import org.springframework.scripting.support.ResourceScriptSource;
/**
* @author Dave Syer
*
* @author Oleg Zhurakousky
* @since 2.0
*
*/

View File

@@ -34,6 +34,8 @@ import org.springframework.scripting.support.ResourceScriptSource;
/**
* @author Mark Fisher
* @author Dave Syer
* @author Oleg Zhurakousky
* @since 2.0
*/
public class GroovyScriptExecutingMessageProcessorTests {
@@ -112,6 +114,27 @@ public class GroovyScriptExecutingMessageProcessorTests {
result = processor.processMessage(message);
assertEquals("payload is foo, header is bar", result.toString());
}
@Test
public void testRefreshableScriptExecutionWithAlwaysRefresh() throws Exception {
String script = "return \"payload is $payload, header is $headers.testHeader\"";
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);
// process with the first script
Object result = processor.processMessage(message);
assertEquals("payload is foo, header is bar", result.toString());
// change script, but since refresh-delay is less then 0 we should still se old script executing
resource.setScript("return \"payload is $payload\"");
// process and see assert that the old script is used
result = processor.processMessage(message);
assertEquals("payload is foo", result.toString());
resource.setScript("return \"payload is 'hello'\"");
// process and see assert that the old script is used
result = processor.processMessage(message);
assertEquals("payload is 'hello'", result.toString());
}
private static class TestResource extends AbstractResource {