diff options
author | Satoshi Fujii <fujii-satoshi@jp.fujitsu.com> | 2020-02-21 16:19:55 +0900 |
---|---|---|
committer | Satoshi Fujii <fujii-satoshi@jp.fujitsu.com> | 2020-02-21 16:24:07 +0900 |
commit | c5411baf4fe1354e6a70742c9d2d33b6b5fdc12e (patch) | |
tree | ae978e8d1a1e8bf89927de8dfe8b09c06f38fadb /common-app-logging/src/test/java/org | |
parent | 32f485b151dba9e40e6b1171c246bf8f3e9c8fc4 (diff) |
Fix logging date format to avoid parse error
When MDCSetup class in logging-filter-base tries to calculate an elapsed
time, it expects a datetime is given in ISO format.
But date format in LogFieldsMdcHandler is not compatible with ISO format
therefore 'Unable to calculate elapsed time due to error' occurs.
This change fixes date format in the class
so that the date string can be parsed by logging-filter.
Change-Id: I07c8f103f46493fe0764f904f3f00f66f35dbcf6
Issue-ID: SDC-2767
Signed-off-by: Satoshi Fujii <fujii-satoshi@jp.fujitsu.com>
Diffstat (limited to 'common-app-logging/src/test/java/org')
-rw-r--r-- | common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandlerTest.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandlerTest.java b/common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandlerTest.java index c6b854ea06..334a1edee6 100644 --- a/common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandlerTest.java +++ b/common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandlerTest.java @@ -20,14 +20,20 @@ package org.openecomp.sdc.common.log.elements; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_CLASS_NAME; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_END_TIMESTAMP; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_OPT_FIELD1; + +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import org.junit.Before; import org.junit.Test; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.MDC; -import static org.junit.Assert.*; -import static org.openecomp.sdc.common.log.api.ILogConfiguration.*; - public class LogFieldsMdcHandlerTest { private LogFieldsMdcHandler ecompMdcWrapper; @@ -70,6 +76,15 @@ public class LogFieldsMdcHandlerTest { } @Test + public void stopTimer_shouldTimestampsBeIsoFormat() { + ecompMdcWrapper.startAuditTimer(); + ecompMdcWrapper.stopAuditTimer(); + // Expect no exceptions thrown + ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP), DateTimeFormatter.ISO_ZONED_DATE_TIME); + ZonedDateTime.parse(MDC.get(MDC_END_TIMESTAMP), DateTimeFormatter.ISO_ZONED_DATE_TIME); + } + + @Test public void clear_shouldRemoveAllMandatoryAndOptionalFields_And_OnlyThem(){ ecompMdcWrapper.setClassName("class1"); ecompMdcWrapper.setPartnerName("partner1"); |