use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodConflict.
@Test
public void postMethodConflict() {
// 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/409"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpConflictException.class);
}
use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method getTest.
protected static void getTest() throws Exception {
HttpClient client = HttpClient.builder().build();
GetRequest request = new GetRequest().setURL("http://localhost:8081/bye?messages=a,b,c&numbers=1,2,3").setEntity(null).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 httpClientBuilderTest.
@Test
public void httpClientBuilderTest() {
// given
int readTimeout = RandomUtil.randomInt();
int connectionTimeout = RandomUtil.randomInt();
Object stringConverter = SingletonStringDeserializer.getInstance();
Object bodyConverter = new MyTextBodyConverter();
HttpClient.Builder clientBuilder = HttpClient.builder().readTimeout(readTimeout).connectTimeout(connectionTimeout).setStringConverter(stringConverter).addBodyConverter(bodyConverter).addBodyConverters(Collections.singletonList(bodyConverter)).addBodyConverters(Collections.singletonMap(ContentTypes.APPLICATION_JSON, bodyConverter));
// when
HttpClient client = clientBuilder.build();
// then
Asserts.assertEquals(FieldUtil.getFieldValue(client, "defaultReadTimeout"), readTimeout);
Asserts.assertEquals(FieldUtil.getFieldValue(client, "defaultConnectTimeout"), connectionTimeout);
}
use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodServer501.
@Test
public void postMethodServer501() {
// 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/501"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpRequestException.class);
}
use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class CustomerApisTest method getCustomerTest.
protected static void getCustomerTest() throws Exception {
HttpClient client = HttpClient.builder().build();
RequestEntity entity = RequestEntity.builder().header("token", "123").build();
GetRequest request = new GetRequest().setURL("http://localhost:8081/api/v1/customer/hello/dung").setEntity(entity).setResponseType(String.class).setReadTimeout(HttpClient.NO_TIMEOUT).setConnectTimeout(HttpClient.NO_TIMEOUT);
String response = client.call(request);
System.out.println(response);
}
Aggregations