From 6ff4d1ab0a5e89a4ee02a04c53f53857e592c84b Mon Sep 17 00:00:00 2001 From: wojtask9 Date: Fri, 6 Sep 2019 12:50:19 +0200 Subject: [PATCH] improve AccessLogSupportTest and fix test with locales other than US --- .../webserver/accesslog/AccessLogSupportTest.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/webserver/access-log/src/test/java/io/helidon/webserver/accesslog/AccessLogSupportTest.java b/webserver/access-log/src/test/java/io/helidon/webserver/accesslog/AccessLogSupportTest.java index 6ae88bf4dcb..8247693140f 100644 --- a/webserver/access-log/src/test/java/io/helidon/webserver/accesslog/AccessLogSupportTest.java +++ b/webserver/access-log/src/test/java/io/helidon/webserver/accesslog/AccessLogSupportTest.java @@ -68,6 +68,10 @@ void testHelidonFormat() { ServerResponse response = mock(ServerResponse.class); when(response.status()).thenReturn(Http.Status.I_AM_A_TEAPOT); + AccessLogContext accessLogContext = mock(AccessLogContext.class); + when(accessLogContext.requestDateTime()).thenReturn(BEGIN_TIME); + String expectedTimestamp = TimestampLogEntry.create().doApply(accessLogContext); + String logRecord = accessLog.createLogRecord(request, response, BEGIN_TIME, @@ -77,7 +81,7 @@ void testHelidonFormat() { //192.168.0.104 - [18/Jun/2019:23:10:44 +0200] "GET /greet/test HTTP/1.1" 200 55 2248 - String expected = REMOTE_IP + " - [03/Dec/2007:10:15:30 +0000] \"" + METHOD + " " + PATH + " " + HTTP_VERSION + "\" " + + String expected = REMOTE_IP + " - " + expectedTimestamp + " \"" + METHOD + " " + PATH + " " + HTTP_VERSION + "\" " + STATUS_CODE + " " + CONTENT_LENGTH + " " + TIME_TAKEN_MICROS; assertThat(logRecord, is(expected)); @@ -102,6 +106,10 @@ void testCommonFormat() { ServerResponse response = mock(ServerResponse.class); when(response.status()).thenReturn(Http.Status.I_AM_A_TEAPOT); + AccessLogContext accessLogContext = mock(AccessLogContext.class); + when(accessLogContext.requestDateTime()).thenReturn(BEGIN_TIME); + String expectedTimestamp = TimestampLogEntry.create().doApply(accessLogContext); + String logRecord = accessLog.createLogRecord(request, response, BEGIN_TIME, @@ -111,7 +119,7 @@ void testCommonFormat() { //192.168.0.104 - [18/Jun/2019:23:10:44 +0200] "GET /greet/test HTTP/1.1" 200 55 2248 - String expected = REMOTE_IP + " - - [03/Dec/2007:10:15:30 +0000] \"" + METHOD + " " + PATH + " " + HTTP_VERSION + "\" " + + String expected = REMOTE_IP + " - - " + expectedTimestamp + " \"" + METHOD + " " + PATH + " " + HTTP_VERSION + "\" " + STATUS_CODE + " " + CONTENT_LENGTH; assertThat(logRecord, is(expected)); @@ -151,4 +159,4 @@ void testCustomFormat() { assertThat(logRecord, is(expected)); } -} \ No newline at end of file +}