use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class CustomerApisTest method addCustomerTest.
protected static void addCustomerTest() throws Exception {
HttpClient client = HttpClient.builder().build();
Customer body = new Customer();
body.setName("dung");
body.setAge(28);
RequestEntity entity = RequestEntity.of(body).header("token", "123").build();
PostRequest request = new PostRequest().setURL("http://localhost:8081/api/v1/customer/add").setEntity(entity).setResponseType(String.class).setReadTimeout(HttpClient.NO_TIMEOUT).setConnectTimeout(HttpClient.NO_TIMEOUT);
String response = client.call(request);
System.out.println(response);
}
use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method postTest.
protected static void postTest() throws Exception {
HttpClient client = HttpClient.builder().build();
HelloRequest body = new HelloRequest();
body.setWho("dzung");
RequestEntity entity = RequestEntity.body(body);
PostRequest request = new PostRequest().setURL("http://localhost:8081/").setEntity(entity).setResponseType(String.class).setReadTimeout(HttpClient.NO_TIMEOUT).setConnectTimeout(HttpClient.NO_TIMEOUT);
String response = client.call(request);
System.out.println(response);
}
use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodTimeout.
@Test
public void postMethodTimeout() {
// given
HttpClient sut = HttpClient.builder().build();
PostRequest request = new PostRequest().setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL(URI.create("http://127.0.0.1:18081/408"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpRequestTimeoutException.class);
}
use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodServerInternalError.
@Test
public void postMethodServerInternalError() {
// given
HttpClient sut = HttpClient.builder().build();
PostRequest request = new PostRequest().setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL(URI.create("http://127.0.0.1:18081/500"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpInternalServerErrorException.class);
}
use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method processDownloadErrorInputStreamIsNull.
@Test
public void processDownloadErrorInputStreamIsNull() {
// given
HttpClient sut = HttpClient.builder().build();
HttpURLConnection connection = mock(HttpURLConnection.class);
// when
Exception e = MethodInvoker.create().object(sut).method("processDownloadError").param(HttpURLConnection.class, connection).param(String.class, "https://example.com/file.jpg").param(int.class, 404).call();
// then
Asserts.assertEqualsType(e, HttpNotFoundException.class);
verify(connection, times(1)).getErrorStream();
}
Aggregations