INT-1614 fixed tests in FTP

This commit is contained in:
Oleg Zhurakousky
2010-11-19 22:35:42 -05:00
parent 294ffb2bfe
commit e4d3bc0a09
12 changed files with 136 additions and 101 deletions

View File

@@ -16,56 +16,62 @@
package org.springframework.integration.ftp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Map;
import org.junit.Test;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.ftp.filters.FtpPatternMatchingFileListFilter;
import org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizer;
import org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizingMessageSource;
import org.springframework.integration.ftp.session.DefaultFtpSessionFactory;
import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
*/
public class FtpInboundChannelAdapterParserTests {
// @Test
// public void testFtpInboundChannelAdapterComplete() throws Exception{
// ApplicationContext ac =
// new ClassPathXmlApplicationContext("FtpInboundChannelAdapterParserTests-context.xml", this.getClass());
// SourcePollingChannelAdapter adapter = ac.getBean("ftpInbound", SourcePollingChannelAdapter.class);
// assertEquals("ftpInbound", adapter.getComponentName());
// assertEquals("ftp:inbound-channel-adapter", adapter.getComponentType());
// assertNotNull(TestUtils.getPropertyValue(adapter, "poller"));
// assertEquals(ac.getBean("ftpChannel"), TestUtils.getPropertyValue(adapter, "outputChannel"));
// FtpInboundFileSynchronizingMessageSource inbound =
// (FtpInboundFileSynchronizingMessageSource) TestUtils.getPropertyValue(adapter, "source");
//
// FtpInboundFileSynchronizer fisync =
// (FtpInboundFileSynchronizer) TestUtils.getPropertyValue(inbound, "synchronizer");
//// CompositeFileListFilter<?> filter = (CompositeFileListFilter<?>) TestUtils.getPropertyValue(fisync, "filter");
//// Set<?> filters = (Set<?>) TestUtils.getPropertyValue(filter, "fileFilters");
//// assertEquals(2, filters.size());
//// assertTrue(filters.contains(ac.getBean("entryListFilter")));
//
// }
@Test
public void testFtpInboundChannelAdapterComplete() throws Exception{
ApplicationContext ac =
new ClassPathXmlApplicationContext("FtpInboundChannelAdapterParserTests-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("ftpInbound", SourcePollingChannelAdapter.class);
assertEquals("ftpInbound", adapter.getComponentName());
assertEquals("ftp:inbound-channel-adapter", adapter.getComponentType());
assertNotNull(TestUtils.getPropertyValue(adapter, "poller"));
assertEquals(ac.getBean("ftpChannel"), TestUtils.getPropertyValue(adapter, "outputChannel"));
FtpInboundFileSynchronizingMessageSource inbound =
(FtpInboundFileSynchronizingMessageSource) TestUtils.getPropertyValue(adapter, "source");
FtpInboundFileSynchronizer fisync =
(FtpInboundFileSynchronizer) TestUtils.getPropertyValue(inbound, "synchronizer");
FtpPatternMatchingFileListFilter filter = (FtpPatternMatchingFileListFilter) TestUtils.getPropertyValue(fisync, "filter");
assertNotNull(filter);
}
@Test
public void testFtpInboundChannelAdapterCompleteNoId() throws Exception{
ApplicationContext ac =
new ClassPathXmlApplicationContext("FtpInboundChannelAdapterParserTests-context.xml", this.getClass());
// Map<String, SourcePollingChannelAdapter> spcas = ac.getBeansOfType(SourcePollingChannelAdapter.class);
// SourcePollingChannelAdapter adapter = null;
// for (String key : spcas.keySet()) {
// if (!key.equals("ftpInbound")){
// adapter = spcas.get(key);
// }
// }
// assertNotNull(adapter);
Map<String, SourcePollingChannelAdapter> spcas = ac.getBeansOfType(SourcePollingChannelAdapter.class);
SourcePollingChannelAdapter adapter = null;
for (String key : spcas.keySet()) {
if (!key.equals("ftpInbound")){
adapter = spcas.get(key);
}
}
assertNotNull(adapter);
}
public static class TestSessionFactoryBean implements FactoryBean<DefaultFtpSessionFactory>{

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-2.0.xsd">
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpClientFactory">
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="localhost"/>
<property name="username" value="ozhurakousky"/>
<property name="password" value="seva@1994"/>
@@ -16,11 +16,11 @@
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannel"
client-factory="ftpClientFactory"
charset="UTF-8"
session-factory="ftpClientFactory"
auto-create-directories="true"
auto-delete-remote-files-on-sync="false"
filename-pattern=".*\.test$"
remote-directory="/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/spring-integration/spring-integration-ftp/remote-test-dir"
local-working-directory="file:local-test-dir">
<int:poller fixed-rate="1000"/>
</int-ftp:inbound-channel-adapter>

View File

@@ -15,10 +15,19 @@
*/
package org.springframework.integration.ftp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.file.remote.session.CachingSessionFactory;
import org.springframework.integration.ftp.outbound.FtpSendingMessageHandler;
import org.springframework.integration.ftp.session.DefaultFtpSessionFactory;
import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
@@ -30,18 +39,18 @@ public class FtpOutboundChannelAdapterParserTests {
public void testFtpOutboundChannelAdapterComplete() throws Exception{
ApplicationContext ac =
new ClassPathXmlApplicationContext("FtpOutboundChannelAdapterParserTests-context.xml", this.getClass());
// Object consumer = ac.getBean("ftpOutbound");
// assertTrue(consumer instanceof EventDrivenConsumer);
// assertEquals(ac.getBean("ftpChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
// assertEquals("ftpOutbound", ((EventDrivenConsumer)consumer).getComponentName());
// FtpSendingMessageHandler handler = (FtpSendingMessageHandler) TestUtils.getPropertyValue(consumer, "handler");
// assertEquals(ac.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "fileNameGenerator"));
// assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "charset"));
// assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolder"));
// assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolderFile"));
// FtpClientPool clientPoll = (FtpClientPool) TestUtils.getPropertyValue(handler, "ftpClientPool");
// FtpClientFactory<?> clientFactory = (FtpClientFactory<?>) TestUtils.getPropertyValue(clientPoll, "factory");
// assertEquals("localhost", TestUtils.getPropertyValue(clientFactory, "host"));
// assertEquals(22, TestUtils.getPropertyValue(clientFactory, "port"));
Object consumer = ac.getBean("ftpOutbound");
assertTrue(consumer instanceof EventDrivenConsumer);
assertEquals(ac.getBean("ftpChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
assertEquals("ftpOutbound", ((EventDrivenConsumer)consumer).getComponentName());
FtpSendingMessageHandler handler = (FtpSendingMessageHandler) TestUtils.getPropertyValue(consumer, "handler");
assertEquals(ac.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "fileNameGenerator"));
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "charset"));
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolder"));
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolderFile"));
CachingSessionFactory cacheSf = (CachingSessionFactory) TestUtils.getPropertyValue(handler, "sessionFactory");
DefaultFtpSessionFactory sf = (DefaultFtpSessionFactory) TestUtils.getPropertyValue(cacheSf, "sessionFactory");
assertEquals("localhost", TestUtils.getPropertyValue(sf, "host"));
assertEquals(22, TestUtils.getPropertyValue(sf, "port"));
}
}

View File

@@ -18,6 +18,7 @@
<int-ftp:outbound-channel-adapter
session-factory="ftpSessionFactory"
remote-directory="/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/spring-integration/spring-integration-ftp/remote-target-dir"
channel="ftpChannel"/>

View File

@@ -18,17 +18,15 @@ package org.springframework.integration.ftp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.file.filters.CompositeFileListFilter;
import org.springframework.integration.ftp.filters.FtpPatternMatchingFileListFilter;
import org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizer;
import org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizingMessageSource;
import org.springframework.integration.test.util.TestUtils;
@@ -53,10 +51,7 @@ public class FtpsInboundChannelAdapterParserTests {
FtpInboundFileSynchronizer fisync =
(FtpInboundFileSynchronizer) TestUtils.getPropertyValue(inbound, "synchronizer");
// CompositeFileListFilter<?> filter = (CompositeFileListFilter<?>) TestUtils.getPropertyValue(fisync, "filter");
// Set<?> filters = (Set<?>) TestUtils.getPropertyValue(filter, "fileFilters");
// assertEquals(2, filters.size());
// assertTrue(filters.contains(ac.getBean("entryListFilter")));
assertNotNull(TestUtils.getPropertyValue(fisync, "filter"));
}

View File

@@ -15,10 +15,20 @@
*/
package org.springframework.integration.ftp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.file.remote.session.CachingSessionFactory;
import org.springframework.integration.ftp.outbound.FtpSendingMessageHandler;
import org.springframework.integration.ftp.session.DefaultFtpSessionFactory;
import org.springframework.integration.ftp.session.DefaultFtpsSessionFactory;
import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
@@ -30,18 +40,18 @@ public class FtpsOutboundChannelAdapterParserTests {
public void testFtpsOutboundChannelAdapterComplete() throws Exception{
ApplicationContext ac =
new ClassPathXmlApplicationContext("FtpsOutboundChannelAdapterParserTests-context.xml", this.getClass());
// Object consumer = ac.getBean("ftpOutbound");
// assertTrue(consumer instanceof EventDrivenConsumer);
// assertEquals(ac.getBean("ftpChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
// assertEquals("ftpOutbound", ((EventDrivenConsumer)consumer).getComponentName());
// FtpSendingMessageHandler handler = (FtpSendingMessageHandler) TestUtils.getPropertyValue(consumer, "handler");
// assertEquals(ac.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "fileNameGenerator"));
// assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "charset"));
// assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolder"));
// assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolderFile"));
// FtpClientPool clientPoll = (FtpClientPool) TestUtils.getPropertyValue(handler, "ftpClientPool");
// FtpClientFactory<?> clientFactory = (FtpClientFactory<?>) TestUtils.getPropertyValue(clientPoll, "factory");
// assertEquals("localhost", TestUtils.getPropertyValue(clientFactory, "host"));
// assertEquals(22, TestUtils.getPropertyValue(clientFactory, "port"));
Object consumer = ac.getBean("ftpOutbound");
assertTrue(consumer instanceof EventDrivenConsumer);
assertEquals(ac.getBean("ftpChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
assertEquals("ftpOutbound", ((EventDrivenConsumer)consumer).getComponentName());
FtpSendingMessageHandler handler = (FtpSendingMessageHandler) TestUtils.getPropertyValue(consumer, "handler");
assertEquals(ac.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "fileNameGenerator"));
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "charset"));
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolder"));
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolderFile"));
CachingSessionFactory cacheSf = (CachingSessionFactory) TestUtils.getPropertyValue(handler, "sessionFactory");
DefaultFtpsSessionFactory sf = (DefaultFtpsSessionFactory) TestUtils.getPropertyValue(cacheSf, "sessionFactory");
assertEquals("localhost", TestUtils.getPropertyValue(sf, "host"));
assertEquals(22, TestUtils.getPropertyValue(sf, "port"));
}
}

View File

@@ -16,7 +16,22 @@
package org.springframework.integration.ftp.inbound;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.File;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.ftp.filters.FtpPatternMatchingFileListFilter;
import org.springframework.integration.ftp.session.DefaultFtpSessionFactory;
import org.springframework.integration.ftp.session.FtpSession;
/**
* @author Oleg Zhurakousky
@@ -27,20 +42,20 @@ public class FtpInboundRemoteFileSystemSynchronizerTest {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testCopyFileToLocalDir() throws Exception {
// File file = new File(System.getProperty("java.io.tmpdir") + "/foo.txt");
// if (file.exists()){
// file.delete();
// }
// FtpInboundFileSynchronizer syncronizer = new FtpInboundFileSynchronizer();
// FileListFilter filter = new FtpPatternMatchingFileListFilter("foo.txt");
// syncronizer.setFilter(filter);
//
// DefaultFtpClientFactory factory = mock(DefaultFtpClientFactory.class);
// FTPClient ftpClient = mock(FTPClient.class);
// when(ftpClient.sendNoOp()).thenReturn(true);
// when(factory.getClient()).thenReturn(ftpClient);
//
// QueuedFtpClientPool clientPoll = new QueuedFtpClientPool(factory);
File file = new File(System.getProperty("java.io.tmpdir") + "/foo.txt");
if (file.exists()){
file.delete();
}
FtpInboundFileSynchronizer syncronizer = new FtpInboundFileSynchronizer();
FileListFilter filter = new FtpPatternMatchingFileListFilter("foo.txt");
syncronizer.setFilter(filter);
DefaultFtpSessionFactory factory = mock(DefaultFtpSessionFactory.class);
FtpSession ftpSession = mock(FtpSession.class);
//when(ftpSession.sendNoOp()).thenReturn(true);
when(factory.getSession()).thenReturn(ftpSession);
// Queue clientPoll = new QueuedFtpClientPool(factory);
//
// FTPFile f1 = mock(FTPFile.class);
// when(f1.isFile()).thenReturn(true);
@@ -48,15 +63,15 @@ public class FtpInboundRemoteFileSystemSynchronizerTest {
//
// FTPFile[] files = new FTPFile[]{f1};
// when(ftpClient.listFiles()).thenReturn(files);
//
// syncronizer.setClientPool(clientPoll);
// syncronizer.setShouldDeleteSourceFile(true);
// syncronizer.afterPropertiesSet();
//
// Resource localDirectory = new FileSystemResource(System.getProperty("java.io.tmpdir"));
// syncronizer.synchronizeToLocalDirectory(localDirectory);
//
// //verify(ftpClient, times(1)).retrieveFile(Mockito.anyString(), Mockito.any(OutputStream.class));
// verify(ftpClient, times(1)).deleteFile(Mockito.anyString());
syncronizer.setSessionFactory(factory);
syncronizer.setShouldDeleteSourceFile(true);
syncronizer.afterPropertiesSet();
File localDirectory = new File(System.getProperty("java.io.tmpdir"));
syncronizer.synchronizeToLocalDirectory(localDirectory);
//verify(ftpClient, times(1)).retrieveFile(Mockito.anyString(), Mockito.any(OutputStream.class));
//verify(ftpClient, times(1)).deleteFile(Mockito.anyString());
}
}

View File

@@ -23,24 +23,21 @@ import org.junit.Test;
*/
public class FtpSendingMessageHandlerTest {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void placeholder() {
}
// @SuppressWarnings({ "unchecked", "rawtypes" })
// @Test
// public void testHandleFileNameMessage() throws Exception {
public void testHandleFileNameMessage() throws Exception {
// FtpSendingMessageHandler handler = new FtpSendingMessageHandler();
// //FtpClientPool clientPoll = mock(FtpClientPool.class);
// FTPClient client = mock(FTPClient.class);
// when(client.storeFile(Mockito.anyString(), Mockito.any(InputStream.class))).thenReturn(true);
// FtpSession session = mock(FtpSession.class);
// when(session.put(Mockito.any(InputStream.class), Mockito.anyString())).th
// //when(session.put(Mockito.any(InputStream.class), Mockito.anyString())).thenReturn(true);
// when(clientPoll.getClient()).thenReturn(client);
//
// handler.setFtpClientPool(clientPoll);
// handler.handleMessage(new GenericMessage("hello"));
// verify(clientPoll, times(1)).getClient();
// verify(client, times(1)).storeFile(Mockito.anyString(), Mockito.any(InputStream.class));
// }
}
// @SuppressWarnings({ "unchecked", "rawtypes" })
// @Test
// public void testHandleFileAsByte() throws Exception {

View File

@@ -0,0 +1 @@
Hello

View File

@@ -0,0 +1 @@
Bye

View File

@@ -10,7 +10,7 @@
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.SimpleSftpSessionFactory">
<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="localhost"/>
<property name="privateKey" value="classpath:org/springframework/integration/sftp/config/sftp_rsa"/>
<property name="privateKeyPassphrase" value="springintegration"/>
@@ -21,10 +21,10 @@
<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"
local-directory="/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/spring-integration/spring-integration-sftp/bar"
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-create-directories="true"
auto-delete-remote-files-on-sync="false"
filename-pattern=".*\.test$">
<int:poller fixed-rate="1000" max-messages-per-poll="10" task-executor="executor"/>

View File

@@ -8,7 +8,7 @@
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.SimpleSftpSessionFactory">
<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="localhost"/>
<property name="privateKey" value="classpath:org/springframework/integration/sftp/config/sftp_rsa"/>
<property name="privateKeyPassphrase" value="springintegration"/>