use of com.tvd12.ezyhttp.client.HttpClient 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.HttpClient 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.HttpClient 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.HttpClient 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.HttpClient in project ezyfox-examples by tvd12.
the class ApiGetUserTest method main.
public static void main(String[] args) throws Exception {
HttpClientProxy httpClient = HttpClientProxy.builder().build();
httpClient.start();
RequestEntity entity = RequestEntity.builder().build();
Request helloRequest = new GetRequest().setURL(API_URL + "tvd12").setEntity(entity).setResponseType(String.class).setResponseType(StatusCodes.NOT_FOUND, String.class);
String response = httpClient.call(helloRequest, 10000);
System.out.println("get user response: " + response);
}
Aggregations