INT-3180: Fix FtpParserInboundTests

JIRA: https://jira.springsource.org/browse/INT-3180

* Change non-existing interface in the config to existing one
* Change `@Test(expected=BeanCreationException.class)` to `try...catch` block
and check the StackTrace for appropriate, expected `Exception`
This commit is contained in:
Artem Bilan
2013-10-28 16:09:11 +02:00
committed by Gary Russell
parent 928b6b8bc3
commit d06c1c269d
2 changed files with 29 additions and 11 deletions

View File

@@ -3,12 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ftp="http://www.springframework.org/schema/integration/ftp"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:ftps="http://www.springframework.org/schema/integration/ftps"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/ftps http://www.springframework.org/schema/integration/ftp/spring-integration-ftps.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd">
<bean id="ftpSessionFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="localhost"/>
@@ -19,10 +16,10 @@
<property name="fileType" value="2"/>
</bean>
<ftp:inbound-channel-adapter id="adapterFtpDontAutoCreate"
<ftp:inbound-channel-adapter id="adapterFtpDontAutoCreate"
channel="ftpIn"
session-factory="ftpSessionFactory"
filter="filter"
filter="filter"
local-directory="file:target/bar"
remote-directory="foo/bar"
auto-create-local-directory="false"
@@ -31,9 +28,9 @@
</ftp:inbound-channel-adapter>
<bean id="filter" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.integration.file.entries.EntryListFilter"/>
<constructor-arg value="org.springframework.integration.file.filters.FileListFilter"/>
</bean>
<int:channel id="ftpIn">
<int:queue/>
</int:channel>

View File

@@ -15,19 +15,28 @@
*/
package org.springframework.integration.ftp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileNotFoundException;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.MessagingException;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Artem Bilan
*
*/
public class FtpParserInboundTests {
@@ -43,14 +52,26 @@ public class FtpParserInboundTests {
assertTrue(new File("target/foo").exists());
assertTrue(!new File("target/bar").exists());
}
@Test(expected=BeanCreationException.class)
@Test
public void testLocalFilesAutoCreationFalse() throws Exception{
assertTrue(!new File("target/bar").exists());
new ClassPathXmlApplicationContext("FtpParserInboundTests-fail-context.xml", this.getClass());
try {
new ClassPathXmlApplicationContext("FtpParserInboundTests-fail-context.xml", this.getClass());
fail("BeansException expected.");
}
catch (BeansException e) {
Throwable cause = e.getCause();
assertThat(cause, Matchers.instanceOf(BeanCreationException.class));
cause = cause.getCause();
assertThat(cause, Matchers.instanceOf(MessagingException.class));
cause = cause.getCause();
assertThat(cause, Matchers.instanceOf(FileNotFoundException.class));
assertEquals("bar", cause.getMessage());
}
}
@After
public void cleanUp() throws Exception{
new File("target/foo").delete();
}
}
}