use of jakarta.servlet.AsyncEvent in project spring-framework by spring-projects.
the class StandardServletAsyncWebRequestTests method onErrorHandler.
@SuppressWarnings("unchecked")
@Test
public void onErrorHandler() throws Exception {
Consumer<Throwable> errorHandler = mock(Consumer.class);
this.asyncRequest.addErrorHandler(errorHandler);
Exception e = new Exception();
this.asyncRequest.onError(new AsyncEvent(new MockAsyncContext(this.request, this.response), e));
verify(errorHandler).accept(e);
}
use of jakarta.servlet.AsyncEvent in project spring-framework by spring-projects.
the class StandardServletAsyncWebRequestTests method onTimeoutDefaultBehavior.
@Test
public void onTimeoutDefaultBehavior() throws Exception {
this.asyncRequest.onTimeout(new AsyncEvent(new MockAsyncContext(this.request, this.response)));
assertThat(this.response.getStatus()).isEqualTo(200);
}
use of jakarta.servlet.AsyncEvent in project spring-framework by spring-projects.
the class StandardServletAsyncWebRequestTests method onTimeoutHandler.
@Test
public void onTimeoutHandler() throws Exception {
Runnable timeoutHandler = mock(Runnable.class);
this.asyncRequest.addTimeoutHandler(timeoutHandler);
this.asyncRequest.onTimeout(new AsyncEvent(new MockAsyncContext(this.request, this.response)));
verify(timeoutHandler).run();
}
use of jakarta.servlet.AsyncEvent in project spring-framework by spring-projects.
the class StandardServletAsyncWebRequestTests method onCompletionHandler.
@Test
public void onCompletionHandler() throws Exception {
Runnable handler = mock(Runnable.class);
this.asyncRequest.addCompletionHandler(handler);
this.asyncRequest.startAsync();
this.asyncRequest.onComplete(new AsyncEvent(this.request.getAsyncContext()));
verify(handler).run();
assertThat(this.asyncRequest.isAsyncComplete()).isTrue();
}
use of jakarta.servlet.AsyncEvent in project spring-framework by spring-projects.
the class WebAsyncManagerErrorTests method startDeferredResultProcessingErrorAndResumeWithDefaultResult.
@Test
public void startDeferredResultProcessingErrorAndResumeWithDefaultResult() throws Exception {
Exception e = new Exception();
DeferredResult<Throwable> deferredResult = new DeferredResult<>(null, e);
this.asyncManager.startDeferredResultProcessing(deferredResult);
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");
}
Aggregations