提交 caf2af07 编写于 作者: R Rossen Stoyanchev

Polish MockHttpServletRequestBuilder

上级 c579cd1c
......@@ -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);
}
};
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册