INT-1631 first round removed factory beans in favor of bootstrapping required components in the parser. Eliminated a lot of repetative code, fixed the schema with regard to what is required and optional attributes, added inbound and outbound ignored samples
This commit is contained in:
@@ -34,9 +34,8 @@
|
||||
channel="requestChannel"
|
||||
session-factory="sftpSessionFactory"
|
||||
filter="filter"
|
||||
filename-pattern="foo*.txt"
|
||||
remote-directory="ftp://foo"
|
||||
local-directory-path="file:target/bar"
|
||||
local-directory="file:local-test-dir"
|
||||
auto-create-directories="false"
|
||||
auto-delete-remote-files-on-sync="false">
|
||||
<poller fixed-rate="1000"/>
|
||||
|
||||
@@ -35,10 +35,9 @@
|
||||
<sftp:inbound-channel-adapter id="sftpAdapterAutoCreate"
|
||||
session-factory="sftpSessionFactory"
|
||||
channel="requestChannel"
|
||||
filter="filter"
|
||||
filename-pattern="foo.txt"
|
||||
remote-directory="ftp://foo"
|
||||
local-directory-path="file:src/main/resources"
|
||||
remote-directory="/foo"
|
||||
local-directory="file:local-test-dir"
|
||||
auto-create-directories="false"
|
||||
auto-delete-remote-files-on-sync="false">
|
||||
<poller fixed-rate="1000"/>
|
||||
@@ -48,9 +47,8 @@
|
||||
channel="requestChannel"
|
||||
session-factory="sftpSessionFactory"
|
||||
filter="filter"
|
||||
filename-pattern="foo.txt"
|
||||
remote-directory="ftp://foo"
|
||||
local-directory-path="file:target"
|
||||
remote-directory="/foo"
|
||||
local-directory="file:local-test-dir"
|
||||
auto-create-directories="true"
|
||||
auto-delete-remote-files-on-sync="false">
|
||||
<poller fixed-rate="1000"/>
|
||||
|
||||
@@ -33,7 +33,8 @@
|
||||
<sftp:inbound-channel-adapter id="sftpAdapter"
|
||||
session-factory="sftpSessionFactory"
|
||||
auto-startup="false"
|
||||
remote-directory="sftp://hello"
|
||||
remote-directory="/hello"
|
||||
local-directory="file:local-test-dir"
|
||||
channel="inboundFilesChannel"
|
||||
filename-pattern=".*?jpg"
|
||||
auto-create-directories="true"
|
||||
|
||||
@@ -50,11 +50,11 @@ public class OutboundChannelAdapaterParserTests {
|
||||
Expression remoteDirectoryExpression = (Expression) TestUtils.getPropertyValue(handler, "remoteDirectoryExpression");
|
||||
assertNotNull(remoteDirectoryExpression);
|
||||
assertTrue(remoteDirectoryExpression instanceof LiteralExpression);
|
||||
assertEquals(context.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "fileNameGenerator"));
|
||||
assertEquals(context.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "filenameGenerator"));
|
||||
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "charset"));
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolder"));
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolderFile"));
|
||||
QueuedSftpSessionPool clientPoll = (QueuedSftpSessionPool) TestUtils.getPropertyValue(handler, "pool");
|
||||
QueuedSftpSessionPool clientPoll = (QueuedSftpSessionPool) TestUtils.getPropertyValue(handler, "sessionPool");
|
||||
SftpSessionFactory clientFactory = (SftpSessionFactory) TestUtils.getPropertyValue(clientPoll, "sftpSessionFactory");
|
||||
assertEquals("localhost", TestUtils.getPropertyValue(clientFactory, "host"));
|
||||
assertEquals(2222, TestUtils.getPropertyValue(clientFactory, "port"));
|
||||
@@ -72,7 +72,7 @@ public class OutboundChannelAdapaterParserTests {
|
||||
SpelExpression remoteDirectoryExpression = (SpelExpression) TestUtils.getPropertyValue(handler, "remoteDirectoryExpression");
|
||||
assertNotNull(remoteDirectoryExpression);
|
||||
assertEquals("'foo' + '/' + 'bar'", remoteDirectoryExpression.getExpressionString());
|
||||
assertEquals(context.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "fileNameGenerator"));
|
||||
assertEquals(context.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "filenameGenerator"));
|
||||
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "charset"));
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolder"));
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolderFile"));
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-2.0.xsd">
|
||||
|
||||
|
||||
<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.SftpSessionFactory">
|
||||
<property name="host" value="localhost"/>
|
||||
<!-- <property name="knownHosts" value="local, foo.com, bar.foo"/>-->
|
||||
<property name="privateKey" value="file:/Users/ozhurakousky/.ssh/sftp_rsa"/>
|
||||
<property name="privateKeyPassphrase" value="seva@1994"/>
|
||||
<!-- <property name="password" value="hello"/>-->
|
||||
<property name="port" value="22"/>
|
||||
<property name="user" value="ozhurakousky"/>
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
<int-sftp:inbound-channel-adapter id="sftpInbondAdapter"
|
||||
channel="receiveChannel"
|
||||
session-factory="sftpSessionFactory"
|
||||
local-directory="file:/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/spring-integration/spring-integration-sftp/local-test-dir"
|
||||
remote-directory="/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/spring-integration/spring-integration-sftp/remote-test-dir"
|
||||
auto-startup="true"
|
||||
auto-create-directories="false"
|
||||
auto-delete-remote-files-on-sync="false"
|
||||
filename-pattern=".*\.txt$">
|
||||
<int:poller fixed-rate="10000" max-messages-per-poll="10"/>
|
||||
</int-sftp:inbound-channel-adapter>
|
||||
|
||||
|
||||
<int:channel id="receiveChannel">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<bean id="filter" class="org.springframework.integration.sftp.filters.SftpPatternMatchingFileListFilter">
|
||||
<constructor-arg value=".*\.txt$"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousy
|
||||
*
|
||||
*/
|
||||
public class SftpInboundReceiveSample {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testInbound() throws Exception{
|
||||
ClassPathXmlApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("SftpInboundReceiveSample-ignored.xml", SftpInboundReceiveSample.class);
|
||||
|
||||
System.out.println("Done");
|
||||
System.in.read();
|
||||
ac.stop();
|
||||
// File file = new File("/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/spring-integration/spring-integration-sftp/foo.txt");
|
||||
// if (file.exists()){
|
||||
// Message<File> message = MessageBuilder.withPayload(file).build();
|
||||
// MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
|
||||
// inputChannel.send(message);
|
||||
// Thread.sleep(2000);
|
||||
// }
|
||||
// System.out.println("Done");
|
||||
// ac.stop();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-2.0.xsd">
|
||||
|
||||
|
||||
<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.SftpSessionFactory">
|
||||
<property name="host" value="localhost"/>
|
||||
<!-- <property name="knownHosts" value="local, foo.com, bar.foo"/>-->
|
||||
<property name="privateKey" value="file:/Users/ozhurakousky/.ssh/sftp_rsa"/>
|
||||
<property name="privateKeyPassphrase" value="seva@1994"/>
|
||||
<!-- <property name="password" value="hello"/>-->
|
||||
<property name="port" value="22"/>
|
||||
<property name="user" value="ozhurakousky"/>
|
||||
</bean>
|
||||
|
||||
<int:channel id="inputChannel"/>
|
||||
|
||||
<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter"
|
||||
session-factory="sftpSessionFactory"
|
||||
channel="inputChannel"
|
||||
charset="UTF-8"
|
||||
remote-directory="/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/spring-integration/spring-integration-sftp/remote-test-dir"/>
|
||||
|
||||
<!-- <int-sftp:outbound-channel-adapter id="sftpOutboundAdapterWithExpression"-->
|
||||
<!-- session-factory="sftpSessionFactory"-->
|
||||
<!-- channel="inputChannel"-->
|
||||
<!-- charset="UTF-8"-->
|
||||
<!-- filename-generator="fileNameGenerator"-->
|
||||
<!-- remote-directory-expression="'foo' + '/' + 'bar'"/>-->
|
||||
|
||||
|
||||
<bean id="fileNameGenerator" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.springframework.integration.file.FileNameGenerator"/>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class SftpOutboundTransferSample {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testOutbound() throws Exception{
|
||||
ClassPathXmlApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("SftpOutboundTransferSample-ignored.xml", SftpOutboundTransferSample.class);
|
||||
ac.start();
|
||||
File file = new File("/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/spring-integration/spring-integration-sftp/local-test-dir/foo.txt");
|
||||
if (file.exists()){
|
||||
Message<File> message = MessageBuilder.withPayload(file).build();
|
||||
MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
|
||||
inputChannel.send(message);
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
System.out.println("Done");
|
||||
ac.stop();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.file.synchronization.AbstractInboundRemoteFileSystemSychronizer.EntryAcknowledgmentStrategy;
|
||||
import org.springframework.integration.sftp.inbound.SftpInboundSynchronizer;
|
||||
import org.springframework.integration.sftp.session.SftpSession;
|
||||
import org.springframework.integration.sftp.session.SftpSessionPool;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
@@ -62,7 +63,7 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
*/
|
||||
@Test
|
||||
public void testCopyAndRenameWhenLocalFileExists() throws Exception {
|
||||
SftpInboundSynchronizer synchronizer = new SftpInboundSynchronizer();
|
||||
SftpInboundSynchronizer synchronizer = new SftpInboundSynchronizer(mock(SftpSessionPool.class));
|
||||
Method method =
|
||||
ReflectionUtils.findMethod(synchronizer.getClass(), "copyFromRemoteToLocalDirectory", SftpSession.class, LsEntry.class, Resource.class);
|
||||
method.setAccessible(true);
|
||||
@@ -84,7 +85,7 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
@org.junit.Ignore
|
||||
@Test
|
||||
public void testCopyAndRenameWhenLocalFileDoesntExist() throws Exception {
|
||||
SftpInboundSynchronizer synchronizer = new SftpInboundSynchronizer();
|
||||
SftpInboundSynchronizer synchronizer = new SftpInboundSynchronizer(mock(SftpSessionPool.class));
|
||||
synchronizer.setEntryAcknowledgmentStrategy(mock(EntryAcknowledgmentStrategy.class));
|
||||
Method method =
|
||||
ReflectionUtils.findMethod(synchronizer.getClass(), "copyFromRemoteToLocalDirectory", SftpSession.class, LsEntry.class, Resource.class);
|
||||
|
||||
@@ -49,7 +49,8 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
if (file.exists()){
|
||||
file.delete();
|
||||
}
|
||||
SftpInboundSynchronizer syncronizer = new SftpInboundSynchronizer();
|
||||
SftpSessionPool sessionPool = mock(SftpSessionPool.class);
|
||||
SftpInboundSynchronizer syncronizer = new SftpInboundSynchronizer(sessionPool);
|
||||
syncronizer.setLocalDirectory(new FileSystemResource(System.getProperty("java.io.tmpdir")));
|
||||
syncronizer.setRemotePath("foo/bar");
|
||||
|
||||
@@ -57,10 +58,10 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
|
||||
syncronizer.setFilter(filter);
|
||||
|
||||
SftpSessionPool sessionPoll = mock(SftpSessionPool.class);
|
||||
|
||||
SftpSession sftpSession = mock(SftpSession.class);
|
||||
|
||||
when(sessionPoll.getSession()).thenReturn(sftpSession);
|
||||
when(sessionPool.getSession()).thenReturn(sftpSession);
|
||||
ChannelSftp channel = mock(ChannelSftp.class);
|
||||
when(channel.get((String) Mockito.any())).thenReturn(new FileInputStream(new File("template.mf")));
|
||||
when(sftpSession.getChannel()).thenReturn(channel);
|
||||
@@ -75,13 +76,12 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
when(channel.ls("foo/bar")).thenReturn(entries);
|
||||
when(filter.filterFiles((Object[]) Mockito.any())).thenReturn(entries);
|
||||
|
||||
syncronizer.setClientPool(sessionPoll);
|
||||
syncronizer.setShouldDeleteSourceFile(true);
|
||||
syncronizer.afterPropertiesSet();
|
||||
|
||||
syncronizer.syncRemoteToLocalFileSystem();
|
||||
|
||||
verify(sessionPoll, times(1)).getSession();
|
||||
verify(sessionPool, times(1)).getSession();
|
||||
verify(sftpSession, atLeast(1)).getChannel();
|
||||
// will add more validation, but for now this test is mainly to get the test coverage up
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user