use of com.tvd12.ezyhttp.client.HttpClientProxy in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method fireJsonTest.
@Test
public void fireJsonTest() 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();
}
@Override
public void onException(Exception e) {
}
});
countDownLatch.await();
// then
TestResponse expectation = new TestResponse("Greet Monkey!");
Asserts.assertEquals(expectation, wrap.getValue());
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.HttpClientProxy in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method downloadToFileButCancelTest.
@Test
public void downloadToFileButCancelTest() {
// given
String fileUrl = "https://resources.tvd12.com/ezy-settings-1.0.0.xsd";
HttpClientProxy sut = HttpClientProxy.builder().requestQueueCapacity(1).threadPoolSize(1).build();
// when
DownloadCancellationToken cancellationToken = new DownloadCancellationToken();
cancellationToken.cancel();
Throwable e = Asserts.assertThrows(() -> sut.download(fileUrl, new File("test-output/no-commit"), cancellationToken));
// then
Asserts.assertEqualsType(e, DownloadCancelledException.class);
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.HttpClientProxy in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method postTest.
protected static void postTest(HttpClientProxy client) throws Exception {
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, 1000);
System.out.println(response);
}
use of com.tvd12.ezyhttp.client.HttpClientProxy in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method downloadToFileByRequestWithCancellationTokenTest.
@Test
public void downloadToFileByRequestWithCancellationTokenTest() 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"), new DownloadCancellationToken());
// 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 downloadToOutputStreamWithCancellationTokenTest.
@Test
public void downloadToOutputStreamWithCancellationTokenTest() throws Exception {
// given
String fileUrl = "https://resources.tvd12.com/ezy-settings-1.0.0.xsd";
HttpClientProxy sut = HttpClientProxy.builder().requestQueueCapacity(1).threadPoolSize(1).build();
File outFile = new File("test-output/no-commit/download-test.xml");
EzyFileUtil.createFileIfNotExists(outFile);
OutputStream outputStream = new FileOutputStream(outFile);
// when
sut.download(fileUrl, outputStream, new DownloadCancellationToken());
// then
Asserts.assertTrue(new File("test-output/no-commit/download-test.xml").exists());
sut.close();
sut.stop();
}
Aggregations