INT-1727 added namespace support for script-variable-source
This commit is contained in:
@@ -17,6 +17,15 @@
|
||||
<groovy:variable name="date" ref="date"/>
|
||||
</groovy:script>
|
||||
</service-activator>
|
||||
|
||||
|
||||
<service-activator input-channel="withScriptVariableSource">
|
||||
<groovy:script location="org/springframework/integration/groovy/config/GroovyServiceActivatorTests.groovy"
|
||||
script-variable-source="scriptVarSource"/>
|
||||
</service-activator>
|
||||
|
||||
<beans:bean id="scriptVarSource"
|
||||
class="org.springframework.integration.groovy.config.GroovyServiceActivatorTests.SampleScriptVariSource"/>
|
||||
|
||||
<service-activator input-channel="inlineScriptInput">
|
||||
<groovy:script>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:groovy="http://www.springframework.org/schema/integration/groovy"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/groovy
|
||||
http://www.springframework.org/schema/integration/groovy/spring-integration-groovy-2.0.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<service-activator input-channel="withScriptVariableSource">
|
||||
<groovy:script location="org/springframework/integration/groovy/config/GroovyServiceActivatorTests.groovy"
|
||||
script-variable-source="scriptVarSource">
|
||||
<groovy:variable name="foo" value="foo"/>
|
||||
<groovy:variable name="bar" value="bar"/>
|
||||
</groovy:script>
|
||||
</service-activator>
|
||||
|
||||
</beans:beans>
|
||||
@@ -21,6 +21,9 @@ import static junit.framework.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -30,6 +33,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.DefaultScriptVariableSource;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -47,6 +51,9 @@ public class GroovyServiceActivatorTests {
|
||||
|
||||
@Autowired
|
||||
private MessageChannel inlineScriptInput;
|
||||
|
||||
@Autowired
|
||||
private MessageChannel withScriptVariableSource;
|
||||
|
||||
|
||||
@Test
|
||||
@@ -71,6 +78,29 @@ public class GroovyServiceActivatorTests {
|
||||
|
||||
assertNull(replyChannel.receive(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withScriptVariableSource() throws Exception{
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
replyChannel.setBeanName("returnAddress");
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
Message<?> message = MessageBuilder.withPayload("test-" + i).setReplyChannel(replyChannel).build();
|
||||
this.withScriptVariableSource.send(message);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
String value1 = (String) replyChannel.receive(0).getPayload();
|
||||
String value2 = (String) replyChannel.receive(0).getPayload();
|
||||
String value3 = (String) replyChannel.receive(0).getPayload();
|
||||
assertTrue(value1.startsWith("groovy-test-1-foo - bar"));
|
||||
assertTrue(value2.startsWith("groovy-test-2-foo - bar"));
|
||||
assertTrue(value3.startsWith("groovy-test-3-foo - bar"));
|
||||
// becouse we are using 'prototype bean the suffix date will be different
|
||||
|
||||
assertFalse(value1.substring(26).equals(value2.substring(26)));
|
||||
assertFalse(value2.substring(26).equals(value3.substring(26)));
|
||||
|
||||
assertNull(replyChannel.receive(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineScript() throws Exception{
|
||||
@@ -90,5 +120,17 @@ public class GroovyServiceActivatorTests {
|
||||
public void inlineScriptAndVariables() throws Exception{
|
||||
new ClassPathXmlApplicationContext("GroovyServiceActivatorTests-fail-context.xml", this.getClass());
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionParsingException.class)
|
||||
public void variablesAndScriptVariableSource() throws Exception{
|
||||
new ClassPathXmlApplicationContext("GroovyServiceActivatorTests-fail-withsource-context.xml", this.getClass());
|
||||
}
|
||||
|
||||
public static class SampleScriptVariSource extends DefaultScriptVariableSource{
|
||||
protected void doResolveScriptVariables(Map<String, Object> variables){
|
||||
variables.put("foo", "foo");
|
||||
variables.put("bar", "bar");
|
||||
variables.put("date", new Date());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user