From 74e4def35e9bc0f5eea6fc14f6a3103c1b1a934f Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Mon, 15 Nov 2010 16:13:09 -0500 Subject: [PATCH] INT-1614 added more inbound/outbound parser tests, polishing --- ...SynchronizingMessageSourceFactoryBean.java | 12 +++- .../FtpSendingMessageHandlerFactoryBean.java | 43 ++++++++------ .../FtpsInboundChannelAdapterParser.java | 2 +- ...SynchronizingMessageSourceFactoryBean.java | 49 ++++++++------- .../FtpsSendingMessageHandlerFactoryBean.java | 50 +++++++--------- .../ftp/config/spring-integration-ftp-2.0.xsd | 2 +- .../config/spring-integration-ftps-2.0.xsd | 2 +- ...boundChannelAdapterParserTests-context.xml | 35 +++++++++++ .../FtpInboundChannelAdapterParserTests.java | 36 +++++++++++ ...boundChannelAdapterParserTests-context.xml | 35 +++++++++++ .../FtpsInboundChannelAdapterParserTests.java | 36 +++++++++++ ...boundChannelAdapterParserTests-context.xml | 6 +- ...FtpsOutboundChannelAdapterParserTests.java | 59 +++++++++++++++++++ 13 files changed, 284 insertions(+), 83 deletions(-) create mode 100644 spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml create mode 100644 spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java create mode 100644 spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParserTests-context.xml create mode 100644 spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParserTests.java create mode 100644 spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsOutboundChannelAdapterParserTests.java diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean.java index a0a9dea9ba..7820423730 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean.java @@ -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 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(); + } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpSendingMessageHandlerFactoryBean.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpSendingMessageHandlerFactoryBean.java index 5da6909161..60a74fc9cd 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpSendingMessageHandlerFactoryBean.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpSendingMessageHandlerFactoryBean.java @@ -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 { - 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 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); diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParser.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParser.java index e7edd79797..837ce823be 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParser.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParser.java @@ -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"; } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean.java index 43458c881b..2bc08d296a 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsInboundRemoteFileSystemSynchronizingMessageSourceFactoryBean.java @@ -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(); + } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsSendingMessageHandlerFactoryBean.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsSendingMessageHandlerFactoryBean.java index 11e7ad9204..eb75dff414 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsSendingMessageHandlerFactoryBean.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsSendingMessageHandlerFactoryBean.java @@ -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(); + } } diff --git a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd b/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd index a4c646b0f5..fb1cfe164b 100644 --- a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd +++ b/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd @@ -59,7 +59,7 @@ - + diff --git a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftps-2.0.xsd b/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftps-2.0.xsd index 819fac7bf4..e3281738ef 100644 --- a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftps-2.0.xsd +++ b/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftps-2.0.xsd @@ -62,7 +62,7 @@ - + diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml new file mode 100644 index 0000000000..1f7e0e032f --- /dev/null +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java new file mode 100644 index 0000000000..f9ff58055f --- /dev/null +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java @@ -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()); + + } +} diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParserTests-context.xml b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParserTests-context.xml new file mode 100644 index 0000000000..3f1486fe08 --- /dev/null +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParserTests-context.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParserTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParserTests.java new file mode 100644 index 0000000000..6d6bffd316 --- /dev/null +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsInboundChannelAdapterParserTests.java @@ -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()); + + } +} diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsOutboundChannelAdapterParserTests-context.xml b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsOutboundChannelAdapterParserTests-context.xml index 80677aeb7a..6d7c4313bf 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsOutboundChannelAdapterParserTests-context.xml +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsOutboundChannelAdapterParserTests-context.xml @@ -2,13 +2,13 @@ + http://www.springframework.org/schema/integration/ftps http://www.springframework.org/schema/integration/ftp/spring-integration-ftps-2.0.xsd"> - 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")); + } +}