INT-1614 added more tests, added si-test as sftp project dependency to fix the previosu build error, code coverage 77%

This commit is contained in:
Oleg Zhurakousky
2010-11-16 14:23:07 -05:00
parent d38027951d
commit 09d5bae0cc
4 changed files with 60 additions and 12 deletions

View File

@@ -343,6 +343,7 @@ project('spring-integration-sftp') {
compile "commons-lang:commons-lang:$commonsLangVersion"
compile "org.springframework:spring-context-support:$springVersion"
compile("javax.activation:activation:$javaxActivationVersion") { optional = true }
testCompile project(":spring-integration-test")
}
}

View File

@@ -22,7 +22,15 @@
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="session-factory" type="xsd:string" use="required"/>
<xsd:attribute name="session-factory" type="xsd:string" use="required">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.sftp.session.SftpSessionFactory"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="channel" use="required" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
@@ -69,7 +77,15 @@
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="session-factory" type="xsd:string" use="required"/>
<xsd:attribute name="session-factory" type="xsd:string" use="required">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.sftp.session.SftpSessionFactory"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="auto-startup" type="xsd:string" default="true"/>
<xsd:attribute name="channel" use="required" type="xsd:string">
<xsd:annotation>

View File

@@ -9,7 +9,7 @@
<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.SftpSessionFactory">
<property name="host" value="loclahost"/>
<property name="host" value="localhost"/>
<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"/>
@@ -21,13 +21,19 @@
<int:channel id="inputChannel"/>
<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter"
session-factory="sftpSessionFactory"
session-factory="sftpSessionFactory"
channel="inputChannel"
charset="UTF-8"
filename-generator="fileNameGenerator"
remote-directory="foo/bar"/>
<int-sftp:outbound-channel-adapter id="sftpOutboundAdapterWithExpression"
session-factory="sftpSessionFactory"
channel="inputChannel"
charset="UTF-8"
filename-generator="fileNameGenerator"
remote-directory-expression="'foo' + '/' + 'bar'"/>
<int-sftp:outbound-channel-adapter
session-factory="sftpSessionFactory"
channel="inputChannel"

View File

@@ -4,16 +4,25 @@
package org.springframework.integration.sftp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpression;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.sftp.outbound.SftpSendingMessageHandler;
import org.springframework.integration.sftp.session.QueuedSftpSessionPool;
import org.springframework.integration.sftp.session.SftpSessionFactory;
import org.springframework.integration.test.util.TestUtils;
import com.sun.tools.doclets.internal.toolkit.taglets.LiteralTaglet;
/**
* @author ozhurakousky
*
@@ -29,19 +38,35 @@ public class OutboundChannelAdapaterParserTests {
assertEquals(context.getBean("inputChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
assertEquals("sftpOutboundAdapter", ((EventDrivenConsumer)consumer).getComponentName());
SftpSendingMessageHandler handler = (SftpSendingMessageHandler) TestUtils.getPropertyValue(consumer, "handler");
Expression remoteDirectoryExpression = (Expression) TestUtils.getPropertyValue(handler, "remoteDirectoryExpression");
assertNotNull(remoteDirectoryExpression);
assertTrue(remoteDirectoryExpression instanceof LiteralExpression);
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"));
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolder"));
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryBufferFolderFile"));
QueuedSftpSessionPool clientPoll = (QueuedSftpSessionPool) TestUtils.getPropertyValue(handler, "pool");
SftpSessionFactory clientFactory = (SftpSessionFactory) TestUtils.getPropertyValue(clientPoll, "sftpSessionFactory");
assertEquals("localhost", TestUtils.getPropertyValue(clientFactory, "host"));
assertEquals(2222, TestUtils.getPropertyValue(clientFactory, "port"));
}
@Test
public void testOutboundChannelAdapaterWithNoId(){
public void testOutboundChannelAdapaterWithWithRemoteDirectoryExopression(){
ApplicationContext context =
new ClassPathXmlApplicationContext("OutboundChannelAdapaterParserTests-context.xml", this.getClass());
Object consumer = context.getBean("sftpOutboundAdapterWithExpression");
assertTrue(consumer instanceof EventDrivenConsumer);
assertEquals(context.getBean("inputChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
assertEquals("sftpOutboundAdapterWithExpression", ((EventDrivenConsumer)consumer).getComponentName());
SftpSendingMessageHandler handler = (SftpSendingMessageHandler) TestUtils.getPropertyValue(consumer, "handler");
SpelExpression remoteDirectoryExpression = (SpelExpression) TestUtils.getPropertyValue(handler, "remoteDirectoryExpression");
assertNotNull(remoteDirectoryExpression);
assertEquals("'foo' + '/' + 'bar'", remoteDirectoryExpression.getExpressionString());
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"));
}
}