fix HTTP module according latest SF changes
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2021 the original author or authors.
|
||||
* Copyright 2015-2022 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.
|
||||
@@ -17,8 +17,7 @@
|
||||
package org.springframework.integration.http.inbound;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -30,8 +29,6 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||
@@ -63,20 +60,7 @@ public class MultipartAsRawByteArrayTests {
|
||||
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
ServletInputStream sis = mock(ServletInputStream.class);
|
||||
doAnswer(new Answer<Integer>() {
|
||||
|
||||
int done;
|
||||
|
||||
@Override
|
||||
public Integer answer(InvocationOnMock invocation) {
|
||||
byte[] buff = invocation.getArgument(0);
|
||||
buff[0] = 'f';
|
||||
buff[1] = 'o';
|
||||
buff[2] = 'o';
|
||||
return done++ > 0 ? -1 : 3;
|
||||
}
|
||||
|
||||
}).when(sis).read(any(byte[].class));
|
||||
doReturn("test data".getBytes()).when(sis).readAllBytes();
|
||||
when(request.getInputStream()).thenReturn(sis);
|
||||
when(request.getMethod()).thenReturn("POST");
|
||||
when(request.getHeaderNames()).thenReturn(mock(Enumeration.class));
|
||||
@@ -87,7 +71,7 @@ public class MultipartAsRawByteArrayTests {
|
||||
Message<?> received = requestChannel.receive(10000);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload()).isInstanceOf(byte[].class);
|
||||
assertThat(new String((byte[]) received.getPayload())).isEqualTo("foo");
|
||||
assertThat(new String((byte[]) received.getPayload())).isEqualTo("test data");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class HttpRequestExecutingMessageHandlerTests {
|
||||
MessageBuilder.withPayload(form)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE,
|
||||
MediaType.APPLICATION_FORM_URLENCODED_VALUE + ";charset=UTF-8")
|
||||
.build();
|
||||
.build();
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
handler.setOutputChannel(replyChannel);
|
||||
|
||||
@@ -204,9 +204,9 @@ public class HttpRequestExecutingMessageHandlerTests {
|
||||
setBeanFactory(handler);
|
||||
handler.afterPropertiesSet();
|
||||
Map<String, Object> form = new LinkedHashMap<>();
|
||||
form.put("a", new String[] { "1", "2", "3" });
|
||||
form.put("a", new String[]{ "1", "2", "3" });
|
||||
form.put("b", "4");
|
||||
form.put("c", new String[] { "5" });
|
||||
form.put("c", new String[]{ "5" });
|
||||
form.put("d", "6");
|
||||
Message<?> message = MessageBuilder.withPayload(form).build();
|
||||
|
||||
@@ -249,9 +249,9 @@ public class HttpRequestExecutingMessageHandlerTests {
|
||||
setBeanFactory(handler);
|
||||
handler.afterPropertiesSet();
|
||||
Map<String, Object> form = new LinkedHashMap<>();
|
||||
form.put("a", new int[] { 1, 2, 3 });
|
||||
form.put("a", new int[]{ 1, 2, 3 });
|
||||
form.put("b", "4");
|
||||
form.put("c", new String[] { "5" });
|
||||
form.put("c", new String[]{ "5" });
|
||||
form.put("d", "6");
|
||||
Message<?> message = MessageBuilder.withPayload(form).build();
|
||||
|
||||
@@ -297,7 +297,7 @@ public class HttpRequestExecutingMessageHandlerTests {
|
||||
setBeanFactory(handler);
|
||||
handler.afterPropertiesSet();
|
||||
Map<String, Object> form = new LinkedHashMap<>();
|
||||
form.put("a", new Object[] { null, 4, null });
|
||||
form.put("a", new Object[]{ null, 4, null });
|
||||
form.put("b", "4");
|
||||
Message<?> message = MessageBuilder.withPayload(form).build();
|
||||
|
||||
@@ -833,9 +833,11 @@ public class HttpRequestExecutingMessageHandlerTests {
|
||||
public void testNoContentTypeAndSmartConverter() {
|
||||
Sinks.One<HttpHeaders> httpHeadersSink = Sinks.one();
|
||||
RestTemplate testRestTemplate = new RestTemplate() {
|
||||
|
||||
@Nullable
|
||||
protected <T> T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback,
|
||||
@Nullable ResponseExtractor<T> responseExtractor) throws RestClientException {
|
||||
protected <T> T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpMethod method,
|
||||
@Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor)
|
||||
throws RestClientException {
|
||||
|
||||
try {
|
||||
ClientHttpRequest request = createRequest(url, method);
|
||||
@@ -847,11 +849,12 @@ public class HttpRequestExecutingMessageHandlerTests {
|
||||
}
|
||||
throw new RuntimeException("intentional");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
HttpRequestExecutingMessageHandler handler =
|
||||
new HttpRequestExecutingMessageHandler("https://www.springsource.org/spring-integration",
|
||||
testRestTemplate);
|
||||
testRestTemplate);
|
||||
setBeanFactory(handler);
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
@@ -911,8 +914,10 @@ public class HttpRequestExecutingMessageHandlerTests {
|
||||
private final AtomicReference<String> actualUrl = new AtomicReference<>();
|
||||
|
||||
@Nullable
|
||||
protected <T> T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback,
|
||||
@Nullable ResponseExtractor<T> responseExtractor) throws RestClientException {
|
||||
protected <T> T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpMethod method,
|
||||
@Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor)
|
||||
throws RestClientException {
|
||||
|
||||
this.actualUrl.set(url.toString());
|
||||
this.lastRequestEntity.set(TestUtils.getPropertyValue(requestCallback, "requestEntity", HttpEntity.class));
|
||||
throw new RuntimeException("intentional");
|
||||
@@ -932,8 +937,10 @@ public class HttpRequestExecutingMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected <T> T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback,
|
||||
@Nullable ResponseExtractor<T> responseExtractor) throws RestClientException {
|
||||
protected <T> T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpMethod method,
|
||||
@Nullable RequestCallback requestCallback, @Nullable ResponseExtractor<T> responseExtractor)
|
||||
throws RestClientException {
|
||||
|
||||
this.actualUrl.set(url.toString());
|
||||
try {
|
||||
return responseExtractor.extractData(new MockClientHttpResponse(new byte[0], HttpStatus.OK));
|
||||
|
||||
Reference in New Issue
Block a user