use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodPaymentRequired.
@Test
public void postMethodPaymentRequired() {
// 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/402"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpPaymentRequiredException.class);
}
use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientTest method postWithNoBody.
@Test
public void postWithNoBody() {
// 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/form"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpBadRequestException.class);
}
use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodNotAcceptable.
@Test
public void postMethodNotAcceptable() {
// 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/406"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpNotAcceptableException.class);
}
use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyfox-examples by tvd12.
the class ApiAddUserTest method main.
public static void main(String[] args) throws Exception {
HttpClient httpClient = HttpClient.builder().build();
User body = new User();
body.setUsername("tvd12");
body.setPassword("123456");
RequestEntity requestEntity = RequestEntity.body(body);
Request request = new PostRequest().setURL(API_URL + "add").setEntity(requestEntity).setResponseType(Boolean.class).setResponseType(StatusCodes.CONFLICT, String.class);
Boolean response = httpClient.call(request);
System.out.println("add user reponse: " + response);
}
use of com.tvd12.ezyhttp.client.request.PostRequest 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);
}
Aggregations