From: xuegao Date: Thu, 25 Mar 2021 09:31:08 +0000 (+0100) Subject: Improve test coverage X-Git-Tag: 1.9.0~64 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F00%2F119800%2F4;p=sdc.git Improve test coverage Add unit tests to improve test coverage. Issue-ID: SDC-3428 Change-Id: I47da0decd6b6df93ace68b2af586b255ef0b792e Signed-off-by: xuegao --- diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java index 393f678af3..79166e552c 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.asdctool.impl.validator; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import org.openecomp.sdc.asdctool.impl.validator.executor.IArtifactValidatorExecutor; import org.openecomp.sdc.asdctool.impl.validator.executor.NodeToscaArtifactsValidatorExecutor; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -29,13 +30,39 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade import java.util.ArrayList; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.*; public class ArtifactToolBLTest { @Test - public void testValidateAll() { + public void testValidateAllOK() { + List validators = new ArrayList<>(); + NodeToscaArtifactsValidatorExecutor executor = Mockito.mock(NodeToscaArtifactsValidatorExecutor.class); + when(executor.executeValidations(Mockito.anyString())).thenReturn(true); + validators.add(executor); + ArtifactToolBL testSubject = new ArtifactToolBL(validators); + + verify(executor, Mockito.times(0)).executeValidations(Mockito.anyString()); + assertTrue(testSubject.validateAll("")); + } + + @Test + public void testValidateAllNOK() { + List validators = new ArrayList<>(); + NodeToscaArtifactsValidatorExecutor executor = Mockito.mock(NodeToscaArtifactsValidatorExecutor.class); + when(executor.executeValidations(Mockito.anyString())).thenReturn(false); + validators.add(executor); + ArtifactToolBL testSubject = new ArtifactToolBL(validators); + + verify(executor, Mockito.times(0)).executeValidations(Mockito.anyString()); + assertFalse(testSubject.validateAll("")); + } + + @Test + public void testValidateAllException() { JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java index b62be60594..529a9b6768 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java @@ -21,33 +21,60 @@ package org.openecomp.sdc.asdctool.impl.validator; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + import org.openecomp.sdc.asdctool.impl.validator.executor.TopologyTemplateValidatorExecutor; import org.openecomp.sdc.asdctool.impl.validator.executor.ValidatorExecutor; import org.openecomp.sdc.asdctool.impl.validator.report.Report; +import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; import java.util.ArrayList; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; +import static org.junit.jupiter.api.Assertions.*; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.makeTxtFile; import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriterTestFactory.makeConsoleWriter; public class ValidationToolBLTest { + private List validators = new ArrayList<>(); + private Report report = Report.make(); + private ValidatorExecutor executor = Mockito.mock(ValidatorExecutor.class); + private ReportFile.TXTFile file= makeTxtFile(makeConsoleWriter()); + @Test - public void testValidateAll() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + public void testValidateAllOK() { + when(executor.executeValidations(report, file)).thenReturn(true); + validators.add(executor); + ValidationToolBL testSubject = new ValidationToolBL(validators); + + verify(executor, Mockito.times(0)).executeValidations(report, file); + assertTrue(testSubject.validateAll(report, file)); + } - List validators = new ArrayList<>(); + @Test + public void testValidateAllNOK() { + when(executor.executeValidations(report, file)).thenReturn(false); + validators.add(executor); + ValidationToolBL testSubject = new ValidationToolBL(validators); + + verify(executor, Mockito.times(0)).executeValidations(report, file); + assertFalse(testSubject.validateAll(report, file)); + } + + @Test + public void testValidateAll() { + JanusGraphDao janusGraphDaoMock = Mockito.mock(JanusGraphDao.class); validators.add(TopologyTemplateValidatorExecutor.serviceValidatorExecutor(janusGraphDaoMock)); ValidationToolBL testSubject = new ValidationToolBL(validators); - Report report = Report.make(); assertThrows( NullPointerException.class, - () -> testSubject.validateAll(report, makeTxtFile(makeConsoleWriter())) + () -> testSubject.validateAll(report, file) ); } } diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabelsTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabelsTest.java new file mode 100644 index 0000000000..c5723b1007 --- /dev/null +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabelsTest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.be.dao.neo4j; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +public class GraphEdgeLabelsTest { + @Test + public void testGetAllProperties() throws Exception { + assertEquals(55, GraphEdgeLabels.getAllProperties().size()); + } + + @Test + public void testGetByName() throws Exception { + assertNotNull(GraphEdgeLabels.getByName("STATE")); + assertNull(GraphEdgeLabels.getByName("state")); + } +} diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstInputsMapTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstInputsMapTest.java index d256cd15c8..92026dd211 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstInputsMapTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstInputsMapTest.java @@ -20,14 +20,17 @@ package org.openecomp.sdc.be.model; -import org.junit.Assert; -import org.junit.Test; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class ComponentInstInputsMapTest { private ComponentInstInputsMap createTestSubject() { @@ -35,85 +38,121 @@ public class ComponentInstInputsMapTest { } @Test - public void testGetComponentInstanceInputsMap() throws Exception { - ComponentInstInputsMap testSubject; - Map> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getComponentInstanceInputsMap(); - } - - @Test - public void testSetComponentInstanceInputsMap() throws Exception { - ComponentInstInputsMap testSubject; + public void testComponentInstanceInputsMap() { + ComponentInstInputsMap testSubject = createTestSubject(); Map> componentInstanceInputsMap = null; // default test - testSubject = createTestSubject(); testSubject.setComponentInstanceInputsMap(componentInstanceInputsMap); - } - @Test - public void testGetComponentInstanceProperties() throws Exception { - ComponentInstInputsMap testSubject; - Map> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getComponentInstanceProperties(); + Map> result = testSubject.getComponentInstanceInputsMap(); + assertEquals(0, result.size()); } @Test - public void testSetComponentInstancePropInput() throws Exception { - ComponentInstInputsMap testSubject; + public void testComponentInstanceProperties() { + ComponentInstInputsMap testSubject = createTestSubject(); Map> componentInstanceProperties = new HashMap<>(); - - // default test - testSubject = createTestSubject(); testSubject.setComponentInstancePropertiesToPolicies(componentInstanceProperties); + Map> result = testSubject.getComponentInstanceProperties(); + assertEquals(0, result.size()); } @Test - public void testResolvePropertiesToDeclareEmpty() throws Exception { + public void testResolvePropertiesToDeclareEmpty() { ComponentInstInputsMap testSubject; - Map> componentInstanceProperties = null; // default test testSubject = createTestSubject(); - try { + assertThrows(IllegalStateException.class, () -> { testSubject.resolvePropertiesToDeclare(); - } catch (Exception e) { - Assert.assertTrue(e.getClass() == IllegalStateException.class); - } + }); } @Test - public void testResolvePropertiesToDeclare() throws Exception { + public void testResolvePropertiesToDeclare() { ComponentInstInputsMap testSubject; - Map> componentInstanceProperties = null; - Map> inputs = new HashMap<>(); - inputs.put("mock", new LinkedList<>()); + inputs.put("test", new LinkedList<>()); // default test testSubject = createTestSubject(); testSubject.setComponentInstanceInputsMap(inputs); - testSubject.resolvePropertiesToDeclare(); + Pair> result = testSubject.resolvePropertiesToDeclare(); + assertEquals(0, result.getValue().size()); + testSubject = createTestSubject(); testSubject.setComponentInstancePropertiesToPolicies(inputs); - testSubject.resolvePropertiesToDeclare(); + result = testSubject.resolvePropertiesToDeclare(); + assertEquals(0, result.getValue().size()); + testSubject = createTestSubject(); testSubject.setPolicyProperties(inputs); - testSubject.resolvePropertiesToDeclare(); + result = testSubject.resolvePropertiesToDeclare(); + assertEquals(0, result.getValue().size()); + + testSubject = createTestSubject(); + testSubject.setComponentInstancePropInput(inputs); + result = testSubject.resolvePropertiesToDeclare(); + assertEquals(0, result.getValue().size()); + + testSubject = createTestSubject(); + testSubject.setServiceProperties(inputs); + result = testSubject.resolvePropertiesToDeclare(); + assertEquals(0, result.getValue().size()); + + testSubject = createTestSubject(); + testSubject.setGroupProperties(inputs); + result = testSubject.resolvePropertiesToDeclare(); + assertEquals(0, result.getValue().size()); + + testSubject = createTestSubject(); + testSubject.setComponentPropertiesToPolicies(inputs); + result = testSubject.resolvePropertiesToDeclare(); + assertEquals(0, result.getValue().size()); } - + @Test - public void testGetPolicyProperties() throws Exception { - ComponentInstInputsMap testSubject; - Map> componentInstanceProperties = null; + public void testPolicyProperties() { + ComponentInstInputsMap testSubject = createTestSubject(); + Map> policyProperties = new HashMap<>(); + testSubject.setPolicyProperties(policyProperties); + Map> result = testSubject.getPolicyProperties(); + assertEquals(0, result.size()); + } - // default test - testSubject = createTestSubject(); - testSubject.getPolicyProperties(); + @Test + public void testServiceProperties() { + ComponentInstInputsMap testSubject = createTestSubject(); + Map> serviceProperties = new HashMap<>(); + testSubject.setServiceProperties(serviceProperties); + Map> result = testSubject.getServiceProperties(); + assertEquals(0, result.size()); + } + + @Test + public void testGroupProperties() { + ComponentInstInputsMap testSubject = createTestSubject(); + Map> groupProperties = new HashMap<>(); + testSubject.setGroupProperties(groupProperties); + Map> result = testSubject.getGroupProperties(); + assertEquals(0, result.size()); + } + + @Test + public void testComponentPropertiesToPolicies() { + ComponentInstInputsMap testSubject = createTestSubject(); + Map> componentPropertiesToPolicies = new HashMap<>(); + testSubject.setComponentPropertiesToPolicies(componentPropertiesToPolicies); + Map> result = testSubject.getComponentPropertiesToPolicies(); + assertEquals(0, result.size()); + } + + @Test + public void testComponentInstancePropertiesToPolicies() { + ComponentInstInputsMap testSubject = createTestSubject(); + Map> componentInstancePropertiesToPolicies = new HashMap<>(); + testSubject.setComponentInstancePropertiesToPolicies(componentInstancePropertiesToPolicies); + Map> result = testSubject.getComponentInstancePropertiesToPolicies(); + assertEquals(0, result.size()); } } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/VersionUtilTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/VersionUtilTest.java new file mode 100644 index 0000000000..89faa3afba --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/VersionUtilTest.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.model.tosca; + +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.model.tosca.version.ApplicationVersionException; +import org.openecomp.sdc.be.model.tosca.version.Version; + +import static org.junit.jupiter.api.Assertions.*; + + +public class VersionUtilTest { + + @Test + public void testIsSnapshot() { + assertTrue(VersionUtil.isSnapshot("test_snapshot")); + assertTrue(VersionUtil.isSnapshot("test_SNAPSHOT")); + assertFalse(VersionUtil.isSnapshot("test_SNAP")); + } + + @Test + public void testIsValid() { + assertTrue(VersionUtil.isValid("1.0.2")); + assertTrue(VersionUtil.isValid("1.0-2")); + assertFalse(VersionUtil.isValid("1!2")); + } + + @Test + public void testParseVersion() { + Version ver1 = VersionUtil.parseVersion("1.0.2"); + assertEquals(1, ver1.getMajorVersion()); + assertEquals(0, ver1.getMinorVersion()); + assertEquals(2, ver1.getIncrementalVersion()); + + Version ver2 = VersionUtil.parseVersion("1.0-2"); + assertEquals(1, ver2.getMajorVersion()); + assertEquals(0, ver2.getMinorVersion()); + assertEquals(2, ver2.getBuildNumber()); + + assertThrows( + ApplicationVersionException.class, + () -> VersionUtil.parseVersion("1!2") + ); + } + + @Test + public void testCompare() { + assertEquals(-1, VersionUtil.compare("1.0.2", "1.0.3")); + assertEquals(0, VersionUtil.compare("1.0.2", "1.0.2")); + assertEquals(1, VersionUtil.compare("1.0.2", "0.0.5")); + } +} diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/config/EcompErrorConfigurationTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/config/EcompErrorConfigurationTest.java index 5c7865e879..1cacd7a32b 100644 --- a/common-app-api/src/test/java/org/openecomp/sdc/common/config/EcompErrorConfigurationTest.java +++ b/common-app-api/src/test/java/org/openecomp/sdc/common/config/EcompErrorConfigurationTest.java @@ -22,14 +22,15 @@ package org.openecomp.sdc.common.config; -import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.HashMap; -import org.junit.Before; -import org.junit.Test; import java.util.Map; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.common.api.ConfigurationSource; import org.openecomp.sdc.common.impl.ExternalConfiguration; @@ -42,7 +43,7 @@ public class EcompErrorConfigurationTest { private ConfigurationManager configurationManager; - @Before + @BeforeEach public void loadEcompErrorConfiguration() { String appConfigDir = "src/test/resources/config/common"; ConfigurationSource configurationSource = @@ -76,20 +77,62 @@ public class EcompErrorConfigurationTest { //when String result = ecompErrorConfiguration.toString(); //then - assertThat(result, containsString( + assertTrue(result.contains( "EcompErrorConfiguration [errors={BeRestApiGeneralError=org.openecomp.sdc.common.config.EcompErrorInfo@")); } @Test public void testValidateEcompoErrorInfo() { - //given + Map errors = new HashMap(); EcompErrorInfo ecompErrorInfo = ecompErrorConfiguration.getEcompErrorInfo("BeInitializationError"); - Map errors = new HashMap<>(); errors.put("BeInitializationError", ecompErrorInfo); //when ecompErrorConfiguration.setErrors(errors); //then - assertEquals(ecompErrorConfiguration.getErrors(), errors); + assertEquals(errors, ecompErrorConfiguration.getErrors()); + + // error info is null + errors.clear(); + ecompErrorConfiguration.setErrors(new HashMap()); + errors.put("error1", null); + ecompErrorConfiguration.setErrors(errors); + assertEquals(0, ecompErrorConfiguration.getErrors().size()); + assertNull(ecompErrorConfiguration.getEcompErrorInfo("error1")); + errors.clear(); + + // type is null or invalid + EcompErrorInfo errorInfo = new EcompErrorInfo(); + errors.put("error1", errorInfo); + ecompErrorConfiguration.setErrors(errors); + assertEquals(0, ecompErrorConfiguration.getErrors().size()); + errorInfo.setType("type"); + ecompErrorConfiguration.setErrors(errors); + assertEquals(0, ecompErrorConfiguration.getErrors().size()); + + // severity is null or invalid + errorInfo.setType(EcompErrorConfiguration.EcompErrorType.CONFIG_ERROR.name()); + ecompErrorConfiguration.setErrors(errors); + assertEquals(0, ecompErrorConfiguration.getErrors().size()); + errorInfo.setSeverity("severity"); + ecompErrorConfiguration.setErrors(errors); + assertEquals(0, ecompErrorConfiguration.getErrors().size()); + + // alarmSeverify is null or invalid + errorInfo.setSeverity(EcompErrorConfiguration.EcompErrorSeverity.INFO.name()); + ecompErrorConfiguration.setErrors(errors); + assertEquals(0, ecompErrorConfiguration.getErrors().size()); + errorInfo.setAlarmSeverity("alarmSeverify"); + ecompErrorConfiguration.setErrors(errors); + assertEquals(0, ecompErrorConfiguration.getErrors().size()); + + // code is null or invalid + errorInfo.setAlarmSeverity(EcompErrorConfiguration.EcompAlarmSeverity.CRITICAL.name()); + ecompErrorConfiguration.setErrors(errors); + assertEquals(0, ecompErrorConfiguration.getErrors().size()); + errorInfo.setCode("ASDC_0001"); + ecompErrorConfiguration.setErrors(errors); + assertEquals(0, ecompErrorConfiguration.getErrors().size()); + } } 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)); + + } } diff --git a/common-be/src/test/java/org/openecomp/sdc/be/csar/security/Sha256WithRsaCmsContentSignerTest.java b/common-be/src/test/java/org/openecomp/sdc/be/csar/security/Sha256WithRsaCmsContentSignerTest.java index 2f0031d6e1..c8f1c68037 100644 --- a/common-be/src/test/java/org/openecomp/sdc/be/csar/security/Sha256WithRsaCmsContentSignerTest.java +++ b/common-be/src/test/java/org/openecomp/sdc/be/csar/security/Sha256WithRsaCmsContentSignerTest.java @@ -19,10 +19,6 @@ package org.openecomp.sdc.be.csar.security; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - import java.io.File; import java.io.IOException; import java.net.URL; @@ -48,6 +44,11 @@ import org.openecomp.sdc.be.csar.security.api.CertificateReader; import org.openecomp.sdc.be.csar.security.api.PrivateKeyReader; import org.openecomp.sdc.be.csar.security.exception.CmsSignatureException; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + class Sha256WithRsaCmsContentSignerTest { private Sha256WithRsaCmsContentSigner cmsContentSigner; @@ -84,6 +85,21 @@ class Sha256WithRsaCmsContentSignerTest { (X509Certificate) certificate)); } + @Test + void formatToPemSignatureTest() throws OperatorCreationException, CMSException, IOException, CmsSignatureException { + final File certFile = getResourceFile(certFilesPath.resolve("realCert1.cert")); + final File keyFile = getResourceFile(certFilesPath.resolve("realCert1.key")); + final File fileToSign = getResourceFile(testFilesPath.resolve("fileToSign.txt")); + final Key privateKey = privateKeyReader.loadPrivateKey(keyFile); + final Certificate certificate = certificateReader.loadCertificate(certFile); + final byte[] actualSignatureBytes = cmsContentSigner + .signData(Files.readAllBytes(fileToSign.toPath()), certificate, privateKey); + + assertNotNull(cmsContentSigner.formatToPemSignature(actualSignatureBytes)); + assertThrows(CmsSignatureException.class, + () -> cmsContentSigner.formatToPemSignature(new byte[10])); + } + @Test void signDataInvalidCertAndKeyTest() { assertThrows(CmsSignatureException.class, diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListRequirementDataDefinitionTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListRequirementDataDefinitionTest.java index 4001599277..b6862393e0 100644 --- a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListRequirementDataDefinitionTest.java +++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListRequirementDataDefinitionTest.java @@ -20,11 +20,12 @@ package org.openecomp.sdc.be.datatypes.elements; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertEquals; public class MapListRequirementDataDefinitionTest { @@ -33,26 +34,16 @@ public class MapListRequirementDataDefinitionTest { return new MapListRequirementDataDefinition(map); } - - @Test - public void testGetMapToscaDataDefinition() throws Exception { - MapListRequirementDataDefinition testSubject; - Map result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getMapToscaDataDefinition(); - } - - @Test public void testAdd() throws Exception { - MapListRequirementDataDefinition testSubject; - String key = ""; + MapListRequirementDataDefinition testSubject = new MapListRequirementDataDefinition(); RequirementDataDefinition value = null; - // default test - testSubject = createTestSubject(); - testSubject.add(key, value); + testSubject.add("key1", value); + testSubject.add("key2", value); + testSubject.add("key2", value); + Map result = testSubject.getMapToscaDataDefinition(); + assertEquals(2, result.size()); + assertEquals(2, result.get("key2").getListToscaDataDefinition().size()); } } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/to/UnifiedCompositionTo.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/to/UnifiedCompositionTo.java index 30c89accd0..6ac12a0642 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/to/UnifiedCompositionTo.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/composition/to/UnifiedCompositionTo.java @@ -16,11 +16,18 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.to; import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; import org.onap.sdc.tosca.datatypes.model.NodeTemplate; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionData; +@Getter +@Setter +@AllArgsConstructor public class UnifiedCompositionTo { private ServiceTemplate serviceTemplate; @@ -28,53 +35,4 @@ public class UnifiedCompositionTo { private List unifiedCompositionDataList; private TranslationContext context; private NodeTemplate nodeTemplate; - - public UnifiedCompositionTo(ServiceTemplate serviceTemplate, ServiceTemplate substitutionServiceTemplate, - List unifiedCompositionDataList, TranslationContext context, NodeTemplate nodeTemplate) { - this.serviceTemplate = serviceTemplate; - this.substitutionServiceTemplate = substitutionServiceTemplate; - this.unifiedCompositionDataList = unifiedCompositionDataList; - this.context = context; - this.nodeTemplate = nodeTemplate; - } - - public ServiceTemplate getServiceTemplate() { - return serviceTemplate; - } - - public void setServiceTemplate(ServiceTemplate serviceTemplate) { - this.serviceTemplate = serviceTemplate; - } - - public ServiceTemplate getSubstitutionServiceTemplate() { - return substitutionServiceTemplate; - } - - public void setSubstitutionServiceTemplate(ServiceTemplate substitutionServiceTemplate) { - this.substitutionServiceTemplate = substitutionServiceTemplate; - } - - public List getUnifiedCompositionDataList() { - return unifiedCompositionDataList; - } - - public void setUnifiedCompositionDataList(List unifiedCompositionDataList) { - this.unifiedCompositionDataList = unifiedCompositionDataList; - } - - public TranslationContext getContext() { - return context; - } - - public void setContext(TranslationContext context) { - this.context = context; - } - - public NodeTemplate getNodeTemplate() { - return nodeTemplate; - } - - public void setNodeTemplate(NodeTemplate nodeTemplate) { - this.nodeTemplate = nodeTemplate; - } }