AccessLogRequestHandler extends ThreadedHttpRequestHandler { @Override public HttpResponse handle(HttpRequest request) { final List<String> uris = circularArrayAccessLogKeeper.getUris(); return new HttpResponse(200) { @Override public void render(OutputStream outputStream) throws IOException { JsonGenerator generator = jsonFactory.createGenerator(outputStream); generator.writeStartObject(); generator.writeArrayFieldStart("entries"); for (String uri : uris) { generator.writeStartObject(); generator.writeStringField("url", uri); generator.writeEndObject(); } generator.writeEndArray(); generator.writeEndObject(); generator.close(); } }; } @Inject  AccessLogRequestHandler(Executor executor, Metric metric, CircularArrayAccessLogKeeper circularArrayAccessLogKeeper); @Override HttpResponse handle(HttpRequest request);  }
@Test public void testOneLogLine() throws IOException { keeper.addUri("foo"); HttpResponse response = handler.handle(null); response.render(out); assertThat(out.toString(), is("{\"entries\":[{\"url\":\"foo\"}]}")); }
@Test public void testEmpty() throws IOException { HttpResponse response = handler.handle(null); response.render(out); assertThat(out.toString(), is("{\"entries\":[]}")); }
@Test public void testManyLogLines() throws IOException { keeper.addUri("foo"); keeper.addUri("foo"); HttpResponse response = handler.handle(null); response.render(out); assertThat(out.toString(), is("{\"entries\":[{\"url\":\"foo\"},{\"url\":\"foo\"}]}")); }