INT-1484, added support for filename-generator to FTP Outbound adapter, restructured FTP module to be consistent with other modules

This commit is contained in:
Oleg Zhurakousky
2010-10-15 09:11:57 -04:00
parent ec8f3486a1
commit b77796e914
16 changed files with 151 additions and 31 deletions

View File

@@ -23,14 +23,13 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
*
*/
public class FtpParserTests {
public class FtpParserInboundTests {
@Before
public void prepare(){
new File("target/foo").delete();
@@ -39,14 +38,14 @@ public class FtpParserTests {
@Test
public void testLocalFilesAutoCreationTrue() throws Exception{
assertTrue(!new File("target/foo").exists());
new ClassPathXmlApplicationContext("FtpParserTests-inbound.xml", this.getClass());
new ClassPathXmlApplicationContext("FtpParserInboundTests-context.xml", this.getClass());
assertTrue(new File("target/foo").exists());
assertTrue(!new File("target/bar").exists());
}
@Test(expected=BeanCreationException.class)
public void testLocalFilesAutoCreationFalse() throws Exception{
assertTrue(!new File("target/bar").exists());
new ClassPathXmlApplicationContext("FtpParserTests-inbound-fail.xml", this.getClass());
new ClassPathXmlApplicationContext("FtpParserInboundTests-fail-context.xml", this.getClass());
}
@After

View File

@@ -0,0 +1,23 @@
<?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:channel id="ftpOutbound"/>
<int-ftp:outbound-channel-adapter id="ftpOutboundAdapter"
username="ozhurakousky"
password="seva@1994"
channel="ftpOutbound"
remote-directory="temp"
host="localhost"
filename-generator="fileNameGenerator"/>
<bean id="fileNameGenerator" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.integration.file.FileNameGenerator"/>
</bean>
</beans>

View File

@@ -0,0 +1,66 @@
/*
* 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;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.file.FileNameGenerator;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
*
*/
public class FtpParserOutboundTests {
@Test
public void testFtpOutboundWithFileGenerator() throws Exception{
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("FtpParserOutboundTests-context.xml", this.getClass());
FileNameGenerator fileNameGenerator = context.getBean("fileNameGenerator", FileNameGenerator.class);
assertNotNull(fileNameGenerator);
when(fileNameGenerator.generateFileName(Mockito.any(Message.class))).thenReturn("oleg-ftp-test.txt");
EventDrivenConsumer fileOutboundEndpoint = context.getBean("ftpOutboundAdapter", EventDrivenConsumer.class);
FtpSendingMessageHandler handler = (FtpSendingMessageHandler) TestUtils.getPropertyValue(fileOutboundEndpoint, "handler");
Message<String> message = new GenericMessage<String>("ftp file generator test");
try {
handler.handleMessage(message);
} catch (Exception e) {
// ignore
}
verify(fileNameGenerator, times(1)).generateFileName(message);
}
}