INT-1864 added tests for SFTP outbound adapters with caching and non-caching SessionFactory instances

This commit is contained in:
Mark Fisher
2011-04-29 11:21:36 -04:00
parent ab0207c49e
commit 88fab8d2ca
2 changed files with 102 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?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.DefaultSftpSessionFactory">
<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"/>
<property name="password" value="hello"/>
<property name="port" value="2222"/>
<property name="user" value="oleg"/>
</bean>
<int:publish-subscribe-channel id="inputChannel"/>
<int-sftp:outbound-channel-adapter id="defaultAdapter"
session-factory="sftpSessionFactory"
channel="inputChannel"
remote-directory="foo/bar"/>
<int-sftp:outbound-channel-adapter id="cachingAdapter"
session-factory="sftpSessionFactory"
cache-sessions="true"
channel="inputChannel"
remote-directory="foo/bar"/>
<int-sftp:outbound-channel-adapter id="nonCachingAdapter"
session-factory="sftpSessionFactory"
cache-sessions="false"
channel="inputChannel"
remote-directory="foo/bar"/>
</beans>

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.sftp.config;
import static junit.framework.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.file.remote.session.CachingSessionFactory;
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class OutboundChannelAdapterParserCachingTests {
@Autowired private Object defaultAdapter;
@Autowired private Object cachingAdapter;
@Autowired private Object nonCachingAdapter;
@Test
public void defaultAdapter() {
Object sessionFactory = TestUtils.getPropertyValue(defaultAdapter, "handler.sessionFactory");
assertEquals(CachingSessionFactory.class, sessionFactory.getClass());
}
@Test
public void cachingAdapter() {
Object sessionFactory = TestUtils.getPropertyValue(cachingAdapter, "handler.sessionFactory");
assertEquals(CachingSessionFactory.class, sessionFactory.getClass());
}
@Test
public void nonCachingAdapter() {
Object sessionFactory = TestUtils.getPropertyValue(nonCachingAdapter, "handler.sessionFactory");
assertEquals(DefaultSftpSessionFactory.class, sessionFactory.getClass());
}
}