INT-1901 added support for 'comparator' atribute for FTP/SFTP Inbound Channel adapters

This commit is contained in:
Oleg Zhurakousky
2011-05-11 15:03:09 -04:00
parent 21cb39b892
commit 08d601a2ba
10 changed files with 67 additions and 2 deletions

View File

@@ -16,6 +16,9 @@
package org.springframework.integration.sftp.inbound;
import java.io.File;
import java.util.Comparator;
import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer;
import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource;
@@ -35,6 +38,10 @@ public class SftpInboundFileSynchronizingMessageSource extends AbstractInboundFi
public SftpInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer<LsEntry> synchronizer) {
super(synchronizer);
}
public SftpInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer<LsEntry> synchronizer, Comparator<File> comparator) {
super(synchronizer, comparator);
}
public String getComponentType() {

View File

@@ -157,6 +157,14 @@ endpoint itself is a Polling Consumer for a channel with a queue.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<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="cache-sessions" type="xsd:boolean" default="true">
<xsd:annotation>
<xsd:documentation><![CDATA[

View File

@@ -44,10 +44,15 @@
auto-create-local-directory="false"
remote-file-separator="."
temporary-file-suffix=".bar"
comparator="comparator"
delete-remote-files="false">
<poller fixed-rate="1000"/>
</sftp:inbound-channel-adapter>
<beans:bean id="comparator" class="org.mockito.Mockito" factory-method="mock">
<beans:constructor-arg value="java.util.Comparator"/>
</beans:bean>
<sftp:inbound-channel-adapter id="sftpAdapter"
channel="requestChannel"
session-factory="sftpSessionFactory"

View File

@@ -22,6 +22,7 @@ import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import java.io.File;
import java.util.Comparator;
import org.junit.After;
import org.junit.Before;
@@ -48,6 +49,7 @@ public class InboundChannelAdapterParserTests {
new File("foo").delete();
}
@SuppressWarnings("unchecked")
@Test
public void testWithLocalFiles() throws Exception{
ApplicationContext context =
@@ -59,7 +61,8 @@ public class InboundChannelAdapterParserTests {
SftpInboundFileSynchronizingMessageSource source =
(SftpInboundFileSynchronizingMessageSource) TestUtils.getPropertyValue(adapter, "source");
assertNotNull(source);
Comparator<File> comparator = TestUtils.getPropertyValue(adapter, "source.fileSource.toBeReceived.q.comparator", Comparator.class);
assertNotNull(comparator);
SftpInboundFileSynchronizer synchronizer = (SftpInboundFileSynchronizer) TestUtils.getPropertyValue(source, "synchronizer");
String remoteFileSeparator = (String) TestUtils.getPropertyValue(synchronizer, "remoteFileSeparator");
assertEquals(".bar", TestUtils.getPropertyValue(synchronizer, "temporaryFileSuffix", String.class));