use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method callTest.
@Test
public void callTest() throws Exception {
// given
HttpClient sut = HttpClient.builder().objectMapper(new Object()).objectMapper(new ObjectMapper()).build();
PostRequest request = new PostRequest().setConnectTimeout(-1).setReadTimeout(15000).setEntity(RequestEntity.builder().body(new TestRequest("Monkey")).header("hello", "world").header("foo", "bar").build()).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL(URI.create("http://127.0.0.1:18081/greet"));
// when
TestResponse actual = sut.call(request);
// then
TestResponse expectation = new TestResponse("Greet Monkey!");
Asserts.assertEquals(expectation, actual);
}
use of com.tvd12.ezyhttp.client.HttpClient 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.HttpClient 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.HttpClient 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.HttpClient 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);
}
Aggregations