From 5f7a5cc52be2c19ee426b2d84174adc12800289b Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 11 Sep 2017 17:28:54 -0400 Subject: [PATCH] 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()` --- .../sftp/SftpOutboundTransferSample.java | 14 ++- .../samples/sftp/SftpTestUtils.java | 94 ++++++++----------- build.gradle | 16 ++-- .../support/EmailFragment.java | 11 ++- 4 files changed, 64 insertions(+), 71 deletions(-) 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 c9ddc96d..9419a30a 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-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 sessionFactory = ac.getBean(CachingSessionFactory.class); RemoteFileTemplate template = new RemoteFileTemplate(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 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)); diff --git a/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/SftpTestUtils.java b/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/SftpTestUtils.java index c1a1d4c0..1ac8b17f 100644 --- a/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/SftpTestUtils.java +++ b/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/SftpTestUtils.java @@ -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 template, final String... fileNames) { if (template != null) { final ByteArrayInputStream stream = new ByteArrayInputStream("foo".getBytes()); - template.execute(new SessionCallback() { - - @Override - public Void doInSession(Session 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) 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 template, final String... fileNames) { if (template != null) { - template.execute(new SessionCallback() { - - @Override - public Void doInSession(Session 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) 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 template, final String... fileNames) { if (template != null) { - return template.execute(new SessionCallback() { - - @Override - public Boolean doInSession(Session 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 { diff --git a/build.gradle b/build.gradle index 03a42275..d4ea6f41 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/intermediate/mail-attachments/src/main/java/org/springframework/integration/samples/mailattachments/support/EmailFragment.java b/intermediate/mail-attachments/src/main/java/org/springframework/integration/samples/mailattachments/support/EmailFragment.java index 1784e2b2..8ffb3d09 100644 --- a/intermediate/mail-attachments/src/main/java/org/springframework/integration/samples/mailattachments/support/EmailFragment.java +++ b/intermediate/mail-attachments/src/main/java/org/springframework/integration/samples/mailattachments/support/EmailFragment.java @@ -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;