INT-1614 finished polishing SFTP, fixed tests, imports etc.
This commit is contained in:
@@ -28,8 +28,8 @@ import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.sftp.filters.SftpPatternMatchingFileListFilter;
|
||||
import org.springframework.integration.sftp.inbound.SftpInboundRemoteFileSystemSynchronizer;
|
||||
import org.springframework.integration.sftp.inbound.SftpInboundRemoteFileSystemSynchronizingMessageSource;
|
||||
import org.springframework.integration.sftp.inbound.SftpInboundSynchronizer;
|
||||
import org.springframework.integration.sftp.inbound.SftpInboundSynchronizingMessageSource;
|
||||
import org.springframework.integration.sftp.session.QueuedSftpSessionPool;
|
||||
import org.springframework.integration.sftp.session.SftpSessionFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -44,7 +44,7 @@ import com.jcraft.jsch.ChannelSftp;
|
||||
* @since 2.0
|
||||
*/
|
||||
class SftpInboundSynchronizingMessageSourceFactoryBean
|
||||
extends AbstractFactoryBean<SftpInboundRemoteFileSystemSynchronizingMessageSource> implements ResourceLoaderAware {
|
||||
extends AbstractFactoryBean<SftpInboundSynchronizingMessageSource> implements ResourceLoaderAware {
|
||||
|
||||
private volatile ResourceLoader resourceLoader;
|
||||
|
||||
@@ -126,10 +126,10 @@ class SftpInboundSynchronizingMessageSourceFactoryBean
|
||||
* @return Fully configured SftpInboundRemoteFileSystemSynchronizingMessageSource
|
||||
*/
|
||||
@Override
|
||||
protected SftpInboundRemoteFileSystemSynchronizingMessageSource createInstance() throws Exception {
|
||||
protected SftpInboundSynchronizingMessageSource createInstance() throws Exception {
|
||||
boolean autoCreatDirs = Boolean.parseBoolean(this.autoCreateDirectories);
|
||||
boolean ackRemoteDir = Boolean.parseBoolean(this.autoDeleteRemoteFilesOnSync);
|
||||
SftpInboundRemoteFileSystemSynchronizingMessageSource sftpMsgSrc = new SftpInboundRemoteFileSystemSynchronizingMessageSource();
|
||||
SftpInboundSynchronizingMessageSource sftpMsgSrc = new SftpInboundSynchronizingMessageSource();
|
||||
sftpMsgSrc.setAutoCreateDirectories(autoCreatDirs);
|
||||
|
||||
// local directories
|
||||
@@ -156,7 +156,7 @@ class SftpInboundSynchronizingMessageSourceFactoryBean
|
||||
QueuedSftpSessionPool pool = new QueuedSftpSessionPool(15, sftpSessionFactory);
|
||||
pool.afterPropertiesSet();
|
||||
|
||||
SftpInboundRemoteFileSystemSynchronizer sftpSync = new SftpInboundRemoteFileSystemSynchronizer();
|
||||
SftpInboundSynchronizer sftpSync = new SftpInboundSynchronizer();
|
||||
sftpSync.setClientPool(pool);
|
||||
sftpSync.setLocalDirectory(this.localDirectoryResource);
|
||||
sftpSync.setShouldDeleteSourceFile(ackRemoteDir);
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.Collection;
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SftpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemoteFileSystemSychronizer<ChannelSftp.LsEntry> {
|
||||
public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSychronizer<ChannelSftp.LsEntry> {
|
||||
|
||||
/**
|
||||
* the path on the remote mount
|
||||
@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SftpInboundRemoteFileSystemSynchronizingMessageSource extends AbstractInboundRemoteFileSystemSynchronizingMessageSource<ChannelSftp.LsEntry, SftpInboundRemoteFileSystemSynchronizer> {
|
||||
public class SftpInboundSynchronizingMessageSource extends AbstractInboundRemoteFileSystemSynchronizingMessageSource<ChannelSftp.LsEntry, SftpInboundSynchronizer> {
|
||||
/**
|
||||
* the pool of sessions
|
||||
*/
|
||||
@@ -16,17 +16,14 @@
|
||||
|
||||
package org.springframework.integration.sftp.session;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.Identity;
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.Session;
|
||||
import com.jcraft.jsch.UserInfo;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* There are many ways to create a {@link SftpSession} just as there are many ways to SSH into a remote system.
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-2.0.xsd">
|
||||
|
||||
|
||||
<channel id="requestChannel"/>
|
||||
<channel id="requestChannel">
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<beans:bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.SftpSessionFactory">
|
||||
<beans:property name="host" value="loclahost"/>
|
||||
@@ -34,10 +36,10 @@
|
||||
session-factory="sftpSessionFactory"
|
||||
channel="requestChannel"
|
||||
filter="filter"
|
||||
filename-pattern="foo*.txt"
|
||||
filename-pattern="foo.txt"
|
||||
remote-directory="ftp://foo"
|
||||
local-directory-path="file:target/foo"
|
||||
auto-create-directories="true"
|
||||
local-directory-path="file:src/main/resources"
|
||||
auto-create-directories="false"
|
||||
auto-delete-remote-files-on-sync="false">
|
||||
<poller fixed-rate="1000"/>
|
||||
</sftp:inbound-channel-adapter>
|
||||
@@ -46,7 +48,7 @@
|
||||
channel="requestChannel"
|
||||
session-factory="sftpSessionFactory"
|
||||
filter="filter"
|
||||
filename-pattern="foo*.txt"
|
||||
filename-pattern="foo.txt"
|
||||
remote-directory="ftp://foo"
|
||||
local-directory-path="file:target"
|
||||
auto-create-directories="true"
|
||||
@@ -55,8 +57,8 @@
|
||||
</sftp:inbound-channel-adapter>
|
||||
|
||||
|
||||
<beans:bean id="filter" class="org.mockito.Mockito" factory-method="mock">
|
||||
<beans:constructor-arg value="org.springframework.integration.file.filters.FileListFilter"/>
|
||||
<beans:bean id="filter" class="org.springframework.integration.sftp.filters.SftpPatternMatchingFileListFilter">
|
||||
<beans:constructor-arg value="."/>
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.sftp.config;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
@@ -25,7 +26,12 @@ 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;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.sftp.inbound.SftpInboundSynchronizingMessageSource;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -38,11 +44,18 @@ public class InboundChannelAdapaterParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalFilesAutoCreationTrue() throws Exception{
|
||||
assertTrue(!new File("target/foo").exists());
|
||||
new ClassPathXmlApplicationContext("InboundChannelAdapaterParserTests-context.xml", this.getClass());
|
||||
assertTrue(new File("target/foo").exists());
|
||||
assertTrue(!new File("target/bar").exists());
|
||||
public void testWithLocalFiles() throws Exception{
|
||||
ApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("InboundChannelAdapaterParserTests-context.xml", this.getClass());
|
||||
assertTrue(new File("src/main/resources").exists());
|
||||
|
||||
Object adapter = context.getBean("sftpAdapterAutoCreate");
|
||||
assertTrue(adapter instanceof SourcePollingChannelAdapter);
|
||||
SftpInboundSynchronizingMessageSource source =
|
||||
(SftpInboundSynchronizingMessageSource) TestUtils.getPropertyValue(adapter, "source");
|
||||
assertNotNull(source);
|
||||
PollableChannel requestChannel = context.getBean("requestChannel", PollableChannel.class);
|
||||
assertNotNull(requestChannel.receive(2000));
|
||||
}
|
||||
|
||||
@Test(expected=BeanCreationException.class)
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* 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.config;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -21,10 +32,8 @@ import org.springframework.integration.sftp.session.QueuedSftpSessionPool;
|
||||
import org.springframework.integration.sftp.session.SftpSessionFactory;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
import com.sun.tools.doclets.internal.toolkit.taglets.LiteralTaglet;
|
||||
|
||||
/**
|
||||
* @author ozhurakousky
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class OutboundChannelAdapaterParserTests {
|
||||
|
||||
@@ -26,7 +26,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.sftp.inbound.SftpInboundRemoteFileSystemSynchronizer;
|
||||
import org.springframework.integration.sftp.inbound.SftpInboundSynchronizer;
|
||||
import org.springframework.integration.sftp.session.SftpSession;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -62,7 +62,7 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
*/
|
||||
@Test
|
||||
public void testCopyAndRenameWhenLocalFileExists() throws Exception {
|
||||
SftpInboundRemoteFileSystemSynchronizer synchronizer = new SftpInboundRemoteFileSystemSynchronizer();
|
||||
SftpInboundSynchronizer synchronizer = new SftpInboundSynchronizer();
|
||||
Method method =
|
||||
ReflectionUtils.findMethod(synchronizer.getClass(), "copyFromRemoteToLocalDirectory", SftpSession.class, LsEntry.class, Resource.class);
|
||||
method.setAccessible(true);
|
||||
@@ -84,7 +84,7 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
@org.junit.Ignore
|
||||
@Test
|
||||
public void testCopyAndRenameWhenLocalFileDoesntExist() throws Exception {
|
||||
SftpInboundRemoteFileSystemSynchronizer synchronizer = new SftpInboundRemoteFileSystemSynchronizer();
|
||||
SftpInboundSynchronizer synchronizer = new SftpInboundSynchronizer();
|
||||
synchronizer.setEntryAcknowledgmentStrategy(mock(EntryAcknowledgmentStrategy.class));
|
||||
Method method =
|
||||
ReflectionUtils.findMethod(synchronizer.getClass(), "copyFromRemoteToLocalDirectory", SftpSession.class, LsEntry.class, Resource.class);
|
||||
|
||||
@@ -49,7 +49,7 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
if (file.exists()){
|
||||
file.delete();
|
||||
}
|
||||
SftpInboundRemoteFileSystemSynchronizer syncronizer = new SftpInboundRemoteFileSystemSynchronizer();
|
||||
SftpInboundSynchronizer syncronizer = new SftpInboundSynchronizer();
|
||||
syncronizer.setLocalDirectory(new FileSystemResource(System.getProperty("java.io.tmpdir")));
|
||||
syncronizer.setRemotePath("foo/bar");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user