INT-1614 added more inbound/outbound parser tests, polishing

This commit is contained in:
Oleg Zhurakousky
2010-11-15 16:13:09 -05:00
parent 6c93d80ac3
commit 74e4def35e
13 changed files with 284 additions and 83 deletions

View File

@@ -43,6 +43,8 @@ import org.springframework.util.StringUtils;
*
* @author Iwein Fuld
* @author Josh Long
* @author Oleg Zhurakousky
* @since 2.0
*/
class FtpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean
extends AbstractFactoryBean<FtpInboundRemoteFileSystemSynchronizingMessageSource> implements ResourceLoaderAware {
@@ -141,8 +143,7 @@ class FtpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean
return (Resource) resourceEditor.getValue();
}
protected AbstractFtpClientFactory<?> defaultClientFactory() throws Exception {
DefaultFtpClientFactory factory = new DefaultFtpClientFactory();
protected AbstractFtpClientFactory<?> initializeFactory(AbstractFtpClientFactory<?> factory) throws Exception {
factory.setHost(this.host);
if (StringUtils.hasText(this.port)) {
factory.setPort(Integer.parseInt(this.port));
@@ -176,7 +177,8 @@ class FtpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean
if (this.filter != null) {
compositeFilter.addFilter(this.filter);
}
QueuedFtpClientPool queuedFtpClientPool = new QueuedFtpClientPool(15, this.defaultClientFactory());
AbstractFtpClientFactory<?> factory = this.createClientFactory();
QueuedFtpClientPool queuedFtpClientPool = new QueuedFtpClientPool(15, this.initializeFactory(factory));
FtpInboundRemoteFileSystemSynchronizer synchronizer = new FtpInboundRemoteFileSystemSynchronizer();
synchronizer.setClientPool(queuedFtpClientPool);
synchronizer.setLocalDirectory(this.localDirectoryResource);
@@ -192,5 +194,9 @@ class FtpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean
messageSource.start();
return messageSource;
}
protected AbstractFtpClientFactory<?> createClientFactory(){
return new DefaultFtpClientFactory();
}
}

View File

@@ -30,24 +30,26 @@ import org.springframework.integration.ftp.outbound.FtpSendingMessageHandler;
*
* @author Iwein Fuld
* @author Josh Long
* @author Oleg Zhurakousky
* @since 2.0
*/
class FtpSendingMessageHandlerFactoryBean extends AbstractFactoryBean<FtpSendingMessageHandler> {
protected int port;
protected volatile int port;
protected String username;
protected volatile String username;
protected String password;
protected volatile String password;
protected String host;
protected volatile String host;
protected String remoteDirectory;
protected volatile String remoteDirectory;
private String charset;
private volatile String charset;
protected int clientMode;
protected volatile int clientMode;
private int fileType;
private volatile int fileType;
private FileNameGenerator fileNameGenerator;
@@ -93,21 +95,24 @@ class FtpSendingMessageHandlerFactoryBean extends AbstractFactoryBean<FtpSending
return FtpSendingMessageHandler.class;
}
protected AbstractFtpClientFactory<?> clientFactory() {
DefaultFtpClientFactory defaultFtpClientFactory = new DefaultFtpClientFactory();
defaultFtpClientFactory.setHost(this.host);
defaultFtpClientFactory.setPort(this.port);
defaultFtpClientFactory.setUsername(this.username);
defaultFtpClientFactory.setPassword(this.password);
defaultFtpClientFactory.setRemoteWorkingDirectory(this.remoteDirectory);
defaultFtpClientFactory.setClientMode(this.clientMode);
defaultFtpClientFactory.setFileType(this.fileType);
return defaultFtpClientFactory;
protected AbstractFtpClientFactory<?> initializeClientFactory(AbstractFtpClientFactory<?> factory) {
factory.setHost(this.host);
factory.setPort(this.port);
factory.setUsername(this.username);
factory.setPassword(this.password);
factory.setRemoteWorkingDirectory(this.remoteDirectory);
factory.setClientMode(this.clientMode);
factory.setFileType(this.fileType);
return factory;
}
protected AbstractFtpClientFactory<?> createClientFactory(){
return new DefaultFtpClientFactory();
}
@Override
protected FtpSendingMessageHandler createInstance() throws Exception {
AbstractFtpClientFactory<?> defaultFtpClientFactory = clientFactory();
AbstractFtpClientFactory<?> defaultFtpClientFactory = this.initializeClientFactory(this.createClientFactory());
QueuedFtpClientPool queuedFtpClientPool = new QueuedFtpClientPool(15, defaultFtpClientFactory);
FtpSendingMessageHandler ftpSendingMessageHandler = new FtpSendingMessageHandler(
queuedFtpClientPool);

View File

@@ -28,6 +28,6 @@ public class FtpsInboundChannelAdapterParser extends AbstractFtpInboundChannelAd
@Override
protected String getClassName() {
return "org.springframework.integration.ftp.config.FtpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean";
return "org.springframework.integration.ftp.config.FtpsInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean";
}
}

View File

@@ -16,19 +16,21 @@
package org.springframework.integration.ftp.config;
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
import org.apache.commons.net.ftp.FTPClient;
import org.springframework.integration.ftp.client.AbstractFtpClientFactory;
import org.springframework.integration.ftp.client.DefaultFtpsClientFactory;
import org.springframework.util.StringUtils;
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
/**
* Factory to make building the namespace easier.
*
* @author Josh Long
* @author Oleg Zhurakousky
* @since 2.0
*/
class FtpsInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean extends FtpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean {
@@ -114,36 +116,31 @@ class FtpsInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean extends F
this.cipherSuites = cipherSuites;
}
protected AbstractFtpClientFactory<?> defaultClientFactory() throws Exception {
DefaultFtpsClientFactory factory = new DefaultFtpsClientFactory();
factory.setHost(this.host);
if (StringUtils.hasText(this.port)) {
factory.setPort(Integer.parseInt(this.port));
}
factory.setUsername(this.username);
factory.setPassword(this.password);
factory.setRemoteWorkingDirectory(this.remoteDirectory);
factory.setFileType(this.fileType);
factory.setClientMode(this.clientMode);
factory.setCipherSuites(this.cipherSuites);
factory.setAuthValue(this.authValue);
factory.setTrustManager(this.trustManager);
factory.setKeyManager(this.keyManager);
factory.setNeedClientAuth(this.needClientAuth);
factory.setWantsClientAuth(this.wantsClientAuth);
factory.setSessionCreation(this.sessionCreation);
factory.setUseClientMode(this.useClientMode);
protected AbstractFtpClientFactory<?> initializeFactory(AbstractFtpClientFactory<?> factory) throws Exception {
super.initializeFactory(factory);
DefaultFtpsClientFactory ftpsFactory = (DefaultFtpsClientFactory) factory;
ftpsFactory.setCipherSuites(this.cipherSuites);
ftpsFactory.setAuthValue(this.authValue);
ftpsFactory.setTrustManager(this.trustManager);
ftpsFactory.setKeyManager(this.keyManager);
ftpsFactory.setNeedClientAuth(this.needClientAuth);
ftpsFactory.setWantsClientAuth(this.wantsClientAuth);
ftpsFactory.setSessionCreation(this.sessionCreation);
ftpsFactory.setUseClientMode(this.useClientMode);
if (StringUtils.hasText(this.prot)) {
factory.setProt(this.prot);
ftpsFactory.setProt(this.prot);
}
if (StringUtils.hasText(this.protocol)) {
factory.setProtocol(this.protocol);
ftpsFactory.setProtocol(this.protocol);
}
if (this.implicit != null) {
factory.setImplicit(this.implicit);
ftpsFactory.setImplicit(this.implicit);
}
return factory;
}
protected AbstractFtpClientFactory<?> createClientFactory(){
return new DefaultFtpsClientFactory();
}
}

View File

@@ -28,6 +28,8 @@ import org.springframework.util.StringUtils;
*
* @author Josh Long
* @author Iwein Fuld
* @author Oleg Zhurakousky
* @since 2.0
*/
class FtpsSendingMessageHandlerFactoryBean extends FtpSendingMessageHandlerFactoryBean {
@@ -62,9 +64,6 @@ class FtpsSendingMessageHandlerFactoryBean extends FtpSendingMessageHandlerFacto
private volatile String[] cipherSuites;
private volatile int fileType;
public void setImplicit(Boolean implicit) {
this.implicit = implicit;
}
@@ -109,38 +108,31 @@ class FtpsSendingMessageHandlerFactoryBean extends FtpSendingMessageHandlerFacto
this.cipherSuites = cipherSuites;
}
public void setFileType(int fileType) {
this.fileType = fileType;
}
@Override
protected AbstractFtpClientFactory<?> clientFactory() {
DefaultFtpsClientFactory factory = new DefaultFtpsClientFactory();
factory.setHost(this.host);
factory.setPort(this.port);
factory.setUsername(this.username);
factory.setPassword(this.password);
factory.setRemoteWorkingDirectory(this.remoteDirectory);
factory.setFileType(this.fileType);
factory.setClientMode(this.clientMode);
factory.setCipherSuites(this.cipherSuites);
factory.setAuthValue(this.authValue);
factory.setTrustManager(this.trustManager);
factory.setKeyManager(this.keyManager);
factory.setNeedClientAuth(this.needClientAuth);
factory.setWantsClientAuth(this.wantsClientAuth);
factory.setSessionCreation(this.sessionCreation);
factory.setUseClientMode(this.useClientMode);
protected AbstractFtpClientFactory<?> initializeClientFactory(AbstractFtpClientFactory<?> factory) {
super.initializeClientFactory(factory);
DefaultFtpsClientFactory ftpsFactory = (DefaultFtpsClientFactory) factory;
ftpsFactory.setCipherSuites(this.cipherSuites);
ftpsFactory.setAuthValue(this.authValue);
ftpsFactory.setTrustManager(this.trustManager);
ftpsFactory.setKeyManager(this.keyManager);
ftpsFactory.setNeedClientAuth(this.needClientAuth);
ftpsFactory.setWantsClientAuth(this.wantsClientAuth);
ftpsFactory.setSessionCreation(this.sessionCreation);
ftpsFactory.setUseClientMode(this.useClientMode);
if (StringUtils.hasText(this.prot)) {
factory.setProt(this.prot);
ftpsFactory.setProt(this.prot);
}
if (StringUtils.hasText(this.protocol)) {
factory.setProtocol(this.protocol);
ftpsFactory.setProtocol(this.protocol);
}
if (this.implicit != null) {
factory.setImplicit(this.implicit);
ftpsFactory.setImplicit(this.implicit);
}
return factory;
return ftpsFactory;
}
protected AbstractFtpClientFactory<?> createClientFactory(){
return new DefaultFtpsClientFactory();
}
}

View File

@@ -59,7 +59,7 @@
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.file.entries.EntryListFilter"/>
<tool:expected-type type="org.springframework.integration.file.filters.FileListFilter"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>

View File

@@ -62,7 +62,7 @@
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.file.entries.EntryListFilter"/>
<tool:expected-type type="org.springframework.integration.file.filters.FileListFilter"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>

View File

@@ -0,0 +1,35 @@
<?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-ftp="http://www.springframework.org/schema/integration/ftp"
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/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-2.0.xsd">
<int-ftp:inbound-channel-adapter
id="ftpOutbound"
username="user"
password="password"
channel="ftpChannel"
remote-directory="foo/bar"
host="localhost"
charset="UTF-8"
client-mode="active-local-data-connection-mode"
file-type="binary-file-type"
port="22"
auto-create-directories="true"
auto-delete-remote-files-on-sync="true"
filename-pattern=".?txt"
filter="entryListFilter"
local-working-directory=".">
<int:poller fixed-rate="1000"/>
</int-ftp:inbound-channel-adapter>
<int:channel id="ftpChannel"/>
<bean id="entryListFilter" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.integration.file.filters.FileListFilter"/>
</bean>
</beans>

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2002-2010 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.ftp.config;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
*
*/
public class FtpInboundChannelAdapterParserTests {
@Test
public void testFtpInboundChannelAdapterComplete() throws Exception{
ApplicationContext ac =
new ClassPathXmlApplicationContext("FtpInboundChannelAdapterParserTests-context.xml", this.getClass());
}
}

View File

@@ -0,0 +1,35 @@
<?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-ftps="http://www.springframework.org/schema/integration/ftps"
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/ftps http://www.springframework.org/schema/integration/ftp/spring-integration-ftps-2.0.xsd">
<int-ftps:inbound-channel-adapter
id="ftpOutbound"
username="user"
password="password"
channel="ftpChannel"
remote-directory="foo/bar"
host="localhost"
charset="UTF-8"
client-mode="active-local-data-connection-mode"
file-type="binary-file-type"
port="22"
auto-create-directories="true"
auto-delete-remote-files-on-sync="true"
filename-pattern=".?txt"
filter="entryListFilter"
local-working-directory=".">
<int:poller fixed-rate="1000"/>
</int-ftps:inbound-channel-adapter>
<int:channel id="ftpChannel"/>
<bean id="entryListFilter" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.integration.file.filters.FileListFilter"/>
</bean>
</beans>

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2002-2010 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.ftp.config;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
*
*/
public class FtpsInboundChannelAdapterParserTests {
@Test
public void testFtpsInboundChannelAdapterComplete() throws Exception{
ApplicationContext ac =
new ClassPathXmlApplicationContext("FtpsInboundChannelAdapterParserTests-context.xml", this.getClass());
}
}

View File

@@ -2,13 +2,13 @@
<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-ftp="http://www.springframework.org/schema/integration/ftp"
xmlns:int-ftps="http://www.springframework.org/schema/integration/ftps"
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/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-2.0.xsd">
http://www.springframework.org/schema/integration/ftps http://www.springframework.org/schema/integration/ftp/spring-integration-ftps-2.0.xsd">
<int-ftp:outbound-channel-adapter
<int-ftps:outbound-channel-adapter
id="ftpOutbound"
username="user"
password="password"

View File

@@ -0,0 +1,59 @@
/*
* Copyright 2002-2010 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.ftp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
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.ftp.client.FtpClientFactory;
import org.springframework.integration.ftp.client.FtpClientPool;
import org.springframework.integration.ftp.outbound.FtpSendingMessageHandler;
import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
*
*/
public class FtpsOutboundChannelAdapterParserTests {
@Test
public void testFtpsOutboundChannelAdapterComplete() throws Exception{
ApplicationContext ac =
new ClassPathXmlApplicationContext("FtpsOutboundChannelAdapterParserTests-context.xml", this.getClass());
Object consumer = ac.getBean("ftpOutbound");
assertTrue(consumer instanceof EventDrivenConsumer);
assertEquals(ac.getBean("ftpChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
assertEquals("ftpOutbound", ((EventDrivenConsumer)consumer).getComponentName());
FtpSendingMessageHandler handler = (FtpSendingMessageHandler) TestUtils.getPropertyValue(consumer, "handler");
assertEquals(ac.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"));
assertEquals("user", TestUtils.getPropertyValue(clientFactory, "username"));
assertEquals("password", TestUtils.getPropertyValue(clientFactory, "password"));
assertEquals("foo/bar", TestUtils.getPropertyValue(clientFactory, "remoteWorkingDirectory"));
}
}