use of com.tvd12.ezyhttp.server.core.servlet.AsyncCallback in project ezyhttp by youngmonkeys.
the class AsyncCallbackTest method onTimeoutWithHttpServletResponse.
@Test
public void onTimeoutWithHttpServletResponse() {
// given
AsyncCallback callback = event -> {
};
AsyncContext asyncContext = mock(AsyncContext.class);
ServletRequest request = mock(ServletRequest.class);
when(asyncContext.getRequest()).thenReturn(request);
HttpServletResponse response = mock(HttpServletResponse.class);
when(asyncContext.getResponse()).thenReturn(response);
AsyncEvent event = new AsyncEvent(asyncContext);
// when
callback.onTimeout(event);
// then
verify(asyncContext, times(1)).getRequest();
verify(asyncContext, times(2)).getResponse();
verify(response, times(1)).setStatus(StatusCodes.REQUEST_TIMEOUT);
}
use of com.tvd12.ezyhttp.server.core.servlet.AsyncCallback in project ezyhttp by youngmonkeys.
the class AsyncCallbackTest method onErrorFailed.
@Test
public void onErrorFailed() {
// given
AsyncCallback callback = event -> {
};
AsyncContext asyncContext = mock(AsyncContext.class);
doThrow(RuntimeException.class).when(asyncContext).complete();
ServletRequest request = mock(ServletRequest.class);
when(asyncContext.getRequest()).thenReturn(request);
HttpServletResponse response = mock(HttpServletResponse.class);
when(asyncContext.getResponse()).thenReturn(response);
AsyncEvent event = new AsyncEvent(asyncContext);
// when
callback.onError(event);
// then
verify(asyncContext, times(1)).getRequest();
verify(asyncContext, times(2)).getResponse();
verify(response, times(1)).setStatus(StatusCodes.INTERNAL_SERVER_ERROR);
}
use of com.tvd12.ezyhttp.server.core.servlet.AsyncCallback in project ezyhttp by youngmonkeys.
the class AsyncCallbackTest method onTimeoutFailed.
@Test
public void onTimeoutFailed() {
// given
AsyncCallback callback = event -> {
};
AsyncContext asyncContext = mock(AsyncContext.class);
doThrow(RuntimeException.class).when(asyncContext).complete();
ServletRequest request = mock(ServletRequest.class);
when(asyncContext.getRequest()).thenReturn(request);
HttpServletResponse response = mock(HttpServletResponse.class);
when(asyncContext.getResponse()).thenReturn(response);
AsyncEvent event = new AsyncEvent(asyncContext);
// when
callback.onTimeout(event);
// then
verify(asyncContext, times(1)).getRequest();
verify(asyncContext, times(2)).getResponse();
verify(response, times(1)).setStatus(StatusCodes.REQUEST_TIMEOUT);
}
use of com.tvd12.ezyhttp.server.core.servlet.AsyncCallback in project ezyhttp by youngmonkeys.
the class AsyncCallbackTest method test.
@Test
public void test() throws Exception {
// given
AsyncCallback callback = event -> {
};
ServletRequest request = mock(ServletRequest.class);
AsyncContext asyncContext = mock(AsyncContext.class);
when(asyncContext.getRequest()).thenReturn(request);
AsyncEvent event = new AsyncEvent(asyncContext);
// when
// then
callback.onComplete(event);
callback.onError(event);
callback.onTimeout(event);
callback.onStartAsync(event);
}
use of com.tvd12.ezyhttp.server.core.servlet.AsyncCallback in project ezyhttp by youngmonkeys.
the class AsyncCallbackTest method onErrorWithHttpServletResponse.
@Test
public void onErrorWithHttpServletResponse() {
// given
AsyncCallback callback = event -> {
};
AsyncContext asyncContext = mock(AsyncContext.class);
ServletRequest request = mock(ServletRequest.class);
when(asyncContext.getRequest()).thenReturn(request);
HttpServletResponse response = mock(HttpServletResponse.class);
when(asyncContext.getResponse()).thenReturn(response);
AsyncEvent event = new AsyncEvent(asyncContext);
// when
callback.onError(event);
// then
verify(asyncContext, times(1)).getRequest();
verify(asyncContext, times(2)).getResponse();
verify(response, times(1)).setStatus(StatusCodes.INTERNAL_SERVER_ERROR);
}
Aggregations