INT-3129: FTP local-filename-generator-expression

* Add `local-filename-generator-expression` attribute to FTP and SFTP Outbound Gateway
* Refactoring for `(S)FtpOutboundGatewayParser`
* Add `local-filename-generator-expression` tests
* Add 'What's New' and attribute description

JIRA: https://jira.springsource.org/browse/INT-3129

Polishing

Doc Polishing

Assert attribute is only set for get/mget

Move tests to the get gateways
This commit is contained in:
Artem Bilan
2013-09-18 18:07:01 +03:00
committed by Gary Russell
parent bbf93e1385
commit 417c848c0b
13 changed files with 198 additions and 49 deletions

View File

@@ -31,6 +31,10 @@
order="1"
/>
<bean id="fooString" class="java.lang.String">
<constructor-arg value="foo" />
</bean>
<int-sftp:outbound-gateway id="gateway2"
local-directory="local-test-dir"
session-factory="csf"
@@ -44,6 +48,7 @@
expression="payload"
order="2"
requires-reply="false"
local-filename-generator-expression="#remoteFileName.toUpperCase() + '.a' + @fooString"
/>
<int-sftp:outbound-gateway id="gateway3"

View File

@@ -21,10 +21,13 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.lang.reflect.Method;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.Message;
import org.springframework.integration.endpoint.AbstractEndpoint;
@@ -37,6 +40,7 @@ import org.springframework.integration.sftp.gateway.SftpOutboundGateway;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ReflectionUtils;
/**
* @author Gary Russell
@@ -77,7 +81,7 @@ public class SftpOutboundGatewayParserTests {
assertNotNull(TestUtils.getPropertyValue(gateway, "filter"));
assertEquals(Command.LS, TestUtils.getPropertyValue(gateway, "command"));
@SuppressWarnings("unchecked")
Set<String> options = TestUtils.getPropertyValue(gateway, "options", Set.class);
Set<Option> options = TestUtils.getPropertyValue(gateway, "options", Set.class);
assertTrue(options.contains(Option.NAME_ONLY));
assertTrue(options.contains(Option.NOSORT));
@@ -86,7 +90,7 @@ public class SftpOutboundGatewayParserTests {
}
@Test
public void testGateway2() {
public void testGateway2() throws Exception {
SftpOutboundGateway gateway = TestUtils.getPropertyValue(gateway2,
"handler", SftpOutboundGateway.class);
assertEquals("X", TestUtils.getPropertyValue(gateway, "remoteFileSeparator"));
@@ -100,6 +104,21 @@ public class SftpOutboundGatewayParserTests {
@SuppressWarnings("unchecked")
Set<String> options = TestUtils.getPropertyValue(gateway, "options", Set.class);
assertTrue(options.contains(Option.PRESERVE_TIMESTAMP));
//INT-3129
assertNotNull(TestUtils.getPropertyValue(gateway, "localFilenameGeneratorExpression"));
final AtomicReference<Method> genMethod = new AtomicReference<Method>();
ReflectionUtils.doWithMethods(SftpOutboundGateway.class, new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
if ("generateLocalFileName".equals(method.getName())) {
method.setAccessible(true);
genMethod.set(method);
}
}
});
assertEquals("FOO.afoo", genMethod.get().invoke(gateway, new GenericMessage<String>(""), "foo"));
}
@Test