use of com.tvd12.ezyhttp.client.request.GetRequest in project ezyhttp by youngmonkeys.
the class HttpClientProxyTest method executeJsonTest.
@Test
public void executeJsonTest() 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.execute(request, new RequestCallback<ResponseEntity>() {
@Override
public void onResponse(ResponseEntity response) {
wrap.setValue(response.getBody());
countDownLatch.countDown();
}
@Override
public void onException(Exception e) {
}
});
countDownLatch.await();
// then
TestResponse expectation = new TestResponse("Greet Monkey!");
Asserts.assertEquals(expectation, wrap.getValue());
sut.close();
sut.stop();
}
use of com.tvd12.ezyhttp.client.request.GetRequest 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);
}
use of com.tvd12.ezyhttp.client.request.GetRequest in project ezyhttp by youngmonkeys.
the class CustomerApisTest method getCustomerTest.
protected static void getCustomerTest() throws Exception {
HttpClient client = HttpClient.builder().build();
RequestEntity entity = RequestEntity.builder().header("token", "123").build();
GetRequest request = new GetRequest().setURL("http://localhost:8081/api/v1/customer/hello/dung").setEntity(entity).setResponseType(String.class).setReadTimeout(HttpClient.NO_TIMEOUT).setConnectTimeout(HttpClient.NO_TIMEOUT);
String response = client.call(request);
System.out.println(response);
}
use of com.tvd12.ezyhttp.client.request.GetRequest 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();
}
use of com.tvd12.ezyhttp.client.request.GetRequest in project ezyhttp by youngmonkeys.
the class FileUploaderTest method acceptFirstMaxUploadSizeException.
@SuppressWarnings("unchecked")
@Test
public void acceptFirstMaxUploadSizeException() throws Exception {
// given
AsyncContext asyncContext = mock(AsyncContext.class);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getRequestURI()).thenReturn("hello-world");
when(asyncContext.getRequest()).thenReturn(request);
HttpServletResponse response = mock(HttpServletResponse.class);
when(asyncContext.getResponse()).thenReturn(response);
ServletOutputStream outputStream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(outputStream);
Part part = mock(Part.class);
File outputFile = new File("test-output/files");
EzyExceptionVoid callback = mock(EzyExceptionVoid.class);
doThrow(new MaxUploadSizeException(100)).when(callback).apply();
ResourceUploadManager resourceUploadManager = mock(ResourceUploadManager.class);
doAnswer(it -> {
EzyResultCallback<Boolean> cb = it.getArgumentAt(3, EzyResultCallback.class);
cb.onResponse(Boolean.TRUE);
return null;
}).when(resourceUploadManager).drainAsync(any(), any(), any(long.class), any());
FileUploader sut = new FileUploader(resourceUploadManager);
// when
sut.accept(asyncContext, part, outputFile, callback);
// then
verify(callback, times(1)).apply();
verify(resourceUploadManager, times(1)).drainAsync(any(), any(), any(long.class), any());
verify(response, times(1)).setStatus(StatusCodes.BAD_REQUEST);
verify(response, times(1)).getOutputStream();
verify(outputStream, times(1)).write(any(byte[].class));
verify(request, times(1)).getRequestURI();
verify(asyncContext, times(1)).getRequest();
verify(asyncContext, times(1)).complete();
}
Aggregations