2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.common.log.elements;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.Mock;
28 import org.mockito.junit.MockitoJUnitRunner;
29 import org.openecomp.sdc.common.config.EcompErrorCode;
30 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
31 import org.openecomp.sdc.common.log.enums.LogLevel;
32 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
33 import org.slf4j.Logger;
36 import static org.junit.Assert.assertEquals;
37 import static org.openecomp.sdc.common.log.api.ILogConfiguration.*;
39 @RunWith(MockitoJUnitRunner.class)
40 public class LoggerErrorTest {
41 private LoggerError errorLog;
44 private Logger logger;
47 errorLog = LoggerFactory.getMdcLogger(LoggerError.class, logger);
52 public void allFieldsArePresentTest() {
53 ThreadLocalsHolder.setUuid("uuid");
54 errorLog.log(LogLevel.ERROR, EcompLoggerErrorCode.AVAILABILITY_TIMEOUTS_ERROR, "service", "entity", "server error");
56 Assert.assertEquals(MDC.get(MDC_ERROR_CODE), String.valueOf(EcompLoggerErrorCode.AVAILABILITY_TIMEOUTS_ERROR.getErrorCode()));
57 Assert.assertEquals("uuid", MDC.get(MDC_KEY_REQUEST_ID));
58 Assert.assertEquals("entity", MDC.get(MDC_TARGET_ENTITY));
59 Assert.assertEquals("service", MDC.get(MDC_SERVICE_NAME));
63 public void missingFieldsTest() {
65 .log(LogLevel.ERROR,"some message");
69 public void convertEcompErrorForLogging_correctName() {
70 assertEquals(EcompLoggerErrorCode.AVAILABILITY_TIMEOUTS_ERROR, EcompLoggerErrorCode.getByValue(EcompErrorCode.E_210.name()));
74 public void convertEcompErrorForLogging_correctName_2() {
75 assertEquals(EcompLoggerErrorCode.DATA_ERROR, EcompLoggerErrorCode.getByValue(EcompErrorCode.E_399.name()));
79 public void convertEcompErrorForLogging_NotConvertable() {
80 assertEquals(EcompLoggerErrorCode.UNKNOWN_ERROR, EcompLoggerErrorCode.getByValue("ABC"));
84 public void convertEcompErrorForLogging_NotConvertable_2() {
85 assertEquals(EcompLoggerErrorCode.UNKNOWN_ERROR, EcompLoggerErrorCode.getByValue("E_ABC"));
89 public void convertEcompErrorForLogging_Success() {
90 assertEquals(EcompLoggerErrorCode.SUCCESS, EcompLoggerErrorCode.getByValue("E_0"));