INT-2493 Add Edit For Filter on Get

Previously, the Filter property was ignored for a Get
command; this adds a hard edit to ensure a filter is
not provided when this command is used.
This commit is contained in:
Gary Russell
2012-04-06 16:57:34 -04:00
committed by Oleg Zhurakousky
parent 6dca78a624
commit b317ece4c8
2 changed files with 50 additions and 3 deletions

View File

@@ -162,9 +162,9 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
"command must be one of "
+ StringUtils
.collectionToCommaDelimitedString(this.supportedCommands));
// NOTE: Filter also not used on GET, need to correct in 2.2.
if (COMMAND_RM.equals(this.command) || COMMAND_MGET.equals(this.command)) {
Assert.isNull(this.filter, "Filters are not supported with the rm and mget commands");
if (COMMAND_RM.equals(this.command) || COMMAND_MGET.equals(this.command) ||
COMMAND_GET.equals(this.command)) {
Assert.isNull(this.filter, "Filters are not supported with the rm, get, and mget commands");
}
if (COMMAND_GET.equals(this.command)
|| COMMAND_MGET.equals(this.command)) {

View File

@@ -18,6 +18,7 @@ package org.springframework.integration.file.remote.gateway;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -37,6 +38,7 @@ import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.file.FileHeaders;
import org.springframework.integration.file.filters.AbstractSimplePatternFileListFilter;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.remote.AbstractFileInfo;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.file.remote.session.SessionFactory;
@@ -62,6 +64,51 @@ public class RemoteFileOutboundGatewayTests {
gw.afterPropertiesSet();
}
@Test
public void testBadFilterGet() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway
(sessionFactory, "get", "payload");
gw.setFilter(new TestPatternFilter(""));
try {
gw.onInit();
fail("Exception expected");
}
catch (IllegalArgumentException e) {
assertTrue(e.getMessage().startsWith("Filters are not supported"));
}
}
@Test
public void testBadFilterMGet() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway
(sessionFactory, "mget", "payload");
gw.setFilter(new TestPatternFilter(""));
try {
gw.onInit();
fail("Exception expected");
}
catch (IllegalArgumentException e) {
assertTrue(e.getMessage().startsWith("Filters are not supported"));
}
}
@Test
public void testBadFilterRm() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway
(sessionFactory, "rm", "payload");
gw.setFilter(new TestPatternFilter(""));
try {
gw.onInit();
fail("Exception expected");
}
catch (IllegalArgumentException e) {
assertTrue(e.getMessage().startsWith("Filters are not supported"));
}
}
@Test
public void testLs() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);