Search in sources :

Example 16 with GetRequest

use of com.tvd12.ezyhttp.client.request.GetRequest in project ezyhttp by youngmonkeys.

the class HttpClientProxyTest method handleRequestsNoFutureWhenResponse.

@Test
public void handleRequestsNoFutureWhenResponse() throws Exception {
    // given
    HttpClientProxy sut = newClientProxy();
    RequestQueue queue = FieldUtil.getFieldValue(sut, "requestQueue");
    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
    queue.add(request);
    Thread.sleep(100);
    // then
    sut.close();
}
Also used : HttpClientProxy(com.tvd12.ezyhttp.client.HttpClientProxy) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) BaseTest(com.tvd12.test.base.BaseTest)

Example 17 with GetRequest

use of com.tvd12.ezyhttp.client.request.GetRequest in project ezyhttp by youngmonkeys.

the class HttpClientProxyTest method executeExceptionTest.

@Test
public void executeExceptionTest() 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.0:18081/greet");
    // when
    CountDownLatch countDownLatch = new CountDownLatch(1);
    EzyWrap<Exception> wrap = new EzyWrap<>();
    sut.execute(request, new RequestCallback<ResponseEntity>() {

        @Override
        public void onResponse(ResponseEntity response) {
            System.out.println(response);
        }

        @Override
        public void onException(Exception e) {
            wrap.setValue(e);
            countDownLatch.countDown();
        }
    });
    countDownLatch.await();
    // then
    Asserts.assertEquals(UnknownHostException.class, wrap.getValue().getClass());
    sut.close();
    sut.stop();
}
Also used : EzyWrap(com.tvd12.ezyfox.util.EzyWrap) ResponseEntity(com.tvd12.ezyhttp.core.response.ResponseEntity) HttpClientProxy(com.tvd12.ezyhttp.client.HttpClientProxy) CountDownLatch(java.util.concurrent.CountDownLatch) DownloadCancelledException(com.tvd12.ezyhttp.client.exception.DownloadCancelledException) RequestQueueFullException(com.tvd12.ezyhttp.client.exception.RequestQueueFullException) UnknownHostException(java.net.UnknownHostException) BadRequestException(com.tvd12.ezyfox.exception.BadRequestException) ClientNotActiveException(com.tvd12.ezyhttp.client.exception.ClientNotActiveException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) BaseTest(com.tvd12.test.base.BaseTest)

Example 18 with GetRequest

use of com.tvd12.ezyhttp.client.request.GetRequest in project ezyhttp by youngmonkeys.

the class V018HttpClientTest method main.

public static void main(String[] args) throws Exception {
    HttpClient client = HttpClient.builder().build();
    PostRequest loveRequest = new PostRequest().setURL("http://localhost:8083/love");
    System.out.println(client.request(loveRequest));
    DeleteRequest deleteRequest = new DeleteRequest().setURL("http://localhost:8083/api/v1/customer/delete").setEntity(RequestEntity.builder().header("token", "123456").build());
    System.out.println(client.request(deleteRequest));
    System.out.println(client.request(deleteRequest).getBody().toString());
    GetRequest textRequest = new GetRequest().setURL("http://localhost:8083/text");
    System.out.println((String) client.call(textRequest));
    GetRequest listRequest = new GetRequest().setResponseType(List.class).setURL("http://localhost:8083/list");
    System.out.println(client.call(listRequest).toString());
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) HttpClient(com.tvd12.ezyhttp.client.HttpClient) GetRequest(com.tvd12.ezyhttp.client.request.GetRequest) List(java.util.List) DeleteRequest(com.tvd12.ezyhttp.client.request.DeleteRequest)

Aggregations

Test (org.testng.annotations.Test)14 HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)8 BaseTest (com.tvd12.test.base.BaseTest)7 AsyncContext (javax.servlet.AsyncContext)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 BeforeTest (org.testng.annotations.BeforeTest)7 BadRequestException (com.tvd12.ezyfox.exception.BadRequestException)5 EzyWrap (com.tvd12.ezyfox.util.EzyWrap)5 ClientNotActiveException (com.tvd12.ezyhttp.client.exception.ClientNotActiveException)5 DownloadCancelledException (com.tvd12.ezyhttp.client.exception.DownloadCancelledException)5 RequestQueueFullException (com.tvd12.ezyhttp.client.exception.RequestQueueFullException)5 UnknownHostException (java.net.UnknownHostException)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 GetRequest (com.tvd12.ezyhttp.client.request.GetRequest)4 StatusCodes (com.tvd12.ezyhttp.core.constant.StatusCodes)4 AsyncCallback (com.tvd12.ezyhttp.server.core.servlet.AsyncCallback)4 AsyncEvent (javax.servlet.AsyncEvent)4 ServletRequest (javax.servlet.ServletRequest)4 Mockito (org.mockito.Mockito)4 EzyExceptionVoid (com.tvd12.ezyfox.function.EzyExceptionVoid)3