use of org.springframework.mock.web.test.MockAsyncContext in project spring-framework by spring-projects.
the class StandardServletAsyncWebRequestTests method startAsyncMultipleTimes.
@Test
public void startAsyncMultipleTimes() throws Exception {
this.asyncRequest.startAsync();
this.asyncRequest.startAsync();
this.asyncRequest.startAsync();
// idempotent
this.asyncRequest.startAsync();
MockAsyncContext context = (MockAsyncContext) this.request.getAsyncContext();
assertNotNull(context);
assertEquals(1, context.getListeners().size());
}
use of org.springframework.mock.web.test.MockAsyncContext in project spring-framework by spring-projects.
the class StandardServletAsyncWebRequestTests method startAsyncAfterCompleted.
@Test
public void startAsyncAfterCompleted() throws Exception {
this.asyncRequest.onComplete(new AsyncEvent(new MockAsyncContext(this.request, this.response)));
try {
this.asyncRequest.startAsync();
fail("expected exception");
} catch (IllegalStateException ex) {
assertEquals("Async processing has already completed", ex.getMessage());
}
}
use of org.springframework.mock.web.test.MockAsyncContext in project spring-framework by spring-projects.
the class ResponseBodyEmitterReturnValueHandlerTests method responseBodyEmitter.
@Test
public void responseBodyEmitter() throws Exception {
MethodParameter returnType = returnType("handle");
ResponseBodyEmitter emitter = new ResponseBodyEmitter();
handleReturnValue(emitter, returnType);
assertTrue(this.request.isAsyncStarted());
assertEquals("", this.response.getContentAsString());
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);
assertEquals("{\"id\":1,\"name\":\"Joe\"}\n" + "{\"id\":2,\"name\":\"John\"}\n" + "{\"id\":3,\"name\":\"Jason\"}", this.response.getContentAsString());
MockAsyncContext asyncContext = (MockAsyncContext) this.request.getAsyncContext();
assertNull(asyncContext.getDispatchedPath());
emitter.complete();
assertNotNull(asyncContext.getDispatchedPath());
}
Aggregations