Polishing
This commit is contained in:
@@ -49,9 +49,8 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
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.springframework.http.codec.json.AbstractJackson2Codec.JSON_VIEW_HINT;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.http.codec.json.AbstractJackson2Codec.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -63,6 +62,7 @@ public class BodyExtractorsTests {
|
||||
|
||||
private Map<String, Object> hints;
|
||||
|
||||
|
||||
@Before
|
||||
public void createContext() {
|
||||
final List<HttpMessageReader<?>> messageReaders = new ArrayList<>();
|
||||
@@ -85,6 +85,7 @@ public class BodyExtractorsTests {
|
||||
this.hints = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void toMono() throws Exception {
|
||||
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
|
||||
@@ -232,7 +233,6 @@ public class BodyExtractorsTests {
|
||||
})
|
||||
.expectComplete()
|
||||
.verify();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,6 +256,7 @@ public class BodyExtractorsTests {
|
||||
|
||||
interface SafeToDeserialize {}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class User {
|
||||
|
||||
@@ -289,4 +290,4 @@ public class BodyExtractorsTests {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ 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.junit.Assert.assertArrayEquals;
|
||||
import static org.springframework.http.codec.json.AbstractJackson2Codec.JSON_VIEW_HINT;
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.http.codec.json.AbstractJackson2Codec.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -73,6 +73,7 @@ public class BodyInsertersTests {
|
||||
|
||||
private Map<String, Object> hints;
|
||||
|
||||
|
||||
@Before
|
||||
public void createContext() {
|
||||
final List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
||||
@@ -96,9 +97,10 @@ public class BodyInsertersTests {
|
||||
return hints;
|
||||
}
|
||||
};
|
||||
this.hints = new HashMap();
|
||||
this.hints = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void ofString() throws Exception {
|
||||
String body = "foo";
|
||||
@@ -255,6 +257,7 @@ public class BodyInsertersTests {
|
||||
|
||||
interface SafeToSerialize {}
|
||||
|
||||
|
||||
private static class User {
|
||||
|
||||
@JsonView(SafeToSerialize.class)
|
||||
@@ -287,5 +290,4 @@ public class BodyInsertersTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,14 +34,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 org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.http.HttpMethod.DELETE;
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.http.HttpMethod.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
||||
@@ -46,11 +46,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
|
||||
@@ -68,10 +66,10 @@ public class DefaultClientResponseTests {
|
||||
public void createMocks() {
|
||||
mockResponse = mock(ClientHttpResponse.class);
|
||||
mockExchangeStrategies = mock(ExchangeStrategies.class);
|
||||
|
||||
defaultClientResponse = new DefaultClientResponse(mockResponse, mockExchangeStrategies);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void statusCode() throws Exception {
|
||||
HttpStatus status = HttpStatus.CONTINUE;
|
||||
@@ -210,5 +208,4 @@ public class DefaultClientResponseTests {
|
||||
.verify();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,8 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DefaultWebClient}.
|
||||
|
||||
@@ -23,11 +23,9 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.http.HttpMethod.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -100,4 +98,4 @@ public class ExchangeFilterFunctionsTests {
|
||||
assertEquals(response, result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ import org.springframework.http.ReactiveHttpOutputMessage;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.http.codec.HttpMessageWriter;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -104,6 +103,7 @@ public class ExchangeStrategiesTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class DummyMessageReader implements HttpMessageReader<Object> {
|
||||
|
||||
@Override
|
||||
@@ -128,5 +128,5 @@ public class ExchangeStrategiesTests {
|
||||
return Mono.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,9 +35,8 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.Pojo;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.*;
|
||||
|
||||
/**
|
||||
* Integration tests using a {@link ExchangeFunction} through {@link WebClient}.
|
||||
@@ -269,7 +268,6 @@ public class WebClientIntegrationTests {
|
||||
RecordedRequest recordedRequest = server.takeRequest();
|
||||
Assert.assertEquals(1, server.getRequestCount());
|
||||
Assert.assertEquals("bar", recordedRequest.getHeader("foo"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -295,7 +293,6 @@ public class WebClientIntegrationTests {
|
||||
RecordedRequest recordedRequest = server.takeRequest();
|
||||
Assert.assertEquals(1, server.getRequestCount());
|
||||
Assert.assertEquals("bar", recordedRequest.getHeader("foo"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -22,8 +22,7 @@ import org.springframework.http.server.reactive.HttpHandler;
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public abstract class AbstractRouterFunctionIntegrationTests
|
||||
extends AbstractHttpHandlerIntegrationTests {
|
||||
public abstract class AbstractRouterFunctionIntegrationTests extends AbstractHttpHandlerIntegrationTests {
|
||||
|
||||
@Override
|
||||
protected final HttpHandler createHttpHandler() {
|
||||
@@ -32,4 +31,5 @@ public abstract class AbstractRouterFunctionIntegrationTests
|
||||
}
|
||||
|
||||
protected abstract RouterFunction<?> routerFunction();
|
||||
|
||||
}
|
||||
|
||||
@@ -48,9 +48,8 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
||||
import org.springframework.web.server.session.MockWebSessionManager;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -122,7 +121,7 @@ public class DefaultEntityResponseBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eTag() throws Exception {
|
||||
public void etag() throws Exception {
|
||||
String body = "foo";
|
||||
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).eTag("foo").build();
|
||||
StepVerifier.create(result)
|
||||
@@ -213,4 +212,4 @@ public class DefaultEntityResponseBuilderTests {
|
||||
assertNotNull(mockResponse.getBody());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
||||
import org.springframework.web.server.session.MockWebSessionManager;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -134,4 +133,4 @@ public class DefaultRenderingResponseTests {
|
||||
.verify();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,10 +52,9 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
|
||||
import org.springframework.web.server.WebSession;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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
|
||||
@@ -72,6 +71,7 @@ public class DefaultServerRequestTests {
|
||||
|
||||
private DefaultServerRequest defaultRequest;
|
||||
|
||||
|
||||
@Before
|
||||
public void createMocks() {
|
||||
mockRequest = mock(ServerHttpRequest.class);
|
||||
@@ -85,6 +85,7 @@ public class DefaultServerRequestTests {
|
||||
defaultRequest = new DefaultServerRequest(mockExchange, mockHandlerStrategies);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void method() throws Exception {
|
||||
HttpMethod method = HttpMethod.HEAD;
|
||||
@@ -258,4 +259,4 @@ public class DefaultServerRequestTests {
|
||||
.verify();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,8 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -23,7 +23,6 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -50,26 +49,22 @@ import org.springframework.web.reactive.function.server.support.ServerResponseRe
|
||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromPublisher;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
import static org.junit.Assert.*;
|
||||
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
|
||||
* {@link DispatcherHandler}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests {
|
||||
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
private AnnotationConfigApplicationContext wac;
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Before
|
||||
public void createRestTemplate() {
|
||||
this.restTemplate = new RestTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpHandler createHttpHandler() {
|
||||
@@ -83,6 +78,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
return WebHttpHandlerBuilder.webHandler(webHandler).build();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void mono() throws Exception {
|
||||
ResponseEntity<Person> result =
|
||||
@@ -160,6 +156,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class PersonHandler {
|
||||
|
||||
public Mono<ServerResponse> mono(ServerRequest request) {
|
||||
@@ -220,11 +217,8 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
"name='" + this.name + '\'' +
|
||||
'}';
|
||||
return "Person{" + "name='" + this.name + '\'' + '}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ import org.springframework.http.ReactiveHttpOutputMessage;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.http.codec.HttpMessageWriter;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -106,6 +105,7 @@ public class HandlerStrategiesTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class DummyMessageReader implements HttpMessageReader<Object> {
|
||||
|
||||
@Override
|
||||
@@ -130,5 +130,6 @@ public class HandlerStrategiesTests {
|
||||
return Mono.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -32,14 +32,13 @@ import org.springframework.http.HttpRange;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.reactive.function.server.support.ServerRequestWrapper;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class HeadersWrapperTest {
|
||||
public class HeadersWrapperTests {
|
||||
|
||||
private ServerRequest.Headers mockHeaders;
|
||||
|
||||
@@ -52,6 +51,7 @@ public class HeadersWrapperTest {
|
||||
wrapper = new ServerRequestWrapper.HeadersWrapper(mockHeaders);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void accept() throws Exception {
|
||||
List<MediaType> accept = Collections.singletonList(MediaType.APPLICATION_JSON);
|
||||
@@ -117,4 +117,4 @@ public class HeadersWrapperTest {
|
||||
assertSame(httpHeaders, wrapper.asHttpHeaders());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -66,10 +66,12 @@ public class MockServerRequest implements ServerRequest {
|
||||
|
||||
private final WebSession session;
|
||||
|
||||
|
||||
private MockServerRequest(HttpMethod method, URI uri,
|
||||
MockHeaders headers, Object body, Map<String, Object> attributes,
|
||||
MultiValueMap<String, String> queryParams,
|
||||
Map<String, String> pathVariables, WebSession session) {
|
||||
|
||||
this.method = method;
|
||||
this.uri = uri;
|
||||
this.headers = headers;
|
||||
@@ -80,9 +82,6 @@ public class MockServerRequest implements ServerRequest {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new BuilderImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpMethod method() {
|
||||
@@ -148,6 +147,12 @@ public class MockServerRequest implements ServerRequest {
|
||||
return Mono.justOrEmpty(this.session);
|
||||
}
|
||||
|
||||
|
||||
public static Builder builder() {
|
||||
return new BuilderImpl();
|
||||
}
|
||||
|
||||
|
||||
public interface Builder {
|
||||
|
||||
Builder method(HttpMethod method);
|
||||
@@ -175,9 +180,9 @@ public class MockServerRequest implements ServerRequest {
|
||||
MockServerRequest body(Object body);
|
||||
|
||||
MockServerRequest build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static class BuilderImpl implements Builder {
|
||||
|
||||
private HttpMethod method = HttpMethod.GET;
|
||||
@@ -289,14 +294,13 @@ public class MockServerRequest implements ServerRequest {
|
||||
return new MockServerRequest(this.method, this.uri, this.headers, null,
|
||||
this.attributes, this.queryParams, this.pathVariables, this.session);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static class MockHeaders implements Headers {
|
||||
|
||||
private final HttpHeaders headers;
|
||||
|
||||
|
||||
public MockHeaders(HttpHeaders headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.web.reactive.function.server;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -25,25 +24,18 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.pathPrefix;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.nest;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.*;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.*;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class NestedRouteIntegrationTests
|
||||
extends AbstractRouterFunctionIntegrationTests {
|
||||
public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrationTests {
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
@Before
|
||||
public void createRestTemplate() {
|
||||
this.restTemplate = new RestTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RouterFunction<?> routerFunction() {
|
||||
@@ -73,6 +65,7 @@ public class NestedRouteIntegrationTests
|
||||
assertEquals("baz", result.getBody());
|
||||
}
|
||||
|
||||
|
||||
private static class NestedHandler {
|
||||
|
||||
public Mono<ServerResponse> bar(ServerRequest request) {
|
||||
@@ -82,7 +75,6 @@ public class NestedRouteIntegrationTests
|
||||
public Mono<ServerResponse> baz(ServerRequest request) {
|
||||
return ServerResponse.ok().body(fromObject("baz"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.web.reactive.function.server;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -31,25 +30,19 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromPublisher;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
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.BodyExtractors.*;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.*;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.*;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class PublisherHandlerFunctionIntegrationTests
|
||||
extends AbstractRouterFunctionIntegrationTests {
|
||||
public class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunctionIntegrationTests {
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
@Before
|
||||
public void createRestTemplate() {
|
||||
this.restTemplate = new RestTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RouterFunction<?> routerFunction() {
|
||||
@@ -112,9 +105,9 @@ public class PublisherHandlerFunctionIntegrationTests
|
||||
return ServerResponse.ok().body(
|
||||
fromPublisher(Flux.just(person1, person2), Person.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static class Person {
|
||||
|
||||
private String name;
|
||||
@@ -154,11 +147,8 @@ public class PublisherHandlerFunctionIntegrationTests
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
"name='" + name + '\'' +
|
||||
'}';
|
||||
return "Person{" + "name='" + name + '\'' + '}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -18,8 +18,7 @@ package org.springframework.web.reactive.function.server;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -63,4 +62,5 @@ public class RequestPredicateTests {
|
||||
assertTrue(predicate2.or(predicate1).test(request));
|
||||
assertFalse(predicate2.or(predicate3).test(request));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.util.patterns.PathPatternParser;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -191,5 +190,4 @@ public class RequestPredicatesTests {
|
||||
assertFalse(predicate.test(request));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -35,8 +35,7 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
||||
import org.springframework.web.server.session.MockWebSessionManager;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -61,13 +60,13 @@ public class ResourceHandlerFunctionTests {
|
||||
|
||||
Mono<Void> result = responseMono.then(response -> {
|
||||
assertEquals(HttpStatus.OK, response.statusCode());
|
||||
/*
|
||||
TODO: enable when ServerEntityResponse is reintroduced
|
||||
/*
|
||||
TODO: enable when ServerEntityResponse is reintroduced
|
||||
StepVerifier.create(response.body())
|
||||
.expectNext(this.resource)
|
||||
.expectComplete()
|
||||
.verify();
|
||||
*/
|
||||
*/
|
||||
return response.writeTo(exchange, HandlerStrategies.withDefaults());
|
||||
});
|
||||
|
||||
@@ -132,12 +131,12 @@ TODO: enable when ServerEntityResponse is reintroduced
|
||||
assertEquals(HttpStatus.OK, response.statusCode());
|
||||
assertEquals(EnumSet.of(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS),
|
||||
response.headers().getAllow());
|
||||
/*
|
||||
TODO: enable when ServerEntityResponse is reintroduced
|
||||
/*
|
||||
TODO: enable when ServerEntityResponse is reintroduced
|
||||
StepVerifier.create(response.body())
|
||||
.expectComplete()
|
||||
.verify();
|
||||
*/
|
||||
*/
|
||||
return response.writeTo(exchange, HandlerStrategies.withDefaults());
|
||||
});
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -84,10 +84,6 @@ public class RouterFunctionTests {
|
||||
.verify();
|
||||
}
|
||||
|
||||
private Mono<ServerResponse> handlerMethod(ServerRequest request) {
|
||||
return ServerResponse.ok().body(fromObject("42"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filter() throws Exception {
|
||||
Mono<String> stringMono = Mono.just("42");
|
||||
@@ -120,4 +116,9 @@ public class RouterFunctionTests {
|
||||
.verify();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Mono<ServerResponse> handlerMethod(ServerRequest request) {
|
||||
return ServerResponse.ok().body(fromObject("42"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,11 +30,8 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
|
||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
||||
@@ -27,13 +27,12 @@ import reactor.test.StepVerifier;
|
||||
import org.springframework.http.codec.ServerSentEvent;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.springframework.core.ResolvableType.forClassWithGenerics;
|
||||
import static org.springframework.http.MediaType.TEXT_EVENT_STREAM;
|
||||
import static org.springframework.web.reactive.function.BodyExtractors.toFlux;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromServerSentEvents;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.core.ResolvableType.*;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -43,12 +42,6 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
|
||||
private WebClient webClient;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
super.setup();
|
||||
this.webClient = WebClient.create("http://localhost:" + this.port);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RouterFunction<?> routerFunction() {
|
||||
SseHandler sseHandler = new SseHandler();
|
||||
@@ -57,6 +50,13 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
|
||||
.and(route(RequestPredicates.GET("/event"), sseHandler::sse));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
super.setup();
|
||||
this.webClient = WebClient.create("http://localhost:" + this.port);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void sseAsString() throws Exception {
|
||||
Flux<String> result = this.webClient.get()
|
||||
@@ -71,6 +71,7 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
|
||||
.expectComplete()
|
||||
.verify(Duration.ofSeconds(5L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sseAsPerson() throws Exception {
|
||||
Flux<Person> result = this.webClient.get()
|
||||
@@ -114,6 +115,7 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
|
||||
.verify(Duration.ofSeconds(5L));
|
||||
}
|
||||
|
||||
|
||||
private static class SseHandler {
|
||||
|
||||
public Mono<ServerResponse> string(ServerRequest request) {
|
||||
@@ -133,11 +135,11 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
|
||||
.id(Long.toString(l))
|
||||
.comment("bar")
|
||||
.build()).take(2);
|
||||
|
||||
return ServerResponse.ok().body(fromServerSentEvents(flux));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class Person {
|
||||
|
||||
private String name;
|
||||
@@ -177,9 +179,7 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
"name='" + name + '\'' +
|
||||
'}';
|
||||
return "Person{" + "name='" + name + '\'' + '}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user