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:
@@ -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) {
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user