use of com.tvd12.ezyhttp.client.request.DownloadRequest 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.request.DownloadRequest in project ezyhttp by youngmonkeys.
the class DownloadRequestTest method test.
@Test
public void test() throws Exception {
// given
String fileURL = "https://youngmonkeys.org";
int readTimeout = RandomUtil.randomInt();
int connectionTimeout = RandomUtil.randomInt();
DownloadRequest sut = new DownloadRequest();
MultiValueMap headers = MultiValueMap.builder().setValue("hello", "world").build();
sut.setFileURL(fileURL);
sut.setFileURL(new URL(fileURL));
sut.setFileURL(URI.create(fileURL));
sut.setReadTimeout(readTimeout);
sut.setConnectTimeout(connectionTimeout);
sut.setHeaders(headers);
// when
// then
Asserts.assertEquals(fileURL, sut.getFileURL());
Asserts.assertEquals(readTimeout, sut.getReadTimeout());
Asserts.assertEquals(connectionTimeout, sut.getConnectTimeout());
Asserts.assertEquals(headers, sut.getHeaders());
}
Aggregations