diff --git a/docs/src/reference/docbook/event.xml b/docs/src/reference/docbook/event.xml
index 29aa0217fc..0e0952da8b 100644
--- a/docs/src/reference/docbook/event.xml
+++ b/docs/src/reference/docbook/event.xml
@@ -34,7 +34,8 @@
In the above example, all Application Context events that match one of the types specified by the 'event-types' (optional) attribute will be
delivered as Spring Integration Messages to the Message Channel named 'eventChannel'. If a downstream component throws
an exception, a MessagingException containing the failed message and exception will be sent to the channel named
-'eventErrorChannel'. If no "error-channel" is specified, the exception will be propagated to the caller.
+'eventErrorChannel'. If no "error-channel" is specified and the downstream channels are synchronous, the Exception
+will be propagated to the caller.
diff --git a/docs/src/reference/docbook/ip.xml b/docs/src/reference/docbook/ip.xml
index f8a5f7c8f5..001063f497 100644
--- a/docs/src/reference/docbook/ip.xml
+++ b/docs/src/reference/docbook/ip.xml
@@ -808,7 +808,7 @@
error-channel
- If a synchronous Exception is thrown by a downstream
+ If an Exception is thrown by a downstream
component, the MessagingException message containing the exception
and failed message is sent to this channel.
@@ -964,7 +964,7 @@
error-channel
- If a synchronous Exception is thrown by a downstream
+ If an Exception is thrown by a downstream
component, the MessagingException message containing the exception
and failed message is sent to this channel.
@@ -1043,7 +1043,7 @@
error-channel
- If a synchronous Exception is thrown by a downstream
+ If an Exception is thrown by a downstream
component, the MessagingException message containing the exception
and failed message is sent to this channel;
any reply from that flow will then be returned as a response by
diff --git a/docs/src/reference/docbook/mail.xml b/docs/src/reference/docbook/mail.xml
index b4a5585574..1382a66cc4 100644
--- a/docs/src/reference/docbook/mail.xml
+++ b/docs/src/reference/docbook/mail.xml
@@ -158,9 +158,10 @@
Finally, the <imap-idle-channel-adapter/> also accepts the 'error-channel' attribute.
- If a synchronous downstream exception is thrown and an 'error-channel' is specified,
- the MessagingException containing the failed message and exception, will be sent to this channel.
- Otherwise, any such exception will simply be logged as a warning by the channel adapter.
+ If a downstream exception is thrown and an 'error-channel' is specified,
+ a MessagingException message containing the failed message and exception, will be sent to this channel.
+ Otherwise, if the downstream channels are synchronous, any such exception will simply be logged as a
+ warning by the channel adapter.
diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/synchronization/AbstractInboundRemoteFileSystemSychronizer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/synchronizer/AbstractInboundFileSynchronizer.java
similarity index 93%
rename from spring-integration-file/src/main/java/org/springframework/integration/file/synchronization/AbstractInboundRemoteFileSystemSychronizer.java
rename to spring-integration-file/src/main/java/org/springframework/integration/file/synchronizer/AbstractInboundFileSynchronizer.java
index 1e8e32bdeb..fded0f1157 100644
--- a/spring-integration-file/src/main/java/org/springframework/integration/file/synchronization/AbstractInboundRemoteFileSystemSychronizer.java
+++ b/spring-integration-file/src/main/java/org/springframework/integration/file/synchronizer/AbstractInboundFileSynchronizer.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.integration.file.synchronization;
+package org.springframework.integration.file.synchronizer;
import java.util.Arrays;
import java.util.List;
@@ -23,7 +23,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
-import org.springframework.core.io.Resource;
import org.springframework.integration.file.filters.FileListFilter;
/**
@@ -36,7 +35,7 @@ import org.springframework.integration.file.filters.FileListFilter;
*
* @author Josh Long
*/
-public abstract class AbstractInboundRemoteFileSystemSychronizer implements InitializingBean {
+public abstract class AbstractInboundFileSynchronizer implements InboundFileSynchronizer, InitializingBean {
protected final Log logger = LogFactory.getLog(this.getClass());
@@ -94,11 +93,6 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer implements I
return (this.filter != null) ? this.filter.filterFiles(files) : Arrays.asList(files);
}
- /**
- * This is the callback where the subclasses must synchronize.
- */
- protected abstract void syncRemoteToLocalFileSystem(Resource localDirectory);
-
/**
* Strategy interface to expose a hook for dispatching, moving, or deleting
diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/synchronization/AbstractInboundRemoteFileSystemSynchronizingMessageSource.java b/spring-integration-file/src/main/java/org/springframework/integration/file/synchronizer/AbstractInboundFileSynchronizingMessageSource.java
similarity index 92%
rename from spring-integration-file/src/main/java/org/springframework/integration/file/synchronization/AbstractInboundRemoteFileSystemSynchronizingMessageSource.java
rename to spring-integration-file/src/main/java/org/springframework/integration/file/synchronizer/AbstractInboundFileSynchronizingMessageSource.java
index b376921d05..424054b4d6 100644
--- a/spring-integration-file/src/main/java/org/springframework/integration/file/synchronization/AbstractInboundRemoteFileSystemSynchronizingMessageSource.java
+++ b/spring-integration-file/src/main/java/org/springframework/integration/file/synchronizer/AbstractInboundFileSynchronizingMessageSource.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.integration.file.synchronization;
+package org.springframework.integration.file.synchronizer;
import java.io.File;
import java.io.FileNotFoundException;
@@ -47,14 +47,13 @@ import org.springframework.util.Assert;
* specific).
*
* This class is to be used as a pair with an implementation of
- * {@link AbstractInboundRemoteFileSystemSychronizer}. The synchronizer must
+ * {@link AbstractInboundFileSynchronizer}. The synchronizer must
* handle the work of actually connecting to the remote file system and
* delivering new {@link File}s.
*
* @author Josh Long
*/
-public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource>
- extends MessageProducerSupport implements MessageSource {
+public abstract class AbstractInboundFileSynchronizingMessageSource extends MessageProducerSupport implements MessageSource {
/**
* Extension used when downloading files. We change it right after we know it's downloaded.
@@ -71,7 +70,7 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
* An implementation that will handle the chores of actually connecting to and synching up
* the remote file system with the local one, in an inbound direction.
*/
- protected volatile S synchronizer;
+ protected volatile AbstractInboundFileSynchronizer synchronizer;
/**
* Directory to which things should be synched locally.
@@ -93,7 +92,7 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
this.autoCreateDirectories = autoCreateDirectories;
}
- public void setSynchronizer(S synchronizer) {
+ public void setSynchronizer(AbstractInboundFileSynchronizer synchronizer) {
this.synchronizer = synchronizer;
}
@@ -151,7 +150,7 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
Assert.state(this.synchronizer != null, "synchronizer must not be null");
Message message = this.fileSource.receive();
if (message == null) {
- this.synchronizer.syncRemoteToLocalFileSystem(this.localDirectory);
+ this.synchronizer.synchronizeToLocalDirectory(this.localDirectory);
message = this.fileSource.receive();
}
return message;
diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/synchronizer/InboundFileSynchronizer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/synchronizer/InboundFileSynchronizer.java
new file mode 100644
index 0000000000..7f87881767
--- /dev/null
+++ b/spring-integration-file/src/main/java/org/springframework/integration/file/synchronizer/InboundFileSynchronizer.java
@@ -0,0 +1,31 @@
+/*
+ * 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.file.synchronizer;
+
+import org.springframework.core.io.Resource;
+
+/**
+ * Strategy for synchronizing from a remote File system to a local directory.
+ *
+ * @author Mark Fisher
+ * @since 2.0
+ */
+public interface InboundFileSynchronizer {
+
+ void synchronizeToLocalDirectory(Resource localDirectory);
+
+}
diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizer.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizer.java
index bec09acbac..169da302ec 100644
--- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizer.java
+++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizer.java
@@ -29,8 +29,8 @@ import org.apache.commons.net.ftp.FTPFile;
import org.springframework.core.io.Resource;
import org.springframework.integration.MessagingException;
-import org.springframework.integration.file.synchronization.AbstractInboundRemoteFileSystemSychronizer;
-import org.springframework.integration.file.synchronization.AbstractInboundRemoteFileSystemSynchronizingMessageSource;
+import org.springframework.integration.file.synchronizer.AbstractInboundFileSynchronizer;
+import org.springframework.integration.file.synchronizer.AbstractInboundFileSynchronizingMessageSource;
import org.springframework.integration.ftp.client.FtpClientPool;
import org.springframework.util.Assert;
@@ -40,7 +40,7 @@ import org.springframework.util.Assert;
* @author Iwein Fuld
* @author Josh Long
*/
-public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemoteFileSystemSychronizer {
+public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundFileSynchronizer {
private volatile FtpClientPool clientPool;
@@ -54,15 +54,14 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
this.clientPool = clientPool;
}
- public void afterPropertiesSet() throws Exception {
+ public void afterPropertiesSet() {
Assert.notNull(this.clientPool, "clientPool must not be null");
if (this.shouldDeleteSourceFile) {
this.setEntryAcknowledgmentStrategy(new DeletionEntryAcknowledgmentStrategy());
}
}
- @Override
- protected void syncRemoteToLocalFileSystem(Resource localDirectory) {
+ public void synchronizeToLocalDirectory(Resource localDirectory) {
try {
FTPClient client = this.clientPool.getClient();
Assert.state(client != null,
@@ -93,7 +92,7 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
String localFileName = localDirectory.getFile().getPath() + "/" + remoteFileName;
File localFile = new File(localFileName);
if (!localFile.exists()) {
- String tempFileName = localFileName + AbstractInboundRemoteFileSystemSynchronizingMessageSource.INCOMPLETE_EXTENSION;
+ String tempFileName = localFileName + AbstractInboundFileSynchronizingMessageSource.INCOMPLETE_EXTENSION;
File file = new File(tempFileName);
FileOutputStream fos = new FileOutputStream(file);
try {
@@ -122,7 +121,7 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
/**
* An acknowledgment strategy that deletes the file.
*/
- private static class DeletionEntryAcknowledgmentStrategy implements AbstractInboundRemoteFileSystemSychronizer.EntryAcknowledgmentStrategy {
+ private static class DeletionEntryAcknowledgmentStrategy implements EntryAcknowledgmentStrategy {
private final Log logger = LogFactory.getLog(this.getClass());
diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizingMessageSource.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizingMessageSource.java
index 9149f67d24..199a07fab8 100644
--- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizingMessageSource.java
+++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizingMessageSource.java
@@ -18,7 +18,8 @@ package org.springframework.integration.ftp.inbound;
import org.apache.commons.net.ftp.FTPFile;
-import org.springframework.integration.file.synchronization.AbstractInboundRemoteFileSystemSynchronizingMessageSource;
+import org.springframework.integration.file.synchronizer.AbstractInboundFileSynchronizer;
+import org.springframework.integration.file.synchronizer.AbstractInboundFileSynchronizingMessageSource;
import org.springframework.integration.ftp.client.FtpClientPool;
/**
@@ -27,8 +28,7 @@ import org.springframework.integration.ftp.client.FtpClientPool;
* @author Iwein Fuld
* @author Josh Long
*/
-public class FtpInboundRemoteFileSystemSynchronizingMessageSource
- extends AbstractInboundRemoteFileSystemSynchronizingMessageSource {
+public class FtpInboundRemoteFileSystemSynchronizingMessageSource extends AbstractInboundFileSynchronizingMessageSource {
private volatile FtpClientPool clientPool;
@@ -41,10 +41,17 @@ public class FtpInboundRemoteFileSystemSynchronizingMessageSource
return "ftp:inbound-channel-adapter";
}
+ @Override
+ public void setSynchronizer(AbstractInboundFileSynchronizer synchronizer) {
+ super.setSynchronizer(synchronizer);
+ }
+
@Override
protected void onInit() {
super.onInit();
- this.synchronizer.setClientPool(this.clientPool);
+ if (this.synchronizer instanceof FtpInboundRemoteFileSystemSynchronizer) {
+ ((FtpInboundRemoteFileSystemSynchronizer) this.synchronizer).setClientPool(this.clientPool);
+ }
}
}
diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizerTest.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizerTest.java
index a30b802147..57ab7bfd58 100644
--- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizerTest.java
+++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/inbound/FtpInboundRemoteFileSystemSynchronizerTest.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.integration.ftp.inbound;
import static org.mockito.Mockito.mock;
@@ -71,7 +72,7 @@ public class FtpInboundRemoteFileSystemSynchronizerTest {
syncronizer.afterPropertiesSet();
Resource localDirectory = new FileSystemResource(System.getProperty("java.io.tmpdir"));
- syncronizer.syncRemoteToLocalFileSystem(localDirectory);
+ syncronizer.synchronizeToLocalDirectory(localDirectory);
verify(ftpClient, times(1)).retrieveFile(Mockito.anyString(), Mockito.any(OutputStream.class));
verify(ftpClient, times(1)).deleteFile(Mockito.anyString());
diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizer.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizer.java
index 61746e20e5..1f4dc83a8f 100644
--- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizer.java
+++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundSynchronizer.java
@@ -25,8 +25,8 @@ import org.apache.commons.io.IOUtils;
import org.springframework.core.io.Resource;
import org.springframework.integration.MessagingException;
-import org.springframework.integration.file.synchronization.AbstractInboundRemoteFileSystemSychronizer;
-import org.springframework.integration.file.synchronization.AbstractInboundRemoteFileSystemSynchronizingMessageSource;
+import org.springframework.integration.file.synchronizer.AbstractInboundFileSynchronizer;
+import org.springframework.integration.file.synchronizer.AbstractInboundFileSynchronizingMessageSource;
import org.springframework.integration.sftp.session.SftpSession;
import org.springframework.integration.sftp.session.SftpSessionFactory;
import org.springframework.util.Assert;
@@ -40,7 +40,7 @@ import com.jcraft.jsch.ChannelSftp;
* @author Oleg Zhurakousky
* @since 2.0
*/
-public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSychronizer {
+public class SftpInboundSynchronizer extends AbstractInboundFileSynchronizer {
/**
* the path on the remote mount
@@ -107,9 +107,8 @@ public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSych
return false;
}
- @Override
@SuppressWarnings("unchecked")
- protected void syncRemoteToLocalFileSystem(Resource localDirectory) {
+ public void synchronizeToLocalDirectory(Resource localDirectory) {
SftpSession session = null;
try {
session = this.sessionFactory.getSession();
@@ -147,7 +146,7 @@ public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSych
FileOutputStream fileOutputStream = null;
try {
File tmpLocalTarget = new File(localFile.getAbsolutePath() +
- AbstractInboundRemoteFileSystemSynchronizingMessageSource.INCOMPLETE_EXTENSION);
+ AbstractInboundFileSynchronizingMessageSource.INCOMPLETE_EXTENSION);
fileOutputStream = new FileOutputStream(tmpLocalTarget);
String remoteFqPath = this.remotePath + "/" + entry.getFilename();
in = sftpSession.get(remoteFqPath);
@@ -178,7 +177,7 @@ public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSych
}
- private class DeletionEntryAcknowledgmentStrategy implements AbstractInboundRemoteFileSystemSychronizer.EntryAcknowledgmentStrategy {
+ private class DeletionEntryAcknowledgmentStrategy implements AbstractInboundFileSynchronizer.EntryAcknowledgmentStrategy {
public void acknowledge(Object useful, ChannelSftp.LsEntry msg) throws Exception {
SftpSession sftpSession = (SftpSession) useful;
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 996cad5bf4..14e16867cd 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
@@ -21,7 +21,7 @@ import java.util.regex.Pattern;
import org.springframework.integration.MessagingException;
import org.springframework.integration.file.FileReadingMessageSource;
-import org.springframework.integration.file.synchronization.AbstractInboundRemoteFileSystemSynchronizingMessageSource;
+import org.springframework.integration.file.synchronizer.AbstractInboundFileSynchronizingMessageSource;
import org.springframework.integration.sftp.filters.SftpPatternMatchingFileListFilter;
import com.jcraft.jsch.ChannelSftp;
@@ -33,8 +33,7 @@ import com.jcraft.jsch.ChannelSftp;
* @author Oleg Zhurakousky
* @since 2.0
*/
-public class SftpInboundSynchronizingMessageSource
- extends AbstractInboundRemoteFileSystemSynchronizingMessageSource {
+public class SftpInboundSynchronizingMessageSource extends AbstractInboundFileSynchronizingMessageSource {
private volatile Pattern filenamePattern;
@@ -68,7 +67,9 @@ public class SftpInboundSynchronizingMessageSource
if (this.filenamePattern != null) {
SftpPatternMatchingFileListFilter filter = new SftpPatternMatchingFileListFilter(this.filenamePattern);
this.synchronizer.setFilter(filter);
- this.synchronizer.setAutoCreateDirectories(this.autoCreateDirectories);
+ if (this.synchronizer instanceof SftpInboundSynchronizer) {
+ ((SftpInboundSynchronizer) this.synchronizer).setAutoCreateDirectories(this.autoCreateDirectories);
+ }
}
}
catch (RuntimeException e) {
diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/impl/SftpInboundRemoteFileSystemSynchronizerTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/impl/SftpInboundRemoteFileSystemSynchronizerTests.java
index e0044babae..376326d06c 100644
--- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/impl/SftpInboundRemoteFileSystemSynchronizerTests.java
+++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/impl/SftpInboundRemoteFileSystemSynchronizerTests.java
@@ -27,7 +27,7 @@ import org.junit.Test;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
-import org.springframework.integration.file.synchronization.AbstractInboundRemoteFileSystemSychronizer.EntryAcknowledgmentStrategy;
+import org.springframework.integration.file.synchronizer.AbstractInboundFileSynchronizer.EntryAcknowledgmentStrategy;
import org.springframework.integration.sftp.inbound.SftpInboundSynchronizer;
import org.springframework.integration.sftp.session.SftpSession;
import org.springframework.integration.sftp.session.SftpSessionFactory;
diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/inbound/SftpInboundRemoteFileSystemSynchronizerTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/inbound/SftpInboundRemoteFileSystemSynchronizerTests.java
index 1c8b6ae7ff..43bd805eaf 100644
--- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/inbound/SftpInboundRemoteFileSystemSynchronizerTests.java
+++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/inbound/SftpInboundRemoteFileSystemSynchronizerTests.java
@@ -16,6 +16,7 @@
package org.springframework.integration.sftp.inbound;
+import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -23,11 +24,13 @@ import static org.mockito.Mockito.when;
import java.io.File;
import java.io.FileInputStream;
+import java.io.InputStream;
import java.util.Vector;
-import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
@@ -47,7 +50,6 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
- @Ignore
public void testCopyFileToLocalDir() throws Exception {
File file = new File(System.getProperty("java.io.tmpdir") + "/foo.txt");
if (file.exists()){
@@ -65,7 +67,7 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
SftpSession sftpSession = mock(SftpSession.class);
when(sessionFactory.getSession()).thenReturn(sftpSession);
- ChannelSftp channel = mock(ChannelSftp.class);
+ final ChannelSftp channel = mock(ChannelSftp.class);
when(channel.get((String) Mockito.any())).thenReturn(new FileInputStream(new File("template.mf")));
Vector entries = new Vector();
LsEntry entry = mock(LsEntry.class);
@@ -77,14 +79,24 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
entries.add(entry);
when(channel.ls("foo/bar")).thenReturn(entries);
when(filter.filterFiles((Object[]) Mockito.any())).thenReturn(entries);
+
+ when(sftpSession.get(Mockito.anyString())).thenAnswer(new Answer() {
+ public InputStream answer(InvocationOnMock invocation)
+ throws Throwable {
+ String filePath = (String) invocation.getArguments()[0];
+ return channel.get(filePath);
+ }
+ });
syncronizer.setShouldDeleteSourceFile(true);
syncronizer.afterPropertiesSet();
Resource localDirectory = new FileSystemResource(System.getProperty("java.io.tmpdir"));
- syncronizer.syncRemoteToLocalFileSystem(localDirectory);
+ syncronizer.synchronizeToLocalDirectory(localDirectory);
verify(sessionFactory, times(1)).getSession();
+ verify(attr, atLeast(1)).isDir();
// will add more validation, but for now this test is mainly to get the test coverage up
}
+
}