use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodServer501.
@Test
public void postMethodServer501() {
// 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/501"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpRequestException.class);
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class CustomerApisTest method getCustomerTest.
protected static void getCustomerTest() throws Exception {
HttpClient client = HttpClient.builder().build();
RequestEntity entity = RequestEntity.builder().header("token", "123").build();
GetRequest request = new GetRequest().setURL("http://localhost:8081/api/v1/customer/hello/dung").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.Request in project ezyhttp by youngmonkeys.
the class DownloadWithTokenTest method main.
public static void main(String[] args) throws Exception {
// given
String fileUrl = "http://localhost:8083/api/v1/files/ansible.jpg";
DownloadRequest request = new DownloadRequest().setFileURL(fileUrl).setConnectTimeout(5000).setReadTimeout(5000).setHeaders(MultiValueMap.builder().setValue("token", "").build());
HttpClientProxy sut = HttpClientProxy.builder().requestQueueCapacity(1).threadPoolSize(1).build();
// when
String fileName = sut.download(request, new File("test-output/no-commit"));
System.out.println(fileName);
// then
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method putJsonTest.
@Test
public void putJsonTest() throws Exception {
// given
HttpClientProxy sut = newClientProxy();
PutRequest request = new PutRequest().setConnectTimeout(15000).setEntity(new TestRequest("Monkey")).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL("http://127.0.0.1:18081/greet").setURL(new URL("http://127.0.0.1:18081/greet")).setURL(URI.create("http://127.0.0.1:18081/greet"));
// when
TestResponse actual = sut.call(request, 15000);
// then
TestResponse expectation = new TestResponse("Greet Monkey!");
Asserts.assertEquals(expectation, actual);
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method fireJsonButExceptionInCallbackTest.
@Test
public void fireJsonButExceptionInCallbackTest() throws Exception {
// given
HttpClientProxy sut = newClientProxy();
GetRequest request = new GetRequest().setConnectTimeout(15000).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL("http://127.0.0.1:18081/greet?who=Monkey");
// when
CountDownLatch countDownLatch = new CountDownLatch(1);
EzyWrap<TestResponse> wrap = new EzyWrap<>();
sut.fire(request, new RequestCallback<TestResponse>() {
@Override
public void onResponse(TestResponse response) {
wrap.setValue(response);
countDownLatch.countDown();
throw new RuntimeException("just test");
}
@Override
public void onException(Exception e) {
}
});
countDownLatch.await();
Thread.sleep(100);
// then
TestResponse expectation = new TestResponse("Greet Monkey!");
Asserts.assertEquals(expectation, wrap.getValue());
sut.close();
sut.stop();
}
Aggregations