use of com.tvd12.ezyhttp.client.HttpClientProxy in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method downloadToFileWithCancellationTokenTest.
@Test
public void downloadToFileWithCancellationTokenTest() throws Exception {
// given
String fileUrl = "https://resources.tvd12.com/ezy-settings-1.0.0.xsd";
HttpClientProxy sut = HttpClientProxy.builder().requestQueueCapacity(1).threadPoolSize(1).build();
// when
String fileName = sut.download(fileUrl, 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 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.HttpClientProxy in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method downloadToOutputStreamButCancelTest.
@Test
public void downloadToOutputStreamButCancelTest() 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);
DownloadCancellationToken cancelledException = new DownloadCancellationToken();
cancelledException.cancel();
// when
Throwable e = Asserts.assertThrows(() -> sut.download(fileUrl, outputStream, cancelledException));
// 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 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.HttpClientProxy 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