Upgrade to SI-4.3.12 SIK-2.3 RC1 SK-1.3 RC1

Some other minor polishing for `build.gradle`

Also fix `SftpTestUtils` do not use `DFA`, but ` session.getClientInstance()`
Fix `EmailFragment` to use `Assert` methods with string explanations arg
Fix `SftpOutboundTransferSample` to use JUnit's `assertTrue()` instead of `Assert.isTrue()`
This commit is contained in:
Artem Bilan
2017-09-11 17:28:54 -04:00
parent 1960492f60
commit 5f7a5cc52b
4 changed files with 64 additions and 71 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@@ -13,8 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.sftp;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.junit.Test;
@@ -26,7 +29,6 @@ import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.util.Assert;
import com.jcraft.jsch.ChannelSftp.LsEntry;
@@ -35,6 +37,7 @@ import com.jcraft.jsch.ChannelSftp.LsEntry;
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
* @author Artem Bilan
*
*/
public class SftpOutboundTransferSample {
@@ -46,7 +49,8 @@ public class SftpOutboundTransferSample {
final String destinationFileName = sourceFileName +"_foo";
final ClassPathXmlApplicationContext ac =
new ClassPathXmlApplicationContext("/META-INF/spring/integration/SftpOutboundTransferSample-context.xml", SftpOutboundTransferSample.class);
new ClassPathXmlApplicationContext("/META-INF/spring/integration/SftpOutboundTransferSample-context.xml",
SftpOutboundTransferSample.class);
@SuppressWarnings("unchecked")
SessionFactory<LsEntry> sessionFactory = ac.getBean(CachingSessionFactory.class);
RemoteFileTemplate<LsEntry> template = new RemoteFileTemplate<LsEntry>(sessionFactory);
@@ -55,7 +59,7 @@ public class SftpOutboundTransferSample {
try {
final File file = new File(sourceFileName);
Assert.isTrue(file.exists(), String.format("File '%s' does not exist.", sourceFileName));
assertTrue(String.format("File '%s' does not exist.", sourceFileName), file.exists());
final Message<File> message = MessageBuilder.withPayload(file).build();
final MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
@@ -63,7 +67,7 @@ public class SftpOutboundTransferSample {
inputChannel.send(message);
Thread.sleep(2000);
Assert.isTrue(SftpTestUtils.fileExists(template, destinationFileName));
assertTrue(SftpTestUtils.fileExists(template, destinationFileName));
System.out.println(String.format("Successfully transferred '%s' file to a " +
"remote location under the name '%s'", sourceFileName, destinationFileName));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2017 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.sftp;
import static org.hamcrest.Matchers.containsString;
@@ -22,10 +23,8 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.integration.file.remote.RemoteFileTemplate;
import org.springframework.integration.file.remote.SessionCallback;
import org.springframework.integration.file.remote.session.Session;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.ChannelSftp.LsEntry;
@@ -34,6 +33,8 @@ import com.jcraft.jsch.SftpException;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 4.1
*
*/
@@ -42,78 +43,63 @@ public class SftpTestUtils {
public static void createTestFiles(RemoteFileTemplate<LsEntry> template, final String... fileNames) {
if (template != null) {
final ByteArrayInputStream stream = new ByteArrayInputStream("foo".getBytes());
template.execute(new SessionCallback<LsEntry, Void>() {
@Override
public Void doInSession(Session<LsEntry> session) throws IOException {
try {
session.mkdir("si.sftp.sample");
}
catch (Exception e) {
assertThat(e.getMessage(), containsString("failed to create"));
}
for (int i = 0; i < fileNames.length; i++) {
stream.reset();
session.write(stream, "si.sftp.sample/" + fileNames[i]);
}
return null;
template.execute((SessionCallback<LsEntry, Void>) session -> {
try {
session.mkdir("si.sftp.sample");
}
catch (Exception e) {
assertThat(e.getMessage(), containsString("failed to create"));
}
for (int i = 0; i < fileNames.length; i++) {
stream.reset();
session.write(stream, "si.sftp.sample/" + fileNames[i]);
}
return null;
});
}
}
public static void cleanUp(RemoteFileTemplate<LsEntry> template, final String... fileNames) {
if (template != null) {
template.execute(new SessionCallback<LsEntry, Void>() {
@Override
public Void doInSession(Session<LsEntry> session) throws IOException {
// TODO: avoid DFAs with Spring 4.1 (INT-3412)
ChannelSftp channel = (ChannelSftp) new DirectFieldAccessor(new DirectFieldAccessor(session)
.getPropertyValue("targetSession")).getPropertyValue("channel");
for (int i = 0; i < fileNames.length; i++) {
try {
session.remove("si.sftp.sample/" + fileNames[i]);
}
catch (IOException e) {}
}
template.execute((SessionCallback<LsEntry, Void>) session -> {
ChannelSftp channel = (ChannelSftp) session.getClientInstance();
for (int i = 0; i < fileNames.length; i++) {
try {
// should be empty
channel.rmdir("si.sftp.sample");
session.remove("si.sftp.sample/" + fileNames[i]);
}
catch (SftpException e) {
fail("Expected remote directory to be empty " + e.getMessage());
catch (IOException e) {
}
return null;
}
try {
// should be empty
channel.rmdir("si.sftp.sample");
}
catch (SftpException e) {
fail("Expected remote directory to be empty " + e.getMessage());
}
return null;
});
}
}
public static boolean fileExists(RemoteFileTemplate<LsEntry> template, final String... fileNames) {
if (template != null) {
return template.execute(new SessionCallback<LsEntry, Boolean>() {
@Override
public Boolean doInSession(Session<LsEntry> session) throws IOException {
// TODO: avoid DFAs with Spring 4.1 (INT-3412)
ChannelSftp channel = (ChannelSftp) new DirectFieldAccessor(new DirectFieldAccessor(session)
.getPropertyValue("targetSession")).getPropertyValue("channel");
for (int i = 0; i < fileNames.length; i++) {
try {
SftpATTRS stat = channel.stat("si.sftp.sample/" + fileNames[i]);
if (stat == null) {
System.out.println("stat returned null for " + fileNames[i]);
return false;
}
}
catch (SftpException e) {
System.out.println("Remote file not present: " + e.getMessage() + ": " + fileNames[i]);
return template.execute(session -> {
ChannelSftp channel = (ChannelSftp) session.getClientInstance();
for (int i = 0; i < fileNames.length; i++) {
try {
SftpATTRS stat = channel.stat("si.sftp.sample/" + fileNames[i]);
if (stat == null) {
System.out.println("stat returned null for " + fileNames[i]);
return false;
}
}
return true;
catch (SftpException e) {
System.out.println("Remote file not present: " + e.getMessage() + ": " + fileNames[i]);
return false;
}
}
return true;
});
}
else {

View File

@@ -147,13 +147,13 @@ subprojects { subproject ->
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.7.2.201409121644"
toolVersion = "0.7.9"
}
sourceCompatibility = 1.8
ext {
activeMqVersion = '5.12.1'
activeMqVersion = '5.15.0'
apacheSshdVersion = '0.13.0'
aspectjVersion = '1.8.4'
commonsDigesterVersion = '2.0'
@@ -195,13 +195,13 @@ subprojects { subproject ->
reactorVersion = '2.0.8.RELEASE'
postgresVersion = '9.1-901-1.jdbc4'
subethasmtpVersion = '1.2'
slf4jVersion = '1.7.11'
springIntegrationVersion = '4.3.11.RELEASE'
springIntegrationDslVersion = '1.2.2.RELEASE'
springIntegrationKafkaVersion = '2.1.0.RELEASE'
slf4jVersion = '1.7.25'
springIntegrationVersion = '4.3.12.RELEASE'
springIntegrationDslVersion = '1.2.3.RELEASE'
springIntegrationKafkaVersion = '2.3.0.RC1'
springIntegrationSplunkVersion = '1.1.0.RELEASE'
springKafkaVersion = '1.1.6.RELEASE'
springVersion = '4.3.10.RELEASE'
springKafkaVersion = '1.3.0.RC1'
springVersion = '4.3.11.RELEASE'
springSecurityVersion = '4.1.4.RELEASE'
springWebFlowVersion = '2.3.3.RELEASE'
tilesJspVersion = '2.2.1'

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.mailattachments.support;
import java.io.File;
@@ -26,6 +27,8 @@ import org.springframework.util.Assert;
* the file system.
*
* @author Gunnar Hillert
* @author Artem Bilan
*
* @since 2.2
*
*/
@@ -45,9 +48,9 @@ public class EmailFragment {
public EmailFragment(File directory, String filename, Object data) {
super();
Assert.notNull(directory);
Assert.hasText(filename);
Assert.notNull(data);
Assert.notNull(directory, "directory must not be null");
Assert.hasText(filename, "filename must not be empty");
Assert.notNull(data, "data must not be null");
this.directory = directory;
this.filename = filename;