use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method downloadToOutputStreamByRequestTest.
@Test
public void downloadToOutputStreamByRequestTest() 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();
File outFile = new File("test-output/no-commit/download-test.xml");
EzyFileUtil.createFileIfNotExists(outFile);
OutputStream outputStream = new FileOutputStream(outFile);
// when
sut.download(request, outputStream);
// then
Asserts.assertTrue(new File("test-output/no-commit/download-test.xml").exists());
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodNotAllow.
@Test
public void postMethodNotAllow() {
// given
HttpClient sut = HttpClient.builder().build();
PostRequest request = new PostRequest().setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL(URI.create("http://127.0.0.1:18081/405"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpMethodNotAllowedException.class);
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodNotFound.
@Test
public void postMethodNotFound() {
// given
HttpClient sut = HttpClient.builder().build();
PostRequest request = new PostRequest().setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL(URI.create("http://127.0.0.1:18081/404"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpNotFoundException.class);
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class HttpClientTest method postMethodConflict.
@Test
public void postMethodConflict() {
// given
HttpClient sut = HttpClient.builder().build();
PostRequest request = new PostRequest().setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL(URI.create("http://127.0.0.1:18081/409"));
// when
Throwable e = Asserts.assertThrows(() -> sut.call(request));
// then
Asserts.assertThat(e).isEqualsType(HttpConflictException.class);
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class HttpClientTest method getTest.
protected static void getTest() throws Exception {
HttpClient client = HttpClient.builder().build();
GetRequest request = new GetRequest().setURL("http://localhost:8081/bye?messages=a,b,c&numbers=1,2,3").setEntity(null).setResponseType(String.class).setReadTimeout(HttpClient.NO_TIMEOUT).setConnectTimeout(HttpClient.NO_TIMEOUT);
String response = client.call(request);
System.out.println(response);
}
Aggregations