Added namespace support for 'file-filter' and 'filename-filter' properties of FileSource (INT-242).
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.adapter.file.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CustomFileFilter implements FileFilter {
|
||||
|
||||
public boolean accept(File pathname) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.adapter.file.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CustomFilenameFilter implements FilenameFilter {
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,8 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -84,10 +86,20 @@ public class FileSourceParserTests {
|
||||
assertTrue(messageCreator instanceof FileMessageCreator);
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testInvalidFileSource() throws Throwable {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("invalidFileSourceTests.xml", this.getClass());
|
||||
fail();
|
||||
} catch (BeanDefinitionStoreException e) {
|
||||
throw e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceCustomType() {
|
||||
public void testFileSourceWithCustomMessageCreator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceCustom");
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceWithCustomMessageCreator");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
@@ -96,12 +108,30 @@ public class FileSourceParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidFileSource() {
|
||||
public void testFileSourceWithCustomFileFilter() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceWithCustomFileFilter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(fileSource);
|
||||
FileFilter filter = (FileFilter) context.getBean("customFileFilter");
|
||||
assertEquals(filter, accessor.getPropertyValue("fileFilter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithCustomFilenameFilter() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceWithCustomFilenameFilter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(fileSource);
|
||||
FilenameFilter filter = (FilenameFilter) context.getBean("customFilenameFilter");
|
||||
assertEquals(filter, accessor.getPropertyValue("filenameFilter"));
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testFileSourceWithFileFilterAndFilenameFilterNotAllowed() throws Throwable {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("invalidFileSourceTests.xml", this.getClass());
|
||||
new ClassPathXmlApplicationContext("fileSourceWithTooManyFilters.xml", this.getClass());
|
||||
fail();
|
||||
} catch (BeanDefinitionStoreException e) {
|
||||
assertTrue(e.getCause() instanceof ConfigurationException);
|
||||
throw e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,17 +11,25 @@
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:file-source id="fileSourceDefault" directory="${java.io.tmpdir}"/>
|
||||
|
||||
|
||||
<si:file-source id="fileSourceText" type="text" directory="${java.io.tmpdir}"/>
|
||||
|
||||
|
||||
<si:file-source id="fileSourceBinary" type="binary" directory="${java.io.tmpdir}"/>
|
||||
|
||||
|
||||
<si:file-source id="fileSourceFile" type="file" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceCustom" message-creator="customMessageCreator" directory="${java.io.tmpdir}"/>
|
||||
|
||||
|
||||
<si:file-source id="fileSourceWithCustomMessageCreator" message-creator="customMessageCreator" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceWithCustomFileFilter" file-filter="customFileFilter" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceWithCustomFilenameFilter" filename-filter="customFilenameFilter" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<bean id="customMessageCreator" class="org.springframework.integration.adapter.file.config.CustomMessageCreator"/>
|
||||
|
||||
<bean id="customFileFilter" class="org.springframework.integration.adapter.file.config.CustomFileFilter"/>
|
||||
|
||||
<bean id="customFilenameFilter" class="org.springframework.integration.adapter.file.config.CustomFilenameFilter"/>
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?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:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:file-source id="fileSource"
|
||||
directory="${java.io.tmpdir}"
|
||||
file-filter="customFileFilter"
|
||||
filename-filter="customFilenameFilter"/>
|
||||
|
||||
<bean id="customFileFilter" class="org.springframework.integration.adapter.file.config.CustomFileFilter"/>
|
||||
|
||||
<bean id="customFilenameFilter" class="org.springframework.integration.adapter.file.config.CustomFilenameFilter"/>
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user