INT-1614 added fileNameGenerator attribute to teh SFTP outbound, added tests
This commit is contained in:
@@ -7,17 +7,6 @@
|
||||
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.client.DefaultFtpClientFactory">-->
|
||||
<!-- <property name="host" value="localhost"/>-->
|
||||
<!-- <property name="port" value="22"/>-->
|
||||
<!-- <property name="username" value="oleg"/>-->
|
||||
<!-- <property name="password" value="password"/>-->
|
||||
<!-- <property name="clientMode" value="1"/>-->
|
||||
<!-- <property name="fileType" value="2"/>-->
|
||||
<!-- <property name="remoteWorkingDirectory" value="foo/bar"/>-->
|
||||
<!-- </bean>-->
|
||||
|
||||
<bean id="ftpClientFactory"
|
||||
class="org.springframework.integration.ftp.config.FtpInboundChannelAdapterParserTests.TestClientFactoryBean"/>
|
||||
|
||||
|
||||
@@ -52,8 +52,5 @@ public class FtpOutboundChannelAdapterParserTests {
|
||||
FtpClientFactory<?> clientFactory = (FtpClientFactory<?>) TestUtils.getPropertyValue(clientPoll, "factory");
|
||||
assertEquals("localhost", TestUtils.getPropertyValue(clientFactory, "host"));
|
||||
assertEquals(22, TestUtils.getPropertyValue(clientFactory, "port"));
|
||||
// assertEquals("user", TestUtils.getPropertyValue(clientFactory, "username"));
|
||||
// assertEquals("password", TestUtils.getPropertyValue(clientFactory, "password"));
|
||||
// assertEquals("foo/bar", TestUtils.getPropertyValue(clientFactory, "remoteWorkingDirectory"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ public class SftpNamespaceHandler extends AbstractIntegrationNamespaceHandler {
|
||||
for (String p : "charset".split(",")) {
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, p);
|
||||
}
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "filename-generator", "fileNameGenerator");
|
||||
String remoteDirectory = element.getAttribute("remote-directory");
|
||||
String remoteDirectoryExpression = element.getAttribute("remote-directory-expression");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "session-factory", "sftpSessionFactory");
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.integration.sftp.config;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.integration.file.FileNameGenerator;
|
||||
import org.springframework.integration.sftp.outbound.SftpSendingMessageHandler;
|
||||
import org.springframework.integration.sftp.session.QueuedSftpSessionPool;
|
||||
import org.springframework.integration.sftp.session.SftpSessionFactory;
|
||||
@@ -38,6 +39,12 @@ class SftpSendingMessageHandlerFactoryBean implements FactoryBean<SftpSendingMes
|
||||
private volatile SftpSessionFactory sftpSessionFactory;
|
||||
|
||||
private volatile String charset;
|
||||
|
||||
private volatile FileNameGenerator fileNameGenerator;
|
||||
|
||||
public void setFileNameGenerator(FileNameGenerator fileNameGenerator) {
|
||||
this.fileNameGenerator = fileNameGenerator;
|
||||
}
|
||||
|
||||
public void setSftpSessionFactory(SftpSessionFactory sftpSessionFactory) {
|
||||
this.sftpSessionFactory = sftpSessionFactory;
|
||||
@@ -62,7 +69,9 @@ class SftpSendingMessageHandlerFactoryBean implements FactoryBean<SftpSendingMes
|
||||
SftpSendingMessageHandler messageHandler = new SftpSendingMessageHandler(sessionPool);
|
||||
messageHandler.setRemoteDirectoryExpression(this.remoteDirectoryExpression);
|
||||
messageHandler.setCharset(this.charset);
|
||||
messageHandler.setFileNameGenerator(this.fileNameGenerator);
|
||||
messageHandler.afterPropertiesSet();
|
||||
|
||||
return messageHandler;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,22 @@
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="filename-generator" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Allows you to specify a reference to
|
||||
[org.springframework.integration.file.FileNameGenerator] implementation.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.file.FileNameGenerator"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="remote-directory" type="xsd:string"/>
|
||||
<xsd:attribute name="remote-directory-expression" type="xsd:string"/>
|
||||
<xsd:attribute name="charset" type="xsd:string"/>
|
||||
<!-- <xsd:attribute name="auto-create-directories" type="xsd:boolean"/>-->
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
||||
@@ -24,5 +24,17 @@
|
||||
session-factory="sftpSessionFactory"
|
||||
channel="inputChannel"
|
||||
charset="UTF-8"
|
||||
filename-generator="fileNameGenerator"
|
||||
remote-directory="foo/bar"/>
|
||||
|
||||
|
||||
<int-sftp:outbound-channel-adapter
|
||||
session-factory="sftpSessionFactory"
|
||||
channel="inputChannel"
|
||||
charset="UTF-8"
|
||||
remote-directory="foo/bar"/>
|
||||
|
||||
<bean id="fileNameGenerator" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.springframework.integration.file.FileNameGenerator"/>
|
||||
</bean>
|
||||
</beans>
|
||||
|
||||
@@ -3,10 +3,16 @@
|
||||
*/
|
||||
package org.springframework.integration.sftp.config;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
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.sftp.outbound.SftpSendingMessageHandler;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
/**
|
||||
* @author ozhurakousky
|
||||
@@ -15,7 +21,26 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
public class OutboundChannelAdapaterParserTests {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
public void testOutboundChannelAdapaterWithId(){
|
||||
ApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("OutboundChannelAdapaterParserTests-context.xml", this.getClass());
|
||||
Object consumer = context.getBean("sftpOutboundAdapter");
|
||||
assertTrue(consumer instanceof EventDrivenConsumer);
|
||||
assertEquals(context.getBean("inputChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
|
||||
assertEquals("sftpOutboundAdapter", ((EventDrivenConsumer)consumer).getComponentName());
|
||||
SftpSendingMessageHandler handler = (SftpSendingMessageHandler) TestUtils.getPropertyValue(consumer, "handler");
|
||||
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"));
|
||||
// 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"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutboundChannelAdapaterWithNoId(){
|
||||
ApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("OutboundChannelAdapaterParserTests-context.xml", this.getClass());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user