From de9224b1ae01755c7cc46e4bdd1a50c1bc08936e Mon Sep 17 00:00:00 2001 From: xuegao Date: Thu, 25 Mar 2021 10:31:08 +0100 Subject: Improve test coverage Add unit tests to improve test coverage. Issue-ID: SDC-3428 Change-Id: I47da0decd6b6df93ace68b2af586b255ef0b792e Signed-off-by: xuegao --- .../log/elements/LogFieldsMdcHandlerTest.java | 93 ++++++++++++++++++++-- 1 file changed, 86 insertions(+), 7 deletions(-) (limited to 'common-app-logging/src/test/java/org/openecomp') diff --git a/common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandlerTest.java b/common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandlerTest.java index 334a1edee6..793e156d8b 100644 --- a/common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandlerTest.java +++ b/common-app-logging/src/test/java/org/openecomp/sdc/common/log/elements/LogFieldsMdcHandlerTest.java @@ -20,17 +20,31 @@ package org.openecomp.sdc.common.log.elements; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.PARTNER_NAME; import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_CLASS_NAME; import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_END_TIMESTAMP; import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_OPT_FIELD1; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_OUTGOING_INVOCATION_ID; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_SUPPORTABLITY_ACTION; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_SERVICE_INSTANCE_ID; +import static org.openecomp.sdc.common.log.api.ILogConfiguration.MDC_TARGET_VIRTUAL_ENTITY; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; -import org.junit.Before; -import org.junit.Test; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.MDC; @@ -38,7 +52,7 @@ public class LogFieldsMdcHandlerTest { private LogFieldsMdcHandler ecompMdcWrapper; - @Before + @BeforeEach public void init(){ ecompMdcWrapper = new LogFieldsMdcHandler(); ecompMdcWrapper.clear(); @@ -89,10 +103,12 @@ public class LogFieldsMdcHandlerTest { ecompMdcWrapper.setClassName("class1"); ecompMdcWrapper.setPartnerName("partner1"); ecompMdcWrapper.setOptCustomField1("of1"); + ecompMdcWrapper.setOutgoingInvocationId("invocationId"); ecompMdcWrapper.clear(); assertNull(MDC.get(MDC_CLASS_NAME)); - assertNull(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + assertNull(MDC.get(PARTNER_NAME)); assertNull(MDC.get(MDC_OPT_FIELD1)); + assertNull(MDC.get(MDC_OUTGOING_INVOCATION_ID)); } @Test @@ -111,5 +127,68 @@ public class LogFieldsMdcHandlerTest { assertNull(exp); } + @Test + public void testSetterGetterRemove(){ + ecompMdcWrapper.setErrorCode(200); + ecompMdcWrapper.setErrorCategory("errorCategory"); + ecompMdcWrapper.setTargetEntity("targetEntity"); + ecompMdcWrapper.setTargetServiceName("targetServiceName"); + ecompMdcWrapper.setPartnerName("partnerName"); + ecompMdcWrapper.setServiceInstanceId("serviceInstanceId"); + ecompMdcWrapper.setServerIPAddress("serverIpAddress"); + ecompMdcWrapper.setAuditMessage("auditMsg"); + ecompMdcWrapper.setTargetVirtualEntity("targetVirtualEntity"); + ecompMdcWrapper.setSupportablityStatusCode("supportablityStatusCode"); + ecompMdcWrapper.setSupportablityAction("supportablityAction"); + ecompMdcWrapper.setRemoteHost("remoteHost"); + ecompMdcWrapper.setSupportablityCsarUUID("csarUUID"); + ecompMdcWrapper.setSupportablityCsarVersion("csarVersion"); + ecompMdcWrapper.setSupportablityComponentName("componentName"); + ecompMdcWrapper.setSupportablityComponentUUID("componentUUID"); + ecompMdcWrapper.setSupportablityComponentVersion("componentVersion"); + ecompMdcWrapper.setKeyInvocationId("keyInvocationId"); + + assertEquals("200", ecompMdcWrapper.getErrorCode()); + assertEquals("errorCategory", ecompMdcWrapper.getErrorCategory()); + assertNotNull(ecompMdcWrapper.getFqdn()); + assertNotNull(ecompMdcWrapper.getHostAddress()); + assertEquals("targetEntity", ecompMdcWrapper.getTargetEntity()); + assertEquals("targetServiceName", ecompMdcWrapper.getTargetServiceName()); + assertEquals("partnerName", ecompMdcWrapper.getPartnerName()); + assertEquals("auditMsg", ecompMdcWrapper.getAuditMessage()); + assertEquals("supportablityStatusCode", ecompMdcWrapper.getSupportablityStatusCode()); + assertEquals("supportablityAction", ecompMdcWrapper.getSupportablityAction()); + assertEquals("remoteHost", ecompMdcWrapper.getRemoteHost()); + assertEquals("serverIpAddress", ecompMdcWrapper.getServerIpAddress()); + assertEquals("csarUUID", ecompMdcWrapper.getSupportablityCsarUUID()); + assertEquals("csarVersion", ecompMdcWrapper.getSupportablityCsarVersion()); + assertEquals("componentName", ecompMdcWrapper.getSupportablityComponentName()); + assertEquals("componentUUID", ecompMdcWrapper.getSupportablityComponentUUID()); + assertEquals("componentVersion", ecompMdcWrapper.getSupportablityComponentVersion()); + assertEquals("keyInvocationId", ecompMdcWrapper.getKeyInvocationId()); + + ecompMdcWrapper.removePartnerName(); + ecompMdcWrapper.removeSupportablityAction(); + ecompMdcWrapper.removeSupportablityComponentName(); + ecompMdcWrapper.removeSupportablityComponentUUID(); + ecompMdcWrapper.removeSupportablityComponentVersion(); + ecompMdcWrapper.removeSupportablityCsarUUID(); + ecompMdcWrapper.removeSupportablityCsarVersion(); + ecompMdcWrapper.removeSupportablityStatusCode(); + ecompMdcWrapper.removeServiceInstanceId(); + ecompMdcWrapper.removeTargetVirtualEntity(); + + assertNull(MDC.get(PARTNER_NAME)); + assertNull(MDC.get(MDC_SUPPORTABLITY_ACTION)); + assertNull(MDC.get(MDC_SUPPORTABLITY_COMPONENT_NAME)); + assertNull(MDC.get(MDC_SUPPORTABLITY_COMPONENT_UUID)); + assertNull(MDC.get(MDC_SUPPORTABLITY_COMPONENT_VERSION)); + assertNull(MDC.get(MDC_SUPPORTABLITY_CSAR_UUID)); + assertNull(MDC.get(MDC_SUPPORTABLITY_CSAR_VERSION)); + assertNull(MDC.get(MDC_SUPPORTABLITY_STATUS_CODE)); + assertNull(MDC.get(MDC_SERVICE_INSTANCE_ID)); + assertNull(MDC.get(MDC_TARGET_VIRTUAL_ENTITY)); + + } } -- cgit 1.2.3-korg