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 tomcat by apache.
the class TestAsyncContextImpl method testAsyncListenerSupplyRequestResponse.
@Test
public void testAsyncListenerSupplyRequestResponse() {
final ServletRequest servletRequest = EasyMock.createMock(ServletRequest.class);
final ServletResponse servletResponse = EasyMock.createMock(ServletResponse.class);
final AsyncListener listener = new AsyncListener() {
@Override
public void onTimeout(AsyncEvent event) throws IOException {
checkRequestResponse(event);
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
checkRequestResponse(event);
}
@Override
public void onError(AsyncEvent event) throws IOException {
checkRequestResponse(event);
}
@Override
public void onComplete(AsyncEvent event) throws IOException {
checkRequestResponse(event);
}
private void checkRequestResponse(AsyncEvent event) {
Assert.assertEquals(servletRequest, event.getSuppliedRequest());
Assert.assertEquals(servletResponse, event.getSuppliedResponse());
}
};
final Context context = new TesterContext();
final Response response = new Response();
final Request request = new Request(null);
request.setCoyoteRequest(new org.apache.coyote.Request());
request.getMappingData().context = context;
final AsyncContextImpl ac = new AsyncContextImpl(request);
ac.addListener(listener, servletRequest, servletResponse);
ac.setStarted(context, request, response, true);
ac.addListener(listener, servletRequest, servletResponse);
ac.setErrorState(new Exception(), true);
ac.fireOnComplete();
}
Aggregations