INT-549 Added namespace support for the 'comparator' attribute on the File namespace's 'inbound-channel-adapter' element.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -43,6 +43,10 @@ public class FileInboundChannelAdapterParser extends AbstractPollingInboundChann
|
||||
protected String parseSource(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
PACKAGE_NAME + ".FileReadingMessageSource");
|
||||
String comparator = element.getAttribute("comparator");
|
||||
if (StringUtils.hasText(comparator)) {
|
||||
builder.addConstructorArgReference(comparator);
|
||||
}
|
||||
String directory = element.getAttribute("directory");
|
||||
if (StringUtils.hasText(directory)) {
|
||||
if (directory.indexOf(':') == -1) {
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
<xsd:element name="inbound-channel-adapter">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Configures an inbound Channel Adapter that polls a directory.
|
||||
Configures an inbound Channel Adapter that polls a directory and sends
|
||||
Messages whose payloads are instances of java.io.File.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
@@ -39,6 +40,14 @@
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="directory" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="comparator" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specify a Comparator to be used when ordering Files. If none is provided, the
|
||||
order will be determined by the java.io.File implementation of Comparable.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="filter" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<inbound-channel-adapter id="inputDirPoller"
|
||||
directory="file:${java.io.tmpdir}"
|
||||
filter="filter"
|
||||
comparator="testComparator"
|
||||
auto-startup="false">
|
||||
<integration:poller>
|
||||
<integration:interval-trigger interval="5000"/>
|
||||
@@ -27,4 +28,7 @@
|
||||
|
||||
<beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
|
||||
|
||||
<beans:bean id="testComparator"
|
||||
class="org.springframework.integration.file.config.FileInboundChannelAdapterParserTests$TestComparator"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -17,13 +17,17 @@
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -42,15 +46,16 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
public class FileInboundChannelAdapterParserTests {
|
||||
|
||||
@Autowired(required=true)
|
||||
ApplicationContext context;
|
||||
private ApplicationContext context;
|
||||
|
||||
@Autowired(required=true)
|
||||
FileReadingMessageSource source;
|
||||
private FileReadingMessageSource source;
|
||||
|
||||
DirectFieldAccessor accessor;
|
||||
private DirectFieldAccessor accessor;
|
||||
|
||||
|
||||
@Before public void init() {
|
||||
@Before
|
||||
public void init() {
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
}
|
||||
|
||||
@@ -67,10 +72,28 @@ public class FileInboundChannelAdapterParserTests {
|
||||
File actual = (File) accessor.getPropertyValue("inputDirectory");
|
||||
assertEquals("'inputDirectory' should be set", expected, actual);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void filter() throws Exception {
|
||||
assertTrue("'filter' should be set", accessor.getPropertyValue("filter") instanceof CompositeFileListFilter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void comparator() throws Exception {
|
||||
Object priorityQueue = accessor.getPropertyValue("toBeReceived");
|
||||
assertEquals(PriorityBlockingQueue.class, priorityQueue.getClass());
|
||||
Object expected = context.getBean("testComparator");
|
||||
Object innerQueue = new DirectFieldAccessor(priorityQueue).getPropertyValue("q");
|
||||
Object actual = new DirectFieldAccessor(innerQueue).getPropertyValue("comparator");
|
||||
assertSame("comparator reference not set, ", expected, actual);
|
||||
}
|
||||
|
||||
|
||||
static class TestComparator implements Comparator<File> {
|
||||
|
||||
public int compare(File f1, File f2) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user