use of com.tvd12.ezyhttp.client.HttpClientProxy in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method downloadToFileByRequestTest.
@Test
public void downloadToFileByRequestTest() throws Exception {
// given
String fileUrl = "https://resources.tvd12.com/ezy-settings-1.0.0.xsd";
DownloadRequest request = new DownloadRequest().setFileURL(fileUrl).setConnectTimeout(5000).setReadTimeout(5000).setHeaders(MultiValueMap.builder().setValue("hello", "world").build());
HttpClientProxy sut = HttpClientProxy.builder().requestQueueCapacity(1).threadPoolSize(1).build();
// when
String fileName = sut.download(request, new File("test-output/no-commit"));
// then
Asserts.assertEquals(fileName, "ezy-settings-1.0.0.xsd");
Asserts.assertTrue(new File("test-output/no-commit/ezy-settings-1.0.0.xsd").exists());
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.HttpClientProxy in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method newClientProxy.
private HttpClientProxy newClientProxy() {
HttpClientProxy sut = HttpClientProxy.builder().autoStart(true).readTimeout(15000).connectTimeout(15000).setStringConverter(SingletonStringDeserializer.getInstance()).addBodyConverter(new TestBodyConverter()).addBodyConverters(Collections.singletonList(new TestBodyConverter())).addBodyConverter("world", new TestBodyConverter()).addBodyConverters(Collections.singletonMap("foo", new TestBodyConverter())).threadPoolSize(1).requestQueueCapacity(10).build();
EzyProcessor.processWithLogException(sut::start);
return sut;
}
use of com.tvd12.ezyhttp.client.HttpClientProxy in project ezyfox-examples by tvd12.
the class ApiGetUserTest method main.
public static void main(String[] args) throws Exception {
HttpClientProxy httpClient = HttpClientProxy.builder().build();
httpClient.start();
RequestEntity entity = RequestEntity.builder().build();
Request helloRequest = new GetRequest().setURL(API_URL + "tvd12").setEntity(entity).setResponseType(String.class).setResponseType(StatusCodes.NOT_FOUND, String.class);
String response = httpClient.call(helloRequest, 10000);
System.out.println("get user response: " + response);
}
use of com.tvd12.ezyhttp.client.HttpClientProxy in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method postWithExceptionTest.
@Test
public void postWithExceptionTest() {
// given
HttpClientProxy sut = newClientProxy();
PostRequest request = new PostRequest().setConnectTimeout(15000).setEntity(boolean.class).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL("http://127.0.0.1.0:18081/greet");
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request, 150000));
// then
Asserts.assertThat(e).isEqualsType(UnknownHostException.class);
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.HttpClientProxy in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method fireExceptionTest.
@Test
public void fireExceptionTest() throws Exception {
// given
HttpClientProxy sut = newClientProxy();
GetRequest request = new GetRequest().setConnectTimeout(15000).setResponseType(String.class).setResponseType(StatusCodes.OK, String.class).setURL("http://unknow-host:18081/greet");
// when
CountDownLatch countDownLatch = new CountDownLatch(1);
EzyWrap<Exception> wrap = new EzyWrap<>();
sut.fire(request, new RequestCallback<String>() {
@Override
public void onResponse(String response) {
}
@Override
public void onException(Exception e) {
wrap.setValue(e);
countDownLatch.countDown();
}
});
countDownLatch.await();
// then
Asserts.assertEquals(BadRequestException.class, wrap.getValue().getClass());
sut.close();
sut.stop();
}
Aggregations