use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientTest method postTest.
protected static void postTest() throws Exception {
HttpClient client = HttpClient.builder().build();
HelloRequest body = new HelloRequest();
body.setWho("dzung");
RequestEntity entity = RequestEntity.body(body);
PostRequest request = new PostRequest().setURL("http://localhost:8081/").setEntity(entity).setResponseType(String.class).setReadTimeout(HttpClient.NO_TIMEOUT).setConnectTimeout(HttpClient.NO_TIMEOUT);
String response = client.call(request);
System.out.println(response);
}
use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodTimeout.
@Test
public void postMethodTimeout() {
// 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/408"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpRequestTimeoutException.class);
}
use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodServerInternalError.
@Test
public void postMethodServerInternalError() {
// 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/500"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpInternalServerErrorException.class);
}
use of com.tvd12.ezyhttp.client.request.PostRequest in project ezyhttp by youngmonkeys.
the class HttpClientTest method callPostFormTest.
@Test
public void callPostFormTest() throws Exception {
// given
HttpClient sut = HttpClient.builder().build();
PostRequest request = new PostRequest().setConnectTimeout(-1).setReadTimeout(15000).setEntity(RequestEntity.builder().body(new TestRequest("Young Monkey")).contentType(ContentTypes.APPLICATION_X_WWW_FORM_URLENCODED).build()).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL(URI.create("http://127.0.0.1:18081/form"));
// when
TestResponse actual = sut.call(request);
// then
TestResponse expectation = new TestResponse("Greet Young Monkey!");
Asserts.assertEquals(expectation, actual);
}
use of com.tvd12.ezyhttp.client.request.PostRequest 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);
}
Aggregations