INT-1631 added failure test cases for mutually exclusive attributes for inbound and outbound, added test case for injecting Pattern as a bean
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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">
|
||||
<poller fixed-rate="1000"/>
|
||||
</sftp:inbound-channel-adapter>
|
||||
|
||||
<beans:bean id="filter" class="org.mockito.Mockito" factory-method="mock">
|
||||
<beans:constructor-arg value="org.springframework.integration.file.entries.EntryListFilter"/>
|
||||
<beans:bean id="filter" class="org.springframework.integration.sftp.filters.SftpPatternMatchingFileListFilter">
|
||||
<beans:constructor-arg value="."/>
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<beans:bean id="pattern" class="java.util.regex.Pattern" factory-method="compile">
|
||||
<beans:constructor-arg value="."/>
|
||||
</beans:bean>
|
||||
|
||||
<beans:bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.SftpSessionFactory">
|
||||
<beans:property name="host" value="loclahost"/>
|
||||
<beans:property name="knownHosts" value="local, foo.com, bar.foo"/>
|
||||
@@ -54,9 +58,21 @@
|
||||
<poller fixed-rate="1000"/>
|
||||
</sftp:inbound-channel-adapter>
|
||||
|
||||
<sftp:inbound-channel-adapter id="sftpAdapterWithPattern"
|
||||
session-factory="sftpSessionFactory"
|
||||
channel="requestChannel"
|
||||
filename-pattern="pattern"
|
||||
remote-directory="/foo"
|
||||
local-directory="file:local-test-dir"
|
||||
auto-create-directories="false"
|
||||
auto-delete-remote-files-on-sync="false">
|
||||
<poller fixed-rate="1000"/>
|
||||
</sftp:inbound-channel-adapter>
|
||||
|
||||
|
||||
<beans:bean id="filter" class="org.springframework.integration.sftp.filters.SftpPatternMatchingFileListFilter">
|
||||
<beans:constructor-arg value="."/>
|
||||
</beans:bean>
|
||||
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user