From d38027951d6569341b94922ca7fbec779570cf77 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Tue, 16 Nov 2010 14:04:56 -0500 Subject: [PATCH] INT-1614 added fileNameGenerator attribute to teh SFTP outbound, added tests --- ...boundChannelAdapterParserTests-context.xml | 11 -------- .../FtpOutboundChannelAdapterParserTests.java | 3 --- .../sftp/config/SftpNamespaceHandler.java | 1 + .../SftpSendingMessageHandlerFactoryBean.java | 9 +++++++ .../config/spring-integration-sftp-2.0.xsd | 14 +++++++++- ...oundChannelAdapaterParserTests-context.xml | 12 +++++++++ .../OutboundChannelAdapaterParserTests.java | 27 ++++++++++++++++++- 7 files changed, 61 insertions(+), 16 deletions(-) diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml index db5f7ccf34..a4867b9940 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml @@ -7,17 +7,6 @@ http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-2.0.xsd"> - - - - - - - - - - - diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests.java index 4bfc0e13eb..a9bd0565d9 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests.java +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests.java @@ -52,8 +52,5 @@ public class FtpOutboundChannelAdapterParserTests { FtpClientFactory clientFactory = (FtpClientFactory) TestUtils.getPropertyValue(clientPoll, "factory"); assertEquals("localhost", TestUtils.getPropertyValue(clientFactory, "host")); assertEquals(22, TestUtils.getPropertyValue(clientFactory, "port")); -// assertEquals("user", TestUtils.getPropertyValue(clientFactory, "username")); -// assertEquals("password", TestUtils.getPropertyValue(clientFactory, "password")); -// assertEquals("foo/bar", TestUtils.getPropertyValue(clientFactory, "remoteWorkingDirectory")); } } diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java index be93425eb1..2bd3e9f798 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java @@ -76,6 +76,7 @@ public class SftpNamespaceHandler extends AbstractIntegrationNamespaceHandler { for (String p : "charset".split(",")) { IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, p); } + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "filename-generator", "fileNameGenerator"); String remoteDirectory = element.getAttribute("remote-directory"); String remoteDirectoryExpression = element.getAttribute("remote-directory-expression"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "session-factory", "sftpSessionFactory"); diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpSendingMessageHandlerFactoryBean.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpSendingMessageHandlerFactoryBean.java index 804f8b6f4c..63b326399a 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpSendingMessageHandlerFactoryBean.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpSendingMessageHandlerFactoryBean.java @@ -19,6 +19,7 @@ package org.springframework.integration.sftp.config; import org.springframework.beans.factory.FactoryBean; import org.springframework.expression.Expression; import org.springframework.expression.common.LiteralExpression; +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; @@ -38,6 +39,12 @@ class SftpSendingMessageHandlerFactoryBean implements FactoryBean + + + + Allows you to specify a reference to + [org.springframework.integration.file.FileNameGenerator] implementation. + + + + + + + + - diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/OutboundChannelAdapaterParserTests-context.xml b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/OutboundChannelAdapaterParserTests-context.xml index 234951e89d..1cb67141ed 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/OutboundChannelAdapaterParserTests-context.xml +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/OutboundChannelAdapaterParserTests-context.xml @@ -24,5 +24,17 @@ session-factory="sftpSessionFactory" channel="inputChannel" charset="UTF-8" + filename-generator="fileNameGenerator" remote-directory="foo/bar"/> + + + + + + + diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/OutboundChannelAdapaterParserTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/OutboundChannelAdapaterParserTests.java index 92b6b11084..44e0b9d242 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/OutboundChannelAdapaterParserTests.java +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/OutboundChannelAdapaterParserTests.java @@ -3,10 +3,16 @@ */ package org.springframework.integration.sftp.config; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; + import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.endpoint.EventDrivenConsumer; +import org.springframework.integration.sftp.outbound.SftpSendingMessageHandler; +import org.springframework.integration.test.util.TestUtils; /** * @author ozhurakousky @@ -15,7 +21,26 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; public class OutboundChannelAdapaterParserTests { @Test - public void test(){ + public void testOutboundChannelAdapaterWithId(){ + ApplicationContext context = + new ClassPathXmlApplicationContext("OutboundChannelAdapaterParserTests-context.xml", this.getClass()); + Object consumer = context.getBean("sftpOutboundAdapter"); + assertTrue(consumer instanceof EventDrivenConsumer); + assertEquals(context.getBean("inputChannel"), TestUtils.getPropertyValue(consumer, "inputChannel")); + assertEquals("sftpOutboundAdapter", ((EventDrivenConsumer)consumer).getComponentName()); + SftpSendingMessageHandler handler = (SftpSendingMessageHandler) TestUtils.getPropertyValue(consumer, "handler"); + assertEquals(context.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "fileNameGenerator")); + assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "charset")); +// assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolder")); +// assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolderFile")); +// FtpClientPool clientPoll = (FtpClientPool) TestUtils.getPropertyValue(handler, "ftpClientPool"); +// FtpClientFactory clientFactory = (FtpClientFactory) TestUtils.getPropertyValue(clientPoll, "factory"); +// assertEquals("localhost", TestUtils.getPropertyValue(clientFactory, "host")); +// assertEquals(22, TestUtils.getPropertyValue(clientFactory, "port")); + } + + @Test + public void testOutboundChannelAdapaterWithNoId(){ ApplicationContext context = new ClassPathXmlApplicationContext("OutboundChannelAdapaterParserTests-context.xml", this.getClass()); }