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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations