use of org.springframework.integration.scripting.RefreshableResourceScriptSource in project spring-integration by spring-projects.
the class RefreshableResourceScriptSourceTests method testSuggestedClassName.
@Test
public void testSuggestedClassName() throws Exception {
RefreshableResourceScriptSource source = new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()) {
@Override
public String getFilename() throws IllegalStateException {
return "Foo";
}
}, 1000);
assertEquals("Foo", source.suggestedClassName());
}
use of org.springframework.integration.scripting.RefreshableResourceScriptSource in project spring-integration by spring-projects.
the class RefreshableResourceScriptSourceTests method testIsModified.
@Test
public void testIsModified() throws Exception {
RefreshableResourceScriptSource source = new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()), 1000);
assertEquals(false, source.isModified());
}
use of org.springframework.integration.scripting.RefreshableResourceScriptSource in project spring-integration by spring-projects.
the class GroovyScriptExecutingMessageProcessorTests method testRefreshableScriptExecution.
@Test
@Ignore("Very sensitive to the time")
public void testRefreshableScriptExecution() 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, 2000L);
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource);
// should be the original script
Object result = processor.processMessage(message);
assertEquals("payload is foo, header is bar", result.toString());
// reset the script with the new string
resource.setScript("return \"payload is $payload\"");
Thread.sleep(20L);
// should still assert to the old script because not enough time elapsed for refresh to kick in
result = processor.processMessage(message);
assertEquals("payload is foo, header is bar", result.toString());
// sleep some more, past refresh time
Thread.sleep(2000L);
// now you go the new script
resource.setScript("return \"payload is $payload\"");
result = processor.processMessage(message);
assertEquals("payload is foo", result.toString());
}
use of org.springframework.integration.scripting.RefreshableResourceScriptSource in project spring-integration by spring-projects.
the class GroovyScriptExecutingMessageProcessorTests method testRefreshableScriptExecutionWithInfiniteDelay.
@Test
public void testRefreshableScriptExecutionWithInfiniteDelay() 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, -1L);
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, header is bar", result.toString());
}
Aggregations