INT-1432 added tests to validate that localdirectories are auto created if auto-create is set to TRUE or exception is thrown if set to false

This commit is contained in:
Oleg Zhurakousky
2010-09-24 15:39:35 -04:00
parent 361477c40a
commit f8ace52bef
7 changed files with 190 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ import org.springframework.integration.endpoint.MessageProducerSupport;
import org.springframework.integration.file.entries.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.regex.Pattern;
@@ -92,10 +93,14 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
this.synchronizer.setFilter(this.remotePredicate);
}
if (this.autoCreateDirectories) {
if ((this.localDirectory != null) && !this.localDirectory.exists() && this.localDirectory.getFile().mkdirs())
logger.debug("the localDirectory " + this.localDirectory + " doesn't exist");
}
if (this.localDirectory != null && !this.localDirectory.exists()){
if (this.autoCreateDirectories){
logger.debug("The '" + localDirectory + "' directory doesn't exist. Creating " + this.localDirectory);
this.localDirectory.getFile().mkdirs();
} else {
throw new FileNotFoundException(localDirectory.getFilename());
}
}
/**
* Handles making sure the remote files get here in one piece
@@ -118,7 +123,7 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
if (e instanceof RuntimeException){
throw (RuntimeException)e;
} else {
throw new MessagingException("Failure during initialization of " + this.getComponentName(), e);
throw new MessagingException("Failure during initialization of MessageSource for: " + this.getComponentType(), e);
}
}

View File

@@ -15,8 +15,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>

View File

@@ -85,5 +85,9 @@
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -97,7 +97,7 @@
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.ftp.FtpFileListFilter"/>
<tool:expected-type type="org.springframework.integration.file.entries.EntryListFilter"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tool="http://www.springframework.org/schema/tool"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:sftp="http://www.springframework.org/schema/integration/sftp"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-2.0.xsd">
<channel id="requestChannel"/>
<sftp:inbound-channel-adapter id="sftpAdapterNoAutoCreate"
channel="requestChannel"
filter="filter"
filename-pattern="foo*.txt"
username="oleg"
remote-directory="ftp://foo"
local-directory-path="file:target/bar"
host="localhost"
password="hello"
port="1234"
key-file="ker.txt"
key-file-password="hello"
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>
</beans:beans>

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tool="http://www.springframework.org/schema/tool"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:sftp="http://www.springframework.org/schema/integration/sftp"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-2.0.xsd">
<channel id="requestChannel"/>
<sftp:inbound-channel-adapter id="sftpAdapterAutoCreate"
channel="requestChannel"
filter="filter"
filename-pattern="foo*.txt"
username="oleg"
remote-directory="ftp://foo"
local-directory-path="file:target/foo"
host="localhost"
password="hello"
port="1234"
key-file="ker.txt"
key-file-password="hello"
auto-create-directories="true"
auto-delete-remote-files-on-sync="false">
<poller fixed-rate="1000"/>
</sftp:inbound-channel-adapter>
<sftp:inbound-channel-adapter id="sftpAdapter"
channel="requestChannel"
filter="filter"
filename-pattern="foo*.txt"
username="oleg"
remote-directory="ftp://foo"
local-directory-path="file:target"
host="localhost"
password="hello"
port="1234"
key-file="ker.txt"
key-file-password="hello"
auto-create-directories="true"
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>
</beans:beans>

View File

@@ -0,0 +1,63 @@
/*
* Copyright 2002-2010 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.
*/
package org.springframework.integration.sftp;
import static junit.framework.Assert.assertTrue;
import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
*
*/
public class SftpParserTests {
@Before
public void prepare(){
new File("target/foo").delete();
}
@Test
public void testLocalFilesAutoCreationTrue() throws Exception{
assertTrue(!new File("target/foo").exists());
new ClassPathXmlApplicationContext("SftpParserTests-inbound-all.xml", this.getClass());
assertTrue(new File("target/foo").exists());
assertTrue(!new File("target/bar").exists());
}
@Test(expected=BeanCreationException.class)
public void testLocalFilesAutoCreationFalse() throws Exception{
assertTrue(!new File("target/bar").exists());
new ClassPathXmlApplicationContext("SftpParserTests-inbound-all-fail.xml", this.getClass());
}
@Test
public void testLocalFilesAreFound() throws Exception{
assertTrue(new File("target").exists());
new ClassPathXmlApplicationContext("SftpParserTests-inbound-all.xml", this.getClass());
assertTrue(new File("target").exists());
}
@After
public void cleanUp() throws Exception{
new File("target/foo").delete();
}
}