From c9b663acac96ca8aaad2a830a65705dd361358b5 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 17 Nov 2010 21:01:45 -0500 Subject: [PATCH] INT-1631 added failure test cases for mutually exclusive attributes for inbound and outbound, added test case for injecting Pattern as a bean --- .../config/SftpInboundChannelAdapterParser.java | 9 ++++++++- .../SftpInboundSynchronizingMessageSource.java | 8 ++++---- ...ndChannelAdapaterParserTests-context-fail.xml | 7 ++++--- ...InboundChannelAdapaterParserTests-context.xml | 16 ++++++++++++++++ .../InboundChannelAdapaterParserTests.java | 4 +++- .../OutboundChannelAdapaterParserTests.java | 6 ++++++ 6 files changed, 41 insertions(+), 9 deletions(-) diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpInboundChannelAdapterParser.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpInboundChannelAdapterParser.java index a9aabacbeb..814b14635a 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpInboundChannelAdapterParser.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpInboundChannelAdapterParser.java @@ -72,7 +72,14 @@ public class SftpInboundChannelAdapterParser extends AbstractPollingInboundChann messageSourceBuilder.addConstructorArgReference(sessionPollName); messageSourceBuilder.addPropertyValue("synchronizer", synchronizerBuilder.getBeanDefinition()); - IntegrationNamespaceUtils.setValueIfAttributeDefined(messageSourceBuilder, element, "filename-pattern"); + if (hasFileNamePattern){ + if (parserContext.getRegistry().containsBeanDefinition(fileNamePattern)){ + messageSourceBuilder.addPropertyReference("filenamePattern", fileNamePattern); + } + else { + messageSourceBuilder.addPropertyValue("filenamePattern", fileNamePattern); + } + } IntegrationNamespaceUtils.setValueIfAttributeDefined(messageSourceBuilder, element, "auto-create-directories"); IntegrationNamespaceUtils.setValueIfAttributeDefined(messageSourceBuilder, element, "local-directory"); diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizingMessageSource.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizingMessageSource.java index 32515843f5..699f62b993 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizingMessageSource.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizingMessageSource.java @@ -17,6 +17,7 @@ package org.springframework.integration.sftp.inbound; import java.io.File; import java.io.FileNotFoundException; +import java.util.regex.Pattern; import org.springframework.integration.Message; import org.springframework.integration.MessagingException; @@ -51,14 +52,13 @@ public class SftpInboundSynchronizingMessageSource extends */ private volatile String remoteDirectory; - private volatile String filenamePattern; + private volatile Pattern filenamePattern; public SftpInboundSynchronizingMessageSource(SftpSessionPool sessionPool){ this.sessionPool = sessionPool; - System.out.println("###### Constructing"); } - public void setFilenamePattern(String filenamePattern) { + public void setFilenamePattern(Pattern filenamePattern) { this.filenamePattern = filenamePattern; } @@ -170,7 +170,7 @@ public class SftpInboundSynchronizingMessageSource extends + this.getComponentType(), e); } - if (StringUtils.hasText(this.filenamePattern)) { + if (filenamePattern != null) { SftpPatternMatchingFileListFilter sftpFilePatternMatchingEntryListFilter = new SftpPatternMatchingFileListFilter(filenamePattern); this.synchronizer.setFilter(sftpFilePatternMatchingEntryListFilter); diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests-context-fail.xml b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests-context-fail.xml index c76baefb57..37248ef4ff 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests-context-fail.xml +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests-context-fail.xml @@ -34,15 +34,16 @@ channel="requestChannel" session-factory="sftpSessionFactory" filter="filter" - remote-directory="ftp://foo" + filename-pattern="." + remote-directory="/foo" local-directory="file:local-test-dir" auto-create-directories="false" auto-delete-remote-files-on-sync="false"> - - + + diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests-context.xml b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests-context.xml index 9975bf2c86..c1a3c829e7 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests-context.xml +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests-context.xml @@ -22,6 +22,10 @@ + + + + @@ -54,9 +58,21 @@ + + + + + diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests.java index 91339ca08c..add3df9593 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests.java +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapaterParserTests.java @@ -26,6 +26,7 @@ import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.BeanCreationException; +import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.core.PollableChannel; @@ -58,7 +59,8 @@ public class InboundChannelAdapaterParserTests { assertNotNull(requestChannel.receive(2000)); } - @Test(expected=BeanCreationException.class) + @Test(expected=BeanDefinitionStoreException.class) + //exactly one of 'filename-pattern' or 'filter' is allowed on SFTP inbound adapter public void testLocalFilesAutoCreationFalse() throws Exception{ assertTrue(!new File("target/bar").exists()); new ClassPathXmlApplicationContext("InboundChannelAdapaterParserTests-context-fail.xml", this.getClass()); 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 f1fb213f62..6b1363467e 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 @@ -21,6 +21,7 @@ import static junit.framework.Assert.assertTrue; import org.junit.Test; +import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.expression.Expression; @@ -78,4 +79,9 @@ public class OutboundChannelAdapaterParserTests { assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolderFile")); } + @Test(expected=BeanDefinitionStoreException.class) + public void testFailWithRemoteDirAndExpression(){ + new ClassPathXmlApplicationContext("OutboundChannelAdapaterParserTests-context-fail.xml", this.getClass()); + + } }