Search in sources :

Example 46 with Request

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

the class EzySimpleRequestAppRequestTest method test.

@Test
public void test() {
    EzySimpleRequestPluginRequest request = new EzySimpleRequestPluginRequest();
    request.deserializeParams(EzyEntityFactory.newArrayBuilder().append(1).append(EzyEntityFactory.newArrayBuilder()).build());
    request.release();
}
Also used : EzySimpleRequestPluginRequest(com.tvd12.ezyfoxserver.request.EzySimpleRequestPluginRequest) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 47 with Request

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

the class EzySimpleRequestPluginRequestTest method test.

@Test
public void test() {
    EzySimpleRequestAppRequest request = new EzySimpleRequestAppRequest();
    request.deserializeParams(EzyEntityFactory.newArrayBuilder().append(1).append(EzyEntityFactory.newArrayBuilder()).build());
    request.release();
}
Also used : EzySimpleRequestAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleRequestAppRequest) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 48 with Request

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

the class HttpClientProxyTest method clientWasNotActive.

@Test
public void clientWasNotActive() {
    // given
    HttpClientProxy sut = HttpClientProxy.builder().build();
    PostRequest request = new PostRequest().setConnectTimeout(15000).setEntity(String.class).setResponseType(TestResponse.class).setResponseType(StatusCodes.OK, TestResponse.class).setURL("http://127.0.0.1:18081/greet");
    // when
    Throwable e = Asserts.assertThrows(() -> sut.call(request, 150000));
    // then
    Asserts.assertThat(e).isEqualsType(ClientNotActiveException.class);
    sut.close();
    sut.stop();
}
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 49 with Request

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

the class HttpClientProxyTest method downloadToOutputStreamByRequestWithCancellationTokenTest.

@Test
public void downloadToOutputStreamByRequestWithCancellationTokenTest() 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, new DownloadCancellationToken());
    // then
    Asserts.assertTrue(new File("test-output/no-commit/download-test.xml").exists());
    sut.close();
    sut.stop();
}
Also used : DownloadCancellationToken(com.tvd12.ezyhttp.client.concurrent.DownloadCancellationToken) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) HttpClientProxy(com.tvd12.ezyhttp.client.HttpClientProxy) File(java.io.File) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) BaseTest(com.tvd12.test.base.BaseTest)

Example 50 with Request

use of com.tvd12.ezyhttp.client.request.Request 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();
}
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)

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