INT-1614 added outbound SFTP tests, more polishing

This commit is contained in:
Oleg Zhurakousky
2010-11-16 13:49:59 -05:00
parent fda3c380b1
commit ed4ec399bc
10 changed files with 79 additions and 13 deletions

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[2.5.0.201010221000-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/test/java/org/springframework/integration/sftp/config/OutboundChannelAdapaterParserTests-context.xml</config>
</configs>
<configSets>
</configSets>
</beansProjectDescription>

View File

@@ -43,7 +43,7 @@ import com.jcraft.jsch.ChannelSftp;
* @author Oleg Zhurakousky
* @since 2.0
*/
class SftpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean
class SftpInboundSynchronizingMessageSourceFactoryBean
extends AbstractFactoryBean<SftpInboundRemoteFileSystemSynchronizingMessageSource> implements ResourceLoaderAware {
private volatile ResourceLoader resourceLoader;
@@ -118,7 +118,7 @@ class SftpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean
*/
@Override
public Class<?> getObjectType() {
return SftpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean.class;
return SftpInboundSynchronizingMessageSourceFactoryBean.class;
}
/**

View File

@@ -34,6 +34,7 @@ import org.springframework.util.StringUtils;
*
* @author Josh Long
* @author Mark Fisher
* @author Oleg ZHurakousky
* @since 2.0
*/
public class SftpNamespaceHandler extends AbstractIntegrationNamespaceHandler {
@@ -51,7 +52,8 @@ public class SftpNamespaceHandler extends AbstractIntegrationNamespaceHandler {
@Override
protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(SftpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean.class.getName());
BeanDefinitionBuilder builder =
BeanDefinitionBuilder.genericBeanDefinition("org.springframework.integration.sftp.config.SftpInboundSynchronizingMessageSourceFactoryBean");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "filter");
for (String p : "auto-startup,filename-pattern,auto-create-directories,remote-directory,local-directory-path,auto-delete-remote-files-on-sync".split(",")) {
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, p);
@@ -69,8 +71,9 @@ public class SftpNamespaceHandler extends AbstractIntegrationNamespaceHandler {
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(SftpSendingMessageHandlerFactoryBean.class.getName());
for (String p : "auto-create-directories,charset".split(",")) {
BeanDefinitionBuilder builder =
BeanDefinitionBuilder.genericBeanDefinition("org.springframework.integration.sftp.config.SftpSendingMessageHandlerFactoryBean");
for (String p : "charset".split(",")) {
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, p);
}
String remoteDirectory = element.getAttribute("remote-directory");

View File

@@ -36,14 +36,13 @@ class SftpSendingMessageHandlerFactoryBean implements FactoryBean<SftpSendingMes
private Expression remoteDirectoryExpression;
private volatile SftpSessionFactory sftpSessionFactory;
private volatile String charset;
public void setSftpSessionFactory(SftpSessionFactory sftpSessionFactory) {
this.sftpSessionFactory = sftpSessionFactory;
}
private String charset;
public void setCharset(String charset) {
this.charset = charset;
}

View File

@@ -35,7 +35,7 @@
<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:attribute name="auto-create-directories" type="xsd:boolean"/>-->
</xsd:complexType>
</xsd:element>

View File

@@ -30,7 +30,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
*/
public class SftpParserTests {
public class InboundChannelAdapaterParserTests {
@Before
public void prepare(){
@@ -40,7 +40,7 @@ public class SftpParserTests {
@Test
public void testLocalFilesAutoCreationTrue() throws Exception{
assertTrue(!new File("target/foo").exists());
new ClassPathXmlApplicationContext("SftpParserTests-inbound-all.xml", this.getClass());
new ClassPathXmlApplicationContext("InboundChannelAdapaterParserTests-context.xml", this.getClass());
assertTrue(new File("target/foo").exists());
assertTrue(!new File("target/bar").exists());
}
@@ -48,13 +48,13 @@ public class SftpParserTests {
@Test(expected=BeanCreationException.class)
public void testLocalFilesAutoCreationFalse() throws Exception{
assertTrue(!new File("target/bar").exists());
new ClassPathXmlApplicationContext("SftpParserTests-inbound-all-fail.xml", this.getClass());
new ClassPathXmlApplicationContext("InboundChannelAdapaterParserTests-context-fail.xml", this.getClass());
}
@Test
public void testLocalFilesAreFound() throws Exception{
assertTrue(new File("target").exists());
new ClassPathXmlApplicationContext("SftpParserTests-inbound-all.xml", this.getClass());
new ClassPathXmlApplicationContext("InboundChannelAdapaterParserTests-context.xml", this.getClass());
assertTrue(new File("target").exists());
}

View File

@@ -0,0 +1,28 @@
<?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="loclahost"/>
<property name="knownHosts" value="local, foo.com, bar.foo"/>
<property name="privateKey" value="classpath:org/springframework/integration/sftp/config/sftpTest"/>
<property name="privateKeyPassphrase" value="ghj"/>
<property name="password" value="hello"/>
<property name="port" value="2222"/>
<property name="user" value="oleg"/>
</bean>
<int:channel id="inputChannel"/>
<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter"
session-factory="sftpSessionFactory"
channel="inputChannel"
charset="UTF-8"
remote-directory="foo/bar"/>
</beans>

View File

@@ -0,0 +1,22 @@
/**
*
*/
package org.springframework.integration.sftp.config;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author ozhurakousky
*
*/
public class OutboundChannelAdapaterParserTests {
@Test
public void test(){
ApplicationContext context =
new ClassPathXmlApplicationContext("OutboundChannelAdapaterParserTests-context.xml", this.getClass());
}
}