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**
This commit is contained in:
@@ -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"));
|
||||
|
||||
@@ -28,8 +28,8 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
@@ -91,7 +91,7 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
@@ -242,7 +242,7 @@ public class FileTests {
|
||||
File resultFile = (File) receive.getPayload();
|
||||
assertThat(resultFile.getAbsolutePath(),
|
||||
endsWith(TestUtils.applySystemFileSeparator("fileWritingFlow/foo.write")));
|
||||
String fileContent = StreamUtils.copyToString(new FileInputStream(resultFile), Charset.defaultCharset());
|
||||
String fileContent = FileCopyUtils.copyToString(new FileReader(resultFile));
|
||||
assertEquals(payload, fileContent);
|
||||
if (FileUtils.IS_POSIX) {
|
||||
assertThat(java.nio.file.Files.getPosixFilePermissions(resultFile.toPath()).size(), equalTo(9));
|
||||
|
||||
@@ -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.
|
||||
@@ -46,6 +46,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@@ -93,7 +94,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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -101,7 +101,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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2017 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.
|
||||
@@ -75,7 +75,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));
|
||||
|
||||
assertEquals("true", TestUtils.getPropertyValue(withStringTemplate, "zsetIncrementScoreExpression",
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -24,8 +24,8 @@ import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@@ -48,7 +48,7 @@ import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.concurrent.SettableListenableFuture;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
@@ -195,7 +195,7 @@ public class SimpleWebServiceOutboundGatewayTests {
|
||||
|
||||
assertNotNull(myAttachment);
|
||||
assertEquals("text/plain", myAttachment.getContentType());
|
||||
assertEquals("my_data", StreamUtils.copyToString(myAttachment.getInputStream(), Charset.forName("UTF-8")));
|
||||
assertEquals("my_data", FileCopyUtils.copyToString(new InputStreamReader(myAttachment.getInputStream())));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user