Refactor reactive mock request and response support

MockServerHttpRequest and MockServerHttpResponse now extend the same
abstract base classes that server-specific implementations do and
therefore approximate their behavior more closely.

As an immediate consequence MockServerHttpRequest is read-only after
it is created. Instead it now exposes static builder methods similar
to those found in RequestEntity. This enforces more strictness as well
as recycling of requests in tests and provides nicer builder methods.

To simplify tests DefaultServerWebExchange now offers a constructor
with just a request and response, and automatically creating a
DefaultWebSessionManager.

The spring-test module now also contains client-side reactive mock
request and response implementations. The mock client request extends
the same AbstractClientHttpRequest as client-specific implementations
do. There is no abstract base class for client responses.

Issue: SPR-14590
This commit is contained in:
Rossen Stoyanchev
2017-01-13 15:08:03 -05:00
parent 4d6c1d0d3f
commit ba3cc535f1
91 changed files with 2314 additions and 1776 deletions

View File

@@ -44,6 +44,7 @@ import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
import org.springframework.web.server.session.DefaultWebSessionManager;
import org.springframework.web.server.session.WebSessionManager;
/**
@@ -81,6 +82,17 @@ public class DefaultServerWebExchange implements ServerWebExchange {
private volatile boolean notModified;
/**
* Constructor with a request and response only.
* By default creates a session manager of type {@link DefaultWebSessionManager}.
*/
public DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response) {
this(request, response, new DefaultWebSessionManager());
}
/**
* Alternate constructor with a WebSessionManager parameter.
*/
public DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response,
WebSessionManager sessionManager) {

View File

@@ -193,6 +193,7 @@ public class WebHttpHandlerBuilder {
}
WebExceptionHandler[] array = new WebExceptionHandler[this.exceptionHandlers.size()];
webHandler = new ExceptionHandlingWebHandler(webHandler, this.exceptionHandlers.toArray(array));
// TODO: protected method for further decoration
HttpWebHandlerAdapter httpHandler = new HttpWebHandlerAdapter(webHandler);
if (this.sessionManager != null) {
httpHandler.setSessionManager(this.sessionManager);