Skip to content

Commit 6261980

Browse files
committed
fix HTTP module according latest SF changes
1 parent df1b8b4 commit 6261980

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2021 the original author or authors.
2+
* Copyright 2015-2022 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.
@@ -17,8 +17,7 @@
1717
package org.springframework.integration.http.inbound;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20-
import static org.mockito.ArgumentMatchers.any;
21-
import static org.mockito.Mockito.doAnswer;
20+
import static org.mockito.Mockito.doReturn;
2221
import static org.mockito.Mockito.mock;
2322
import static org.mockito.Mockito.when;
2423

@@ -30,8 +29,6 @@
3029
import jakarta.servlet.http.HttpServletResponse;
3130

3231
import org.junit.jupiter.api.Test;
33-
import org.mockito.invocation.InvocationOnMock;
34-
import org.mockito.stubbing.Answer;
3532

3633
import org.springframework.beans.factory.BeanFactory;
3734
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
@@ -63,20 +60,7 @@ public void testMultiPass() throws Exception {
6360

6461
HttpServletRequest request = mock(HttpServletRequest.class);
6562
ServletInputStream sis = mock(ServletInputStream.class);
66-
doAnswer(new Answer<Integer>() {
67-
68-
int done;
69-
70-
@Override
71-
public Integer answer(InvocationOnMock invocation) {
72-
byte[] buff = invocation.getArgument(0);
73-
buff[0] = 'f';
74-
buff[1] = 'o';
75-
buff[2] = 'o';
76-
return done++ > 0 ? -1 : 3;
77-
}
78-
79-
}).when(sis).read(any(byte[].class));
63+
doReturn("test data".getBytes()).when(sis).readAllBytes();
8064
when(request.getInputStream()).thenReturn(sis);
8165
when(request.getMethod()).thenReturn("POST");
8266
when(request.getHeaderNames()).thenReturn(mock(Enumeration.class));
@@ -87,7 +71,7 @@ public Integer answer(InvocationOnMock invocation) {
8771
Message<?> received = requestChannel.receive(10000);
8872
assertThat(received).isNotNull();
8973
assertThat(received.getPayload()).isInstanceOf(byte[].class);
90-
assertThat(new String((byte[]) received.getPayload())).isEqualTo("foo");
74+
assertThat(new String((byte[]) received.getPayload())).isEqualTo("test data");
9175
}
9276

9377
}

spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void simpleStringKeyStringValueFormData() {
111111
MessageBuilder.withPayload(form)
112112
.setHeader(MessageHeaders.CONTENT_TYPE,
113113
MediaType.APPLICATION_FORM_URLENCODED_VALUE + ";charset=UTF-8")
114-
.build();
114+
.build();
115115
QueueChannel replyChannel = new QueueChannel();
116116
handler.setOutputChannel(replyChannel);
117117

@@ -204,9 +204,9 @@ public void stringKeyStringArrayValueFormData() {
204204
setBeanFactory(handler);
205205
handler.afterPropertiesSet();
206206
Map<String, Object> form = new LinkedHashMap<>();
207-
form.put("a", new String[] { "1", "2", "3" });
207+
form.put("a", new String[]{ "1", "2", "3" });
208208
form.put("b", "4");
209-
form.put("c", new String[] { "5" });
209+
form.put("c", new String[]{ "5" });
210210
form.put("d", "6");
211211
Message<?> message = MessageBuilder.withPayload(form).build();
212212

@@ -249,9 +249,9 @@ public void stringKeyPrimitiveArrayValueMixedFormData() {
249249
setBeanFactory(handler);
250250
handler.afterPropertiesSet();
251251
Map<String, Object> form = new LinkedHashMap<>();
252-
form.put("a", new int[] { 1, 2, 3 });
252+
form.put("a", new int[]{ 1, 2, 3 });
253253
form.put("b", "4");
254-
form.put("c", new String[] { "5" });
254+
form.put("c", new String[]{ "5" });
255255
form.put("d", "6");
256256
Message<?> message = MessageBuilder.withPayload(form).build();
257257

@@ -297,7 +297,7 @@ public void stringKeyNullArrayValueMixedFormData() {
297297
setBeanFactory(handler);
298298
handler.afterPropertiesSet();
299299
Map<String, Object> form = new LinkedHashMap<>();
300-
form.put("a", new Object[] { null, 4, null });
300+
form.put("a", new Object[]{ null, 4, null });
301301
form.put("b", "4");
302302
Message<?> message = MessageBuilder.withPayload(form).build();
303303

@@ -833,9 +833,11 @@ public void acceptHeaderForSerializableResponseMessageExchange() throws IOExcept
833833
public void testNoContentTypeAndSmartConverter() {
834834
Sinks.One<HttpHeaders> httpHeadersSink = Sinks.one();
835835
RestTemplate testRestTemplate = new RestTemplate() {
836+
836837
@Nullable
837-
protected <T> T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback,
838-
@Nullable ResponseExtractor<T> responseExtractor) throws RestClientException {
838+
protected <T> T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpMethod method,
839+
@Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor)
840+
throws RestClientException {
839841

840842
try {
841843
ClientHttpRequest request = createRequest(url, method);
@@ -847,11 +849,12 @@ protected <T> T doExecute(URI url, @Nullable HttpMethod method, @Nullable Reques
847849
}
848850
throw new RuntimeException("intentional");
849851
}
852+
850853
};
851854

852855
HttpRequestExecutingMessageHandler handler =
853856
new HttpRequestExecutingMessageHandler("https://www.springsource.org/spring-integration",
854-
testRestTemplate);
857+
testRestTemplate);
855858
setBeanFactory(handler);
856859
handler.afterPropertiesSet();
857860

@@ -911,8 +914,10 @@ private static class MockRestTemplate extends RestTemplate {
911914
private final AtomicReference<String> actualUrl = new AtomicReference<>();
912915

913916
@Nullable
914-
protected <T> T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback,
915-
@Nullable ResponseExtractor<T> responseExtractor) throws RestClientException {
917+
protected <T> T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpMethod method,
918+
@Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor)
919+
throws RestClientException {
920+
916921
this.actualUrl.set(url.toString());
917922
this.lastRequestEntity.set(TestUtils.getPropertyValue(requestCallback, "requestEntity", HttpEntity.class));
918923
throw new RuntimeException("intentional");
@@ -932,8 +937,10 @@ private static class MockRestTemplate2 extends RestTemplate {
932937
}
933938

934939
@Nullable
935-
protected <T> T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback,
936-
@Nullable ResponseExtractor<T> responseExtractor) throws RestClientException {
940+
protected <T> T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpMethod method,
941+
@Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor)
942+
throws RestClientException {
943+
937944
this.actualUrl.set(url.toString());
938945
try {
939946
return responseExtractor.extractData(new MockClientHttpResponse(new byte[0], HttpStatus.OK));

0 commit comments

Comments
 (0)