Search in sources :

Example 11 with HttpClient

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);
}
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 12 with HttpClient

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);
}
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 13 with HttpClient

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);
}
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 14 with HttpClient

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);
}
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 15 with HttpClient

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);
}
Also used : GetRequest(com.tvd12.ezyhttp.client.request.GetRequest) GetRequest(com.tvd12.ezyhttp.client.request.GetRequest) Request(com.tvd12.ezyhttp.client.request.Request) HttpClientProxy(com.tvd12.ezyhttp.client.HttpClientProxy) RequestEntity(com.tvd12.ezyhttp.client.request.RequestEntity)

Aggregations

HttpClient (com.tvd12.ezyhttp.client.HttpClient)31 BeforeTest (org.testng.annotations.BeforeTest)25 Test (org.testng.annotations.Test)25 PostRequest (com.tvd12.ezyhttp.client.request.PostRequest)20 RequestEntity (com.tvd12.ezyhttp.client.request.RequestEntity)5 GetRequest (com.tvd12.ezyhttp.client.request.GetRequest)4 BodyDeserializer (com.tvd12.ezyhttp.core.codec.BodyDeserializer)3 InputStream (java.io.InputStream)3 Request (com.tvd12.ezyhttp.client.request.Request)2 IOException (java.io.IOException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)1 DeleteRequest (com.tvd12.ezyhttp.client.request.DeleteRequest)1 Customer (com.tvd12.ezyhttp.client.test.request.Customer)1 HelloRequest (com.tvd12.ezyhttp.client.test.request.HelloRequest)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 HashMap (java.util.HashMap)1 List (java.util.List)1