INT-1614 naming changes for synchronizers and the interface's strategy method itself
This commit is contained in:
@@ -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.synchronizer.AbstractInboundRemoteFileSystemSychronizer;
|
||||
import org.springframework.integration.file.synchronizer.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<ChannelSftp.LsEntry> {
|
||||
public class SftpInboundSynchronizer extends AbstractInboundFileSynchronizer<ChannelSftp.LsEntry> {
|
||||
|
||||
/**
|
||||
* 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<ChannelSftp.LsEntry> {
|
||||
private class DeletionEntryAcknowledgmentStrategy implements AbstractInboundFileSynchronizer.EntryAcknowledgmentStrategy<ChannelSftp.LsEntry> {
|
||||
|
||||
public void acknowledge(Object useful, ChannelSftp.LsEntry msg) throws Exception {
|
||||
SftpSession sftpSession = (SftpSession) useful;
|
||||
|
||||
@@ -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.synchronizer.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<ChannelSftp.LsEntry, SftpInboundSynchronizer> {
|
||||
public class SftpInboundSynchronizingMessageSource extends AbstractInboundFileSynchronizingMessageSource<ChannelSftp.LsEntry> {
|
||||
|
||||
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) {
|
||||
|
||||
@@ -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.synchronizer.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;
|
||||
|
||||
@@ -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<LsEntry> entries = new Vector<ChannelSftp.LsEntry>();
|
||||
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<InputStream>() {
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user