Polish MockHttpServletRequestBuilder
This commit is contained in:
parent
c579cd1ce9
commit
caf2af077a
|
|
@ -73,6 +73,8 @@ final class TestDispatcherServlet extends DispatcherServlet {
|
|||
|
||||
super.service(request, response);
|
||||
|
||||
// TODO: add CountDownLatch to DeferredResultInterceptor and wait in request().asyncResult(..)
|
||||
|
||||
Object handler = getMvcResult(request).getHandler();
|
||||
if (asyncManager.isConcurrentHandlingStarted() && !deferredResultInterceptor.wasInvoked) {
|
||||
if (!callableInterceptor.await()) {
|
||||
|
|
|
|||
|
|
@ -202,6 +202,21 @@ public class MockHttpServletRequestBuilder implements RequestBuilder, Mergeable
|
|||
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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -84,9 +84,6 @@ public class RequestResultMatchers {
|
|||
|
||||
/**
|
||||
* 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) {
|
||||
return new ResultMatcher() {
|
||||
|
|
@ -95,7 +92,7 @@ public class RequestResultMatchers {
|
|||
HttpServletRequest request = result.getRequest();
|
||||
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
|
||||
MatcherAssert.assertThat("Async started", request.isAsyncStarted(), equalTo(true));
|
||||
MatcherAssert.assertThat("Callable result", (T) asyncManager.getConcurrentResult(), matcher);
|
||||
MatcherAssert.assertThat("Async result", (T) asyncManager.getConcurrentResult(), matcher);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue