提交 3a66927b 编写于 作者: J Juergen Hoeller

Polishing

上级 c58da710
...@@ -66,7 +66,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { ...@@ -66,7 +66,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
public static final int DEFAULT_CACHE_LIMIT = 1024; public static final int DEFAULT_CACHE_LIMIT = 1024;
/** Static evaluation context to reuse. */ /** Static evaluation context to reuse. */
private static EvaluationContext messageEvalContext = private static final EvaluationContext messageEvalContext =
SimpleEvaluationContext.forPropertyAccessors(new SimpMessageHeaderPropertyAccessor()).build(); SimpleEvaluationContext.forPropertyAccessors(new SimpMessageHeaderPropertyAccessor()).build();
...@@ -130,7 +130,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { ...@@ -130,7 +130,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
* @since 4.2 * @since 4.2
*/ */
public void setSelectorHeaderName(@Nullable String selectorHeaderName) { public void setSelectorHeaderName(@Nullable String selectorHeaderName) {
this.selectorHeaderName = StringUtils.hasText(selectorHeaderName) ? selectorHeaderName : null; this.selectorHeaderName = (StringUtils.hasText(selectorHeaderName) ? selectorHeaderName : null);
} }
/** /**
......
...@@ -1017,9 +1017,10 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable ...@@ -1017,9 +1017,10 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
} }
/** /**
* Return the value of the required {@code Host} header. * Return the value of the {@code Host} header, if available.
* <p>If the header value does not contain a port, the returned * <p>If the header value does not contain a port, the
* {@linkplain InetSocketAddress#getPort() port} will be {@code 0}. * {@linkplain InetSocketAddress#getPort() port} in the returned address will
* be {@code 0}.
* @since 5.0 * @since 5.0
*/ */
@Nullable @Nullable
......
...@@ -90,7 +90,7 @@ public interface ServerWebExchange { ...@@ -90,7 +90,7 @@ public interface ServerWebExchange {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
default <T> T getRequiredAttribute(String name) { default <T> T getRequiredAttribute(String name) {
T value = getAttribute(name); T value = getAttribute(name);
Assert.notNull(value, () -> "Required attribute '" + name + "' is missing."); Assert.notNull(value, () -> "Required attribute '" + name + "' is missing");
return value; return value;
} }
...@@ -124,7 +124,6 @@ public interface ServerWebExchange { ...@@ -124,7 +124,6 @@ public interface ServerWebExchange {
/** /**
* Return the form data from the body of the request if the Content-Type is * Return the form data from the body of the request if the Content-Type is
* {@code "application/x-www-form-urlencoded"} or an empty map otherwise. * {@code "application/x-www-form-urlencoded"} or an empty map otherwise.
*
* <p><strong>Note:</strong> calling this method causes the request body to * <p><strong>Note:</strong> calling this method causes the request body to
* be read and parsed in full and the resulting {@code MultiValueMap} is * be read and parsed in full and the resulting {@code MultiValueMap} is
* cached so that this method is safe to call more than once. * cached so that this method is safe to call more than once.
...@@ -134,7 +133,6 @@ public interface ServerWebExchange { ...@@ -134,7 +133,6 @@ public interface ServerWebExchange {
/** /**
* Return the parts of a multipart request if the Content-Type is * Return the parts of a multipart request if the Content-Type is
* {@code "multipart/form-data"} or an empty map otherwise. * {@code "multipart/form-data"} or an empty map otherwise.
*
* <p><strong>Note:</strong> calling this method causes the request body to * <p><strong>Note:</strong> calling this method causes the request body to
* be read and parsed in full and the resulting {@code MultiValueMap} is * be read and parsed in full and the resulting {@code MultiValueMap} is
* cached so that this method is safe to call more than once. * cached so that this method is safe to call more than once.
...@@ -150,10 +148,9 @@ public interface ServerWebExchange { ...@@ -150,10 +148,9 @@ public interface ServerWebExchange {
/** /**
* Return the {@link ApplicationContext} associated with the web application, * Return the {@link ApplicationContext} associated with the web application,
* if it was initialized with one via * if it was initialized with one via
* {@link org.springframework.web.server.adapter.WebHttpHandlerBuilder#applicationContext * {@link org.springframework.web.server.adapter.WebHttpHandlerBuilder#applicationContext}.
* WebHttpHandlerBuilder#applicationContext}.
* @since 5.0.3 * @since 5.0.3
* @see org.springframework.web.server.adapter.WebHttpHandlerBuilder#applicationContext(ApplicationContext) * @see org.springframework.web.server.adapter.WebHttpHandlerBuilder#applicationContext
*/ */
@Nullable @Nullable
ApplicationContext getApplicationContext(); ApplicationContext getApplicationContext();
......
...@@ -99,6 +99,8 @@ public abstract class BodyInserters { ...@@ -99,6 +99,8 @@ public abstract class BodyInserters {
public static <T, P extends Publisher<T>> BodyInserter<P, ReactiveHttpOutputMessage> fromPublisher( public static <T, P extends Publisher<T>> BodyInserter<P, ReactiveHttpOutputMessage> fromPublisher(
P publisher, Class<T> elementClass) { P publisher, Class<T> elementClass) {
Assert.notNull(publisher, "Publisher must not be null");
Assert.notNull(elementClass, "Element Class must not be null");
return (message, context) -> return (message, context) ->
writeWithMessageWriters(message, context, publisher, ResolvableType.forClass(elementClass)); writeWithMessageWriters(message, context, publisher, ResolvableType.forClass(elementClass));
} }
...@@ -109,16 +111,18 @@ public abstract class BodyInserters { ...@@ -109,16 +111,18 @@ public abstract class BodyInserters {
* {@link org.springframework.web.reactive.function.client.WebClient WebClient} and * {@link org.springframework.web.reactive.function.client.WebClient WebClient} and
* {@link org.springframework.web.reactive.function.server.ServerResponse ServerResponse}. * {@link org.springframework.web.reactive.function.server.ServerResponse ServerResponse}.
* @param publisher the publisher to write with * @param publisher the publisher to write with
* @param typeRef the type of elements contained in the publisher * @param typeReference the type of elements contained in the publisher
* @param <T> the type of the elements contained in the publisher * @param <T> the type of the elements contained in the publisher
* @param <P> the {@code Publisher} type * @param <P> the {@code Publisher} type
* @return the inserter to write a {@code Publisher} * @return the inserter to write a {@code Publisher}
*/ */
public static <T, P extends Publisher<T>> BodyInserter<P, ReactiveHttpOutputMessage> fromPublisher( public static <T, P extends Publisher<T>> BodyInserter<P, ReactiveHttpOutputMessage> fromPublisher(
P publisher, ParameterizedTypeReference<T> typeRef) { P publisher, ParameterizedTypeReference<T> typeReference) {
Assert.notNull(publisher, "Publisher must not be null");
Assert.notNull(typeReference, "ParameterizedTypeReference must not be null");
return (message, context) -> return (message, context) ->
writeWithMessageWriters(message, context, publisher, ResolvableType.forType(typeRef.getType())); writeWithMessageWriters(message, context, publisher, ResolvableType.forType(typeReference.getType()));
} }
/** /**
...@@ -130,6 +134,7 @@ public abstract class BodyInserters { ...@@ -130,6 +134,7 @@ public abstract class BodyInserters {
* @return the inserter to write a {@code Publisher} * @return the inserter to write a {@code Publisher}
*/ */
public static <T extends Resource> BodyInserter<T, ReactiveHttpOutputMessage> fromResource(T resource) { public static <T extends Resource> BodyInserter<T, ReactiveHttpOutputMessage> fromResource(T resource) {
Assert.notNull(resource, "Resource must not be null");
return (outputMessage, context) -> { return (outputMessage, context) -> {
ResolvableType elementType = RESOURCE_TYPE; ResolvableType elementType = RESOURCE_TYPE;
HttpMessageWriter<Resource> writer = findWriter(context, elementType, null); HttpMessageWriter<Resource> writer = findWriter(context, elementType, null);
...@@ -151,6 +156,7 @@ public abstract class BodyInserters { ...@@ -151,6 +156,7 @@ public abstract class BodyInserters {
public static <T, S extends Publisher<ServerSentEvent<T>>> BodyInserter<S, ServerHttpResponse> fromServerSentEvents( public static <T, S extends Publisher<ServerSentEvent<T>>> BodyInserter<S, ServerHttpResponse> fromServerSentEvents(
S eventsPublisher) { S eventsPublisher) {
Assert.notNull(eventsPublisher, "Publisher must not be null");
return (serverResponse, context) -> { return (serverResponse, context) -> {
ResolvableType elmentType = SSE_TYPE; ResolvableType elmentType = SSE_TYPE;
MediaType mediaType = MediaType.TEXT_EVENT_STREAM; MediaType mediaType = MediaType.TEXT_EVENT_STREAM;
...@@ -163,13 +169,11 @@ public abstract class BodyInserters { ...@@ -163,13 +169,11 @@ public abstract class BodyInserters {
* Return a {@link FormInserter} to write the given {@code MultiValueMap} * Return a {@link FormInserter} to write the given {@code MultiValueMap}
* as URL-encoded form data. The returned inserter allows for additional * as URL-encoded form data. The returned inserter allows for additional
* entries to be added via {@link FormInserter#with(String, Object)}. * entries to be added via {@link FormInserter#with(String, Object)}.
*
* <p>Note that you can also use the {@code syncBody(Object)} method in the * <p>Note that you can also use the {@code syncBody(Object)} method in the
* request builders of both the {@code WebClient} and {@code WebTestClient}. * request builders of both the {@code WebClient} and {@code WebTestClient}.
* In that case the setting of the request content type is also not required, * In that case the setting of the request content type is also not required,
* just be sure the map contains String values only or otherwise it would be * just be sure the map contains String values only or otherwise it would be
* interpreted as a multipart request. * interpreted as a multipart request.
*
* @param formData the form data to write to the output message * @param formData the form data to write to the output message
* @return the inserter that allows adding more form data * @return the inserter that allows adding more form data
*/ */
......
...@@ -106,8 +106,7 @@ public interface ClientRequest { ...@@ -106,8 +106,7 @@ public interface ClientRequest {
String logPrefix(); String logPrefix();
/** /**
* Writes this request to the given {@link ClientHttpRequest}. * Write this request to the given {@link ClientHttpRequest}.
*
* @param request the client http request to write to * @param request the client http request to write to
* @param strategies the strategies to use when writing * @param strategies the strategies to use when writing
* @return {@code Mono<Void>} to indicate when writing is complete * @return {@code Mono<Void>} to indicate when writing is complete
......
...@@ -64,13 +64,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { ...@@ -64,13 +64,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder {
private BodyInserter<?, ? super ClientHttpRequest> body = BodyInserters.empty(); private BodyInserter<?, ? super ClientHttpRequest> body = BodyInserters.empty();
public DefaultClientRequestBuilder(HttpMethod method, URI url) {
Assert.notNull(method, "HttpMethod must not be null");
Assert.notNull(url, "URI must not be null");
this.method = method;
this.url = url;
}
public DefaultClientRequestBuilder(ClientRequest other) { public DefaultClientRequestBuilder(ClientRequest other) {
Assert.notNull(other, "ClientRequest must not be null"); Assert.notNull(other, "ClientRequest must not be null");
this.method = other.method(); this.method = other.method();
...@@ -81,17 +74,24 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { ...@@ -81,17 +74,24 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder {
body(other.body()); body(other.body());
} }
public DefaultClientRequestBuilder(HttpMethod method, URI url) {
Assert.notNull(method, "HttpMethod must not be null");
Assert.notNull(url, "URI must not be null");
this.method = method;
this.url = url;
}
@Override @Override
public ClientRequest.Builder method(HttpMethod method) { public ClientRequest.Builder method(HttpMethod method) {
Assert.notNull(method, "'method' must not be null"); Assert.notNull(method, "HttpMethod must not be null");
this.method = method; this.method = method;
return this; return this;
} }
@Override @Override
public ClientRequest.Builder url(URI url) { public ClientRequest.Builder url(URI url) {
Assert.notNull(url, "'url' must not be null"); Assert.notNull(url, "URI must not be null");
this.url = url; this.url = url;
return this; return this;
} }
...@@ -126,9 +126,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { ...@@ -126,9 +126,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder {
@Override @Override
public <S, P extends Publisher<S>> ClientRequest.Builder body(P publisher, Class<S> elementClass) { public <S, P extends Publisher<S>> ClientRequest.Builder body(P publisher, Class<S> elementClass) {
Assert.notNull(publisher, "'publisher' must not be null");
Assert.notNull(elementClass, "'elementClass' must not be null");
this.body = BodyInserters.fromPublisher(publisher, elementClass); this.body = BodyInserters.fromPublisher(publisher, elementClass);
return this; return this;
} }
...@@ -137,9 +134,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { ...@@ -137,9 +134,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder {
public <S, P extends Publisher<S>> ClientRequest.Builder body( public <S, P extends Publisher<S>> ClientRequest.Builder body(
P publisher, ParameterizedTypeReference<S> typeReference) { P publisher, ParameterizedTypeReference<S> typeReference) {
Assert.notNull(publisher, "'publisher' must not be null");
Assert.notNull(typeReference, "'typeReference' must not be null");
this.body = BodyInserters.fromPublisher(publisher, typeReference); this.body = BodyInserters.fromPublisher(publisher, typeReference);
return this; return this;
} }
...@@ -184,7 +178,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { ...@@ -184,7 +178,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder {
private final String logPrefix; private final String logPrefix;
public BodyInserterRequest(HttpMethod method, URI url, HttpHeaders headers, public BodyInserterRequest(HttpMethod method, URI url, HttpHeaders headers,
MultiValueMap<String, String> cookies, BodyInserter<?, ? super ClientHttpRequest> body, MultiValueMap<String, String> cookies, BodyInserter<?, ? super ClientHttpRequest> body,
Map<String, Object> attributes) { Map<String, Object> attributes) {
...@@ -200,7 +193,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { ...@@ -200,7 +193,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder {
this.logPrefix = "[" + id + "] "; this.logPrefix = "[" + id + "] ";
} }
@Override @Override
public HttpMethod method() { public HttpMethod method() {
return this.method; return this.method;
......
...@@ -116,9 +116,9 @@ public abstract class ExchangeFilterFunctions { ...@@ -116,9 +116,9 @@ public abstract class ExchangeFilterFunctions {
@Deprecated @Deprecated
public static ExchangeFilterFunction basicAuthentication() { public static ExchangeFilterFunction basicAuthentication() {
return (request, next) -> { return (request, next) -> {
Credentials cred = (Credentials) request Object attr = request.attributes().get(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE);
.attribute(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE).orElse(null); if (attr instanceof Credentials) {
if (cred != null) { Credentials cred = (Credentials) attr;
return next.exchange(ClientRequest.from(request) return next.exchange(ClientRequest.from(request)
.headers(headers -> headers.setBasicAuth(cred.username, cred.password)) .headers(headers -> headers.setBasicAuth(cred.username, cred.password))
.build()); .build());
......
...@@ -140,7 +140,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { ...@@ -140,7 +140,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder {
@Override @Override
public ServerRequest.Builder body(Flux<DataBuffer> body) { public ServerRequest.Builder body(Flux<DataBuffer> body) {
Assert.notNull(body, "'body' must not be null"); Assert.notNull(body, "Body must not be null");
releaseBody(); releaseBody();
this.body = body; this.body = body;
return this; return this;
...@@ -148,7 +148,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { ...@@ -148,7 +148,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder {
@Override @Override
public ServerRequest.Builder body(String body) { public ServerRequest.Builder body(String body) {
Assert.notNull(body, "'body' must not be null"); Assert.notNull(body, "Body must not be null");
releaseBody(); releaseBody();
DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
this.body = Flux.just(body). this.body = Flux.just(body).
...@@ -165,7 +165,6 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { ...@@ -165,7 +165,6 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder {
@Override @Override
public ServerRequest.Builder attribute(String name, Object value) { public ServerRequest.Builder attribute(String name, Object value) {
Assert.notNull(name, "'name' must not be null");
this.attributes.put(name, value); this.attributes.put(name, value);
return this; return this;
} }
......
...@@ -39,6 +39,7 @@ import static org.mockito.Mockito.*; ...@@ -39,6 +39,7 @@ import static org.mockito.Mockito.*;
/** /**
* Unit tests for {@link DefaultWebClient}. * Unit tests for {@link DefaultWebClient}.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class DefaultWebClientTests { public class DefaultWebClientTests {
......
...@@ -38,6 +38,7 @@ import static org.mockito.Mockito.*; ...@@ -38,6 +38,7 @@ import static org.mockito.Mockito.*;
/** /**
* Unit tests for {@link ExchangeFilterFunctions}. * Unit tests for {@link ExchangeFilterFunctions}.
*
* @author Arjen Poutsma * @author Arjen Poutsma
*/ */
public class ExchangeFilterFunctionsTests { public class ExchangeFilterFunctionsTests {
......
...@@ -42,6 +42,7 @@ import static org.junit.Assert.*; ...@@ -42,6 +42,7 @@ import static org.junit.Assert.*;
/** /**
* WebClient integration tests focusing on data buffer management. * WebClient integration tests focusing on data buffer management.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class WebClientDataBufferAllocatingTests extends AbstractDataBufferAllocatingTestCase { public class WebClientDataBufferAllocatingTests extends AbstractDataBufferAllocatingTestCase {
......
...@@ -75,13 +75,13 @@ public class WebClientIntegrationTests { ...@@ -75,13 +75,13 @@ public class WebClientIntegrationTests {
@Parameterized.Parameters(name = "webClient [{0}]") @Parameterized.Parameters(name = "webClient [{0}]")
public static Object[][] arguments() { public static Object[][] arguments() {
return new Object[][] { return new Object[][] {
{new JettyClientHttpConnector()}, {new JettyClientHttpConnector()},
{new ReactorClientHttpConnector()} {new ReactorClientHttpConnector()}
}; };
} }
@Before @Before
public void setup() { public void setup() {
this.server = new MockWebServer(); this.server = new MockWebServer();
......
...@@ -62,6 +62,7 @@ public class DefaultServerResponseBuilderTests { ...@@ -62,6 +62,7 @@ public class DefaultServerResponseBuilderTests {
} }
}; };
@Test @Test
public void from() { public void from() {
ServerResponse other = ServerResponse.ok().header("foo", "bar").build().block(); ServerResponse other = ServerResponse.ok().header("foo", "bar").build().block();
...@@ -383,5 +384,4 @@ public class DefaultServerResponseBuilderTests { ...@@ -383,5 +384,4 @@ public class DefaultServerResponseBuilderTests {
.verify(); .verify();
} }
} }
...@@ -43,9 +43,8 @@ import org.springframework.web.server.adapter.WebHttpHandlerBuilder; ...@@ -43,9 +43,8 @@ import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import org.springframework.web.util.pattern.PathPattern; import org.springframework.web.util.pattern.PathPattern;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.springframework.web.reactive.function.BodyInserters.fromPublisher; import static org.springframework.web.reactive.function.BodyInserters.*;
import static org.springframework.web.reactive.function.server.RouterFunctions.nest; import static org.springframework.web.reactive.function.server.RouterFunctions.*;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
/** /**
* Tests the use of {@link HandlerFunction} and {@link RouterFunction} in a * Tests the use of {@link HandlerFunction} and {@link RouterFunction} in a
...@@ -134,7 +133,6 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr ...@@ -134,7 +133,6 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
return new AttributesHandler(); return new AttributesHandler();
} }
@Bean @Bean
public RouterFunction<EntityResponse<Person>> monoRouterFunction(PersonHandler personHandler) { public RouterFunction<EntityResponse<Person>> monoRouterFunction(PersonHandler personHandler) {
return route(RequestPredicates.GET("/mono"), personHandler::mono); return route(RequestPredicates.GET("/mono"), personHandler::mono);
...@@ -150,7 +148,6 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr ...@@ -150,7 +148,6 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
return nest(RequestPredicates.GET("/attributes"), return nest(RequestPredicates.GET("/attributes"),
route(RequestPredicates.GET("/{foo}"), attributesHandler::attributes)); route(RequestPredicates.GET("/{foo}"), attributesHandler::attributes));
} }
} }
...@@ -167,16 +164,15 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr ...@@ -167,16 +164,15 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
return ServerResponse.ok().body( return ServerResponse.ok().body(
fromPublisher(Flux.just(person1, person2), Person.class)); fromPublisher(Flux.just(person1, person2), Person.class));
} }
} }
private static class AttributesHandler { private static class AttributesHandler {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Mono<ServerResponse> attributes(ServerRequest request) { public Mono<ServerResponse> attributes(ServerRequest request) {
assertTrue(request.attributes().containsKey(RouterFunctions.REQUEST_ATTRIBUTE)); assertTrue(request.attributes().containsKey(RouterFunctions.REQUEST_ATTRIBUTE));
assertTrue(request.attributes() assertTrue(request.attributes().containsKey(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE));
.containsKey(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE));
Map<String, String> pathVariables = Map<String, String> pathVariables =
(Map<String, String>) request.attributes().get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE); (Map<String, String>) request.attributes().get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
...@@ -203,9 +199,9 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr ...@@ -203,9 +199,9 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
return ServerResponse.ok().build(); return ServerResponse.ok().build();
} }
} }
@Controller @Controller
public static class PersonController { public static class PersonController {
...@@ -216,6 +212,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr ...@@ -216,6 +212,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
} }
} }
private static class Person { private static class Person {
private String name; private String name;
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -44,21 +44,6 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio ...@@ -44,21 +44,6 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio
private final WebClient webClient = WebClient.create(); 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 @Override
protected RouterFunction<?> routerFunction() { protected RouterFunction<?> routerFunction() {
...@@ -77,6 +62,24 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio ...@@ -77,6 +62,24 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio
.build(); .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 { private static class DummyViewResolver implements ViewResolver {
@Override @Override
...@@ -85,6 +88,7 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio ...@@ -85,6 +88,7 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio
} }
} }
private static class DummyView implements View { private static class DummyView implements View {
private final Locale locale; private final Locale locale;
...@@ -105,4 +109,5 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio ...@@ -105,4 +109,5 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio
return Mono.empty(); return Mono.empty();
} }
} }
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -69,9 +69,9 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt ...@@ -69,9 +69,9 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
return HandlerStrategies.builder() return HandlerStrategies.builder()
.viewResolver(new DummyViewResolver()) .viewResolver(new DummyViewResolver())
.build(); .build();
} }
@Test @Test
public void normal() { public void normal() {
ResponseEntity<String> result = ResponseEntity<String> result =
...@@ -109,6 +109,7 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt ...@@ -109,6 +109,7 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
return result; return result;
} }
private static class RenderingResponseHandler { private static class RenderingResponseHandler {
public Mono<RenderingResponse> render(ServerRequest request) { public Mono<RenderingResponse> render(ServerRequest request) {
...@@ -116,7 +117,6 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt ...@@ -116,7 +117,6 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
.modelAttribute("bar", "baz") .modelAttribute("bar", "baz")
.build(); .build();
} }
} }
private static class DummyViewResolver implements ViewResolver { private static class DummyViewResolver implements ViewResolver {
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
...@@ -209,7 +209,6 @@ public class RouterFunctionBuilderTests { ...@@ -209,7 +209,6 @@ public class RouterFunctionBuilderTests {
StepVerifier.create(barResponseMono) StepVerifier.create(barResponseMono)
.expectNext(500) .expectNext(500)
.verifyComplete(); .verifyComplete();
} }
} }
\ No newline at end of file
...@@ -35,8 +35,8 @@ import org.springframework.web.reactive.function.server.ServerResponse; ...@@ -35,8 +35,8 @@ import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder; import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept; import static org.springframework.web.reactive.function.server.RequestPredicates.*;
import static org.springframework.web.reactive.function.server.RouterFunctions.route; import static org.springframework.web.reactive.function.server.RouterFunctions.*;
/** /**
* @author Arjen Poutsma * @author Arjen Poutsma
...@@ -45,6 +45,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr ...@@ -45,6 +45,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
private final RestTemplate restTemplate = new RestTemplate(); private final RestTemplate restTemplate = new RestTemplate();
@Override @Override
protected HttpHandler createHttpHandler() { protected HttpHandler createHttpHandler() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
...@@ -54,6 +55,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr ...@@ -54,6 +55,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build(); return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build();
} }
@Test @Test
public void nested() { public void nested() {
ResponseEntity<String> result = this.restTemplate ResponseEntity<String> result = this.restTemplate
...@@ -83,6 +85,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr ...@@ -83,6 +85,7 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
} }
} }
static class Handler { static class Handler {
public Mono<ServerResponse> handle(ServerRequest request) { public Mono<ServerResponse> handle(ServerRequest request) {
...@@ -90,7 +93,4 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr ...@@ -90,7 +93,4 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
} }
} }
} }
\ No newline at end of file
...@@ -21,7 +21,6 @@ import java.util.Collections; ...@@ -21,7 +21,6 @@ import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
...@@ -44,15 +43,10 @@ import static org.mockito.Mockito.*; ...@@ -44,15 +43,10 @@ import static org.mockito.Mockito.*;
*/ */
public class ServerRequestWrapperTests { 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 @Test
public void request() { public void request() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册