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;
27 import static org.junit.Assert.*;
28 import static org.openecomp.sdc.common.log.api.ILogConfiguration.*;
30 public class LogFieldsMdcHandlerTest {
32 private LogFieldsMdcHandler ecompMdcWrapper;
36 ecompMdcWrapper = new LogFieldsMdcHandler();
37 ecompMdcWrapper.clear();
42 public void isMDCParamEmpty_shouldReturnTrue_onNonNullValueInMDC(){
43 MDC.put("Key","value1");
44 assertFalse(ecompMdcWrapper.isMDCParamEmpty("Key"));
47 public void isMDCParamEmpty_shouldReturnFalse_onEmptyStringInMDC(){
49 assertTrue(ecompMdcWrapper.isMDCParamEmpty("Key"));
53 public void isMDCParamEmpty_shouldReturnFalse_onNullValueInMDC(){
55 assertTrue(ecompMdcWrapper.isMDCParamEmpty("Key"));
59 public void startTimer_shouldFilecompMdcWrappereginTimestampField(){
60 ecompMdcWrapper.startMetricTimer();
61 assertFalse(ecompMdcWrapper.isMDCParamEmpty(MDC_METRIC_BEGIN_TIMESTAMP));
65 public void stopTimer_shouldFillEndTimestampField_ifStartTimerWasCalledPreviously(){
66 ecompMdcWrapper.startAuditTimer();
67 ecompMdcWrapper.stopAuditTimer();
68 assertFalse(ecompMdcWrapper.isMDCParamEmpty(MDC_END_TIMESTAMP));
72 public void clear_shouldRemoveAllMandatoryAndOptionalFields_And_OnlyThem(){
73 ecompMdcWrapper.setClassName("class1");
74 ecompMdcWrapper.setPartnerName("partner1");
75 ecompMdcWrapper.setOptCustomField1("of1");
76 ecompMdcWrapper.clear();
77 assertNull(MDC.get(MDC_CLASS_NAME));
78 assertNull(MDC.get(MDC_PARTNER_NAME));
79 assertNull(MDC.get(MDC_OPT_FIELD1));
83 public void clear_shouldNotThrowAnException_WhenNoFieldWasAssignedAsMandatoryOrOptional(){
84 ecompMdcWrapper.setClassName("class1");
85 ecompMdcWrapper.setPartnerName("partner1");
86 ecompMdcWrapper.setOptCustomField1("of1");
89 ecompMdcWrapper.clear();