use of org.springframework.web.testfixture.servlet.MockAsyncContext in project spring-framework by spring-projects.
the class WebAsyncManagerErrorTests method startCallableProcessingErrorAndResumeThroughCallback.
@Test
public void startCallableProcessingErrorAndResumeThroughCallback() throws Exception {
StubCallable callable = new StubCallable();
WebAsyncTask<Object> webAsyncTask = new WebAsyncTask<>(callable);
webAsyncTask.onError(() -> 7);
this.asyncManager.startCallableProcessing(webAsyncTask);
Exception e = new Exception();
AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
this.asyncWebRequest.onError(event);
assertThat(this.asyncManager.hasConcurrentResult()).isTrue();
assertThat(this.asyncManager.getConcurrentResult()).isEqualTo(7);
assertThat(((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath()).isEqualTo("/test");
}
use of org.springframework.web.testfixture.servlet.MockAsyncContext in project spring-framework by spring-projects.
the class WebAsyncManagerErrorTests method startDeferredResultProcessingAfterException.
@Test
public void startDeferredResultProcessingAfterException() throws Exception {
DeferredResult<Integer> deferredResult = new DeferredResult<>();
final Exception exception = new Exception();
DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptor() {
@Override
public <T> boolean handleError(NativeWebRequest request, DeferredResult<T> result, Throwable t) throws Exception {
throw exception;
}
};
this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
this.asyncManager.startDeferredResultProcessing(deferredResult);
Exception e = new Exception();
AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
this.asyncWebRequest.onError(event);
assertThat(this.asyncManager.hasConcurrentResult()).isTrue();
assertThat(this.asyncManager.getConcurrentResult()).isEqualTo(e);
assertThat(((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath()).isEqualTo("/test");
}
use of org.springframework.web.testfixture.servlet.MockAsyncContext in project spring-framework by spring-projects.
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);
}
Aggregations