Search in sources :

Example 21 with PostRequest

use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.

the class HttpClientTest method postMethodForbidden.

@Test
public void postMethodForbidden() {
    // 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/403"));
    // when
    Throwable e = Asserts.assertThrows(() -> sut.call(request));
    // then
    Asserts.assertThat(e).isEqualsType(HttpForbiddenException.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 22 with PostRequest

use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.

the class HttpClientTest method deserializeResponseBodyString.

@Test
public void deserializeResponseBodyString() throws Exception {
    // given
    HttpClient sut = HttpClient.builder().build();
    PostRequest request = new PostRequest().setResponseType(TestResponse.class).setEntity(RequestEntity.builder().body(new TestRequest("Monkey")).build()).setResponseType(StatusCodes.OK, String.class).setURL(URI.create("http://127.0.0.1:18081/greet"));
    // when
    String actual = sut.call(request);
    // then
    String expectation = "{\"message\":\"Greet Monkey!\"}";
    Asserts.assertEquals(expectation, actual);
}
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 23 with PostRequest

use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.

the class HttpClientTest method postMethodUnsupportedMediaType.

@Test
public void postMethodUnsupportedMediaType() {
    // 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/415"));
    // when
    Throwable e = Asserts.assertThrows(() -> sut.call(request));
    // then
    Asserts.assertThat(e).isEqualsType(HttpUnsupportedMediaTypeException.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 24 with PostRequest

use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.

the class HttpClientTest method postMethodTooManyRequests.

@Test
public void postMethodTooManyRequests() {
    // 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/429"));
    // when
    Throwable e = Asserts.assertThrows(() -> sut.call(request));
    // then
    Asserts.assertThat(e).isEqualsType(HttpTooManyRequestsException.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 25 with PostRequest

use of com.tvd12.ezyhttp.client.request.PostRequest 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)

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