Polish MockHttpServletRequestBuilder
This commit is contained in:
@@ -73,6 +73,8 @@ final class TestDispatcherServlet extends DispatcherServlet {
|
|||||||
|
|
||||||
super.service(request, response);
|
super.service(request, response);
|
||||||
|
|
||||||
|
// TODO: add CountDownLatch to DeferredResultInterceptor and wait in request().asyncResult(..)
|
||||||
|
|
||||||
Object handler = getMvcResult(request).getHandler();
|
Object handler = getMvcResult(request).getHandler();
|
||||||
if (asyncManager.isConcurrentHandlingStarted() && !deferredResultInterceptor.wasInvoked) {
|
if (asyncManager.isConcurrentHandlingStarted() && !deferredResultInterceptor.wasInvoked) {
|
||||||
if (!callableInterceptor.await()) {
|
if (!callableInterceptor.await()) {
|
||||||
|
|||||||
@@ -202,6 +202,21 @@ public class MockHttpServletRequestBuilder implements RequestBuilder, Mergeable
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the request body as a UTF-8 String.
|
||||||
|
*
|
||||||
|
* @param content the body content
|
||||||
|
*/
|
||||||
|
public MockHttpServletRequestBuilder content(String content) {
|
||||||
|
try {
|
||||||
|
this.content = content.getBytes("UTF-8");
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException e) {
|
||||||
|
// should never happen
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the given cookies to the request. Cookies are always added.
|
* Add the given cookies to the request. Cookies are always added.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -84,9 +84,6 @@ public class RequestResultMatchers {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert the result from asynchronous processing with the given matcher.
|
* Assert the result from asynchronous processing with the given matcher.
|
||||||
* This method can be used when a controller method returns {@link Callable}
|
|
||||||
* or {@link AsyncTask}. The value matched is the value returned from the
|
|
||||||
* {@code Callable} or the exception raised.
|
|
||||||
*/
|
*/
|
||||||
public <T> ResultMatcher asyncResult(final Matcher<T> matcher) {
|
public <T> ResultMatcher asyncResult(final Matcher<T> matcher) {
|
||||||
return new ResultMatcher() {
|
return new ResultMatcher() {
|
||||||
@@ -95,7 +92,7 @@ public class RequestResultMatchers {
|
|||||||
HttpServletRequest request = result.getRequest();
|
HttpServletRequest request = result.getRequest();
|
||||||
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
|
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
|
||||||
MatcherAssert.assertThat("Async started", request.isAsyncStarted(), equalTo(true));
|
MatcherAssert.assertThat("Async started", request.isAsyncStarted(), equalTo(true));
|
||||||
MatcherAssert.assertThat("Callable result", (T) asyncManager.getConcurrentResult(), matcher);
|
MatcherAssert.assertThat("Async result", (T) asyncManager.getConcurrentResult(), matcher);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user