From e83d137179fa3c532c191f89f9e6cdd53b0778c7 Mon Sep 17 00:00:00 2001 From: xuegao Date: Thu, 25 Mar 2021 16:00:32 +0100 Subject: Improve test coverage Add unit tests to improve test coverage. Issue-ID: SDC-3428 Change-Id: Ifd9e6eb25fa3ec9f4f93d283277574120edff835 Signed-off-by: xuegao --- .../sdc/be/model/ComponentInstanceTest.java | 183 +++++++++++---------- 1 file changed, 92 insertions(+), 91 deletions(-) (limited to 'catalog-model/src') diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceTest.java index c1a9ad8bba..0cb6f15367 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstanceTest.java @@ -20,13 +20,24 @@ package org.openecomp.sdc.be.model; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.CreatedFrom; +import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; +import org.openecomp.sdc.common.log.api.ILogConfiguration; +import java.util.HashMap; import java.util.List; import java.util.Map; +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; + public class ComponentInstanceTest { private ComponentInstance createTestSubject() { @@ -35,127 +46,81 @@ public class ComponentInstanceTest { @Test public void testCtor() throws Exception { - new ComponentInstance(new ComponentInstanceDataDefinition()); + assertNotNull(new ComponentInstance(new ComponentInstanceDataDefinition())); } @Test - public void testGetCapabilities() throws Exception { - ComponentInstance testSubject; - Map> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getCapabilities(); - } - - @Test - public void testSetCapabilities() throws Exception { + public void testCapabilities() throws Exception { ComponentInstance testSubject; Map> capabilities = null; // default test testSubject = createTestSubject(); testSubject.setCapabilities(capabilities); + assertNull(testSubject.getCapabilities()); } @Test - public void testGetRequirements() throws Exception { - ComponentInstance testSubject; - Map> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getRequirements(); - } - - @Test - public void testSetRequirements() throws Exception { + public void testRequirements() throws Exception { ComponentInstance testSubject; Map> requirements = null; // default test testSubject = createTestSubject(); testSubject.setRequirements(requirements); + assertNull(testSubject.getRequirements()); } @Test - public void testGetDeploymentArtifacts() throws Exception { - ComponentInstance testSubject; - Map result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getDeploymentArtifacts(); + public void testDeploymentArtifacts() throws Exception { + ComponentInstance testSubject = createTestSubject(); + Map deploymentArtifacts = null; + testSubject.setDeploymentArtifacts(deploymentArtifacts); + assertNull(testSubject.getDeploymentArtifacts()); } @Test - public void testSafeGetDeploymentArtifacts() throws Exception { - ComponentInstance testSubject; - Map result; + public void testSafeGetDeploymentArtifacts() { + ComponentInstance testSubject = createTestSubject(); + assertEquals(0, testSubject.safeGetDeploymentArtifacts().size()); - // default test - testSubject = createTestSubject(); - result = testSubject.safeGetDeploymentArtifacts(); + Map deploymentArtifacts = new HashMap(); + deploymentArtifacts.put("test", new ArtifactDefinition()); + testSubject.setDeploymentArtifacts(deploymentArtifacts); + assertEquals(1, testSubject.safeGetDeploymentArtifacts().size()); } @Test public void testSafeGetInformationalArtifacts() throws Exception { - ComponentInstance testSubject; - Map result; + ComponentInstance testSubject = createTestSubject(); + assertEquals(0, testSubject.safeGetInformationalArtifacts().size()); - // default test - testSubject = createTestSubject(); - result = testSubject.safeGetInformationalArtifacts(); + Map informationArtifacts = new HashMap(); + informationArtifacts.put("test", new ArtifactDefinition()); + testSubject.setArtifacts(informationArtifacts); + assertNull(testSubject.safeGetInformationalArtifacts()); } - @Test - public void testSetDeploymentArtifacts() throws Exception { - ComponentInstance testSubject; - Map deploymentArtifacts = null; + @Test + public void testSafeGetArtifacts() throws Exception { + ComponentInstance testSubject = createTestSubject(); + assertEquals(0, testSubject.safeGetArtifacts().size()); - // default test - testSubject = createTestSubject(); - testSubject.setDeploymentArtifacts(deploymentArtifacts); - } + Map artifacts = new HashMap(); + artifacts.put("test", new ArtifactDefinition()); + testSubject.setArtifacts(artifacts); + assertEquals(1, testSubject.safeGetArtifacts().size()); + } @Test - public void testGetArtifacts() throws Exception { - ComponentInstance testSubject; - Map result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getArtifacts(); - } - - @Test - public void testSafeGetArtifacts() throws Exception { - ComponentInstance testSubject; - Map result; - - // default test - testSubject = createTestSubject(); - result = testSubject.safeGetArtifacts(); - } - - @Test - public void testSetArtifacts() throws Exception { + public void testArtifacts() throws Exception { ComponentInstance testSubject; Map artifacts = null; // default test testSubject = createTestSubject(); testSubject.setArtifacts(artifacts); - } - - @Test - public void testGetGroupInstances() throws Exception { - ComponentInstance testSubject; - List result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getGroupInstances(); + assertNull(testSubject.getArtifacts()); } @Test @@ -166,29 +131,65 @@ public class ComponentInstanceTest { // default test testSubject = createTestSubject(); testSubject.setGroupInstances(groupInstances); + assertNull(testSubject.getGroupInstances()); } @Test public void testGetActualComponentUid() throws Exception { - ComponentInstance testSubject; - String result; + ComponentInstance testSubject = createTestSubject(); + testSubject.setOriginType(OriginTypeEnum.ServiceSubstitution); + testSubject.setSourceModelUid("sourceModelUid"); + testSubject.setComponentUid("componentUid"); + assertEquals("sourceModelUid", testSubject.getActualComponentUid()); - // default test - testSubject = createTestSubject(); - result = testSubject.getActualComponentUid(); + testSubject.setOriginType(OriginTypeEnum.VFC); + assertEquals("componentUid", testSubject.getActualComponentUid()); } @Test public void testIsArtifactExists() throws Exception { ComponentInstance testSubject; - ArtifactGroupTypeEnum groupType = null; - String artifactLabel = ""; - boolean result; // default test testSubject = createTestSubject(); - result = testSubject.isArtifactExists(groupType, artifactLabel); + assertFalse(testSubject.isArtifactExists(null, "")); + Map deploymentArtifacts = new HashMap(); + deploymentArtifacts.put("test", new ArtifactDefinition()); + testSubject.setDeploymentArtifacts(deploymentArtifacts); + testSubject.setArtifacts(deploymentArtifacts); + assertTrue(testSubject.isArtifactExists(null, "test")); + testSubject = createTestSubject(); - result = testSubject.isArtifactExists(ArtifactGroupTypeEnum.DEPLOYMENT, artifactLabel); + assertFalse(testSubject.isArtifactExists(ArtifactGroupTypeEnum.DEPLOYMENT, "")); + testSubject.setDeploymentArtifacts(deploymentArtifacts); + assertTrue(testSubject.isArtifactExists(ArtifactGroupTypeEnum.DEPLOYMENT, "test")); } + + @Test + public void testAddInterface() throws Exception { + ComponentInstance testSubject = createTestSubject(); + assertNull(testSubject.getInterfaces()); + testSubject.addInterface("test", new InterfaceDefinition()); + assertEquals(1, testSubject.getInterfaces().size()); + } + + @Test + public void testGetComponentMetadataForSupportLog() throws Exception { + ComponentInstance testSubject = createTestSubject(); + testSubject.setName("testName"); + testSubject.setToscaPresentationValue(JsonPresentationFields.VERSION, "1.0"); + testSubject.setSourceModelUuid("sourceModelUuid"); + assertEquals(3, testSubject.getComponentMetadataForSupportLog().size()); + assertEquals("testName", testSubject.getComponentMetadataForSupportLog().get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME)); + assertEquals("1.0", testSubject.getComponentMetadataForSupportLog().get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION)); + assertEquals("sourceModelUuid", testSubject.getComponentMetadataForSupportLog().get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID)); + } + + @Test + public void testIsCreatedFromCsar() throws Exception { + ComponentInstance testSubject = createTestSubject(); + testSubject.setCreatedFrom(CreatedFrom.CSAR); + assertTrue(testSubject.isCreatedFromCsar()); + testSubject.setCreatedFrom(CreatedFrom.UI); + assertFalse(testSubject.isCreatedFromCsar());} } -- cgit 1.2.3-korg