INT-1631 added remote-file-generator attribute to te outbound adapter, final polishing 76.4% coverage
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-2.0.xsd">
|
||||
|
||||
|
||||
<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.SftpSessionFactory">
|
||||
<property name="host" value="localhost"/>
|
||||
<property name="knownHosts" value="local, foo.com, bar.foo"/>
|
||||
<property name="privateKey" value="classpath:org/springframework/integration/sftp/config/sftpTest"/>
|
||||
<property name="privateKeyPassphrase" value="ghj"/>
|
||||
<property name="password" value="hello"/>
|
||||
<property name="port" value="2222"/>
|
||||
<property name="user" value="oleg"/>
|
||||
</bean>
|
||||
|
||||
<int:channel id="inputChannel"/>
|
||||
|
||||
<int-sftp:outbound-channel-adapter id="sftpOutboundAdapterWithExpression"
|
||||
session-factory="sftpSessionFactory"
|
||||
channel="inputChannel"
|
||||
charset="UTF-8"
|
||||
filename-generator="fileNameGenerator"
|
||||
remote-directory-expression="'foo' + '/' + 'bar'"
|
||||
remote-file-expression="payload.getName() + '-foo'"/>
|
||||
|
||||
|
||||
<bean id="fileNameGenerator" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.springframework.integration.file.FileNameGenerator"/>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -31,8 +31,8 @@
|
||||
session-factory="sftpSessionFactory"
|
||||
channel="inputChannel"
|
||||
charset="UTF-8"
|
||||
filename-generator="fileNameGenerator"
|
||||
remote-directory-expression="'foo' + '/' + 'bar'"/>
|
||||
remote-directory-expression="'foo' + '/' + 'bar'"
|
||||
remote-file-expression="payload.getName() + '-foo'"/>
|
||||
|
||||
<int-sftp:outbound-channel-adapter
|
||||
session-factory="sftpSessionFactory"
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.file.FileNameGenerator;
|
||||
import org.springframework.integration.sftp.outbound.SftpSendingMessageHandler;
|
||||
import org.springframework.integration.sftp.session.QueuedSftpSessionPool;
|
||||
import org.springframework.integration.sftp.session.SftpSessionFactory;
|
||||
@@ -62,7 +63,7 @@ public class OutboundChannelAdapaterParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutboundChannelAdapaterWithWithRemoteDirectoryExopression(){
|
||||
public void testOutboundChannelAdapaterWithWithRemoteDirectoryAndFileExpression(){
|
||||
ApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("OutboundChannelAdapaterParserTests-context.xml", this.getClass());
|
||||
Object consumer = context.getBean("sftpOutboundAdapterWithExpression");
|
||||
@@ -73,15 +74,24 @@ public class OutboundChannelAdapaterParserTests {
|
||||
SpelExpression remoteDirectoryExpression = (SpelExpression) TestUtils.getPropertyValue(handler, "remoteDirectoryExpression");
|
||||
assertNotNull(remoteDirectoryExpression);
|
||||
assertEquals("'foo' + '/' + 'bar'", remoteDirectoryExpression.getExpressionString());
|
||||
assertEquals(context.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "filenameGenerator"));
|
||||
FileNameGenerator generator = (FileNameGenerator) TestUtils.getPropertyValue(handler, "filenameGenerator");
|
||||
String fileNameGeneratorExpression = (String) TestUtils.getPropertyValue(generator, "expression");
|
||||
assertEquals("payload.getName() + '-foo'", fileNameGeneratorExpression);
|
||||
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "charset"));
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolder"));
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolderFile"));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testFailWithRemoteDirAndExpression(){
|
||||
new ClassPathXmlApplicationContext("OutboundChannelAdapaterParserTests-context-fail.xml", this.getClass());
|
||||
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testFailWithFileExpressionAndFileGenerator(){
|
||||
new ClassPathXmlApplicationContext("OutboundChannelAdapaterParserTests-context-fail-fileFileGen.xml", this.getClass());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
session-factory="sftpSessionFactory"
|
||||
channel="inputChannel"
|
||||
charset="UTF-8"
|
||||
remote-file-expression="payload.getName() + '_foo'"
|
||||
remote-directory="/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/spring-integration/spring-integration-sftp/remote-test-dir"/>
|
||||
|
||||
<!-- <int-sftp:outbound-channel-adapter id="sftpOutboundAdapterWithExpression"-->
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
log4j.rootCategory=WARN, stdout
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
|
||||
|
||||
log4j.category.org.springframework=WARN
|
||||
log4j.category.org.springframework.integration.sftp=TRACE
|
||||
Reference in New Issue
Block a user