use of com.tvd12.ezyhttp.client.request.GetRequest 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.client.request.GetRequest 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);
}
use of com.tvd12.ezyhttp.client.request.GetRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method fireExceptionTest.
@Test
public void fireExceptionTest() throws Exception {
// given
HttpClientProxy sut = newClientProxy();
GetRequest request = new GetRequest().setConnectTimeout(15000).setResponseType(String.class).setResponseType(StatusCodes.OK, String.class).setURL("http://unknow-host:18081/greet");
// when
CountDownLatch countDownLatch = new CountDownLatch(1);
EzyWrap<Exception> wrap = new EzyWrap<>();
sut.fire(request, new RequestCallback<String>() {
@Override
public void onResponse(String response) {
}
@Override
public void onException(Exception e) {
wrap.setValue(e);
countDownLatch.countDown();
}
});
countDownLatch.await();
// then
Asserts.assertEquals(BadRequestException.class, wrap.getValue().getClass());
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.GetRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method getJsonTest.
@Test
public void getJsonTest() throws Exception {
// given
HttpClientProxy sut = newClientProxy();
GetRequest request = new GetRequest().setConnectTimeout(15000).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL("http://127.0.0.1:18081/greet?who=Monkey").setURL(new URL("http://127.0.0.1:18081/greet?who=Monkey")).setURL(URI.create("http://127.0.0.1:18081/greet?who=Monkey"));
// when
TestResponse actual = sut.call(request, 15000);
// then
TestResponse expectation = new TestResponse("Greet Monkey!");
Asserts.assertEquals(expectation, actual);
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.GetRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method fireJsonTest.
@Test
public void fireJsonTest() throws Exception {
// given
HttpClientProxy sut = newClientProxy();
GetRequest request = new GetRequest().setConnectTimeout(15000).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL("http://127.0.0.1:18081/greet?who=Monkey");
// when
CountDownLatch countDownLatch = new CountDownLatch(1);
EzyWrap<TestResponse> wrap = new EzyWrap<>();
sut.fire(request, new RequestCallback<TestResponse>() {
@Override
public void onResponse(TestResponse response) {
wrap.setValue(response);
countDownLatch.countDown();
}
@Override
public void onException(Exception e) {
}
});
countDownLatch.await();
// then
TestResponse expectation = new TestResponse("Greet Monkey!");
Asserts.assertEquals(expectation, wrap.getValue());
sut.close();
sut.stop();
}
Aggregations