Skip to content

Commit a1f016a

Browse files
committed
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: spring-projects/spring-framework@6d6aa72 **Cherry-pick to 5.0.x and 4.3.x**
1 parent 8eac5b4 commit a1f016a

File tree

8 files changed

+28
-23
lines changed

8 files changed

+28
-23
lines changed

spring-integration-core/src/test/java/org/springframework/integration/config/xml/DefaultOutboundChannelAdapterParserTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -82,7 +82,7 @@ public void checkConfigWithInnerBeanAndPoller() {
8282
assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(adapter, "autoStartup"));
8383
MessageHandler handler = TestUtils.getPropertyValue(adapter, "handler", MessageHandler.class);
8484
assertTrue(AopUtils.isAopProxy(handler));
85-
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
85+
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"),
8686
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
8787

8888
handler.handleMessage(new GenericMessage<>("foo"));

spring-integration-file/src/test/java/org/springframework/integration/file/dsl/FileTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import static org.junit.Assert.fail;
2929

3030
import java.io.File;
31-
import java.io.FileInputStream;
3231
import java.io.FileOutputStream;
32+
import java.io.FileReader;
3333
import java.nio.charset.Charset;
3434
import java.nio.charset.StandardCharsets;
3535
import java.util.ArrayList;
@@ -91,7 +91,7 @@
9191
import org.springframework.stereotype.Service;
9292
import org.springframework.test.annotation.DirtiesContext;
9393
import org.springframework.test.context.junit4.SpringRunner;
94-
import org.springframework.util.StreamUtils;
94+
import org.springframework.util.FileCopyUtils;
9595

9696
/**
9797
* @author Artem Bilan
@@ -242,7 +242,7 @@ public void testFileWritingFlow() throws Exception {
242242
File resultFile = (File) receive.getPayload();
243243
assertThat(resultFile.getAbsolutePath(),
244244
endsWith(TestUtils.applySystemFileSeparator("fileWritingFlow/foo.write")));
245-
String fileContent = StreamUtils.copyToString(new FileInputStream(resultFile), Charset.defaultCharset());
245+
String fileContent = FileCopyUtils.copyToString(new FileReader(resultFile));
246246
assertEquals(payload, fileContent);
247247
if (FileUtils.IS_POSIX) {
248248
assertThat(java.nio.file.Files.getPosixFilePermissions(resultFile.toPath()).size(), equalTo(9));

spring-integration-mqtt/src/test/java/org/springframework/integration/mqtt/config/xml/MqttOutboundChannelAdapterParserTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,6 +46,7 @@
4646
/**
4747
* @author Gary Russell
4848
* @author Artem Bilan
49+
*
4950
* @since 4.0
5051
*/
5152
@RunWith(SpringRunner.class)
@@ -93,7 +94,7 @@ public void testWithConverter() throws Exception {
9394

9495
assertSame(((Advised) handler).getTargetSource().getTarget(), this.withConverterHandler);
9596

96-
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
97+
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"),
9798
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
9899
}
99100

spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisOutboundChannelAdapterParserTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -101,7 +101,7 @@ public void validateConfiguration() {
101101

102102
assertTrue(AopUtils.isAopProxy(endpointHandler));
103103

104-
assertThat(TestUtils.getPropertyValue(endpointHandler, "h.advised.advisors.first.item.advice"),
104+
assertThat(TestUtils.getPropertyValue(endpointHandler, "h.advised.advisors[0].advice"),
105105
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
106106
}
107107

spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueOutboundChannelAdapterParserTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2016 the original author or authors.
2+
* Copyright 2013-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@
4545
* @author Artem Bilan
4646
* @author Gary Russell
4747
* @author Rainer Frey
48+
*
4849
* @since 3.0
4950
*/
5051
@ContextConfiguration
@@ -88,15 +89,17 @@ public void testInt3017DefaultConfig() throws Exception {
8889

8990
assertSame(((Advised) handler).getTargetSource().getTarget(), this.defaultAdapter);
9091

91-
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
92+
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"),
9293
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
9394
assertTrue(TestUtils.getPropertyValue(this.defaultAdapter, "leftPush", Boolean.class));
9495
}
9596

9697
@Test
9798
public void testInt3017CustomConfig() {
98-
assertSame(this.customRedisConnectionFactory, TestUtils.getPropertyValue(this.customAdapter, "template.connectionFactory"));
99-
assertEquals("headers['redis_queue']", TestUtils.getPropertyValue(this.customAdapter, "queueNameExpression", Expression.class).getExpressionString());
99+
assertSame(this.customRedisConnectionFactory,
100+
TestUtils.getPropertyValue(this.customAdapter, "template.connectionFactory"));
101+
assertEquals("headers['redis_queue']",
102+
TestUtils.getPropertyValue(this.customAdapter, "queueNameExpression.expression"));
100103
assertFalse(TestUtils.getPropertyValue(this.customAdapter, "extractPayload", Boolean.class));
101104
assertTrue(TestUtils.getPropertyValue(this.customAdapter, "serializerExplicitlySet", Boolean.class));
102105
assertSame(this.serializer, TestUtils.getPropertyValue(this.customAdapter, "serializer"));

spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisStoreOutboundChannelAdapterParserTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2007-2017 the original author or authors.
2+
* Copyright 2007-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@ public void validateWithStringTemplate() throws Exception {
7575

7676
assertSame(((Advised) handler).getTargetSource().getTarget(), withStringTemplate);
7777

78-
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
78+
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"),
7979
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
8080

8181
assertEquals("true", TestUtils.getPropertyValue(withStringTemplate, "zsetIncrementScoreExpression",

spring-integration-sftp/src/test/java/org/springframework/integration/sftp/session/SftpServerTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@
4444
import org.springframework.core.io.ClassPathResource;
4545
import org.springframework.integration.file.remote.session.Session;
4646
import org.springframework.util.Base64Utils;
47-
import org.springframework.util.StreamUtils;
47+
import org.springframework.util.FileCopyUtils;
4848

4949
import com.jcraft.jsch.ChannelSftp.LsEntry;
5050

@@ -53,6 +53,7 @@
5353
* @author Gary Russell
5454
* @author David Liu
5555
* @author Artem Bilan
56+
*
5657
* @since 4.1
5758
*
5859
*/
@@ -115,7 +116,7 @@ private void testKeyExchange(String pubKey, String privKey, String passphrase)
115116
f.setUser("user");
116117
f.setAllowUnknownKeys(true);
117118
InputStream stream = new ClassPathResource(privKey).getInputStream();
118-
f.setPrivateKey(new ByteArrayResource(StreamUtils.copyToByteArray(stream)));
119+
f.setPrivateKey(new ByteArrayResource(FileCopyUtils.copyToByteArray(stream)));
119120
f.setPrivateKeyPassphrase(passphrase);
120121
Session<LsEntry> session = f.getSession();
121122
doTest(server, session);
@@ -127,7 +128,7 @@ private void testKeyExchange(String pubKey, String privKey, String passphrase)
127128

128129
private PublicKey decodePublicKey(String key) throws Exception {
129130
InputStream stream = new ClassPathResource(key).getInputStream();
130-
byte[] keyBytes = StreamUtils.copyToByteArray(stream);
131+
byte[] keyBytes = FileCopyUtils.copyToByteArray(stream);
131132
// strip any newline chars
132133
while (keyBytes[keyBytes.length - 1] == 0x0a || keyBytes[keyBytes.length - 1] == 0x0d) {
133134
keyBytes = Arrays.copyOf(keyBytes, keyBytes.length - 1);

spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,8 @@
2424
import static org.mockito.Mockito.mock;
2525

2626
import java.io.ByteArrayInputStream;
27+
import java.io.InputStreamReader;
2728
import java.net.URI;
28-
import java.nio.charset.Charset;
2929
import java.util.concurrent.TimeUnit;
3030
import java.util.concurrent.atomic.AtomicReference;
3131

@@ -48,7 +48,7 @@
4848
import org.springframework.messaging.MessageHandlingException;
4949
import org.springframework.messaging.PollableChannel;
5050
import org.springframework.messaging.support.GenericMessage;
51-
import org.springframework.util.StreamUtils;
51+
import org.springframework.util.FileCopyUtils;
5252
import org.springframework.util.concurrent.SettableListenableFuture;
5353
import org.springframework.ws.WebServiceMessage;
5454
import org.springframework.ws.WebServiceMessageFactory;
@@ -195,7 +195,7 @@ public boolean handleRequest(MessageContext messageContext) throws WebServiceCli
195195

196196
assertNotNull(myAttachment);
197197
assertEquals("text/plain", myAttachment.getContentType());
198-
assertEquals("my_data", StreamUtils.copyToString(myAttachment.getInputStream(), Charset.forName("UTF-8")));
198+
assertEquals("my_data", FileCopyUtils.copyToString(new InputStreamReader(myAttachment.getInputStream())));
199199
}
200200

201201
@Test

0 commit comments

Comments
 (0)