@Test public void shouldPreserveStringFormatting() { final HttpLogFormatter formatter = new HttpLogFormatter("%%log output%% %U"); final String expected = "%log output% http://some.place.net/u/r/l"; assertEquals(expected, formatter.format(request, response)); }
@Test public void shouldCorrectlyDetectEscapeSequences() { final HttpLogFormatter formatter = new HttpLogFormatter("%h %% %u %U"); assertTrue( "Should have parsed seven handlers. Only found: " + formatter.getHandlerList().size(), formatter.getHandlerList().size() == 7); }
@Test public void shouldCorrectlyParseEmptySpace() { final HttpLogFormatter formatter = new HttpLogFormatter("%h%%%u%U"); assertTrue( "Should have parsed four handlers. Only found: " + formatter.getHandlerList().size(), formatter.getHandlerList().size() == 4); }
@Test public void shouldParseCustomTimeFormat() { final String customDateFormatRegex = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}"; final HttpLogFormatter formatter = new HttpLogFormatter("%{yyyy-MM-dd HH:mm:ss}t"); assertEquals(1, formatter.getHandlerList().size()); assertTrue(Pattern.matches(customDateFormatRegex, formatter.format(request, response))); }
@Test public void shouldParseExclusiveStatusCodeRestrictions() { final HttpLogFormatter formatter = new HttpLogFormatter("%!401,403U"); final String expected = "http://some.place.net/u/r/l"; assertEquals(expected, formatter.format(request, response)); when(response.getStatus()).thenReturn(401); assertEquals("-", formatter.format(request, response)); }
@Test public void shouldParseSimpleTimeFormat() { final String defaultDateFormatRegex = "\\d{2}-\\d{2}-\\d{4}-\\d{2}:\\d{2}:\\d{2}\\.\\d{3}"; final HttpLogFormatter formatter = new HttpLogFormatter("%t"); assertEquals(1, formatter.getHandlerList().size()); assertTrue(Pattern.matches(defaultDateFormatRegex, formatter.format(request, response))); }
@Test public void shouldCorrectlyConstructRequestLine() { when(request.getProtocol()).thenReturn("HTTP/1.1"); when(request.getRequestURI()).thenReturn("/index.html"); when(request.getMethod()).thenReturn("GET"); final HttpLogFormatter formatter = new HttpLogFormatter("%r"); final String expected = "GET /index.html HTTP/1.1"; assertEquals(expected, formatter.format(request, response)); }
@Test public void shouldReplaceTokenWithRequestGuid() { final HttpLogFormatter formatter = new HttpLogFormatter("%" + LogFormatArgument.TRACE_GUID.toString()); final String expected = "test-guid"; Vector<String> reqGuidValues = new Vector<>(); reqGuidValues.add("test-guid"); when(request.getHeaders(CommonHttpHeader.TRACE_GUID.toString())) .thenReturn(reqGuidValues.elements()); assertEquals(expected, formatter.format(request, response)); }
@Test public void StringHandler() { final LogArgumentGroupExtractor extractor = LogArgumentGroupExtractor.instance("", "", "", "", LogFormatArgument.STRING.toString()); httpLogFormatter.setLogic(extractor, formatter); assertTrue(formatter.getLogic() instanceof StringHandler); }
@Test public void TimeReceivedHandler() { final LogArgumentGroupExtractor extractor = LogArgumentGroupExtractor.instance( "", "", "", "", LogFormatArgument.TIME_RECEIVED.toString()); httpLogFormatter.setLogic(extractor, formatter); assertTrue(formatter.getLogic() instanceof TimeReceivedHandler); }
@Test public void ResponseTimeHandlerSeconds() { final LogArgumentGroupExtractor extractor = LogArgumentGroupExtractor.instance( "", "", "", "", LogFormatArgument.RESPONSE_TIME_SECONDS.toString()); httpLogFormatter.setLogic(extractor, formatter); assertTrue(formatter.getLogic() instanceof ResponseTimeHandler); }
@Test public void CanonicalPortHandler() { final LogArgumentGroupExtractor extractor = LogArgumentGroupExtractor.instance( "", "", "", "", LogFormatArgument.CANONICAL_PORT.toString()); httpLogFormatter.setLogic(extractor, formatter); assertTrue(formatter.getLogic() instanceof CanonicalPortHandler); }
@Test public void LocalAddressHandler() { final LogArgumentGroupExtractor extractor = LogArgumentGroupExtractor.instance( "", "", "", "", LogFormatArgument.LOCAL_ADDRESS.toString()); httpLogFormatter.setLogic(extractor, formatter); assertTrue(formatter.getLogic() instanceof LocalAddressHandler); }
@Test public void RemoteUserHandler() { final LogArgumentGroupExtractor extractor = LogArgumentGroupExtractor.instance( "", "", "", "", LogFormatArgument.REMOTE_USER.toString()); httpLogFormatter.setLogic(extractor, formatter); assertTrue(formatter.getLogic() instanceof RemoteUserHandler); }
@Test public void RequestGuidHandler() { final LogArgumentGroupExtractor extractor = LogArgumentGroupExtractor.instance( "", "", "", "", LogFormatArgument.TRACE_GUID.toString()); httpLogFormatter.setLogic(extractor, formatter); assertTrue(formatter.getLogic() instanceof TraceGuidHandler); }
@Test public void ResponseMessageHandler() { final LogArgumentGroupExtractor extractor = LogArgumentGroupExtractor.instance( "", "", "", "", LogFormatArgument.ERROR_MESSAGE.toString()); httpLogFormatter.setLogic(extractor, formatter); assertTrue(formatter.getLogic() instanceof ResponseMessageHandler); }
@Test public void UrlRequestedHandler() { final LogArgumentGroupExtractor extractor = LogArgumentGroupExtractor.instance( "", "", "", "", LogFormatArgument.URL_REQUESTED.toString()); httpLogFormatter.setLogic(extractor, formatter); assertTrue(formatter.getLogic() instanceof UrlRequestedHandler); }
@Test public void RequestMethodHandler() { final LogArgumentGroupExtractor extractor = LogArgumentGroupExtractor.instance( "", "", "", "", LogFormatArgument.REQUEST_METHOD.toString()); httpLogFormatter.setLogic(extractor, formatter); assertTrue(formatter.getLogic() instanceof RequestMethodHandler); }
@Test public void ResponseBytesHandler() { final LogArgumentGroupExtractor extractor = LogArgumentGroupExtractor.instance( "", "", "", "", LogFormatArgument.RESPONSE_BYTES.toString()); httpLogFormatter.setLogic(extractor, formatter); assertTrue(formatter.getLogic() instanceof ResponseBytesHandler); }