INT-1029: Support for outbound-gateways in chain

XSD refactoring: remove use="required" from 'request-channel' attribute of all 'outbound-gateways'
Tests for all 'outbound-gateways' inside the <chain>
This commit is contained in:
Artem Bilan
2012-06-07 15:03:39 +03:00
committed by Oleg Zhurakousky
parent c3860e14b7
commit 5bc41bc60b
37 changed files with 731 additions and 214 deletions

View File

@@ -115,7 +115,7 @@
<xsd:element name="inbound-channel-adapter">
<xsd:annotation>
<xsd:documentation><![CDATA[
Builds an inbound-channel-adapter that synchronizes a local directory with the contents of a remote FTP endpoint.
Builds an inbound-channel-adapter that synchronizes a local directory with the contents of a remote FTP endpoint.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
@@ -264,8 +264,7 @@
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="request-channel" use="required"
type="xsd:string">
<xsd:attribute name="request-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
@@ -403,8 +402,8 @@
</tool:annotation>
</xsd:appinfo>
<xsd:documentation>
Identifies channel attached to this adapter. Depending on the type of the adapter
this channel could be the receiving channel (e.g., outbound-channel-adapter) or channel where
Identifies channel attached to this adapter. Depending on the type of the adapter
this channel could be the receiving channel (e.g., outbound-channel-adapter) or channel where
messages will be sent to by this adapter (e.g., inbound-channel-adapter).
</xsd:documentation>
</xsd:annotation>
@@ -419,7 +418,7 @@
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="base-adapter-type">
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="session-factory" type="xsd:string"
@@ -478,6 +477,6 @@
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:schema>

View File

@@ -1,13 +1,10 @@
<?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:context="http://www.springframework.org/schema/context"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:ftp="http://www.springframework.org/schema/integration/ftp"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/ftp
@@ -22,9 +19,21 @@
</si:chain>
<bean id="ftpSessionFactory"
class="org.springframework.integration.ftp.outbound.FtpSendingMessageHandlerTests$TestFtpSessionFactory">
class="org.springframework.integration.ftp.outbound.FtpOutboundTests$TestFtpSessionFactory">
<property name="username" value="kermit"/>
<property name="password" value="frog"/>
<property name="host" value="foo.com"/>
</bean>
<si:channel id="output">
<si:queue/>
</si:channel>
<si:chain input-channel="ftpOutboundGatewayInsideChain" output-channel="output">
<ftp:outbound-gateway session-factory="ftpSessionFactory"
command="ls"
expression="payload"/>
</si:chain>
</beans>

View File

@@ -16,6 +16,7 @@
package org.springframework.integration.ftp.outbound;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@@ -24,6 +25,8 @@ import static org.mockito.Mockito.when;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
@@ -37,21 +40,24 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.file.FileNameGenerator;
import org.springframework.integration.file.remote.FileInfo;
import org.springframework.integration.file.remote.handler.FileTransferringMessageHandler;
import org.springframework.integration.ftp.session.AbstractFtpSessionFactory;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.util.FileCopyUtils;
/**
* @author Oleg Zhurakousky
* @author Artem Bilan
*/
public class FtpSendingMessageHandlerTests {
public class FtpOutboundTests {
private static FTPClient ftpClient;
private TestFtpSessionFactory sessionFactory;
@Before
public void prepare(){
ftpClient = mock(FTPClient.class);
@@ -71,7 +77,7 @@ public class FtpSendingMessageHandlerTests {
assertFalse(file.exists());
FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>(sessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));
handler.setFileNameGenerator(new FileNameGenerator() {
handler.setFileNameGenerator(new FileNameGenerator() {
public String generateFileName(Message<?> message) {
return "handlerContent.test";
}
@@ -90,7 +96,7 @@ public class FtpSendingMessageHandlerTests {
assertFalse(file.exists());
FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>(sessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));
handler.setFileNameGenerator(new FileNameGenerator() {
handler.setFileNameGenerator(new FileNameGenerator() {
public String generateFileName(Message<?> message) {
return "handlerContent.test";
}
@@ -99,7 +105,7 @@ public class FtpSendingMessageHandlerTests {
handler.handleMessage(new GenericMessage<byte[]>("hello".getBytes()));
assertTrue(file.exists());
}
@Test
public void testHandleFileMessage() throws Exception {
File targetDir = new File("remote-target-dir");
@@ -135,7 +141,7 @@ public class FtpSendingMessageHandlerTests {
File destFile = new File(targetDir, srcFile.getName());
destFile.deleteOnExit();
ApplicationContext context = new ClassPathXmlApplicationContext("FtpOutboundChannelAdapterInsideChainTests-context.xml", getClass());
ApplicationContext context = new ClassPathXmlApplicationContext("FtpOutboundInsideChainTests-context.xml", getClass());
MessageChannel channel = context.getBean("outboundChainChannel", MessageChannel.class);
@@ -143,6 +149,28 @@ public class FtpSendingMessageHandlerTests {
assertTrue("destination file was not created", destFile.exists());
}
@Test //INT-2275
public void testFtpOutboundGatewayInsideChain() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("FtpOutboundInsideChainTests-context.xml", getClass());
MessageChannel channel = context.getBean("ftpOutboundGatewayInsideChain", MessageChannel.class);
channel.send(MessageBuilder.withPayload("remote-test-dir").build());
PollableChannel output = context.getBean("output", PollableChannel.class);
Message<?> result = output.receive();
Object payload = result.getPayload();
assertTrue(payload instanceof List<?>);
@SuppressWarnings("unchecked")
List<? extends FileInfo> remoteFiles = (List<? extends FileInfo>) payload;
assertEquals(3, remoteFiles.size());
List<String> files = Arrays.asList(new File("remote-test-dir").list());
for (FileInfo remoteFile : remoteFiles) {
assertTrue(files.contains(remoteFile.getFilename()));
}
}
public static class TestFtpSessionFactory extends AbstractFtpSessionFactory<FTPClient> {
@@ -170,6 +198,17 @@ public class FtpSendingMessageHandlerTests {
return true;
}
});
String[] files = new File("remote-test-dir").list();
Collection<Object> ftpFiles = new ArrayList<Object>();
for (String fileName : files) {
FTPFile file = new FTPFile();
file.setName(fileName);
file.setType(FTPFile.FILE_TYPE);
file.setTimestamp(Calendar.getInstance());
ftpFiles.add(file);
when(ftpClient.retrieveFile(Mockito.eq("remote-test-dir/" + fileName) , Mockito.any(OutputStream.class))).thenReturn(true);
}
when(ftpClient.listFiles("remote-test-dir/")).thenReturn(ftpFiles.toArray(new FTPFile[]{}));
return ftpClient;
} catch (Exception e) {
throw new RuntimeException("Failed to create mock client", e);