Search in sources :

Example 56 with Request

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

the class HttpClientTest method postMethodServer501.

@Test
public void postMethodServer501() {
    // 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/501"));
    // when
    Throwable e = Asserts.assertThrows(() -> sut.call(request));
    // then
    Asserts.assertThat(e).isEqualsType(HttpRequestException.class);
}
Also used : PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) HttpClient(com.tvd12.ezyhttp.client.HttpClient) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 57 with Request

use of com.tvd12.ezyhttp.client.request.Request 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);
}
Also used : HttpClient(com.tvd12.ezyhttp.client.HttpClient) GetRequest(com.tvd12.ezyhttp.client.request.GetRequest) RequestEntity(com.tvd12.ezyhttp.client.request.RequestEntity)

Example 58 with Request

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

the class DownloadWithTokenTest method main.

public static void main(String[] args) throws Exception {
    // given
    String fileUrl = "http://localhost:8083/api/v1/files/ansible.jpg";
    DownloadRequest request = new DownloadRequest().setFileURL(fileUrl).setConnectTimeout(5000).setReadTimeout(5000).setHeaders(MultiValueMap.builder().setValue("token", "").build());
    HttpClientProxy sut = HttpClientProxy.builder().requestQueueCapacity(1).threadPoolSize(1).build();
    // when
    String fileName = sut.download(request, new File("test-output/no-commit"));
    System.out.println(fileName);
    // then
    sut.close();
    sut.stop();
}
Also used : DownloadRequest(com.tvd12.ezyhttp.client.request.DownloadRequest) HttpClientProxy(com.tvd12.ezyhttp.client.HttpClientProxy) File(java.io.File)

Example 59 with Request

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

the class HttpClientProxyTest method putJsonTest.

@Test
public void putJsonTest() throws Exception {
    // given
    HttpClientProxy sut = newClientProxy();
    PutRequest request = new PutRequest().setConnectTimeout(15000).setEntity(new TestRequest("Monkey")).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL("http://127.0.0.1:18081/greet").setURL(new URL("http://127.0.0.1:18081/greet")).setURL(URI.create("http://127.0.0.1:18081/greet"));
    // when
    TestResponse actual = sut.call(request, 15000);
    // then
    TestResponse expectation = new TestResponse("Greet Monkey!");
    Asserts.assertEquals(expectation, actual);
    sut.close();
    sut.stop();
}
Also used : HttpClientProxy(com.tvd12.ezyhttp.client.HttpClientProxy) URL(java.net.URL) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) BaseTest(com.tvd12.test.base.BaseTest)

Example 60 with Request

use of com.tvd12.ezyhttp.client.request.Request 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();
}
Also used : EzyWrap(com.tvd12.ezyfox.util.EzyWrap) 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)

Aggregations

Test (org.testng.annotations.Test)128 HttpServletResponse (javax.servlet.http.HttpServletResponse)48 HttpServletRequest (javax.servlet.http.HttpServletRequest)45 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)37 BeforeTest (org.testng.annotations.BeforeTest)36 BaseTest (com.tvd12.test.base.BaseTest)31 EzyArray (com.tvd12.ezyfox.entity.EzyArray)30 ComponentManager (com.tvd12.ezyhttp.server.core.manager.ComponentManager)29 BlockingServlet (com.tvd12.ezyhttp.server.core.servlet.BlockingServlet)29 ToString (lombok.ToString)29 RequestURI (com.tvd12.ezyhttp.server.core.request.RequestURI)27 ServletOutputStream (javax.servlet.ServletOutputStream)25 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)24 RequestHandlerManager (com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager)24 Cookie (javax.servlet.http.Cookie)24 HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)22 RequestCookie (com.tvd12.ezyhttp.server.core.annotation.RequestCookie)22 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)21 HttpClient (com.tvd12.ezyhttp.client.HttpClient)21 PostRequest (com.tvd12.ezyhttp.client.request.PostRequest)21