diff options
author | 2019-11-26 11:22:33 +0200 | |
---|---|---|
committer | 2019-12-02 10:40:15 +0200 | |
commit | cc8f8c056b99d530d48190b67846be3705a4225f (patch) | |
tree | 2521bcffbd441d6510b545158364fa36c3c2d4cd /common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LoggerErrorTest.java | |
parent | 1bb3b03e1ebb16f3a9937ec5ae7d3b9c4a987c40 (diff) |
add common-app-logging module
This module is responsible of logging mechanism in sdc project
Issue-ID: SDC-2686
Signed-off-by: Yuli Shlosberg <ys9693@att.com>
Change-Id: Icf9817fe2c8b8032757a700f6e6be18d2bc9f891
Diffstat (limited to 'common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LoggerErrorTest.java')
-rw-r--r-- | common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LoggerErrorTest.java | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LoggerErrorTest.java b/common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LoggerErrorTest.java new file mode 100644 index 0000000000..06376ed48f --- /dev/null +++ b/common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LoggerErrorTest.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.common.log.elements; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; +import org.openecomp.sdc.common.log.enums.LogLevel; +import org.openecomp.sdc.common.log.utils.EcompLogErrorCode; +import org.openecomp.sdc.common.log.utils.LoggingThreadLocalsHolder; +import org.slf4j.Logger; +import org.slf4j.MDC; + +import static org.junit.Assert.assertEquals; +import static org.openecomp.sdc.common.log.api.LogConfigurationConstants.MDC_ERROR_CODE; + +@RunWith(MockitoJUnitRunner.class) +public class LoggerErrorTest { + private LoggerError errorLog; + + @Mock + private Logger logger; + @Before + public void init() { + errorLog = LoggerFactory.getMdcLogger(LoggerError.class, logger); + MDC.clear(); + } + + @Test + public void allFieldsArePresentTest() { + LoggingThreadLocalsHolder.setUuid("uuid"); + errorLog.log(LogLevel.ERROR, EcompLoggerErrorCode.AVAILABILITY_TIMEOUTS_ERROR, "service", "entity", "server error"); + + assertEquals(MDC.get(MDC_ERROR_CODE), String.valueOf(EcompLoggerErrorCode.AVAILABILITY_TIMEOUTS_ERROR.getErrorCode())); + assertEquals("uuid", MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)); + assertEquals("entity", MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY)); + assertEquals("service", MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME)); + } + + @Test + public void missingFieldsTest() { + errorLog.clear() + .log(LogLevel.ERROR,"some message"); + } + + @Test + public void convertEcompErrorForLogging_correctName() { + assertEquals(EcompLoggerErrorCode.AVAILABILITY_TIMEOUTS_ERROR, EcompLoggerErrorCode.getByValue(EcompLogErrorCode.E_210.name())); + } + + @Test + public void convertEcompErrorForLogging_correctName_2() { + assertEquals(EcompLoggerErrorCode.DATA_ERROR, EcompLoggerErrorCode.getByValue(EcompLogErrorCode.E_399.name())); + } + + @Test + public void convertEcompErrorForLogging_NotConvertable() { + assertEquals(EcompLoggerErrorCode.UNKNOWN_ERROR, EcompLoggerErrorCode.getByValue("ABC")); + } + + @Test + public void convertEcompErrorForLogging_NotConvertable_2() { + assertEquals(EcompLoggerErrorCode.UNKNOWN_ERROR, EcompLoggerErrorCode.getByValue("E_ABC")); + } + + @Test + public void convertEcompErrorForLogging_Success() { + assertEquals(EcompLoggerErrorCode.SUCCESS, EcompLoggerErrorCode.getByValue("E_0")); + } +} |