2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.Before;
24 import org.junit.Test;
25 import org.onap.logging.ref.slf4j.ONAPLogConstants;
28 import static org.junit.Assert.*;
29 import static org.openecomp.sdc.common.log.api.ILogConfiguration.*;
31 public class LogFieldsMdcHandlerTest {
33 private LogFieldsMdcHandler ecompMdcWrapper;
37 ecompMdcWrapper = new LogFieldsMdcHandler();
38 ecompMdcWrapper.clear();
43 public void isMDCParamEmpty_shouldReturnTrue_onNonNullValueInMDC(){
44 MDC.put("Key","value1");
45 assertFalse(ecompMdcWrapper.isMDCParamEmpty("Key"));
48 public void isMDCParamEmpty_shouldReturnFalse_onEmptyStringInMDC(){
50 assertTrue(ecompMdcWrapper.isMDCParamEmpty("Key"));
54 public void isMDCParamEmpty_shouldReturnFalse_onNullValueInMDC(){
56 assertTrue(ecompMdcWrapper.isMDCParamEmpty("Key"));
60 public void startTimer_shouldFilecompMdcWrappereginTimestampField(){
61 ecompMdcWrapper.startMetricTimer();
62 assertFalse(ecompMdcWrapper.isMDCParamEmpty(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP));
66 public void stopTimer_shouldFillEndTimestampField_ifStartTimerWasCalledPreviously(){
67 ecompMdcWrapper.startAuditTimer();
68 ecompMdcWrapper.stopAuditTimer();
69 assertFalse(ecompMdcWrapper.isMDCParamEmpty(MDC_END_TIMESTAMP));
73 public void clear_shouldRemoveAllMandatoryAndOptionalFields_And_OnlyThem(){
74 ecompMdcWrapper.setClassName("class1");
75 ecompMdcWrapper.setPartnerName("partner1");
76 ecompMdcWrapper.setOptCustomField1("of1");
77 ecompMdcWrapper.clear();
78 assertNull(MDC.get(MDC_CLASS_NAME));
79 assertNull(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME));
80 assertNull(MDC.get(MDC_OPT_FIELD1));
84 public void clear_shouldNotThrowAnException_WhenNoFieldWasAssignedAsMandatoryOrOptional(){
85 ecompMdcWrapper.setClassName("class1");
86 ecompMdcWrapper.setPartnerName("partner1");
87 ecompMdcWrapper.setOptCustomField1("of1");
90 ecompMdcWrapper.clear();