use of com.tvd12.ezyfox.stream.EzyAnywayInputStreamLoader in project ezyfox-server-example by tvd12.
the class WheelService method loadWheelFromJsonFile.
private Wheel loadWheelFromJsonFile() {
ObjectMapper objectMapper = new ObjectMapper();
InputStream inputStream = new EzyAnywayInputStreamLoader().load("wheel.json");
try {
Wheel res = objectMapper.readValue(inputStream, Wheel.class);
res.setId("wheel");
return res;
} catch (IOException e) {
throw new IllegalStateException("can not load wheel", e);
}
}
use of com.tvd12.ezyfox.stream.EzyAnywayInputStreamLoader in project ezyhttp by youngmonkeys.
the class ResourceRequestHandlerTest method handleWithDrainExceptionTest.
@Test
public void handleWithDrainExceptionTest() throws Exception {
// given
String resourcePath = "static/index.html";
String resourceURI = "/index.html";
String resourceExtension = "html";
ResourceDownloadManager downloadManager = new ResourceDownloadManager();
ResourceRequestHandler sut = new ResourceRequestHandler(resourcePath, resourceURI, resourceExtension, new EzyAnywayInputStreamLoader(), downloadManager);
RequestArguments arguments = mock(RequestArguments.class);
AsyncContext asyncContext = mock(AsyncContext.class);
when(arguments.getAsyncContext()).thenReturn(asyncContext);
HttpServletResponse response = mock(HttpServletResponse.class);
when(asyncContext.getResponse()).thenReturn(response);
ServletOutputStream outputStream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(outputStream);
doThrow(IOException.class).when(outputStream).write(any(byte[].class), anyInt(), anyInt());
when(asyncContext.getResponse()).thenReturn(response);
// when
sut.handle(arguments);
// then
Asserts.assertEquals(HttpMethod.GET, sut.getMethod());
Asserts.assertEquals("/index.html", sut.getRequestURI());
Asserts.assertEquals(ContentTypes.TEXT_HTML_UTF8, sut.getResponseContentType());
Thread.sleep(300);
downloadManager.stop();
verify(arguments, times(1)).getAsyncContext();
verify(response, times(1)).getOutputStream();
verify(response, times(1)).setStatus(StatusCodes.INTERNAL_SERVER_ERROR);
verify(asyncContext, times(1)).getResponse();
verify(asyncContext, times(1)).complete();
}
Aggregations