Browse Source

Polish MockHttpServletRequestBuilder

pull/163/merge
Rossen Stoyanchev 14 years ago
parent
commit
caf2af077a
  1. 2
      spring-test-mvc/src/main/java/org/springframework/test/web/mock/servlet/TestDispatcherServlet.java
  2. 15
      spring-test-mvc/src/main/java/org/springframework/test/web/mock/servlet/request/MockHttpServletRequestBuilder.java
  3. 5
      spring-test-mvc/src/main/java/org/springframework/test/web/mock/servlet/result/RequestResultMatchers.java

2
spring-test-mvc/src/main/java/org/springframework/test/web/mock/servlet/TestDispatcherServlet.java

@ -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()) {

15
spring-test-mvc/src/main/java/org/springframework/test/web/mock/servlet/request/MockHttpServletRequestBuilder.java

@ -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.
* *

5
spring-test-mvc/src/main/java/org/springframework/test/web/mock/servlet/result/RequestResultMatchers.java

@ -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);
} }
}; };
} }

Loading…
Cancel
Save