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;
24 * Created by dd4296 on 12/25/2017.
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.junit.MockitoJUnitRunner;
33 import org.openecomp.sdc.common.log.enums.LogLevel;
34 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
35 import org.slf4j.Logger;
38 import java.net.UnknownHostException;
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertNull;
42 import static org.openecomp.sdc.common.log.api.ILogConfiguration.*;
44 @RunWith(MockitoJUnitRunner.class)
45 public class LoggerDebugTest {
48 private Logger logger;
50 private LoggerDebug debugLog;
54 debugLog = new LoggerDebug(LogFieldsMdcHandler.getInstance(), logger);
55 ThreadLocalsHolder.setUuid(null);
60 public void whenNoFieldsIsPopulated_RequestedMdcFieldsAreEmpty() {
62 .log(LogLevel.DEBUG, "some error code");
63 assertNull(MDC.get(MDC_KEY_REQUEST_ID));
67 public void debugLogCheckValidationValidFieldsTest() {
70 .setKeyRequestId("uuid")
71 .log(LogLevel.DEBUG, "some error code");
73 Assert.assertEquals(MDC.get(MDC_KEY_REQUEST_ID), "uuid");
77 public void whenOnlyDebugUUIDFieldsIsPopulated_ShouldReturnAssertTrue_onUUIDFieldCheck() {
79 .setKeyRequestId("uuid")
80 .log(LogLevel.DEBUG, "some error code");
82 Assert.assertEquals(MDC.get(MDC_KEY_REQUEST_ID), "uuid");
86 public void whenAllDebugFieldsArePopulated_ShouldReturnAssertTrue_onEachMACFieldCheck() throws UnknownHostException {
89 .setKeyRequestId(MDC_KEY_REQUEST_ID)
90 .log(LogLevel.DEBUG, "some message");
92 Assert.assertTrue(LogFieldsMdcHandler.getInstance().isMDCParamEmpty(MDC_END_TIMESTAMP));
93 Assert.assertTrue(LogFieldsMdcHandler.getInstance().isMDCParamEmpty(MDC_ELAPSED_TIME));
94 Assert.assertTrue(LogFieldsMdcHandler.getInstance().isMDCParamEmpty(MDC_STATUS_CODE));
99 public void validateMandatoryFields(){
100 assertEquals(MDC_KEY_REQUEST_ID, debugLog.checkMandatoryFieldsExistInMDC().trim());
104 public void validateMandatoryFieldsWhenFieldIsSet(){
106 .setKeyRequestId("1234");
107 assertEquals("", debugLog.checkMandatoryFieldsExistInMDC());