From f4fcc22fa652438da59f0aa7e1d085d46e22f0a7 Mon Sep 17 00:00:00 2001 From: Gunnar Hillert Date: Mon, 3 Dec 2012 22:41:01 -0500 Subject: [PATCH] INTSAMPLES-71 - Fix SFTP Outbound Sample For reference see: https://jira.springsource.org/browse/INTSAMPLES-71 --- basic/sftp/README.md | 4 +- .../sftp/SftpOutboundTransferSample.java | 40 +++++++++++++------ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/basic/sftp/README.md b/basic/sftp/README.md index ad03f1c2..00132577 100644 --- a/basic/sftp/README.md +++ b/basic/sftp/README.md @@ -24,9 +24,9 @@ As you can see, although the remote directory had 3 files we only received 2 sin ## OUTBOUND CHANNEL ADAPTER -To run the OUTBOUND CHANNEL ADAPTER sample execute the **SftpOutboundTransferSample** test. You will see that based on the configuration it will attempt to transfer this **readme.txt** file to a remote directory **remote-target-dir**. The output should look like this: +To run the OUTBOUND CHANNEL ADAPTER sample execute the **SftpOutboundTransferSample** test. You will see that based on the configuration it will attempt to transfer the **README.md** file to a remote directory **remote-target-dir**. The output should look like this: - Successfully transfered 'readme.txt' file to a remote location under the name 'readme.txt_foo' + Successfully transferred 'README.md' file to a remote location under the name 'README.md_foo' NOTE: You can see that we are using *SpEL* via the **remote-filename-generator-expression** attribute to define the remote file name by simply appending **_foo** to the original file name. diff --git a/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/SftpOutboundTransferSample.java b/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/SftpOutboundTransferSample.java index 665bd2ac..4633b9f8 100644 --- a/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/SftpOutboundTransferSample.java +++ b/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/SftpOutboundTransferSample.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -23,30 +23,44 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; import org.springframework.integration.support.MessageBuilder; +import org.springframework.util.Assert; /** + * * @author Oleg Zhurakousky + * @author Gunnar Hillert * */ public class SftpOutboundTransferSample { @Test public void testOutbound() throws Exception{ - ClassPathXmlApplicationContext ac = + + final String sourceFileName = "README.md"; + final String destinationFileName = sourceFileName +"_foo"; + final String destinationFilePath = "remote-target-dir/" + destinationFileName; + + final ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring/integration/SftpOutboundTransferSample-context.xml", SftpOutboundTransferSample.class); ac.start(); - File file = new File("readme.txt"); - if (file.exists()){ - Message message = MessageBuilder.withPayload(file).build(); - MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class); - inputChannel.send(message); - Thread.sleep(2000); - } - if (new File("remote-target-dir/readme.txt_foo").exists()){ - System.out.println("Successfully transfered 'readme.txt' file to a remote location under the name 'readme.txt_foo'"); - } + + final File file = new File(sourceFileName); + + Assert.isTrue(file.exists(), String.format("File '%s' does not exist.", sourceFileName)); + + final Message message = MessageBuilder.withPayload(file).build(); + final MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class); + + inputChannel.send(message); + Thread.sleep(2000); + + Assert.isTrue(new File(destinationFilePath).exists(), String.format("File '%s' does not exist.", destinationFilePath)); + + System.out.println(String.format("Successfully transferred '%s' file to a " + + "remote location under the name '%s'", sourceFileName, destinationFileName)); + ac.stop(); - + } }