Search in sources :

Example 6 with ResponseEntity

use of com.tvd12.ezyhttp.core.response.ResponseEntity in project ezyhttp by youngmonkeys.

the class ResponseEntityTest method createByOkAndBody.

@Test
public void createByOkAndBody() {
    // given
    Object body = "Hello World";
    // when
    ResponseEntity sut = ResponseEntity.ok(body);
    // then
    Asserts.assertEquals(body, sut.getBody());
}
Also used : ResponseEntity(com.tvd12.ezyhttp.core.response.ResponseEntity) Test(org.testng.annotations.Test)

Example 7 with ResponseEntity

use of com.tvd12.ezyhttp.core.response.ResponseEntity in project ezyhttp by youngmonkeys.

the class ResponseEntityTest method headersNull.

@Test
public void headersNull() {
    // given
    // when
    ResponseEntity sut = ResponseEntity.ok();
    // then
    Asserts.assertNull(sut.getHeader("nothing"));
    System.out.println(sut);
}
Also used : ResponseEntity(com.tvd12.ezyhttp.core.response.ResponseEntity) Test(org.testng.annotations.Test)

Example 8 with ResponseEntity

use of com.tvd12.ezyhttp.core.response.ResponseEntity in project ezyhttp by youngmonkeys.

the class ResponseEntityTest method createByBadRequestAndBody.

@Test
public void createByBadRequestAndBody() {
    // given
    Object body = "Hello World";
    // when
    ResponseEntity sut = ResponseEntity.badRequest(body);
    // then
    Asserts.assertEquals(StatusCodes.BAD_REQUEST, sut.getStatus());
    Asserts.assertEquals(body, sut.getBody());
}
Also used : ResponseEntity(com.tvd12.ezyhttp.core.response.ResponseEntity) Test(org.testng.annotations.Test)

Example 9 with ResponseEntity

use of com.tvd12.ezyhttp.core.response.ResponseEntity in project ezyhttp by youngmonkeys.

the class HealthCheckControllerTest method healthCheck.

@Test
public void healthCheck() {
    // given
    HealthCheckController sut = new HealthCheckController();
    // when
    ResponseEntity actual = sut.healthCheck();
    // then
    Asserts.assertEquals(actual, ResponseEntity.ok());
}
Also used : ResponseEntity(com.tvd12.ezyhttp.core.response.ResponseEntity) HealthCheckController(com.tvd12.ezyhttp.server.management.HealthCheckController) Test(org.testng.annotations.Test)

Example 10 with ResponseEntity

use of com.tvd12.ezyhttp.core.response.ResponseEntity in project ezyhttp by youngmonkeys.

the class BlockingServletTest method requestHandlerEmptyAndHasErrorHandlerButException.

@Test
public void requestHandlerEmptyAndHasErrorHandlerButException() throws Exception {
    // given
    ComponentManager componentManager = ComponentManager.getInstance();
    componentManager.setServerPort(PORT);
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    UnhandledErrorHandler unhandledErrorHandler = mock(UnhandledErrorHandler.class);
    ResponseEntity responseEntity = ResponseEntity.ok();
    when(unhandledErrorHandler.handleError(HttpMethod.GET, request, response, HttpServletResponse.SC_METHOD_NOT_ALLOWED, null)).thenReturn(responseEntity);
    componentManager.setUnhandledErrorHandler(Collections.singletonList(unhandledErrorHandler));
    BlockingServlet sut = new BlockingServlet();
    sut.init();
    String requestURI = "/get";
    when(request.getMethod()).thenReturn(HttpMethod.GET.toString());
    when(request.getRequestURI()).thenReturn(requestURI);
    when(request.getServerPort()).thenReturn(PORT);
    when(response.getContentType()).thenReturn(ContentTypes.APPLICATION_JSON);
    doThrow(new IllegalStateException("just test")).when(response).setStatus(StatusCodes.OK);
    ServletOutputStream outputStream = mock(ServletOutputStream.class);
    when(response.getOutputStream()).thenReturn(outputStream);
    RequestHandlerManager requestHandlerManager = componentManager.getRequestHandlerManager();
    GetRequestHandler requestHandler = new GetRequestHandler();
    requestHandlerManager.addHandler(new RequestURI(HttpMethod.POST, requestURI, false), requestHandler);
    // when
    sut.service(request, response);
    // then
    verify(request, times(1)).getMethod();
    verify(request, times(2)).getRequestURI();
    verify(response, times(1)).setStatus(StatusCodes.OK);
    verify(response, times(1)).setStatus(StatusCodes.INTERNAL_SERVER_ERROR);
    componentManager.destroy();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ResponseEntity(com.tvd12.ezyhttp.core.response.ResponseEntity) ServletOutputStream(javax.servlet.ServletOutputStream) RequestHandlerManager(com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager) ComponentManager(com.tvd12.ezyhttp.server.core.manager.ComponentManager) UnhandledErrorHandler(com.tvd12.ezyhttp.server.core.handler.UnhandledErrorHandler) BlockingServlet(com.tvd12.ezyhttp.server.core.servlet.BlockingServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) ToString(lombok.ToString) Test(org.testng.annotations.Test)

Aggregations

ResponseEntity (com.tvd12.ezyhttp.core.response.ResponseEntity)24 Test (org.testng.annotations.Test)21 ClientNotActiveException (com.tvd12.ezyhttp.client.exception.ClientNotActiveException)6 RequestQueueFullException (com.tvd12.ezyhttp.client.exception.RequestQueueFullException)6 UnhandledErrorHandler (com.tvd12.ezyhttp.server.core.handler.UnhandledErrorHandler)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 EzyFuture (com.tvd12.ezyfox.concurrent.EzyFuture)3 BadRequestException (com.tvd12.ezyfox.exception.BadRequestException)3 EzyProcessor.processWithException (com.tvd12.ezyfox.util.EzyProcessor.processWithException)3 HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)3 DownloadCancelledException (com.tvd12.ezyhttp.client.exception.DownloadCancelledException)3 MultiValueMap (com.tvd12.ezyhttp.core.data.MultiValueMap)3 ComponentManager (com.tvd12.ezyhttp.server.core.manager.ComponentManager)3 BlockingServlet (com.tvd12.ezyhttp.server.core.servlet.BlockingServlet)3 BaseTest (com.tvd12.test.base.BaseTest)3 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 ServletOutputStream (javax.servlet.ServletOutputStream)3 ToString (lombok.ToString)3