tested and fixed onFailure for FtpSource

This commit is contained in:
Iwein Fuld
2008-08-08 14:56:51 +00:00
parent fbb5123e8e
commit e88776463a
7 changed files with 105 additions and 16 deletions

View File

@@ -48,6 +48,7 @@ import org.junit.Test;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageCreator;
import org.springframework.integration.message.MessagingException;
@SuppressWarnings("unchecked")
public class FtpSourceTests {
@@ -92,9 +93,9 @@ public class FtpSourceTests {
ftpClient.connect(HOST, 21);
expect(ftpClient.login(USER, PASS)).andReturn(true);
expect(ftpClient.setFileType(anyInt())).andReturn(true);
expect(ftpClient.printWorkingDirectory()).andReturn("/");
expect(ftpClient.listFiles()).andReturn(mockedFTPFilesNamed("test"));
expect(ftpClient.retrieveFile(eq("test"), isA(OutputStream.class))).andReturn(true);
expect(ftpClient.printWorkingDirectory()).andReturn("/").anyTimes();
expect(ftpClient.listFiles()).andReturn(mockedFTPFilesNamed("test1"));
expect(ftpClient.retrieveFile(eq("test1"), isA(OutputStream.class))).andReturn(true);
// create message
expect(messageCreator.createMessage(isA(List.class))).andReturn(
new GenericMessage(Arrays.asList(new File("test1"))));
@@ -130,7 +131,7 @@ public class FtpSourceTests {
ftpClient.connect(HOST, 21);
expect(ftpClient.login(USER, PASS)).andReturn(true);
expect(ftpClient.setFileType(anyInt())).andReturn(true);
expect(ftpClient.printWorkingDirectory()).andReturn("/");
expect(ftpClient.printWorkingDirectory()).andReturn("/").anyTimes();
// get files
expect(ftpClient.listFiles()).andReturn(mockedFTPFilesNamed("test1", "test2")).times(2);
@@ -274,6 +275,24 @@ public class FtpSourceTests {
receivesDone.await();
verify(globalMocks);
}
@Test public void onFailure() throws Exception{
// connect client and get file
expect(ftpClient.isConnected()).andReturn(true).anyTimes();
expect(ftpClient.listFiles()).andReturn(mockedFTPFilesNamed("test1")).times(2);
expect(ftpClient.retrieveFile(eq("test1"), isA(OutputStream.class))).andReturn(true).times(2);
// create message
expect(messageCreator.createMessage(isA(List.class))).andReturn(
new GenericMessage(Arrays.asList(new File("test1")))).times(2);
ftpClient.disconnect();
ftpClient.disconnect();
replay(globalMocks);
Message<List<File>> received = ftpSource.receive();
ftpSource.onFailure(new MessagingException(received));
assertEquals(received, ftpSource.receive());
verify(globalMocks);
}
@AfterClass
public static void deleteFiles() {

View File

@@ -3,13 +3,20 @@ package org.springframework.integration.adapter.ftp.config;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.adapter.ftp.FtpSource;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.config.MessageBusParser;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageCreator;
@@ -64,6 +71,15 @@ public class FtpSourceIntegrationTests {
Message<List<File>> received = ftpSource.receive();
assertTrue(received.getPayload().iterator().next().exists());
}
@Test public void withChannelAdapter() {
ApplicationContext context = new ClassPathXmlApplicationContext("ftpSourceWithChannelAdapter.xml", this.getClass());
ChannelRegistry channelRegistry = (ChannelRegistry) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
PollableChannel input = (PollableChannel) channelRegistry.lookupChannel("output");
List<File> files = new ArrayList<File>();
files.add((File) input.receive().getPayload());
files.add((File) input.receive().getPayload());
assertTrue(files.containsAll(Arrays.asList(new File("file1"), new File("file2"))));
}
}

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<si:message-bus />
<bean id="ftpSource"
class="org.springframework.integration.adapter.ftp.FtpSource"
p:host="localhost" p:password="kaas" p:username="ftp-user"
p:remoteWorkingDirectory="ftp-test">
<constructor-arg>
<bean
class="org.springframework.integration.message.DefaultMessageCreator" />
</constructor-arg>
</bean>
<si:channel-adapter id="input" source="ftpSource" />
<si:splitter output-channel="output" input-channel="input" ref="defaultSplitter" method="split"/>
<bean id="defaultSplitter"
class="org.springframework.integration.util.CollectionSplitter" />
<si:channel id="output"/>
</beans>