use of com.tvd12.ezyhttp.core.response.ResponseEntity in project ezyhttp by youngmonkeys.
the class HttpClientProxy method request.
public ResponseEntity request(Request request, int timeout) throws Exception {
EzyFuture future = new EzyFutureTask();
futures.addFuture(request, future);
try {
addRequest(request);
} catch (Exception e) {
futures.removeFuture(request);
throw e;
}
return future.get(timeout);
}
use of com.tvd12.ezyhttp.core.response.ResponseEntity in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method executeExceptionTest.
@Test
public void executeExceptionTest() 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.0:18081/greet");
// when
CountDownLatch countDownLatch = new CountDownLatch(1);
EzyWrap<Exception> wrap = new EzyWrap<>();
sut.execute(request, new RequestCallback<ResponseEntity>() {
@Override
public void onResponse(ResponseEntity response) {
System.out.println(response);
}
@Override
public void onException(Exception e) {
wrap.setValue(e);
countDownLatch.countDown();
}
});
countDownLatch.await();
// then
Asserts.assertEquals(UnknownHostException.class, wrap.getValue().getClass());
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.core.response.ResponseEntity in project ezyhttp by youngmonkeys.
the class ResponseEntityTest method createByStatusAndBody.
@Test
public void createByStatusAndBody() {
// given
int status = StatusCodes.ACCEPTED;
Object body = "Hello World";
// when
ResponseEntity sut = ResponseEntity.of(status, body).build();
// then
Asserts.assertEquals(status, sut.getStatus());
Asserts.assertEquals(body, sut.getBody());
}
use of com.tvd12.ezyhttp.core.response.ResponseEntity in project ezyhttp by youngmonkeys.
the class ResponseEntityTest method createByBadRequest.
@Test
public void createByBadRequest() {
// given
// when
ResponseEntity sut = ResponseEntity.badRequest();
// then
Asserts.assertEquals(StatusCodes.BAD_REQUEST, sut.getStatus());
}
use of com.tvd12.ezyhttp.core.response.ResponseEntity in project ezyhttp by youngmonkeys.
the class ResponseEntityTest method createByStatusHeadersAndBody.
@Test
public void createByStatusHeadersAndBody() {
// given
int status = StatusCodes.ACCEPTED;
Map<String, List<String>> headers = new HashMap<>();
headers.put("hello", Arrays.asList("world", "galaxy"));
headers.put("foo", Arrays.asList("bar", "animal"));
Object body = "Hello World";
// when
ResponseEntity sut = new ResponseEntity(status, headers, body);
// then
Asserts.assertEquals(status, sut.getStatus());
Asserts.assertEquals(new MultiValueMap(headers), sut.getHeaders());
Asserts.assertEquals("world", sut.getHeader("hello"));
Asserts.assertEquals(body, sut.getBody());
}
Aggregations