Search in sources :

Example 6 with DownloadRequest

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();
}
Also used : DownloadCancellationToken(com.tvd12.ezyhttp.client.concurrent.DownloadCancellationToken) HttpClientProxy(com.tvd12.ezyhttp.client.HttpClientProxy) File(java.io.File) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) BaseTest(com.tvd12.test.base.BaseTest)

Example 7 with DownloadRequest

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());
}
Also used : DownloadRequest(com.tvd12.ezyhttp.client.request.DownloadRequest) MultiValueMap(com.tvd12.ezyhttp.core.data.MultiValueMap) URL(java.net.URL) Test(org.testng.annotations.Test)

Aggregations

HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)5 File (java.io.File)5 Test (org.testng.annotations.Test)5 BaseTest (com.tvd12.test.base.BaseTest)4 BeforeTest (org.testng.annotations.BeforeTest)4 DownloadCancellationToken (com.tvd12.ezyhttp.client.concurrent.DownloadCancellationToken)2 DownloadRequest (com.tvd12.ezyhttp.client.request.DownloadRequest)2 MultiValueMap (com.tvd12.ezyhttp.core.data.MultiValueMap)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 URL (java.net.URL)1