INT-4498: StreamUtils -> FileCopyUtils

JIRA: https://jira.spring.io/browse/INT-4498

* Use `FileCopyUtils` instead of `StreamUtils` in test-cases when we deal
with `InputStream` s and files resources.
* Fix reflection-based tests with AOP to use an `ArrayList` access
instead of `LinkedList` since an optimization in SF:
6d6aa72e8f

**Cherry-pick to 5.0.x and 4.3.x**

(cherry picked from commit a1f016a)

# Conflicts:
#	spring-integration-file/src/test/java/org/springframework/integration/file/dsl/FileTests.java
#	spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisStoreOutboundChannelAdapterParserTests.java
#	spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java
This commit is contained in:
Artem Bilan
2018-07-09 12:41:45 -04:00
parent 963a2fbbb0
commit 1f50b96bb2
6 changed files with 21 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 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.
@@ -82,7 +82,7 @@ public class DefaultOutboundChannelAdapterParserTests {
assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(adapter, "autoStartup"));
MessageHandler handler = TestUtils.getPropertyValue(adapter, "handler", MessageHandler.class);
assertTrue(AopUtils.isAopProxy(handler));
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"),
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
handler.handleMessage(new GenericMessage<>("foo"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 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.
@@ -44,6 +44,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 4.0
*/
@ContextConfiguration
@@ -81,7 +82,7 @@ public class MqttOutboundChannelAdapterParserTests {
assertSame(((Advised) handler).getTargetSource().getTarget(), this.withConverterHandler);
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"),
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -84,7 +84,7 @@ public class RedisOutboundChannelAdapterParserTests extends RedisAvailableTests
assertTrue(AopUtils.isAopProxy(endpointHandler));
assertThat(TestUtils.getPropertyValue(endpointHandler, "h.advised.advisors.first.item.advice"),
assertThat(TestUtils.getPropertyValue(endpointHandler, "h.advised.advisors[0].advice"),
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2018 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.
@@ -45,6 +45,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Artem Bilan
* @author Gary Russell
* @author Rainer Frey
*
* @since 3.0
*/
@ContextConfiguration
@@ -88,15 +89,17 @@ public class RedisQueueOutboundChannelAdapterParserTests {
assertSame(((Advised) handler).getTargetSource().getTarget(), this.defaultAdapter);
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"),
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
assertTrue(TestUtils.getPropertyValue(this.defaultAdapter, "leftPush", Boolean.class));
}
@Test
public void testInt3017CustomConfig() {
assertSame(this.customRedisConnectionFactory, TestUtils.getPropertyValue(this.customAdapter, "template.connectionFactory"));
assertEquals("headers['redis_queue']", TestUtils.getPropertyValue(this.customAdapter, "queueNameExpression", Expression.class).getExpressionString());
assertSame(this.customRedisConnectionFactory,
TestUtils.getPropertyValue(this.customAdapter, "template.connectionFactory"));
assertEquals("headers['redis_queue']",
TestUtils.getPropertyValue(this.customAdapter, "queueNameExpression.expression"));
assertFalse(TestUtils.getPropertyValue(this.customAdapter, "extractPayload", Boolean.class));
assertTrue(TestUtils.getPropertyValue(this.customAdapter, "serializerExplicitlySet", Boolean.class));
assertSame(this.serializer, TestUtils.getPropertyValue(this.customAdapter, "serializer"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2007-2016 the original author or authors.
* Copyright 2007-2018 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.
@@ -73,7 +73,7 @@ public class RedisStoreOutboundChannelAdapterParserTests {
assertSame(((Advised) handler).getTargetSource().getTarget(), withStringTemplate);
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"),
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 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.
@@ -44,7 +44,7 @@ import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.util.Base64Utils;
import org.springframework.util.StreamUtils;
import org.springframework.util.FileCopyUtils;
import com.jcraft.jsch.ChannelSftp.LsEntry;
@@ -53,6 +53,7 @@ import com.jcraft.jsch.ChannelSftp.LsEntry;
* @author Gary Russell
* @author David Liu
* @author Artem Bilan
*
* @since 4.1
*
*/
@@ -115,7 +116,7 @@ public class SftpServerTests {
f.setUser("user");
f.setAllowUnknownKeys(true);
InputStream stream = new ClassPathResource(privKey).getInputStream();
f.setPrivateKey(new ByteArrayResource(StreamUtils.copyToByteArray(stream)));
f.setPrivateKey(new ByteArrayResource(FileCopyUtils.copyToByteArray(stream)));
f.setPrivateKeyPassphrase(passphrase);
Session<LsEntry> session = f.getSession();
doTest(server, session);
@@ -127,7 +128,7 @@ public class SftpServerTests {
private PublicKey decodePublicKey(String key) throws Exception {
InputStream stream = new ClassPathResource(key).getInputStream();
byte[] keyBytes = StreamUtils.copyToByteArray(stream);
byte[] keyBytes = FileCopyUtils.copyToByteArray(stream);
// strip any newline chars
while (keyBytes[keyBytes.length - 1] == 0x0a || keyBytes[keyBytes.length - 1] == 0x0d) {
keyBytes = Arrays.copyOf(keyBytes, keyBytes.length - 1);