Polishing
This commit is contained in:
parent
df6b01a329
commit
e22466e9d5
|
|
@ -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.
|
||||
|
|
@ -97,7 +97,7 @@ public class MessageMethodArgumentResolver implements HandlerMethodArgumentResol
|
|||
private Class<?> getPayloadType(MethodParameter parameter) {
|
||||
Type genericParamType = parameter.getGenericParameterType();
|
||||
ResolvableType resolvableType = ResolvableType.forType(genericParamType).as(Message.class);
|
||||
return resolvableType.getGeneric(0).resolve(Object.class);
|
||||
return resolvableType.getGeneric().resolve(Object.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.
|
||||
|
|
@ -36,6 +36,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||
|
||||
/**
|
||||
* Mock implementation of {@link ClientHttpRequest}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
|
|
@ -97,11 +98,9 @@ public class MockClientHttpRequest extends AbstractClientHttpRequest {
|
|||
|
||||
/**
|
||||
* Configure a custom handler for writing the request body.
|
||||
*
|
||||
* <p>The default write handler consumes and caches the request body so it
|
||||
* may be accessed subsequently, e.g. in test assertions. Use this property
|
||||
* when the request body is an infinite stream.
|
||||
*
|
||||
* @param writeHandler the write handler to use returning {@code Mono<Void>}
|
||||
* when the body has been "written" (i.e. consumed).
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -125,10 +125,8 @@ public class MockServerHttpResponse extends AbstractServerHttpResponse {
|
|||
* charset or "UTF-8" by default.
|
||||
*/
|
||||
public Mono<String> getBodyAsString() {
|
||||
|
||||
Charset charset = Optional.ofNullable(getHeaders().getContentType()).map(MimeType::getCharset)
|
||||
.orElse(StandardCharsets.UTF_8);
|
||||
|
||||
return getBody()
|
||||
.reduce(bufferFactory().allocateBuffer(), (previous, current) -> {
|
||||
previous.write(current);
|
||||
|
|
@ -139,7 +137,6 @@ public class MockServerHttpResponse extends AbstractServerHttpResponse {
|
|||
}
|
||||
|
||||
private static String bufferToString(DataBuffer buffer, Charset charset) {
|
||||
Assert.notNull(charset, "'charset' must not be null");
|
||||
byte[] bytes = new byte[buffer.readableByteCount()];
|
||||
buffer.read(bytes);
|
||||
return new String(bytes, charset);
|
||||
|
|
|
|||
|
|
@ -239,13 +239,16 @@ public abstract class AbstractRequestExpectationManager implements RequestExpect
|
|||
|
||||
/**
|
||||
* Add expectations to this group.
|
||||
* @deprecated as of 5.0.3 please use {@link #addAllExpectations(Collection)} instead.
|
||||
* @deprecated as of 5.0.3, if favor of {@link #addAllExpectations}
|
||||
*/
|
||||
@Deprecated
|
||||
public void updateAll(Collection<RequestExpectation> expectations) {
|
||||
expectations.forEach(this::updateInternal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all expectations for this group.
|
||||
*/
|
||||
public void reset() {
|
||||
this.expectations.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
|
|||
Map<String, Object> hints) {
|
||||
|
||||
boolean shouldWrap = isServerSentEvent(elementType);
|
||||
ResolvableType valueType = (shouldWrap ? elementType.getGeneric(0) : elementType);
|
||||
ResolvableType valueType = (shouldWrap ? elementType.getGeneric() : elementType);
|
||||
|
||||
return stringDecoder.decode(message.getBody(), STRING_TYPE, null, Collections.emptyMap())
|
||||
.bufferUntil(line -> line.equals(""))
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa
|
|||
ResolvableType elementType;
|
||||
if (adapter != null) {
|
||||
publisher = adapter.toPublisher(body);
|
||||
ResolvableType genericType = bodyType.getGeneric(0);
|
||||
ResolvableType genericType = bodyType.getGeneric();
|
||||
elementType = getElementType(adapter, genericType);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ public abstract class AbstractView implements View, BeanNameAware, ApplicationCo
|
|||
private static final Object NO_VALUE = new Object();
|
||||
|
||||
|
||||
private final List<MediaType> mediaTypes = new ArrayList<>(4);
|
||||
private final ReactiveAdapterRegistry reactiveAdapterRegistry;
|
||||
|
||||
private final ReactiveAdapterRegistry adapterRegistry;
|
||||
private final List<MediaType> mediaTypes = new ArrayList<>(4);
|
||||
|
||||
private Charset defaultCharset = StandardCharsets.UTF_8;
|
||||
|
||||
|
|
@ -77,9 +77,9 @@ public abstract class AbstractView implements View, BeanNameAware, ApplicationCo
|
|||
this(ReactiveAdapterRegistry.getSharedInstance());
|
||||
}
|
||||
|
||||
public AbstractView(ReactiveAdapterRegistry registry) {
|
||||
public AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry) {
|
||||
this.reactiveAdapterRegistry = reactiveAdapterRegistry;
|
||||
this.mediaTypes.add(ViewResolverSupport.DEFAULT_CONTENT_TYPE);
|
||||
this.adapterRegistry = registry;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -232,7 +232,6 @@ public abstract class AbstractView implements View, BeanNameAware, ApplicationCo
|
|||
* @return {@code Mono} for the completion of async attributes resolution
|
||||
*/
|
||||
protected Mono<Void> resolveAsyncAttributes(Map<String, Object> model) {
|
||||
|
||||
List<String> names = new ArrayList<>();
|
||||
List<Mono<?>> valueMonos = new ArrayList<>();
|
||||
|
||||
|
|
@ -241,7 +240,7 @@ public abstract class AbstractView implements View, BeanNameAware, ApplicationCo
|
|||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
ReactiveAdapter adapter = this.adapterRegistry.getAdapter(null, value);
|
||||
ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(null, value);
|
||||
if (adapter != null) {
|
||||
names.add(entry.getKey());
|
||||
if (adapter.isMultiValue()) {
|
||||
|
|
|
|||
|
|
@ -77,13 +77,14 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest
|
|||
|
||||
try {
|
||||
StepVerifier.create(result)
|
||||
.consumeNextWith(value -> assertTrue(value.length() == 20000 * "0123456789".length()))
|
||||
.consumeNextWith(value -> assertTrue(value.length() >= 20000 * "0123456789".length()))
|
||||
.expectComplete()
|
||||
.verify(Duration.ofSeconds(10L));
|
||||
}
|
||||
catch (AssertionError err) {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
if (os.contains("windows") && err.getMessage().startsWith("VerifySubscriber timed out")) {
|
||||
if (os.contains("windows") && err.getMessage() != null &&
|
||||
err.getMessage().startsWith("VerifySubscriber timed out")) {
|
||||
// TODO: Reactor usually times out on Windows ...
|
||||
err.printStackTrace();
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -56,10 +56,8 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
|
|||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.http.codec.json.Jackson2CodecSupport.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -171,7 +169,7 @@ public class BodyExtractorsTests {
|
|||
.verify();
|
||||
}
|
||||
|
||||
@Test // SPR-15758
|
||||
@Test // SPR-15758
|
||||
public void toMonoWithEmptyBodyAndNoContentType() {
|
||||
BodyExtractor<Mono<Map<String, String>>, ReactiveHttpInputMessage> extractor =
|
||||
BodyExtractors.toMono(new ParameterizedTypeReference<Map<String, String>>() {});
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.web.reactive.function;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
|
@ -64,10 +65,10 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
|
|||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT;
|
||||
import static org.springframework.http.codec.json.Jackson2CodecSupport.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -99,12 +100,10 @@ public class BodyInsertersTests {
|
|||
public List<HttpMessageWriter<?>> messageWriters() {
|
||||
return messageWriters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ServerHttpRequest> serverRequest() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> hints() {
|
||||
return hints;
|
||||
|
|
@ -115,7 +114,7 @@ public class BodyInsertersTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void ofString() throws Exception {
|
||||
public void ofString() {
|
||||
String body = "foo";
|
||||
BodyInserter<String, ReactiveHttpOutputMessage> inserter = BodyInserters.fromObject(body);
|
||||
|
||||
|
|
@ -131,7 +130,7 @@ public class BodyInsertersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void ofObject() throws Exception {
|
||||
public void ofObject() {
|
||||
User body = new User("foo", "bar");
|
||||
BodyInserter<User, ReactiveHttpOutputMessage> inserter = BodyInserters.fromObject(body);
|
||||
MockServerHttpResponse response = new MockServerHttpResponse();
|
||||
|
|
@ -145,7 +144,7 @@ public class BodyInsertersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void ofObjectWithHints() throws Exception {
|
||||
public void ofObjectWithHints() {
|
||||
User body = new User("foo", "bar");
|
||||
BodyInserter<User, ReactiveHttpOutputMessage> inserter = BodyInserters.fromObject(body);
|
||||
this.hints.put(JSON_VIEW_HINT, SafeToSerialize.class);
|
||||
|
|
@ -160,7 +159,7 @@ public class BodyInsertersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void ofPublisher() throws Exception {
|
||||
public void ofPublisher() {
|
||||
Flux<String> body = Flux.just("foo");
|
||||
BodyInserter<Flux<String>, ReactiveHttpOutputMessage> inserter = BodyInserters.fromPublisher(body, String.class);
|
||||
|
||||
|
|
@ -177,7 +176,7 @@ public class BodyInsertersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void ofResource() throws Exception {
|
||||
public void ofResource() throws IOException {
|
||||
Resource body = new ClassPathResource("response.txt", getClass());
|
||||
BodyInserter<Resource, ReactiveHttpOutputMessage> inserter = BodyInserters.fromResource(body);
|
||||
|
||||
|
|
@ -199,7 +198,7 @@ public class BodyInsertersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void ofResourceRange() throws Exception {
|
||||
public void ofResourceRange() throws IOException {
|
||||
final int rangeStart = 10;
|
||||
Resource body = new ClassPathResource("response.txt", getClass());
|
||||
BodyInserter<Resource, ReactiveHttpOutputMessage> inserter = BodyInserters.fromResource(body);
|
||||
|
|
@ -242,7 +241,7 @@ public class BodyInsertersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void ofServerSentEventFlux() throws Exception {
|
||||
public void ofServerSentEventFlux() {
|
||||
ServerSentEvent<String> event = ServerSentEvent.builder("foo").build();
|
||||
Flux<ServerSentEvent<String>> body = Flux.just(event);
|
||||
BodyInserter<Flux<ServerSentEvent<String>>, ServerHttpResponse> inserter =
|
||||
|
|
@ -254,7 +253,7 @@ public class BodyInsertersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void fromFormDataMap() throws Exception {
|
||||
public void fromFormDataMap() {
|
||||
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
|
||||
body.set("name 1", "value 1");
|
||||
body.add("name 2", "value 2+1");
|
||||
|
|
@ -282,7 +281,7 @@ public class BodyInsertersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void fromFormDataWith() throws Exception {
|
||||
public void fromFormDataWith() {
|
||||
BodyInserter<MultiValueMap<String, String>, ClientHttpRequest>
|
||||
inserter = BodyInserters.fromFormData("name 1", "value 1")
|
||||
.with("name 2", "value 2+1")
|
||||
|
|
@ -307,7 +306,7 @@ public class BodyInsertersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void fromMultipartData() throws Exception {
|
||||
public void fromMultipartData() {
|
||||
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
||||
map.set("name 3", "value 3");
|
||||
|
||||
|
|
@ -322,7 +321,7 @@ public class BodyInsertersTests {
|
|||
|
||||
}
|
||||
|
||||
@Test // SPR-16350
|
||||
@Test // SPR-16350
|
||||
public void fromMultipartDataWithMultipleValues() {
|
||||
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
||||
map.put("name", Arrays.asList("value1", "value2"));
|
||||
|
|
@ -354,7 +353,7 @@ public class BodyInsertersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void ofDataBuffers() throws Exception {
|
||||
public void ofDataBuffers() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ import org.springframework.web.reactive.function.server.RouterFunction;
|
|||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.*;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.*;
|
||||
|
||||
public class MultipartIntegrationTests extends AbstractRouterFunctionIntegrationTests {
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.web.reactive.function.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -35,13 +36,10 @@ import org.springframework.http.codec.HttpMessageWriter;
|
|||
import org.springframework.mock.http.client.reactive.test.MockClientHttpRequest;
|
||||
import org.springframework.web.reactive.function.BodyInserter;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.http.HttpMethod.DELETE;
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.springframework.http.HttpMethod.OPTIONS;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.springframework.http.HttpMethod.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -49,7 +47,7 @@ import static org.springframework.http.HttpMethod.POST;
|
|||
public class DefaultClientRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
public void from() throws Exception {
|
||||
public void from() throws URISyntaxException {
|
||||
ClientRequest other = ClientRequest.create(GET, URI.create("http://example.com"))
|
||||
.header("foo", "bar")
|
||||
.cookie("baz", "qux").build();
|
||||
|
|
@ -66,7 +64,7 @@ public class DefaultClientRequestBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void method() throws Exception {
|
||||
public void method() throws URISyntaxException {
|
||||
URI url = new URI("http://example.com");
|
||||
ClientRequest.Builder builder = ClientRequest.create(DELETE, url);
|
||||
assertEquals(DELETE, builder.build().method());
|
||||
|
|
@ -76,7 +74,7 @@ public class DefaultClientRequestBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void url() throws Exception {
|
||||
public void url() throws URISyntaxException {
|
||||
URI url1 = new URI("http://example.com/foo");
|
||||
URI url2 = new URI("http://example.com/bar");
|
||||
ClientRequest.Builder builder = ClientRequest.create(DELETE, url1);
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class DefaultClientResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void from() throws Exception {
|
||||
public void from() {
|
||||
Flux<DataBuffer> otherBody = Flux.just("foo", "bar")
|
||||
.map(s -> s.getBytes(StandardCharsets.UTF_8))
|
||||
.map(dataBufferFactory::wrap);
|
||||
|
|
|
|||
|
|
@ -48,11 +48,9 @@ import org.springframework.http.codec.HttpMessageReader;
|
|||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.web.reactive.function.BodyExtractors.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -75,7 +73,7 @@ public class DefaultClientResponseTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void statusCode() throws Exception {
|
||||
public void statusCode() {
|
||||
HttpStatus status = HttpStatus.CONTINUE;
|
||||
when(mockResponse.getStatusCode()).thenReturn(status);
|
||||
|
||||
|
|
@ -83,7 +81,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void header() throws Exception {
|
||||
public void header() {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
long contentLength = 42L;
|
||||
httpHeaders.setContentLength(contentLength);
|
||||
|
|
@ -103,7 +101,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void cookies() throws Exception {
|
||||
public void cookies() {
|
||||
ResponseCookie cookie = ResponseCookie.from("foo", "bar").build();
|
||||
MultiValueMap<String, ResponseCookie> cookies = new LinkedMultiValueMap<>();
|
||||
cookies.add("foo", cookie);
|
||||
|
|
@ -115,7 +113,7 @@ public class DefaultClientResponseTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void body() throws Exception {
|
||||
public void body() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -135,7 +133,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToMono() throws Exception {
|
||||
public void bodyToMono() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -156,7 +154,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToMonoTypeReference() throws Exception {
|
||||
public void bodyToMonoTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -179,7 +177,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToFlux() throws Exception {
|
||||
public void bodyToFlux() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -201,7 +199,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToFluxTypeReference() throws Exception {
|
||||
public void bodyToFluxTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -225,7 +223,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toEntity() throws Exception {
|
||||
public void toEntity() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -248,7 +246,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toEntityTypeReference() throws Exception {
|
||||
public void toEntityTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -273,7 +271,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toEntityList() throws Exception {
|
||||
public void toEntityList() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -296,7 +294,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toEntityListTypeReference() throws Exception {
|
||||
public void toEntityListTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -321,7 +319,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toMonoVoid() throws Exception {
|
||||
public void toMonoVoid() {
|
||||
TestPublisher<DataBuffer> body = TestPublisher.create();
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
|
|
@ -343,7 +341,7 @@ public class DefaultClientResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toMonoVoidNonEmptyBody() throws Exception {
|
||||
public void toMonoVoidNonEmptyBody() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class DefaultWebClientTests {
|
|||
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.exchangeFunction = mock(ExchangeFunction.class);
|
||||
when(this.exchangeFunction.exchange(captor.capture())).thenReturn(Mono.empty());
|
||||
|
|
@ -55,7 +55,7 @@ public class DefaultWebClientTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void basic() throws Exception {
|
||||
public void basic() {
|
||||
WebClient client = builder().build();
|
||||
client.get().uri("/path").exchange();
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ public class DefaultWebClientTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void uriBuilder() throws Exception {
|
||||
public void uriBuilder() {
|
||||
WebClient client = builder().build();
|
||||
client.get().uri(builder -> builder.path("/path").queryParam("q", "12").build()).exchange();
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ public class DefaultWebClientTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void uriBuilderWithPathOverride() throws Exception {
|
||||
public void uriBuilderWithPathOverride() {
|
||||
WebClient client = builder().build();
|
||||
client.get().uri(builder -> builder.replacePath("/path").build()).exchange();
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ public class DefaultWebClientTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void requestHeaderAndCookie() throws Exception {
|
||||
public void requestHeaderAndCookie() {
|
||||
WebClient client = builder().build();
|
||||
client.get().uri("/path").accept(MediaType.APPLICATION_JSON)
|
||||
.cookies(cookies -> cookies.add("id", "123")) // SPR-16178
|
||||
|
|
@ -99,7 +99,7 @@ public class DefaultWebClientTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void defaultHeaderAndCookie() throws Exception {
|
||||
public void defaultHeaderAndCookie() {
|
||||
WebClient client = builder().defaultHeader("Accept", "application/json").defaultCookie("id", "123").build();
|
||||
client.get().uri("/path").exchange();
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ public class DefaultWebClientTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void defaultHeaderAndCookieOverrides() throws Exception {
|
||||
public void defaultHeaderAndCookieOverrides() {
|
||||
WebClient client = builder().defaultHeader("Accept", "application/json").defaultCookie("id", "123").build();
|
||||
client.get().uri("/path").header("Accept", "application/xml").cookie("id", "456").exchange();
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ public class DefaultWebClientTests {
|
|||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void bodyObjectPublisher() throws Exception {
|
||||
public void bodyObjectPublisher() {
|
||||
Mono<Void> mono = Mono.empty();
|
||||
WebClient client = builder().build();
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ public class DefaultWebClientTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void mutateDoesCopy() throws Exception {
|
||||
public void mutateDoesCopy() {
|
||||
|
||||
WebClient.Builder builder = WebClient.builder();
|
||||
builder.filter((request, next) -> next.exchange(request));
|
||||
|
|
@ -188,7 +188,7 @@ public class DefaultWebClientTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void switchToErrorOnEmptyClientResponseMono() throws Exception {
|
||||
public void switchToErrorOnEmptyClientResponseMono() {
|
||||
StepVerifier.create(builder().build().get().uri("/path").exchange())
|
||||
.expectErrorMessage("The underlying HTTP client completed without emitting a response.")
|
||||
.verify(Duration.ofSeconds(5));
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ import org.springframework.http.HttpStatus;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials;
|
||||
import static org.springframework.http.HttpMethod.*;
|
||||
import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ public class WebClientIntegrationTests {
|
|||
|
||||
private WebClient webClient;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.server = new MockWebServer();
|
||||
|
|
@ -69,12 +70,13 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@After
|
||||
public void shutdown() throws Exception {
|
||||
public void shutdown() throws IOException {
|
||||
this.server.shutdown();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldReceiveResponseHeaders() throws Exception {
|
||||
public void shouldReceiveResponseHeaders() {
|
||||
prepareResponse(response -> response
|
||||
.setHeader("Content-Type", "text/plain")
|
||||
.setBody("Hello Spring!"));
|
||||
|
|
@ -100,7 +102,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceivePlainText() throws Exception {
|
||||
public void shouldReceivePlainText() {
|
||||
prepareResponse(response -> response.setBody("Hello Spring!"));
|
||||
|
||||
Mono<String> result = this.webClient.get()
|
||||
|
|
@ -122,7 +124,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceiveJsonAsString() throws Exception {
|
||||
public void shouldReceiveJsonAsString() {
|
||||
String content = "{\"bar\":\"barbar\",\"foo\":\"foofoo\"}";
|
||||
prepareResponse(response -> response
|
||||
.setHeader("Content-Type", "application/json").setBody(content));
|
||||
|
|
@ -143,8 +145,8 @@ public class WebClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test // SPR-16715
|
||||
public void shouldReceiveJsonAsTypeReferenceString() throws Exception {
|
||||
@Test // SPR-16715
|
||||
public void shouldReceiveJsonAsTypeReferenceString() {
|
||||
String content = "{\"containerValue\":{\"fooValue\":\"bar\"}}";
|
||||
prepareResponse(response -> response
|
||||
.setHeader("Content-Type", "application/json").setBody(content));
|
||||
|
|
@ -170,7 +172,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceiveJsonAsResponseEntityString() throws Exception {
|
||||
public void shouldReceiveJsonAsResponseEntityString() {
|
||||
String content = "{\"bar\":\"barbar\",\"foo\":\"foofoo\"}";
|
||||
prepareResponse(response -> response
|
||||
.setHeader("Content-Type", "application/json").setBody(content));
|
||||
|
|
@ -197,7 +199,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceiveJsonAsResponseEntityList() throws Exception {
|
||||
public void shouldReceiveJsonAsResponseEntityList() {
|
||||
String content = "[{\"bar\":\"bar1\",\"foo\":\"foo1\"}, {\"bar\":\"bar2\",\"foo\":\"foo2\"}]";
|
||||
prepareResponse(response -> response
|
||||
.setHeader("Content-Type", "application/json").setBody(content));
|
||||
|
|
@ -226,7 +228,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceiveJsonAsFluxString() throws Exception {
|
||||
public void shouldReceiveJsonAsFluxString() {
|
||||
String content = "{\"bar\":\"barbar\",\"foo\":\"foofoo\"}";
|
||||
prepareResponse(response -> response
|
||||
.setHeader("Content-Type", "application/json").setBody(content));
|
||||
|
|
@ -248,7 +250,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceiveJsonAsPojo() throws Exception {
|
||||
public void shouldReceiveJsonAsPojo() {
|
||||
prepareResponse(response -> response
|
||||
.setHeader("Content-Type", "application/json")
|
||||
.setBody("{\"bar\":\"barbar\",\"foo\":\"foofoo\"}"));
|
||||
|
|
@ -272,7 +274,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceiveJsonAsFluxPojo() throws Exception {
|
||||
public void shouldReceiveJsonAsFluxPojo() {
|
||||
prepareResponse(response -> response
|
||||
.setHeader("Content-Type", "application/json")
|
||||
.setBody("[{\"bar\":\"bar1\",\"foo\":\"foo1\"},{\"bar\":\"bar2\",\"foo\":\"foo2\"}]"));
|
||||
|
|
@ -297,7 +299,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendPojoAsJson() throws Exception {
|
||||
public void shouldSendPojoAsJson() {
|
||||
prepareResponse(response -> response.setHeader("Content-Type", "application/json")
|
||||
.setBody("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}"));
|
||||
|
||||
|
|
@ -325,7 +327,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendCookies() throws Exception {
|
||||
public void shouldSendCookies() {
|
||||
prepareResponse(response -> response
|
||||
.setHeader("Content-Type", "text/plain").setBody("test"));
|
||||
|
||||
|
|
@ -347,8 +349,8 @@ public class WebClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test // SPR-16246
|
||||
public void shouldSendLargeTextFile() throws Exception {
|
||||
@Test // SPR-16246
|
||||
public void shouldSendLargeTextFile() throws IOException {
|
||||
prepareResponse(response -> {});
|
||||
|
||||
Resource resource = new ClassPathResource("largeTextFile.txt", getClass());
|
||||
|
|
@ -382,7 +384,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceive404Response() throws Exception {
|
||||
public void shouldReceive404Response() {
|
||||
prepareResponse(response -> response.setResponseCode(404)
|
||||
.setHeader("Content-Type", "text/plain").setBody("Not Found"));
|
||||
|
||||
|
|
@ -401,7 +403,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetErrorSignalOn404() throws Exception {
|
||||
public void shouldGetErrorSignalOn404() {
|
||||
prepareResponse(response -> response.setResponseCode(404)
|
||||
.setHeader("Content-Type", "text/plain").setBody("Not Found"));
|
||||
|
||||
|
|
@ -421,8 +423,8 @@ public class WebClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test // SPR-15946
|
||||
public void shouldGetErrorSignalOnEmptyErrorResponse() throws Exception {
|
||||
@Test // SPR-15946
|
||||
public void shouldGetErrorSignalOnEmptyErrorResponse() {
|
||||
prepareResponse(response -> response.setResponseCode(404)
|
||||
.setHeader("Content-Type", "text/plain"));
|
||||
|
||||
|
|
@ -442,7 +444,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetInternalServerErrorSignal() throws Exception {
|
||||
public void shouldGetInternalServerErrorSignal() {
|
||||
String errorMessage = "Internal Server error";
|
||||
prepareResponse(response -> response.setResponseCode(500)
|
||||
.setHeader("Content-Type", "text/plain").setBody(errorMessage));
|
||||
|
|
@ -470,7 +472,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldApplyCustomStatusHandler() throws Exception {
|
||||
public void shouldApplyCustomStatusHandler() {
|
||||
prepareResponse(response -> response.setResponseCode(500)
|
||||
.setHeader("Content-Type", "text/plain").setBody("Internal Server error"));
|
||||
|
||||
|
|
@ -492,7 +494,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldApplyCustomStatusHandlerParameterizedTypeReference() throws Exception {
|
||||
public void shouldApplyCustomStatusHandlerParameterizedTypeReference() {
|
||||
prepareResponse(response -> response.setResponseCode(500)
|
||||
.setHeader("Content-Type", "text/plain").setBody("Internal Server error"));
|
||||
|
||||
|
|
@ -514,7 +516,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceiveNotFoundEntity() throws Exception {
|
||||
public void shouldReceiveNotFoundEntity() {
|
||||
prepareResponse(response -> response.setResponseCode(404)
|
||||
.setHeader("Content-Type", "text/plain").setBody("Not Found"));
|
||||
|
||||
|
|
@ -536,7 +538,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldApplyExchangeFilter() throws Exception {
|
||||
public void shouldApplyExchangeFilter() {
|
||||
prepareResponse(response -> response.setHeader("Content-Type", "text/plain")
|
||||
.setBody("Hello Spring!"));
|
||||
|
||||
|
|
@ -563,7 +565,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldApplyErrorHandlingFilter() throws Exception {
|
||||
public void shouldApplyErrorHandlingFilter() {
|
||||
|
||||
ExchangeFilterFunction filter = ExchangeFilterFunction.ofResponseProcessor(
|
||||
clientResponse -> {
|
||||
|
|
@ -606,7 +608,7 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceiveEmptyResponse() throws Exception {
|
||||
public void shouldReceiveEmptyResponse() {
|
||||
prepareResponse(response -> response.setHeader("Content-Length", "0").setBody(""));
|
||||
|
||||
Mono<ResponseEntity<Void>> result = this.webClient.get()
|
||||
|
|
@ -619,8 +621,8 @@ public class WebClientIntegrationTests {
|
|||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // SPR-15782
|
||||
public void shouldFailWithRelativeUrls() throws Exception {
|
||||
@Test // SPR-15782
|
||||
public void shouldFailWithRelativeUrls() {
|
||||
String uri = "/api/v4/groups/1";
|
||||
Mono<ClientResponse> responseMono = WebClient.builder().build().get().uri(uri).exchange();
|
||||
|
||||
|
|
@ -629,14 +631,20 @@ public class WebClientIntegrationTests {
|
|||
.verify(Duration.ofSeconds(5));
|
||||
}
|
||||
|
||||
|
||||
private void prepareResponse(Consumer<MockResponse> consumer) {
|
||||
MockResponse response = new MockResponse();
|
||||
consumer.accept(response);
|
||||
this.server.enqueue(response);
|
||||
}
|
||||
|
||||
private void expectRequest(Consumer<RecordedRequest> consumer) throws InterruptedException {
|
||||
consumer.accept(this.server.takeRequest());
|
||||
private void expectRequest(Consumer<RecordedRequest> consumer) {
|
||||
try {
|
||||
consumer.accept(this.server.takeRequest());
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void expectRequestCount(int count) {
|
||||
|
|
@ -667,11 +675,11 @@ public class WebClientIntegrationTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static class Foo {
|
||||
|
||||
private String fooValue;
|
||||
|
||||
|
||||
public String getFooValue() {
|
||||
return fooValue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import org.springframework.web.reactive.function.BodyExtractor;
|
|||
import org.springframework.web.reactive.function.BodyExtractors;
|
||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.Collections.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
|
|
@ -53,12 +53,12 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void response() throws Exception {
|
||||
public void response() {
|
||||
assertSame(mockResponse, wrapper.response());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusCode() throws Exception {
|
||||
public void statusCode() {
|
||||
HttpStatus status = HttpStatus.BAD_REQUEST;
|
||||
when(mockResponse.statusCode()).thenReturn(status);
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void headers() throws Exception {
|
||||
public void headers() {
|
||||
ClientResponse.Headers headers = mock(ClientResponse.Headers.class);
|
||||
when(mockResponse.headers()).thenReturn(headers);
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void cookies() throws Exception {
|
||||
public void cookies() {
|
||||
MultiValueMap<String, ResponseCookie> cookies = mock(MultiValueMap.class);
|
||||
when(mockResponse.cookies()).thenReturn(cookies);
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyExtractor() throws Exception {
|
||||
public void bodyExtractor() {
|
||||
Mono<String> result = Mono.just("foo");
|
||||
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
|
||||
when(mockResponse.body(extractor)).thenReturn(result);
|
||||
|
|
@ -91,7 +91,7 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToMonoClass() throws Exception {
|
||||
public void bodyToMonoClass() {
|
||||
Mono<String> result = Mono.just("foo");
|
||||
when(mockResponse.bodyToMono(String.class)).thenReturn(result);
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToMonoParameterizedTypeReference() throws Exception {
|
||||
public void bodyToMonoParameterizedTypeReference() {
|
||||
Mono<String> result = Mono.just("foo");
|
||||
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
|
||||
when(mockResponse.bodyToMono(reference)).thenReturn(result);
|
||||
|
|
@ -108,7 +108,7 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToFluxClass() throws Exception {
|
||||
public void bodyToFluxClass() {
|
||||
Flux<String> result = Flux.just("foo");
|
||||
when(mockResponse.bodyToFlux(String.class)).thenReturn(result);
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToFluxParameterizedTypeReference() throws Exception {
|
||||
public void bodyToFluxParameterizedTypeReference() {
|
||||
Flux<String> result = Flux.just("foo");
|
||||
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
|
||||
when(mockResponse.bodyToFlux(reference)).thenReturn(result);
|
||||
|
|
@ -125,7 +125,7 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toEntityClass() throws Exception {
|
||||
public void toEntityClass() {
|
||||
Mono<ResponseEntity<String>> result = Mono.just(new ResponseEntity<>("foo", HttpStatus.OK));
|
||||
when(mockResponse.toEntity(String.class)).thenReturn(result);
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toEntityParameterizedTypeReference() throws Exception {
|
||||
public void toEntityParameterizedTypeReference() {
|
||||
Mono<ResponseEntity<String>> result = Mono.just(new ResponseEntity<>("foo", HttpStatus.OK));
|
||||
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
|
||||
when(mockResponse.toEntity(reference)).thenReturn(result);
|
||||
|
|
@ -142,7 +142,7 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toEntityListClass() throws Exception {
|
||||
public void toEntityListClass() {
|
||||
Mono<ResponseEntity<List<String>>> result = Mono.just(new ResponseEntity<>(singletonList("foo"), HttpStatus.OK));
|
||||
when(mockResponse.toEntityList(String.class)).thenReturn(result);
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ public class ClientResponseWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toEntityListParameterizedTypeReference() throws Exception {
|
||||
public void toEntityListParameterizedTypeReference() {
|
||||
Mono<ResponseEntity<List<String>>> result = Mono.just(new ResponseEntity<>(singletonList("foo"), HttpStatus.OK));
|
||||
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
|
||||
when(mockResponse.toEntityList(reference)).thenReturn(result);
|
||||
|
|
|
|||
|
|
@ -55,21 +55,21 @@ import static org.junit.Assert.*;
|
|||
public class DefaultEntityResponseBuilderTests {
|
||||
|
||||
@Test
|
||||
public void fromObject() throws Exception {
|
||||
public void fromObject() {
|
||||
String body = "foo";
|
||||
EntityResponse<String> response = EntityResponse.fromObject(body).build().block();
|
||||
assertSame(body, response.entity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromPublisherClass() throws Exception {
|
||||
public void fromPublisherClass() {
|
||||
Flux<String> body = Flux.just("foo", "bar");
|
||||
EntityResponse<Flux<String>> response = EntityResponse.fromPublisher(body, String.class).build().block();
|
||||
assertSame(body, response.entity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromPublisher() throws Exception {
|
||||
public void fromPublisher() {
|
||||
Flux<String> body = Flux.just("foo", "bar");
|
||||
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
|
||||
EntityResponse<Flux<String>> response = EntityResponse.fromPublisher(body, typeReference).build().block();
|
||||
|
|
@ -77,7 +77,7 @@ public class DefaultEntityResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void status() throws Exception {
|
||||
public void status() {
|
||||
String body = "foo";
|
||||
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).status(HttpStatus.CREATED).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -87,7 +87,7 @@ public class DefaultEntityResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void allow() throws Exception {
|
||||
public void allow() {
|
||||
String body = "foo";
|
||||
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).allow(HttpMethod.GET).build();
|
||||
Set<HttpMethod> expected = EnumSet.of(HttpMethod.GET);
|
||||
|
|
@ -98,7 +98,7 @@ public class DefaultEntityResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void contentLength() throws Exception {
|
||||
public void contentLength() {
|
||||
String body = "foo";
|
||||
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).contentLength(42).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -108,7 +108,7 @@ public class DefaultEntityResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void contentType() throws Exception {
|
||||
public void contentType() {
|
||||
String body = "foo";
|
||||
Mono<EntityResponse<String>>
|
||||
result = EntityResponse.fromObject(body).contentType(MediaType.APPLICATION_JSON).build();
|
||||
|
|
@ -119,7 +119,7 @@ public class DefaultEntityResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void etag() throws Exception {
|
||||
public void etag() {
|
||||
String body = "foo";
|
||||
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).eTag("foo").build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -129,7 +129,7 @@ public class DefaultEntityResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void lastModified() throws Exception {
|
||||
public void lastModified() {
|
||||
ZonedDateTime now = ZonedDateTime.now();
|
||||
String body = "foo";
|
||||
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).lastModified(now).build();
|
||||
|
|
@ -141,7 +141,7 @@ public class DefaultEntityResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void cacheControlTag() throws Exception {
|
||||
public void cacheControlTag() {
|
||||
String body = "foo";
|
||||
Mono<EntityResponse<String>>
|
||||
result = EntityResponse.fromObject(body).cacheControl(CacheControl.noCache()).build();
|
||||
|
|
@ -152,7 +152,7 @@ public class DefaultEntityResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void varyBy() throws Exception {
|
||||
public void varyBy() {
|
||||
String body = "foo";
|
||||
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).varyBy("foo").build();
|
||||
List<String> expected = Collections.singletonList("foo");
|
||||
|
|
@ -163,7 +163,7 @@ public class DefaultEntityResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void headers() throws Exception {
|
||||
public void headers() {
|
||||
String body = "foo";
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).headers(headers).build();
|
||||
|
|
@ -174,7 +174,7 @@ public class DefaultEntityResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void cookies() throws Exception {
|
||||
public void cookies() {
|
||||
MultiValueMap<String, ResponseCookie> newCookies = new LinkedMultiValueMap<>();
|
||||
newCookies.add("name", ResponseCookie.from("name", "value").build());
|
||||
Mono<EntityResponse<String>> result =
|
||||
|
|
@ -186,7 +186,7 @@ public class DefaultEntityResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyInserter() throws Exception {
|
||||
public void bodyInserter() {
|
||||
String body = "foo";
|
||||
Publisher<String> publisher = Mono.just(body);
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ import static org.mockito.Mockito.*;
|
|||
public class DefaultRenderingResponseTests {
|
||||
|
||||
@Test
|
||||
public void create() throws Exception {
|
||||
public void create() {
|
||||
String name = "foo";
|
||||
Mono<RenderingResponse> result = RenderingResponse.create(name).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -64,7 +64,7 @@ public class DefaultRenderingResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void headers() throws Exception {
|
||||
public void headers() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
Mono<RenderingResponse> result = RenderingResponse.create("foo").headers(headers).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -75,7 +75,7 @@ public class DefaultRenderingResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void modelAttribute() throws Exception {
|
||||
public void modelAttribute() {
|
||||
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
||||
.modelAttribute("foo", "bar").build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -85,7 +85,7 @@ public class DefaultRenderingResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void modelAttributeConventions() throws Exception {
|
||||
public void modelAttributeConventions() {
|
||||
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
||||
.modelAttribute("bar").build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -95,7 +95,7 @@ public class DefaultRenderingResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void modelAttributes() throws Exception {
|
||||
public void modelAttributes() {
|
||||
Map<String, String> model = Collections.singletonMap("foo", "bar");
|
||||
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
||||
.modelAttributes(model).build();
|
||||
|
|
@ -106,7 +106,7 @@ public class DefaultRenderingResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void modelAttributesConventions() throws Exception {
|
||||
public void modelAttributesConventions() {
|
||||
Set<String> model = Collections.singleton("bar");
|
||||
Mono<RenderingResponse> result = RenderingResponse.create("foo")
|
||||
.modelAttributes(model).build();
|
||||
|
|
@ -117,7 +117,7 @@ public class DefaultRenderingResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void cookies() throws Exception {
|
||||
public void cookies() {
|
||||
MultiValueMap<String, ResponseCookie> newCookies = new LinkedMultiValueMap<>();
|
||||
newCookies.add("name", ResponseCookie.from("name", "value").build());
|
||||
Mono<RenderingResponse> result =
|
||||
|
|
@ -130,7 +130,7 @@ public class DefaultRenderingResponseTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void render() throws Exception {
|
||||
public void render() {
|
||||
Map<String, Object> model = Collections.singletonMap("foo", "bar");
|
||||
Mono<RenderingResponse> result = RenderingResponse.create("view").modelAttributes(model).build();
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ public class DefaultRenderingResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void defaultContentType() throws Exception {
|
||||
public void defaultContentType() {
|
||||
Mono<RenderingResponse> result = RenderingResponse.create("view").build();
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package org.springframework.web.reactive.function.server;
|
|||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
|
@ -38,16 +37,11 @@ import static org.junit.Assert.*;
|
|||
*/
|
||||
public class DefaultServerRequestBuilderTests {
|
||||
|
||||
private DataBufferFactory dataBufferFactory;
|
||||
private final DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
@Before
|
||||
public void createBufferFactory() {
|
||||
this.dataBufferFactory = new DefaultDataBufferFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void from() throws Exception {
|
||||
|
||||
public void from() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("http://example.com")
|
||||
.header("foo", "bar")
|
||||
.build();
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.springframework.web.reactive.function.server;
|
|||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
|
@ -53,7 +54,7 @@ import org.springframework.util.MultiValueMap;
|
|||
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
|
||||
import static org.springframework.web.reactive.function.BodyExtractors.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -65,7 +66,7 @@ public class DefaultServerRequestTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void method() throws Exception {
|
||||
public void method() {
|
||||
HttpMethod method = HttpMethod.HEAD;
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.method(method, "http://example.com")),
|
||||
|
|
@ -75,7 +76,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void uri() throws Exception {
|
||||
public void uri() {
|
||||
URI uri = URI.create("https://example.com");
|
||||
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
|
|
@ -86,7 +87,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void uriBuilder() throws Exception {
|
||||
public void uriBuilder() throws URISyntaxException {
|
||||
URI uri = new URI("http", "localhost", "/path", "a=1", null);
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, uri)),
|
||||
|
|
@ -102,7 +103,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void attribute() throws Exception {
|
||||
public void attribute() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.method(HttpMethod.GET, "http://example.com"));
|
||||
exchange.getAttributes().put("foo", "bar");
|
||||
|
|
@ -113,7 +114,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void queryParams() throws Exception {
|
||||
public void queryParams() {
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar")),
|
||||
this.messageReaders);
|
||||
|
|
@ -122,7 +123,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyQueryParam() throws Exception {
|
||||
public void emptyQueryParam() {
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo")),
|
||||
this.messageReaders);
|
||||
|
|
@ -131,7 +132,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void absentQueryParam() throws Exception {
|
||||
public void absentQueryParam() {
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo")),
|
||||
this.messageReaders);
|
||||
|
|
@ -140,7 +141,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void pathVariable() throws Exception {
|
||||
public void pathVariable() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com"));
|
||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||
|
|
@ -152,7 +153,7 @@ public class DefaultServerRequestTests {
|
|||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void pathVariableNotFound() throws Exception {
|
||||
public void pathVariableNotFound() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com"));
|
||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||
|
|
@ -163,7 +164,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void pathVariables() throws Exception {
|
||||
public void pathVariables() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com"));
|
||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||
|
|
@ -174,7 +175,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void header() throws Exception {
|
||||
public void header() {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
List<MediaType> accept =
|
||||
Collections.singletonList(MediaType.APPLICATION_JSON);
|
||||
|
|
@ -220,7 +221,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void body() throws Exception {
|
||||
public void body() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -240,7 +241,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToMono() throws Exception {
|
||||
public void bodyToMono() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -259,7 +260,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToMonoParameterizedTypeReference() throws Exception {
|
||||
public void bodyToMonoParameterizedTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -279,7 +280,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToFlux() throws Exception {
|
||||
public void bodyToFlux() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -298,7 +299,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToFluxParameterizedTypeReference() throws Exception {
|
||||
public void bodyToFluxParameterizedTypeReference() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -318,7 +319,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyUnacceptable() throws Exception {
|
||||
public void bodyUnacceptable() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -339,7 +340,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void formData() throws Exception {
|
||||
public void formData() {
|
||||
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
|
||||
DefaultDataBuffer dataBuffer =
|
||||
factory.wrap(ByteBuffer.wrap("foo=bar&baz=qux".getBytes(StandardCharsets.UTF_8)));
|
||||
|
|
@ -364,7 +365,7 @@ public class DefaultServerRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void multipartData() throws Exception {
|
||||
public void multipartData() {
|
||||
String data = "--12345\r\n" +
|
||||
"Content-Disposition: form-data; name=\"foo\"\r\n" +
|
||||
"\r\n" +
|
||||
|
|
@ -404,4 +405,5 @@ public class DefaultServerRequestTests {
|
|||
})
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
};
|
||||
|
||||
@Test
|
||||
public void from() throws Exception {
|
||||
public void from() {
|
||||
ServerResponse other = ServerResponse.ok().header("foo", "bar").build().block();
|
||||
Mono<ServerResponse> result = ServerResponse.from(other).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -74,7 +74,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void status() throws Exception {
|
||||
public void status() {
|
||||
Mono<ServerResponse> result = ServerResponse.status(HttpStatus.CREATED).build();
|
||||
StepVerifier.create(result)
|
||||
.expectNextMatches(response -> HttpStatus.CREATED.equals(response.statusCode()))
|
||||
|
|
@ -83,7 +83,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void ok() throws Exception {
|
||||
public void ok() {
|
||||
Mono<ServerResponse> result = ServerResponse.ok().build();
|
||||
StepVerifier.create(result)
|
||||
.expectNextMatches(response -> HttpStatus.OK.equals(response.statusCode()))
|
||||
|
|
@ -93,7 +93,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void created() throws Exception {
|
||||
public void created() {
|
||||
URI location = URI.create("http://example.com");
|
||||
Mono<ServerResponse> result = ServerResponse.created(location).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -104,7 +104,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void accepted() throws Exception {
|
||||
public void accepted() {
|
||||
Mono<ServerResponse> result = ServerResponse.accepted().build();
|
||||
StepVerifier.create(result)
|
||||
.expectNextMatches(response -> HttpStatus.ACCEPTED.equals(response.statusCode()))
|
||||
|
|
@ -114,7 +114,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void noContent() throws Exception {
|
||||
public void noContent() {
|
||||
Mono<ServerResponse> result = ServerResponse.noContent().build();
|
||||
StepVerifier.create(result)
|
||||
.expectNextMatches(response -> HttpStatus.NO_CONTENT.equals(response.statusCode()))
|
||||
|
|
@ -124,7 +124,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void seeOther() throws Exception {
|
||||
public void seeOther() {
|
||||
URI location = URI.create("http://example.com");
|
||||
Mono<ServerResponse> result = ServerResponse.seeOther(location).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -135,7 +135,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void temporaryRedirect() throws Exception {
|
||||
public void temporaryRedirect() {
|
||||
URI location = URI.create("http://example.com");
|
||||
Mono<ServerResponse> result = ServerResponse.temporaryRedirect(location).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -146,7 +146,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void permanentRedirect() throws Exception {
|
||||
public void permanentRedirect() {
|
||||
URI location = URI.create("http://example.com");
|
||||
Mono<ServerResponse> result = ServerResponse.permanentRedirect(location).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -157,7 +157,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void badRequest() throws Exception {
|
||||
public void badRequest() {
|
||||
Mono<ServerResponse> result = ServerResponse.badRequest().build();
|
||||
StepVerifier.create(result)
|
||||
.expectNextMatches(response -> HttpStatus.BAD_REQUEST.equals(response.statusCode()))
|
||||
|
|
@ -167,7 +167,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void notFound() throws Exception {
|
||||
public void notFound() {
|
||||
Mono<ServerResponse> result = ServerResponse.notFound().build();
|
||||
StepVerifier.create(result)
|
||||
.expectNextMatches(response -> HttpStatus.NOT_FOUND.equals(response.statusCode()))
|
||||
|
|
@ -177,7 +177,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void unprocessableEntity() throws Exception {
|
||||
public void unprocessableEntity() {
|
||||
Mono<ServerResponse> result = ServerResponse.unprocessableEntity().build();
|
||||
StepVerifier.create(result)
|
||||
.expectNextMatches(response -> HttpStatus.UNPROCESSABLE_ENTITY.equals(response.statusCode()))
|
||||
|
|
@ -187,7 +187,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void allow() throws Exception {
|
||||
public void allow() {
|
||||
Mono<ServerResponse> result = ServerResponse.ok().allow(HttpMethod.GET).build();
|
||||
Set<HttpMethod> expected = EnumSet.of(HttpMethod.GET);
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -198,7 +198,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void contentLength() throws Exception {
|
||||
public void contentLength() {
|
||||
Mono<ServerResponse> result = ServerResponse.ok().contentLength(42).build();
|
||||
StepVerifier.create(result)
|
||||
.expectNextMatches(response -> Long.valueOf(42).equals(response.headers().getContentLength()))
|
||||
|
|
@ -208,7 +208,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void contentType() throws Exception {
|
||||
public void contentType() {
|
||||
Mono<ServerResponse>
|
||||
result = ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -218,7 +218,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void eTag() throws Exception {
|
||||
public void eTag() {
|
||||
Mono<ServerResponse> result = ServerResponse.ok().eTag("foo").build();
|
||||
StepVerifier.create(result)
|
||||
.expectNextMatches(response -> "\"foo\"".equals(response.headers().getETag()))
|
||||
|
|
@ -228,7 +228,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void lastModified() throws Exception {
|
||||
public void lastModified() {
|
||||
ZonedDateTime now = ZonedDateTime.now();
|
||||
Mono<ServerResponse> result = ServerResponse.ok().lastModified(now).build();
|
||||
Long expected = now.toInstant().toEpochMilli() / 1000;
|
||||
|
|
@ -239,7 +239,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void cacheControlTag() throws Exception {
|
||||
public void cacheControlTag() {
|
||||
Mono<ServerResponse>
|
||||
result = ServerResponse.ok().cacheControl(CacheControl.noCache()).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -249,7 +249,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void varyBy() throws Exception {
|
||||
public void varyBy() {
|
||||
Mono<ServerResponse> result = ServerResponse.ok().varyBy("foo").build();
|
||||
List<String> expected = Collections.singletonList("foo");
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -260,7 +260,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void statusCode() throws Exception {
|
||||
public void statusCode() {
|
||||
HttpStatus statusCode = HttpStatus.ACCEPTED;
|
||||
Mono<ServerResponse> result = ServerResponse.status(statusCode).build();
|
||||
StepVerifier.create(result)
|
||||
|
|
@ -271,7 +271,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void headers() throws Exception {
|
||||
public void headers() {
|
||||
HttpHeaders newHeaders = new HttpHeaders();
|
||||
newHeaders.set("foo", "bar");
|
||||
Mono<ServerResponse> result =
|
||||
|
|
@ -284,7 +284,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void cookies() throws Exception {
|
||||
public void cookies() {
|
||||
MultiValueMap<String, ResponseCookie> newCookies = new LinkedMultiValueMap<>();
|
||||
newCookies.add("name", ResponseCookie.from("name", "value").build());
|
||||
Mono<ServerResponse> result =
|
||||
|
|
@ -296,7 +296,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void build() throws Exception {
|
||||
public void build() {
|
||||
ResponseCookie cookie = ResponseCookie.from("name", "value").build();
|
||||
Mono<ServerResponse>
|
||||
result = ServerResponse.status(HttpStatus.CREATED)
|
||||
|
|
@ -316,7 +316,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void buildVoidPublisher() throws Exception {
|
||||
public void buildVoidPublisher() {
|
||||
Mono<Void> mono = Mono.empty();
|
||||
Mono<ServerResponse> result = ServerResponse.ok().build(mono);
|
||||
|
||||
|
|
@ -330,7 +330,7 @@ public class DefaultServerResponseBuilderTests {
|
|||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void bodyObjectPublisher() throws Exception {
|
||||
public void bodyObjectPublisher() {
|
||||
Mono<Void> mono = Mono.empty();
|
||||
|
||||
ServerResponse.ok().syncBody(mono);
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ import org.springframework.web.reactive.config.EnableWebFlux;
|
|||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromPublisher;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.*;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.*;
|
||||
|
||||
/**
|
||||
* Tests the use of {@link HandlerFunction} and {@link RouterFunction} in a
|
||||
|
|
@ -70,7 +70,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
|||
|
||||
|
||||
@Test
|
||||
public void mono() throws Exception {
|
||||
public void mono() {
|
||||
ResponseEntity<Person> result =
|
||||
this.restTemplate.getForEntity("http://localhost:" + this.port + "/mono", Person.class);
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
|||
}
|
||||
|
||||
@Test
|
||||
public void flux() throws Exception {
|
||||
public void flux() {
|
||||
ParameterizedTypeReference<List<Person>> reference = new ParameterizedTypeReference<List<Person>>() {};
|
||||
ResponseEntity<List<Person>> result =
|
||||
this.restTemplate
|
||||
|
|
@ -93,7 +93,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
|||
}
|
||||
|
||||
@Test
|
||||
public void controller() throws Exception {
|
||||
public void controller() {
|
||||
ResponseEntity<Person> result =
|
||||
this.restTemplate.getForEntity("http://localhost:" + this.port + "/controller", Person.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class HeadersWrapperTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void accept() throws Exception {
|
||||
public void accept() {
|
||||
List<MediaType> accept = Collections.singletonList(MediaType.APPLICATION_JSON);
|
||||
when(mockHeaders.accept()).thenReturn(accept);
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ public class HeadersWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void acceptCharset() throws Exception {
|
||||
public void acceptCharset() {
|
||||
List<Charset> acceptCharset = Collections.singletonList(StandardCharsets.UTF_8);
|
||||
when(mockHeaders.acceptCharset()).thenReturn(acceptCharset);
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ public class HeadersWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void contentLength() throws Exception {
|
||||
public void contentLength() {
|
||||
OptionalLong contentLength = OptionalLong.of(42L);
|
||||
when(mockHeaders.contentLength()).thenReturn(contentLength);
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ public class HeadersWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void contentType() throws Exception {
|
||||
public void contentType() {
|
||||
Optional<MediaType> contentType = Optional.of(MediaType.APPLICATION_JSON);
|
||||
when(mockHeaders.contentType()).thenReturn(contentType);
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ public class HeadersWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void host() throws Exception {
|
||||
public void host() {
|
||||
InetSocketAddress host = InetSocketAddress.createUnresolved("example.com", 42);
|
||||
when(mockHeaders.host()).thenReturn(host);
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ public class HeadersWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void range() throws Exception {
|
||||
public void range() {
|
||||
List<HttpRange> range = Collections.singletonList(HttpRange.createByteRange(42));
|
||||
when(mockHeaders.range()).thenReturn(range);
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ public class HeadersWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void header() throws Exception {
|
||||
public void header() {
|
||||
String name = "foo";
|
||||
List<String> value = Collections.singletonList("bar");
|
||||
when(mockHeaders.header(name)).thenReturn(value);
|
||||
|
|
@ -110,7 +110,7 @@ public class HeadersWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void asHttpHeaders() throws Exception {
|
||||
public void asHttpHeaders() {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
when(mockHeaders.asHttpHeaders()).thenReturn(httpHeaders);
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.web.reactive.function.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
|
@ -32,12 +34,11 @@ public class InvalidHttpMethodIntegrationTests extends AbstractRouterFunctionInt
|
|||
protected RouterFunction<?> routerFunction() {
|
||||
return RouterFunctions.route(RequestPredicates.GET("/"),
|
||||
request -> ServerResponse.ok().syncBody("FOO"))
|
||||
.andRoute(RequestPredicates.all(),
|
||||
request -> ServerResponse.ok().syncBody("BAR"));
|
||||
.andRoute(RequestPredicates.all(), request -> ServerResponse.ok().syncBody("BAR"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidHttpMethod() throws Exception {
|
||||
public void invalidHttpMethod() throws IOException {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
|
|
@ -49,4 +50,5 @@ public class InvalidHttpMethodIntegrationTests extends AbstractRouterFunctionInt
|
|||
assertEquals("BAR", response.body().string());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import org.springframework.web.reactive.result.view.ViewResolver;
|
|||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.i18n.FixedLocaleContextResolver;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Sebastien Deleuze
|
||||
|
|
|
|||
|
|
@ -24,10 +24,8 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.path;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.nest;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.*;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -52,7 +50,7 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
|
|||
|
||||
|
||||
@Test
|
||||
public void bar() throws Exception {
|
||||
public void bar() {
|
||||
ResponseEntity<String> result =
|
||||
restTemplate.getForEntity("http://localhost:" + port + "/foo/bar", String.class);
|
||||
|
||||
|
|
@ -61,7 +59,7 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
|
|||
}
|
||||
|
||||
@Test
|
||||
public void baz() throws Exception {
|
||||
public void baz() {
|
||||
ResponseEntity<String> result =
|
||||
restTemplate.getForEntity("http://localhost:" + port + "/foo/baz", String.class);
|
||||
|
||||
|
|
@ -70,7 +68,7 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
|
|||
}
|
||||
|
||||
@Test
|
||||
public void variables() throws Exception {
|
||||
public void variables() {
|
||||
ResponseEntity<String> result =
|
||||
restTemplate.getForEntity("http://localhost:" + port + "/1/2/3", String.class);
|
||||
|
||||
|
|
@ -80,7 +78,7 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
|
|||
|
||||
// SPR-16868
|
||||
@Test
|
||||
public void parentVariables() throws Exception {
|
||||
public void parentVariables() {
|
||||
ResponseEntity<String> result =
|
||||
restTemplate.getForEntity("http://localhost:" + port + "/1/bar", String.class);
|
||||
|
||||
|
|
@ -91,7 +89,7 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
|
|||
|
||||
// SPR 16692
|
||||
@Test
|
||||
public void removeFailedPathVariables() throws Exception {
|
||||
public void removeFailedPathVariables() {
|
||||
ResponseEntity<String> result =
|
||||
restTemplate.getForEntity("http://localhost:" + port + "/qux/quux", String.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -98,13 +98,12 @@ public class PathResourceLookupFunctionTests {
|
|||
|
||||
@Test
|
||||
public void composeResourceLookupFunction() throws Exception {
|
||||
ClassPathResource defaultResource = new ClassPathResource("response.txt", getClass());
|
||||
|
||||
Function<ServerRequest, Mono<Resource>> lookupFunction =
|
||||
new PathResourceLookupFunction("/resources/**",
|
||||
new ClassPathResource("org/springframework/web/reactive/function/server/"));
|
||||
|
||||
ClassPathResource defaultResource = new ClassPathResource("response.txt", getClass());
|
||||
|
||||
Function<ServerRequest, Mono<Resource>> customLookupFunction =
|
||||
lookupFunction.andThen(resourceMono -> resourceMono
|
||||
.switchIfEmpty(Mono.just(defaultResource)));
|
||||
|
|
@ -125,8 +124,6 @@ public class PathResourceLookupFunctionTests {
|
|||
})
|
||||
.expectComplete()
|
||||
.verify();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunc
|
|||
|
||||
|
||||
@Test
|
||||
public void mono() throws Exception {
|
||||
public void mono() {
|
||||
ResponseEntity<Person> result =
|
||||
restTemplate.getForEntity("http://localhost:" + port + "/mono", Person.class);
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ public class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunc
|
|||
}
|
||||
|
||||
@Test
|
||||
public void flux() throws Exception {
|
||||
public void flux() {
|
||||
ParameterizedTypeReference<List<Person>> reference = new ParameterizedTypeReference<List<Person>>() {};
|
||||
ResponseEntity<List<Person>> result =
|
||||
restTemplate.exchange("http://localhost:" + port + "/flux", HttpMethod.GET, null, reference);
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ import org.springframework.web.reactive.result.view.ViewResolver;
|
|||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.reactive.function.server.HandlerFilterFunction.ofResponseProcessor;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
import static org.springframework.web.reactive.function.server.HandlerFilterFunction.*;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.*;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -73,7 +73,7 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
|
|||
}
|
||||
|
||||
@Test
|
||||
public void normal() throws Exception {
|
||||
public void normal() {
|
||||
ResponseEntity<String> result =
|
||||
restTemplate.getForEntity("http://localhost:" + port + "/normal", String.class);
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
|
|||
}
|
||||
|
||||
@Test
|
||||
public void filter() throws Exception {
|
||||
public void filter() {
|
||||
ResponseEntity<String> result =
|
||||
restTemplate.getForEntity("http://localhost:" + port + "/filter", String.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import static org.junit.Assert.*;
|
|||
public class RequestPredicateTests {
|
||||
|
||||
@Test
|
||||
public void and() throws Exception {
|
||||
public void and() {
|
||||
RequestPredicate predicate1 = request -> true;
|
||||
RequestPredicate predicate2 = request -> true;
|
||||
RequestPredicate predicate3 = request -> false;
|
||||
|
|
@ -38,7 +38,7 @@ public class RequestPredicateTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void negate() throws Exception {
|
||||
public void negate() {
|
||||
RequestPredicate predicate = request -> false;
|
||||
RequestPredicate negated = predicate.negate();
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ public class RequestPredicateTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void or() throws Exception {
|
||||
public void or() {
|
||||
RequestPredicate predicate1 = request -> true;
|
||||
RequestPredicate predicate2 = request -> false;
|
||||
RequestPredicate predicate3 = request -> false;
|
||||
|
|
|
|||
|
|
@ -34,14 +34,14 @@ import static org.junit.Assert.*;
|
|||
public class RequestPredicatesTests {
|
||||
|
||||
@Test
|
||||
public void all() throws Exception {
|
||||
public void all() {
|
||||
RequestPredicate predicate = RequestPredicates.all();
|
||||
MockServerRequest request = MockServerRequest.builder().build();
|
||||
assertTrue(predicate.test(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void method() throws Exception {
|
||||
public void method() {
|
||||
HttpMethod httpMethod = HttpMethod.GET;
|
||||
RequestPredicate predicate = RequestPredicates.method(httpMethod);
|
||||
MockServerRequest request = MockServerRequest.builder().method(httpMethod).build();
|
||||
|
|
@ -52,7 +52,7 @@ public class RequestPredicatesTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void methods() throws Exception {
|
||||
public void methods() {
|
||||
URI uri = URI.create("http://localhost/path");
|
||||
|
||||
RequestPredicate predicate = RequestPredicates.GET("/p*");
|
||||
|
|
@ -85,7 +85,7 @@ public class RequestPredicatesTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void path() throws Exception {
|
||||
public void path() {
|
||||
URI uri = URI.create("http://localhost/path");
|
||||
RequestPredicate predicate = RequestPredicates.path("/p*");
|
||||
MockServerRequest request = MockServerRequest.builder().uri(uri).build();
|
||||
|
|
@ -96,7 +96,7 @@ public class RequestPredicatesTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void pathEncoded() throws Exception {
|
||||
public void pathEncoded() {
|
||||
URI uri = URI.create("http://localhost/foo%20bar");
|
||||
RequestPredicate predicate = RequestPredicates.path("/foo bar");
|
||||
MockServerRequest request = MockServerRequest.builder().uri(uri).build();
|
||||
|
|
@ -107,7 +107,7 @@ public class RequestPredicatesTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void pathPredicates() throws Exception {
|
||||
public void pathPredicates() {
|
||||
PathPatternParser parser = new PathPatternParser();
|
||||
parser.setCaseSensitive(false);
|
||||
Function<String, RequestPredicate> pathPredicates = RequestPredicates.pathPredicates(parser);
|
||||
|
|
@ -119,7 +119,7 @@ public class RequestPredicatesTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void headers() throws Exception {
|
||||
public void headers() {
|
||||
String name = "MyHeader";
|
||||
String value = "MyValue";
|
||||
RequestPredicate predicate =
|
||||
|
|
@ -133,7 +133,7 @@ public class RequestPredicatesTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void contentType() throws Exception {
|
||||
public void contentType() {
|
||||
MediaType json = MediaType.APPLICATION_JSON;
|
||||
RequestPredicate predicate = RequestPredicates.contentType(json);
|
||||
MockServerRequest request = MockServerRequest.builder().header("Content-Type", json.toString()).build();
|
||||
|
|
@ -144,7 +144,7 @@ public class RequestPredicatesTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void accept() throws Exception {
|
||||
public void accept() {
|
||||
MediaType json = MediaType.APPLICATION_JSON;
|
||||
RequestPredicate predicate = RequestPredicates.accept(json);
|
||||
MockServerRequest request = MockServerRequest.builder().header("Accept", json.toString()).build();
|
||||
|
|
@ -155,7 +155,7 @@ public class RequestPredicatesTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void pathExtension() throws Exception {
|
||||
public void pathExtension() {
|
||||
RequestPredicate predicate = RequestPredicates.pathExtension("txt");
|
||||
|
||||
URI uri = URI.create("http://localhost/file.txt");
|
||||
|
|
@ -175,7 +175,7 @@ public class RequestPredicatesTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void queryParam() throws Exception {
|
||||
public void queryParam() {
|
||||
MockServerRequest request = MockServerRequest.builder().queryParam("foo", "bar").build();
|
||||
RequestPredicate predicate = RequestPredicates.queryParam("foo", s -> s.equals("bar"));
|
||||
assertTrue(predicate.test(request));
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -37,9 +37,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
|
|||
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -53,6 +51,7 @@ public class ResourceHandlerFunctionTests {
|
|||
|
||||
private ServerResponse.Context context;
|
||||
|
||||
|
||||
@Before
|
||||
public void createContext() {
|
||||
HandlerStrategies strategies = HandlerStrategies.withDefaults();
|
||||
|
|
@ -61,13 +60,11 @@ public class ResourceHandlerFunctionTests {
|
|||
public List<HttpMessageWriter<?>> messageWriters() {
|
||||
return strategies.messageWriters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ViewResolver> viewResolvers() {
|
||||
return strategies.viewResolvers();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -30,7 +30,7 @@ import static org.springframework.web.reactive.function.BodyInserters.*;
|
|||
public class RouterFunctionTests {
|
||||
|
||||
@Test
|
||||
public void and() throws Exception {
|
||||
public void and() {
|
||||
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
|
||||
RouterFunction<ServerResponse> routerFunction1 = request -> Mono.empty();
|
||||
RouterFunction<ServerResponse> routerFunction2 = request -> Mono.just(handlerFunction);
|
||||
|
|
@ -48,7 +48,7 @@ public class RouterFunctionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void andOther() throws Exception {
|
||||
public void andOther() {
|
||||
HandlerFunction<ServerResponse> handlerFunction =
|
||||
request -> ServerResponse.ok().body(fromObject("42"));
|
||||
RouterFunction<?> routerFunction1 = request -> Mono.empty();
|
||||
|
|
@ -68,7 +68,7 @@ public class RouterFunctionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void andRoute() throws Exception {
|
||||
public void andRoute() {
|
||||
RouterFunction<ServerResponse> routerFunction1 = request -> Mono.empty();
|
||||
RequestPredicate requestPredicate = request -> true;
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ public class RouterFunctionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void filter() throws Exception {
|
||||
public void filter() {
|
||||
Mono<String> stringMono = Mono.just("42");
|
||||
HandlerFunction<EntityResponse<Mono<String>>> handlerFunction =
|
||||
request -> EntityResponse.fromPublisher(stringMono, String.class).build();
|
||||
|
|
@ -99,6 +99,7 @@ public class RouterFunctionTests {
|
|||
.map(Integer::parseInt);
|
||||
return EntityResponse.fromPublisher(intMono, Integer.class).build();
|
||||
});
|
||||
|
||||
RouterFunction<EntityResponse<Mono<Integer>>> result = routerFunction.filter(filterFunction);
|
||||
assertNotNull(result);
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ import static org.mockito.Mockito.*;
|
|||
public class RouterFunctionsTests {
|
||||
|
||||
@Test
|
||||
public void routeMatch() throws Exception {
|
||||
public void routeMatch() {
|
||||
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
|
||||
|
||||
MockServerRequest request = MockServerRequest.builder().build();
|
||||
|
|
@ -67,7 +67,7 @@ public class RouterFunctionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void routeNoMatch() throws Exception {
|
||||
public void routeNoMatch() {
|
||||
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
|
||||
|
||||
MockServerRequest request = MockServerRequest.builder().build();
|
||||
|
|
@ -84,7 +84,7 @@ public class RouterFunctionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void nestMatch() throws Exception {
|
||||
public void nestMatch() {
|
||||
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
|
||||
RouterFunction<ServerResponse> routerFunction = request -> Mono.just(handlerFunction);
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ public class RouterFunctionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void nestNoMatch() throws Exception {
|
||||
public void nestNoMatch() {
|
||||
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
|
||||
RouterFunction<ServerResponse> routerFunction = request -> Mono.just(handlerFunction);
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ public class RouterFunctionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toHttpHandlerNormal() throws Exception {
|
||||
public void toHttpHandlerNormal() {
|
||||
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.accepted().build();
|
||||
RouterFunction<ServerResponse> routerFunction =
|
||||
RouterFunctions.route(RequestPredicates.all(), handlerFunction);
|
||||
|
|
@ -136,7 +136,7 @@ public class RouterFunctionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toHttpHandlerHandlerThrowsException() throws Exception {
|
||||
public void toHttpHandlerHandlerThrowsException() {
|
||||
HandlerFunction<ServerResponse> handlerFunction =
|
||||
request -> {
|
||||
throw new IllegalStateException();
|
||||
|
|
@ -154,7 +154,7 @@ public class RouterFunctionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toHttpHandlerHandlerReturnsException() throws Exception {
|
||||
public void toHttpHandlerHandlerReturnsException() {
|
||||
HandlerFunction<ServerResponse> handlerFunction =
|
||||
request -> Mono.error(new IllegalStateException());
|
||||
RouterFunction<ServerResponse> routerFunction =
|
||||
|
|
@ -170,7 +170,7 @@ public class RouterFunctionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toHttpHandlerHandlerResponseStatusException() throws Exception {
|
||||
public void toHttpHandlerHandlerResponseStatusException() {
|
||||
HandlerFunction<ServerResponse> handlerFunction =
|
||||
request -> Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found"));
|
||||
RouterFunction<ServerResponse> routerFunction =
|
||||
|
|
@ -186,28 +186,24 @@ public class RouterFunctionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toHttpHandlerHandlerReturnResponseStatusExceptionInResponseWriteTo() throws Exception {
|
||||
public void toHttpHandlerHandlerReturnResponseStatusExceptionInResponseWriteTo() {
|
||||
HandlerFunction<ServerResponse> handlerFunction =
|
||||
// Mono.<ServerResponse> is required for compilation in Eclipse
|
||||
request -> Mono.<ServerResponse> just(new ServerResponse() {
|
||||
request -> Mono.just(new ServerResponse() {
|
||||
@Override
|
||||
public HttpStatus statusCode() {
|
||||
return HttpStatus.OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders headers() {
|
||||
return new HttpHeaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiValueMap<String, ResponseCookie> cookies() {
|
||||
return new LinkedMultiValueMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> writeTo(ServerWebExchange exchange,
|
||||
Context context) {
|
||||
public Mono<Void> writeTo(ServerWebExchange exchange, Context context) {
|
||||
return Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found"));
|
||||
}
|
||||
});
|
||||
|
|
@ -224,28 +220,24 @@ public class RouterFunctionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toHttpHandlerHandlerThrowResponseStatusExceptionInResponseWriteTo() throws Exception {
|
||||
public void toHttpHandlerHandlerThrowResponseStatusExceptionInResponseWriteTo() {
|
||||
HandlerFunction<ServerResponse> handlerFunction =
|
||||
// Mono.<ServerResponse> is required for compilation in Eclipse
|
||||
request -> Mono.<ServerResponse> just(new ServerResponse() {
|
||||
request -> Mono.just(new ServerResponse() {
|
||||
@Override
|
||||
public HttpStatus statusCode() {
|
||||
return HttpStatus.OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders headers() {
|
||||
return new HttpHeaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiValueMap<String, ResponseCookie> cookies() {
|
||||
return new LinkedMultiValueMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> writeTo(ServerWebExchange exchange,
|
||||
Context context) {
|
||||
public Mono<Void> writeTo(ServerWebExchange exchange, Context context) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found");
|
||||
}
|
||||
});
|
||||
|
|
@ -262,7 +254,7 @@ public class RouterFunctionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toHttpHandlerWebFilter() throws Exception {
|
||||
public void toHttpHandlerWebFilter() {
|
||||
AtomicBoolean filterInvoked = new AtomicBoolean();
|
||||
|
||||
WebFilter webFilter = new WebFilter() {
|
||||
|
|
@ -291,5 +283,4 @@ public class RouterFunctionsTests {
|
|||
assertTrue(filterInvoked.get());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import org.springframework.web.reactive.function.client.WebClient;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.http.MediaType.*;
|
||||
import static org.springframework.web.reactive.function.BodyExtractors.*;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.*;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.*;
|
||||
|
||||
|
|
@ -120,7 +119,6 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
|
|||
|
||||
private static final Flux<Long> INTERVAL = interval(Duration.ofMillis(100), 2);
|
||||
|
||||
|
||||
Mono<ServerResponse> string(ServerRequest request) {
|
||||
return ServerResponse.ok()
|
||||
.contentType(MediaType.TEXT_EVENT_STREAM)
|
||||
|
|
|
|||
|
|
@ -55,12 +55,12 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void request() throws Exception {
|
||||
public void request() {
|
||||
assertSame(mockRequest, wrapper.request());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void method() throws Exception {
|
||||
public void method() {
|
||||
HttpMethod method = HttpMethod.POST;
|
||||
when(mockRequest.method()).thenReturn(method);
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void uri() throws Exception {
|
||||
public void uri() {
|
||||
URI uri = URI.create("https://example.com");
|
||||
when(mockRequest.uri()).thenReturn(uri);
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void path() throws Exception {
|
||||
public void path() {
|
||||
String path = "/foo/bar";
|
||||
when(mockRequest.path()).thenReturn(path);
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void headers() throws Exception {
|
||||
public void headers() {
|
||||
ServerRequest.Headers headers = mock(ServerRequest.Headers.class);
|
||||
when(mockRequest.headers()).thenReturn(headers);
|
||||
|
||||
|
|
@ -92,7 +92,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void attribute() throws Exception {
|
||||
public void attribute() {
|
||||
String name = "foo";
|
||||
String value = "bar";
|
||||
when(mockRequest.attribute(name)).thenReturn(Optional.of(value));
|
||||
|
|
@ -101,7 +101,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void queryParam() throws Exception {
|
||||
public void queryParam() {
|
||||
String name = "foo";
|
||||
String value = "bar";
|
||||
when(mockRequest.queryParam(name)).thenReturn(Optional.of(value));
|
||||
|
|
@ -110,7 +110,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void queryParams() throws Exception {
|
||||
public void queryParams() {
|
||||
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
|
||||
value.add("foo", "bar");
|
||||
when(mockRequest.queryParams()).thenReturn(value);
|
||||
|
|
@ -119,7 +119,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void pathVariable() throws Exception {
|
||||
public void pathVariable() {
|
||||
String name = "foo";
|
||||
String value = "bar";
|
||||
when(mockRequest.pathVariable(name)).thenReturn(value);
|
||||
|
|
@ -128,7 +128,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void pathVariables() throws Exception {
|
||||
public void pathVariables() {
|
||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||
when(mockRequest.pathVariables()).thenReturn(pathVariables);
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void cookies() throws Exception {
|
||||
public void cookies() {
|
||||
MultiValueMap<String, HttpCookie> cookies = mock(MultiValueMap.class);
|
||||
when(mockRequest.cookies()).thenReturn(cookies);
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyExtractor() throws Exception {
|
||||
public void bodyExtractor() {
|
||||
Mono<String> result = Mono.just("foo");
|
||||
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
|
||||
when(mockRequest.body(extractor)).thenReturn(result);
|
||||
|
|
@ -153,7 +153,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToMonoClass() throws Exception {
|
||||
public void bodyToMonoClass() {
|
||||
Mono<String> result = Mono.just("foo");
|
||||
when(mockRequest.bodyToMono(String.class)).thenReturn(result);
|
||||
|
||||
|
|
@ -161,7 +161,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToMonoParameterizedTypeReference() throws Exception {
|
||||
public void bodyToMonoParameterizedTypeReference() {
|
||||
Mono<String> result = Mono.just("foo");
|
||||
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
|
||||
when(mockRequest.bodyToMono(reference)).thenReturn(result);
|
||||
|
|
@ -170,7 +170,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToFluxClass() throws Exception {
|
||||
public void bodyToFluxClass() {
|
||||
Flux<String> result = Flux.just("foo");
|
||||
when(mockRequest.bodyToFlux(String.class)).thenReturn(result);
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ public class ServerRequestWrapperTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void bodyToFluxParameterizedTypeReference() throws Exception {
|
||||
public void bodyToFluxParameterizedTypeReference() {
|
||||
Flux<String> result = Flux.just("foo");
|
||||
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
|
||||
when(mockRequest.bodyToFlux(reference)).thenReturn(result);
|
||||
|
|
|
|||
|
|
@ -86,9 +86,7 @@ class ReactiveTypeHandler {
|
|||
this(ReactiveAdapterRegistry.getSharedInstance(), new SyncTaskExecutor(), new ContentNegotiationManager());
|
||||
}
|
||||
|
||||
ReactiveTypeHandler(ReactiveAdapterRegistry registry, TaskExecutor executor,
|
||||
ContentNegotiationManager manager) {
|
||||
|
||||
ReactiveTypeHandler(ReactiveAdapterRegistry registry, TaskExecutor executor, ContentNegotiationManager manager) {
|
||||
Assert.notNull(registry, "ReactiveAdapterRegistry is required");
|
||||
Assert.notNull(executor, "TaskExecutor is required");
|
||||
Assert.notNull(manager, "ContentNegotiationManager is required");
|
||||
|
|
@ -120,7 +118,7 @@ class ReactiveTypeHandler {
|
|||
ReactiveAdapter adapter = this.reactiveRegistry.getAdapter(returnValue.getClass());
|
||||
Assert.state(adapter != null, "Unexpected return value: " + returnValue);
|
||||
|
||||
ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric(0);
|
||||
ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric();
|
||||
Class<?> elementClass = elementType.resolve(Object.class);
|
||||
|
||||
Collection<MediaType> mediaTypes = getMediaTypes(request);
|
||||
|
|
|
|||
|
|
@ -82,17 +82,14 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur
|
|||
|
||||
/**
|
||||
* Complete constructor with pluggable "reactive" type support.
|
||||
*
|
||||
* @param messageConverters converters to write emitted objects with
|
||||
* @param reactiveRegistry for reactive return value type support
|
||||
* @param executor for blocking I/O writes of items emitted from reactive types
|
||||
* @param manager for detecting streaming media types
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public ResponseBodyEmitterReturnValueHandler(List<HttpMessageConverter<?>> messageConverters,
|
||||
ReactiveAdapterRegistry reactiveRegistry, TaskExecutor executor,
|
||||
ContentNegotiationManager manager) {
|
||||
ReactiveAdapterRegistry reactiveRegistry, TaskExecutor executor, ContentNegotiationManager manager) {
|
||||
|
||||
Assert.notEmpty(messageConverters, "HttpMessageConverter List must not be empty");
|
||||
this.messageConverters = messageConverters;
|
||||
|
|
@ -102,13 +99,12 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur
|
|||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
|
||||
Class<?> bodyType = ResponseEntity.class.isAssignableFrom(returnType.getParameterType()) ?
|
||||
ResolvableType.forMethodParameter(returnType).getGeneric(0).resolve() :
|
||||
ResolvableType.forMethodParameter(returnType).getGeneric().resolve() :
|
||||
returnType.getParameterType();
|
||||
|
||||
return bodyType != null && (ResponseBodyEmitter.class.isAssignableFrom(bodyType) ||
|
||||
this.reactiveHandler.isReactiveType(bodyType));
|
||||
return (bodyType != null && (ResponseBodyEmitter.class.isAssignableFrom(bodyType) ||
|
||||
this.reactiveHandler.isReactiveType(bodyType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
|
|||
this.returnValue = returnValue;
|
||||
this.returnType = (returnValue instanceof ReactiveTypeHandler.CollectedValuesList ?
|
||||
((ReactiveTypeHandler.CollectedValuesList) returnValue).getReturnType() :
|
||||
ResolvableType.forType(super.getGenericParameterType()).getGeneric(0));
|
||||
ResolvableType.forType(super.getGenericParameterType()).getGeneric());
|
||||
}
|
||||
|
||||
public ConcurrentResultMethodParameter(ConcurrentResultMethodParameter original) {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class StreamingResponseBodyReturnValueHandler implements HandlerMethodRet
|
|||
return true;
|
||||
}
|
||||
else if (ResponseEntity.class.isAssignableFrom(returnType.getParameterType())) {
|
||||
Class<?> bodyType = ResolvableType.forMethodParameter(returnType).getGeneric(0).resolve();
|
||||
Class<?> bodyType = ResolvableType.forMethodParameter(returnType).getGeneric().resolve();
|
||||
return (bodyType != null && StreamingResponseBody.class.isAssignableFrom(bodyType));
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue