Search in sources :

Example 6 with RefreshableResourceScriptSource

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());
}
Also used : RefreshableResourceScriptSource(org.springframework.integration.scripting.RefreshableResourceScriptSource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 7 with RefreshableResourceScriptSource

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());
}
Also used : RefreshableResourceScriptSource(org.springframework.integration.scripting.RefreshableResourceScriptSource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 8 with RefreshableResourceScriptSource

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());
}
Also used : RefreshableResourceScriptSource(org.springframework.integration.scripting.RefreshableResourceScriptSource) StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) RefreshableResourceScriptSource(org.springframework.integration.scripting.RefreshableResourceScriptSource) ScriptSource(org.springframework.scripting.ScriptSource) ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with RefreshableResourceScriptSource

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());
}
Also used : RefreshableResourceScriptSource(org.springframework.integration.scripting.RefreshableResourceScriptSource) StaticScriptSource(org.springframework.scripting.support.StaticScriptSource) RefreshableResourceScriptSource(org.springframework.integration.scripting.RefreshableResourceScriptSource) ScriptSource(org.springframework.scripting.ScriptSource) ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) Test(org.junit.Test)

Aggregations

RefreshableResourceScriptSource (org.springframework.integration.scripting.RefreshableResourceScriptSource)9 Test (org.junit.Test)8 ByteArrayResource (org.springframework.core.io.ByteArrayResource)5 ScriptSource (org.springframework.scripting.ScriptSource)4 ResourceScriptSource (org.springframework.scripting.support.ResourceScriptSource)3 StaticScriptSource (org.springframework.scripting.support.StaticScriptSource)3 IOException (java.io.IOException)2 Ignore (org.junit.Ignore)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 AbstractScriptExecutingMessageProcessor (org.springframework.integration.scripting.AbstractScriptExecutingMessageProcessor)1 ScriptExecutingProcessorFactory (org.springframework.integration.scripting.config.ScriptExecutingProcessorFactory)1 ScriptExecutingMessageProcessor (org.springframework.integration.scripting.jsr223.ScriptExecutingMessageProcessor)1