Search in sources :

Example 31 with HttpClient

use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.

the class HttpClientTest method postMethodUnauthorized.

@Test
public void postMethodUnauthorized() {
    // 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/401"));
    // when
    Throwable e = Asserts.assertThrows(() -> sut.call(request));
    // then
    Asserts.assertThat(e).isEqualsType(HttpUnauthorizedException.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 32 with HttpClient

use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.

the class V018HttpClientTest method main.

public static void main(String[] args) throws Exception {
    HttpClient client = HttpClient.builder().build();
    PostRequest loveRequest = new PostRequest().setURL("http://localhost:8083/love");
    System.out.println(client.request(loveRequest));
    DeleteRequest deleteRequest = new DeleteRequest().setURL("http://localhost:8083/api/v1/customer/delete").setEntity(RequestEntity.builder().header("token", "123456").build());
    System.out.println(client.request(deleteRequest));
    System.out.println(client.request(deleteRequest).getBody().toString());
    GetRequest textRequest = new GetRequest().setURL("http://localhost:8083/text");
    System.out.println((String) client.call(textRequest));
    GetRequest listRequest = new GetRequest().setResponseType(List.class).setURL("http://localhost:8083/list");
    System.out.println(client.call(listRequest).toString());
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) HttpClient(com.tvd12.ezyhttp.client.HttpClient) GetRequest(com.tvd12.ezyhttp.client.request.GetRequest) List(java.util.List) DeleteRequest(com.tvd12.ezyhttp.client.request.DeleteRequest)

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