QUALITY: cleaned up FileToChannelIntegrationTests
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns:file="http://www.springframework.org/schema/integration/file"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/file
|
||||
http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd">
|
||||
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">
|
||||
|
||||
<!-- under test -->
|
||||
<file:inbound-channel-adapter
|
||||
directory="${java.io.tmpdir}/FileToChannelIntegrationTests"
|
||||
channel="fileMessages" filter="compositeFilter" />
|
||||
directory="#{inputDirectory.path}"
|
||||
channel="fileMessages" filter="compositeFilter"/>
|
||||
|
||||
<bean id="temp" class="org.junit.rules.TemporaryFolder"
|
||||
init-method="create" destroy-method="delete"/>
|
||||
|
||||
<bean id="inputDirectory" class="java.io.File">
|
||||
<constructor-arg value="#{temp.newFolder('FileToChannelIntegrationTests').path}"/>
|
||||
</bean>
|
||||
|
||||
<si:channel id="fileMessages">
|
||||
<si:queue capacity="10" />
|
||||
@@ -20,25 +27,20 @@
|
||||
|
||||
<!-- customized filter -->
|
||||
<bean id="compositeFilter"
|
||||
class="org.springframework.integration.file.CompositeFileListFilter">
|
||||
class="org.springframework.integration.file.CompositeFileListFilter">
|
||||
<constructor-arg>
|
||||
<list>
|
||||
<bean
|
||||
class="org.springframework.integration.file.AcceptOnceFileListFilter" />
|
||||
<bean class="org.springframework.integration.file.TestFileListFilter" />
|
||||
<bean
|
||||
class="org.springframework.integration.file.PatternMatchingFileListFilter">
|
||||
<constructor-arg value="^test.*$" />
|
||||
<bean class="org.springframework.integration.file.AcceptOnceFileListFilter"/>
|
||||
<bean class="org.springframework.integration.file.TestFileListFilter"/>
|
||||
<bean class="org.springframework.integration.file.PatternMatchingFileListFilter">
|
||||
<constructor-arg value="^test.*$"/>
|
||||
</bean>
|
||||
</list>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<si:poller default="true">
|
||||
<si:interval-trigger interval="10" />
|
||||
</si:poller>
|
||||
|
||||
<bean
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
|
||||
<si:poller default="true" fixed-rate="10"/>
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
|
||||
|
||||
</beans>
|
||||
@@ -16,24 +16,19 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
@@ -41,35 +36,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class FileToChannelIntegrationTests {
|
||||
|
||||
private static File inputDir;
|
||||
@Autowired File inputDirectory;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("fileMessages")
|
||||
PollableChannel fileMessages;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupInputDir() {
|
||||
inputDir = new File(System.getProperty("java.io.tmpdir") + "/"
|
||||
+ FileToChannelIntegrationTests.class.getSimpleName());
|
||||
inputDir.mkdir();
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanoutInputDir() throws Exception {
|
||||
File[] listFiles = inputDir.listFiles();
|
||||
for (int i = 0; i < listFiles.length; i++) {
|
||||
listFiles[i].delete();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void removeInputDir() throws Exception {
|
||||
inputDir.delete();
|
||||
}
|
||||
|
||||
@Test(timeout = 2000)
|
||||
public void fileMessageToChannel() throws Exception {
|
||||
File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000);
|
||||
File.createTempFile("test", null, inputDirectory).setLastModified(System.currentTimeMillis() - 1000);
|
||||
Message<File> received = receiveFileMessage();
|
||||
while (received == null) {
|
||||
Thread.sleep(50);
|
||||
@@ -85,7 +59,7 @@ public class FileToChannelIntegrationTests {
|
||||
|
||||
@Test(timeout = 2000)
|
||||
public void directoryExhaustion() throws Exception {
|
||||
File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000);
|
||||
File.createTempFile("test", null, inputDirectory).setLastModified(System.currentTimeMillis() - 1000);
|
||||
Message<File> received = receiveFileMessage();
|
||||
while (received == null) {
|
||||
Thread.sleep(5);
|
||||
|
||||
Reference in New Issue
Block a user