use of cn.taketoday.web.testfixture.servlet.MockAsyncContext in project today-framework by TAKETODAY.
the class ServerHttpRequestTests method createRequest.
private ServerHttpRequest createRequest(String uriString, String contextPath) throws Exception {
URI uri = URI.create(uriString);
MockHttpServletRequest request = new TestHttpServletRequest(uri);
request.setContextPath(contextPath);
AsyncContext asyncContext = new MockAsyncContext(request, new MockHttpServletResponse());
return new ServletServerHttpRequest(request, asyncContext, "", DefaultDataBufferFactory.sharedInstance, 1024);
}
use of cn.taketoday.web.testfixture.servlet.MockAsyncContext in project today-framework by TAKETODAY.
the class ResponseBodyEmitterReturnValueHandlerTests method responseBodyEmitter.
@Test
public void responseBodyEmitter() throws Exception {
HandlerMethod handlerMethod = on(TestController.class).resolveHandlerMethod(ResponseBodyEmitter.class);
ResponseBodyEmitter emitter = new ResponseBodyEmitter();
this.handler.handleReturnValue(webRequest, handlerMethod, emitter);
assertThat(this.request.isAsyncStarted()).isTrue();
assertThat(this.response.getContentAsString()).isEqualTo("");
SimpleBean bean = new SimpleBean();
bean.setId(1L);
bean.setName("Joe");
emitter.send(bean);
emitter.send("\n");
bean.setId(2L);
bean.setName("John");
emitter.send(bean);
emitter.send("\n");
bean.setId(3L);
bean.setName("Jason");
emitter.send(bean);
assertThat(this.response.getContentAsString()).isEqualTo(("{\"id\":1,\"name\":\"Joe\"}\n" + "{\"id\":2,\"name\":\"John\"}\n" + "{\"id\":3,\"name\":\"Jason\"}"));
MockAsyncContext asyncContext = (MockAsyncContext) this.request.getAsyncContext();
assertThat(asyncContext.getDispatchedPath()).isNull();
emitter.complete();
assertThat(asyncContext.getDispatchedPath()).isNotNull();
}
Aggregations