use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method downloadToOutputStreamNotFoundTest.
@Test
public void downloadToOutputStreamNotFoundTest() {
// given
String fileUrl = "https://resources.tvd12.com/ezy-settings-1.0.0.xsd/not-found-here";
HttpClient sut = HttpClient.builder().build();
OutputStream outputStream = mock(OutputStream.class);
// when
Throwable e = Asserts.assertThrows(() -> sut.download(fileUrl, outputStream));
// then
Asserts.assertEqualsType(e, HttpNotFoundException.class);
}
use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method getDownloadFileNameWithEmptyDispositionTest.
@Test
public void getDownloadFileNameWithEmptyDispositionTest() {
// given
HttpClient sut = HttpClient.builder().build();
String contentDisposition = "";
// when
String actual = MethodInvoker.create().object(sut).method("getDownloadFileName").param("https://example.com/file.jpg").param(contentDisposition).call();
// then
Asserts.assertEquals(actual, "file.jpg");
}
use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method callPostFormTest.
@Test
public void callPostFormTest() throws Exception {
// given
HttpClient sut = HttpClient.builder().build();
PostRequest request = new PostRequest().setConnectTimeout(-1).setReadTimeout(15000).setEntity(RequestEntity.builder().body(new TestRequest("Young Monkey")).contentType(ContentTypes.APPLICATION_X_WWW_FORM_URLENCODED).build()).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL(URI.create("http://127.0.0.1:18081/form"));
// when
TestResponse actual = sut.call(request);
// then
TestResponse expectation = new TestResponse("Greet Young Monkey!");
Asserts.assertEquals(expectation, actual);
}
use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method getDownloadFileNameTest.
@Test
public void getDownloadFileNameTest() {
// given
HttpClient sut = HttpClient.builder().build();
String contentDisposition = "Content-Disposition: attachment; filename=\"filename.jpg\"";
// when
String actual = MethodInvoker.create().object(sut).method("getDownloadFileName").param("fileUrl").param(contentDisposition).call();
// then
Asserts.assertEquals(actual, "filename.jpg");
}
use of com.tvd12.ezyhttp.client.HttpClient in project ezyhttp by youngmonkeys.
the class HttpClientTest method tryDeserializeResponseBodyStringNull.
@Test
public void tryDeserializeResponseBodyStringNull() {
// given
String contentType = RandomUtil.randomShortAlphabetString();
int contentLength = RandomUtil.randomSmallInt();
InputStream inputStream = mock(InputStream.class);
BodyDeserializer deserializer = mock(BodyDeserializer.class);
HttpClient sut = HttpClient.builder().addBodyConverter(contentType, deserializer).build();
// when
Map<String, String> actual = MethodInvoker.create().object(sut).method("deserializeResponseBody").param(String.class, contentType).param(int.class, contentLength).param(InputStream.class, inputStream).param(Class.class, null).call();
// then
Asserts.assertNull(actual);
}
Aggregations