Search in sources :

Example 6 with PostRequest

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);
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) HttpClient(com.tvd12.ezyhttp.client.HttpClient) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 7 with PostRequest

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);
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) HttpClient(com.tvd12.ezyhttp.client.HttpClient) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with PostRequest

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);
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) HttpClient(com.tvd12.ezyhttp.client.HttpClient) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 9 with PostRequest

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);
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) User(org.youngmonkeys.example.ezyhttp.website.user_management.entity.User) HttpClient(com.tvd12.ezyhttp.client.HttpClient) PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) Request(com.tvd12.ezyhttp.client.request.Request) RequestEntity(com.tvd12.ezyhttp.client.request.RequestEntity)

Example 10 with PostRequest

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);
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) Customer(com.tvd12.ezyhttp.client.test.request.Customer) HttpClient(com.tvd12.ezyhttp.client.HttpClient) RequestEntity(com.tvd12.ezyhttp.client.request.RequestEntity)

Aggregations

PostRequest (com.tvd12.ezyhttp.client.request.PostRequest)22 BeforeTest (org.testng.annotations.BeforeTest)21 Test (org.testng.annotations.Test)21 HttpClient (com.tvd12.ezyhttp.client.HttpClient)20 HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)5 BaseTest (com.tvd12.test.base.BaseTest)5 RequestEntity (com.tvd12.ezyhttp.client.request.RequestEntity)3 BadRequestException (com.tvd12.ezyfox.exception.BadRequestException)2 ClientNotActiveException (com.tvd12.ezyhttp.client.exception.ClientNotActiveException)2 DownloadCancelledException (com.tvd12.ezyhttp.client.exception.DownloadCancelledException)2 RequestQueueFullException (com.tvd12.ezyhttp.client.exception.RequestQueueFullException)2 HelloRequest (com.tvd12.ezyhttp.client.test.request.HelloRequest)2 UnknownHostException (java.net.UnknownHostException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RequestCallback (com.tvd12.ezyhttp.client.callback.RequestCallback)1 DeleteRequest (com.tvd12.ezyhttp.client.request.DeleteRequest)1 GetRequest (com.tvd12.ezyhttp.client.request.GetRequest)1 Request (com.tvd12.ezyhttp.client.request.Request)1 Customer (com.tvd12.ezyhttp.client.test.request.Customer)1 ResponseEntity (com.tvd12.ezyhttp.core.response.ResponseEntity)1