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());
}
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);
}
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());
}
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());
}
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();
}
Aggregations