Polishing
This commit is contained in:
@@ -39,6 +39,7 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DefaultWebClient}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class DefaultWebClientTests {
|
||||
|
||||
@@ -38,6 +38,7 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ExchangeFilterFunctions}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class ExchangeFilterFunctionsTests {
|
||||
|
||||
@@ -42,6 +42,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* WebClient integration tests focusing on data buffer management.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class WebClientDataBufferAllocatingTests extends AbstractDataBufferAllocatingTestCase {
|
||||
|
||||
@@ -75,13 +75,13 @@ public class WebClientIntegrationTests {
|
||||
|
||||
@Parameterized.Parameters(name = "webClient [{0}]")
|
||||
public static Object[][] arguments() {
|
||||
|
||||
return new Object[][] {
|
||||
{new JettyClientHttpConnector()},
|
||||
{new ReactorClientHttpConnector()}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.server = new MockWebServer();
|
||||
|
||||
@@ -62,6 +62,7 @@ public class DefaultServerResponseBuilderTests {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Test
|
||||
public void from() {
|
||||
ServerResponse other = ServerResponse.ok().header("foo", "bar").build().block();
|
||||
@@ -383,5 +384,4 @@ public class DefaultServerResponseBuilderTests {
|
||||
.verify();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -43,9 +43,8 @@ import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
import org.springframework.web.util.pattern.PathPattern;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromPublisher;
|
||||
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.BodyInserters.*;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.*;
|
||||
|
||||
/**
|
||||
* Tests the use of {@link HandlerFunction} and {@link RouterFunction} in a
|
||||
@@ -134,7 +133,6 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
return new AttributesHandler();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public RouterFunction<EntityResponse<Person>> monoRouterFunction(PersonHandler personHandler) {
|
||||
return route(RequestPredicates.GET("/mono"), personHandler::mono);
|
||||
@@ -150,7 +148,6 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
return nest(RequestPredicates.GET("/attributes"),
|
||||
route(RequestPredicates.GET("/{foo}"), attributesHandler::attributes));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -167,16 +164,15 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
return ServerResponse.ok().body(
|
||||
fromPublisher(Flux.just(person1, person2), Person.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static class AttributesHandler {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Mono<ServerResponse> attributes(ServerRequest request) {
|
||||
assertTrue(request.attributes().containsKey(RouterFunctions.REQUEST_ATTRIBUTE));
|
||||
assertTrue(request.attributes()
|
||||
.containsKey(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE));
|
||||
assertTrue(request.attributes().containsKey(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE));
|
||||
|
||||
Map<String, String> pathVariables =
|
||||
(Map<String, String>) request.attributes().get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
|
||||
@@ -203,9 +199,9 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
|
||||
return ServerResponse.ok().build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Controller
|
||||
public static class PersonController {
|
||||
|
||||
@@ -216,6 +212,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class Person {
|
||||
|
||||
private String name;
|
||||
|
||||
@@ -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.
|
||||
@@ -44,21 +44,6 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio
|
||||
|
||||
private final WebClient webClient = WebClient.create();
|
||||
|
||||
@Test
|
||||
public void fixedLocale() {
|
||||
Mono<ClientResponse> result = webClient
|
||||
.get()
|
||||
.uri("http://localhost:" + this.port + "/")
|
||||
.exchange();
|
||||
|
||||
StepVerifier
|
||||
.create(result)
|
||||
.consumeNextWith(response -> {
|
||||
assertEquals(HttpStatus.OK, response.statusCode());
|
||||
assertEquals(Locale.GERMANY, response.headers().asHttpHeaders().getContentLanguage());
|
||||
})
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RouterFunction<?> routerFunction() {
|
||||
@@ -77,6 +62,24 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void fixedLocale() {
|
||||
Mono<ClientResponse> result = webClient
|
||||
.get()
|
||||
.uri("http://localhost:" + this.port + "/")
|
||||
.exchange();
|
||||
|
||||
StepVerifier
|
||||
.create(result)
|
||||
.consumeNextWith(response -> {
|
||||
assertEquals(HttpStatus.OK, response.statusCode());
|
||||
assertEquals(Locale.GERMANY, response.headers().asHttpHeaders().getContentLanguage());
|
||||
})
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
|
||||
private static class DummyViewResolver implements ViewResolver {
|
||||
|
||||
@Override
|
||||
@@ -85,6 +88,7 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class DummyView implements View {
|
||||
|
||||
private final Locale locale;
|
||||
@@ -105,4 +109,5 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio
|
||||
return Mono.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -69,9 +69,9 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
|
||||
return HandlerStrategies.builder()
|
||||
.viewResolver(new DummyViewResolver())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void normal() {
|
||||
ResponseEntity<String> result =
|
||||
@@ -109,6 +109,7 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static class RenderingResponseHandler {
|
||||
|
||||
public Mono<RenderingResponse> render(ServerRequest request) {
|
||||
@@ -116,7 +117,6 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
|
||||
.modelAttribute("bar", "baz")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class DummyViewResolver implements ViewResolver {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -209,7 +209,6 @@ public class RouterFunctionBuilderTests {
|
||||
StepVerifier.create(barResponseMono)
|
||||
.expectNext(500)
|
||||
.verifyComplete();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
|
||||
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
|
||||
@@ -45,6 +45,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
|
||||
@Override
|
||||
protected HttpHandler createHttpHandler() {
|
||||
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
|
||||
@@ -54,6 +55,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void nested() {
|
||||
ResponseEntity<String> result = this.restTemplate
|
||||
@@ -83,6 +85,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class Handler {
|
||||
|
||||
public Mono<ServerResponse> handle(ServerRequest request) {
|
||||
@@ -90,7 +93,4 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -44,15 +43,10 @@ import static org.mockito.Mockito.*;
|
||||
*/
|
||||
public class ServerRequestWrapperTests {
|
||||
|
||||
private ServerRequest mockRequest;
|
||||
private final ServerRequest mockRequest = mock(ServerRequest.class);
|
||||
|
||||
private ServerRequestWrapper wrapper;
|
||||
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
|
||||
|
||||
@Before
|
||||
public void createWrapper() {
|
||||
mockRequest = mock(ServerRequest.class);
|
||||
wrapper = new ServerRequestWrapper(mockRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void request() {
|
||||
|
||||
Reference in New Issue
Block a user