Merge remote-tracking branch 'upstream/master' into 4.0.0-WIP
Conflicts: spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java spring-integration-core/src/main/java/org/springframework/integration/support/channel/BeanFactoryChannelResolver.java spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java spring-integration-core/src/test/java/org/springframework/integration/config/annotation/AggregatorAnnotationTests.java spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusTests.java spring-integration-file/src/main/java/org/springframework/integration/file/DefaultFileNameGenerator.java spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundGatewayParserTests.java spring-integration-ftp/src/test/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizerTests.java spring-integration-ftp/src/test/java/org/springframework/integration/ftp/outbound/FtpServerOutboundTests.java spring-integration-groovy/src/main/java/org/springframework/integration/groovy/GroovyScriptExecutingMessageProcessor.java spring-integration-http/src/test/java/org/springframework/integration/http/outbound/UriVariableExpressionTests.java spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/HelloWorldInterceptor.java spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundGatewayIntegrationTests.java spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoDbMessageGroupStoreTests.java spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoDbMessageStoreTests.java spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisOutboundChannelAdapterParserTests.java spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/SftpOutboundGatewayParserTests.java spring-integration-sftp/src/test/java/org/springframework/integration/sftp/inbound/SftpInboundRemoteFileSystemSynchronizerTests.java spring-integration-sftp/src/test/java/org/springframework/integration/sftp/outbound/SftpServerOutboundTests.java Resolved.
This commit is contained in:
@@ -10,30 +10,31 @@
|
||||
http://www.springframework.org/schema/integration/scripting http://www.springframework.org/schema/integration/scripting/spring-integration-scripting.xsd">
|
||||
|
||||
<service-activator input-channel="referencedScriptInput">
|
||||
<script:script
|
||||
<script:script
|
||||
lang="python"
|
||||
location="org/springframework/integration/scripting/config/jsr223/Jsr223ServiceActivatorTests.py">
|
||||
location="org/springframework/integration/scripting/config/jsr223/Jsr223ServiceActivatorTests.py"
|
||||
variables="foo2=#{'foo2'}, date2-ref=date">
|
||||
<script:variable name="foo" value="foo"/>
|
||||
<script:variable name="bar" value="bar"/>
|
||||
<script:variable name="date" ref="date"/>
|
||||
</script:script>
|
||||
</service-activator>
|
||||
|
||||
|
||||
|
||||
|
||||
<service-activator input-channel="withScriptVariableGenerator">
|
||||
<script:script lang="ruby" location="org/springframework/integration/scripting/config/jsr223/Jsr223ServiceActivatorTests.rb"
|
||||
script-variable-generator="scriptVarSource"/>
|
||||
</service-activator>
|
||||
|
||||
|
||||
|
||||
<beans:bean id="scriptVarSource"
|
||||
class="org.springframework.integration.scripting.config.jsr223.Jsr223ServiceActivatorTests.SampleScriptVariSource"/>
|
||||
|
||||
|
||||
|
||||
<beans:bean id="scriptVarSource"
|
||||
class="org.springframework.integration.scripting.config.jsr223.Jsr223ServiceActivatorTests$SampleScriptVariSource"/>
|
||||
|
||||
<service-activator input-channel="inlineScriptInput">
|
||||
<script:script lang="ruby">
|
||||
<script:script lang="ruby" variables="foo=#{'FOO'}, date-ref=date">
|
||||
<![CDATA[
|
||||
"inline-#{payload}"
|
||||
"inline-#{payload} - #{foo} :#{date}"
|
||||
]]>
|
||||
</script:script>
|
||||
</service-activator>
|
||||
@@ -41,5 +42,5 @@
|
||||
<beans:bean id="date" class="java.util.Date" scope="prototype">
|
||||
<aop:scoped-proxy/>
|
||||
</beans:bean>
|
||||
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -7,14 +7,13 @@
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/scripting http://www.springframework.org/schema/integration/scripting/spring-integration-scripting.xsd">
|
||||
|
||||
<service-activator input-channel="inlineScriptInput">
|
||||
<script:script lang="ruby">
|
||||
<![CDATA[
|
||||
return "inline-#{payload}-" + "#{foo}" + " - " + bar + " - " + date
|
||||
]]>
|
||||
<service-activator input-channel="duplicateVariableInput">
|
||||
<script:script lang="ruby" variables="foo=FOO">
|
||||
<script:variable name="foo" value="foo"/>
|
||||
<script:variable name="bar" value="bar"/>
|
||||
<![CDATA[
|
||||
payload
|
||||
]]>
|
||||
</script:script>
|
||||
</service-activator>
|
||||
|
||||
|
||||
</beans:beans>
|
||||
@@ -17,19 +17,21 @@
|
||||
package org.springframework.integration.scripting.config.jsr223;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -72,14 +74,24 @@ public class Jsr223ServiceActivatorTests {
|
||||
String value1 = (String) replyChannel.receive(0).getPayload();
|
||||
String value2 = (String) replyChannel.receive(0).getPayload();
|
||||
String value3 = (String) replyChannel.receive(0).getPayload();
|
||||
assertTrue(value1.startsWith("python-test-1-foo - bar"));
|
||||
assertTrue(value2.startsWith("python-test-2-foo - bar"));
|
||||
assertTrue(value3.startsWith("python-test-3-foo - bar"));
|
||||
assertTrue(value1.startsWith("python-test-1-foo (foo2) - bar"));
|
||||
assertTrue(value2.startsWith("python-test-2-foo (foo2) - bar"));
|
||||
assertTrue(value3.startsWith("python-test-3-foo (foo2) - bar"));
|
||||
|
||||
// because 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)));
|
||||
assertFalse(value1.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))
|
||||
.equals(value2.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))));
|
||||
assertFalse(value1.substring(value1.indexOf(":") +1, value1.lastIndexOf(":"))
|
||||
.equals(value1.substring(value1.lastIndexOf(":"))));
|
||||
|
||||
assertFalse(value2.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))
|
||||
.equals(value3.substring(value1.indexOf(":") + 1, value1.lastIndexOf(":"))));
|
||||
|
||||
assertFalse(value1.substring(value1.lastIndexOf(":") + 1)
|
||||
.equals(value2.substring(value1.lastIndexOf(":") + 1)));
|
||||
assertFalse(value2.substring(value1.lastIndexOf(":") + 1)
|
||||
.equals(value3.substring(value1.lastIndexOf(":") + 1)));
|
||||
|
||||
assertNull(replyChannel.receive(0));
|
||||
}
|
||||
@@ -118,22 +130,41 @@ public class Jsr223ServiceActivatorTests {
|
||||
Message<?> message = MessageBuilder.withPayload("test-" + i).setReplyChannel(replyChannel).build();
|
||||
this.inlineScriptInput.send(message);
|
||||
}
|
||||
assertEquals("inline-test-1", replyChannel.receive(0).getPayload());
|
||||
assertEquals("inline-test-2", replyChannel.receive(0).getPayload());
|
||||
assertEquals("inline-test-3", replyChannel.receive(0).getPayload());
|
||||
String payload = (String) replyChannel.receive(0).getPayload();
|
||||
|
||||
assertThat(payload, Matchers.startsWith("inline-test-1 - FOO"));
|
||||
|
||||
payload = (String) replyChannel.receive(0).getPayload();
|
||||
assertThat(payload, Matchers.startsWith("inline-test-2 - FOO"));
|
||||
|
||||
payload = (String) replyChannel.receive(0).getPayload();
|
||||
assertThat(payload, Matchers.startsWith("inline-test-3 - FOO"));
|
||||
assertTrue(payload.substring(payload.indexOf(":") + 1).matches(".+\\d{2}:\\d{2}:\\d{2}.+"));
|
||||
|
||||
assertNull(replyChannel.receive(0));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
public void inlineScriptAndVariables() throws Exception {
|
||||
new ClassPathXmlApplicationContext("Jsr223ServiceActivatorTests-fail-context.xml", this.getClass());
|
||||
@Test
|
||||
public void variablesAndScriptVariableGenerator() throws Exception {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("Jsr223ServiceActivatorTests-fail-withgenerator-context.xml", this.getClass());
|
||||
fail("BeansException expected.");
|
||||
}
|
||||
catch (BeansException e) {
|
||||
assertThat(e.getMessage(), Matchers.containsString("'script-variable-generator' and 'variable' sub-elements are mutually exclusive."));
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
public void variablesAndScriptVariableGenerator() throws Exception {
|
||||
new ClassPathXmlApplicationContext("Jsr223ServiceActivatorTests-fail-withgenerator-context.xml",
|
||||
this.getClass());
|
||||
@Test
|
||||
public void testDuplicateVariable() throws Exception {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("Jsr223ServiceActivatorTests-fail-duplicated-variable-context.xml", this.getClass());
|
||||
fail("BeansException expected.");
|
||||
}
|
||||
catch (BeansException e) {
|
||||
assertThat(e.getMessage(), Matchers.containsString("Duplicated variable: foo"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class SampleScriptVariSource implements ScriptVariableGenerator {
|
||||
|
||||
@@ -1 +1 @@
|
||||
"python-%s-%s - %s - %s" %(payload,foo,bar,date)
|
||||
"python-%s-%s (%s) - %s - :%s:%s" %(payload,foo,foo2,bar,date,date2)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
@@ -19,6 +19,9 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
@@ -31,42 +34,45 @@ import org.springframework.scripting.support.ResourceScriptSource;
|
||||
*
|
||||
*/
|
||||
public class Jsr223ScriptExecutingMessageProcessorTests {
|
||||
|
||||
ScriptExecutor executor;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
executor = ScriptExecutorFactory.getScriptExecutor("jruby");
|
||||
}
|
||||
@Test
|
||||
public void testExecuteWithVariables(){
|
||||
|
||||
|
||||
Map<String,Object> vars = new HashMap<String,Object>();
|
||||
vars.put("one",1);
|
||||
vars.put("two","two");
|
||||
vars.put("three", new Integer(3));
|
||||
|
||||
vars.put("three", 3);
|
||||
|
||||
ScriptSource scriptSource = new ResourceScriptSource(new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb"));
|
||||
|
||||
ScriptExecutingMessageProcessor messageProcessor = new ScriptExecutingMessageProcessor(scriptSource,executor,vars);
|
||||
|
||||
|
||||
ScriptExecutingMessageProcessor messageProcessor = new ScriptExecutingMessageProcessor(scriptSource, executor, vars);
|
||||
messageProcessor.setBeanFactory(Mockito.mock(BeanFactory.class));
|
||||
|
||||
Message<?> message = new GenericMessage<String>("hello");
|
||||
|
||||
|
||||
Object obj = messageProcessor.processMessage(message);
|
||||
|
||||
|
||||
assertEquals("hello modified",obj.toString().substring(0,"hello modified".length()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithNoVars(){
|
||||
ScriptSource scriptSource = new ResourceScriptSource(new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb"));
|
||||
|
||||
ScriptExecutingMessageProcessor messageProcessor = new ScriptExecutingMessageProcessor(scriptSource,executor);
|
||||
|
||||
|
||||
ScriptExecutingMessageProcessor messageProcessor = new ScriptExecutingMessageProcessor(scriptSource, executor);
|
||||
messageProcessor.setBeanFactory(Mockito.mock(BeanFactory.class));
|
||||
|
||||
Message<?> message = new GenericMessage<String>("hello");
|
||||
|
||||
|
||||
Object obj = messageProcessor.processMessage(message);
|
||||
|
||||
|
||||
assertEquals("hello modified",obj.toString().substring(0,"hello modified".length()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user