From 3d5114a2028a6728af8825daa003f1c9a596deba Mon Sep 17 00:00:00 2001 From: "Sindhuri.A" Date: Mon, 15 Oct 2018 22:12:55 +0530 Subject: UT-asdctool ArtifactUuidFix UT for asdctool impl ArtifactUuidFix class Issue-ID: SDC-1775 Change-Id: Idcf66bf73cdf013d615f4b7967197c3b99ee70e2 Signed-off-by: Sindhuri.A --- .../sdc/asdctool/impl/ArtifactUuidFixTest.java | 237 +++++++++++++++------ 1 file changed, 170 insertions(+), 67 deletions(-) (limited to 'asdctool/src') diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFixTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFixTest.java index 3fce1b6d66..891946d26c 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFixTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFixTest.java @@ -1,92 +1,195 @@ package org.openecomp.sdc.asdctool.impl; +import com.thinkaurelius.titan.core.TitanVertex; +import fj.data.Either; import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.dao.jsongraph.TitanDao; +import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.Component; - +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; +import org.openecomp.sdc.be.resources.data.ESArtifactData; +import org.openecomp.sdc.common.api.ArtifactTypeEnum; +import org.openecomp.sdc.common.api.Constants; + +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.ArrayList; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; +@RunWith(MockitoJUnitRunner.class) public class ArtifactUuidFixTest { + @InjectMocks + private ArtifactUuidFix test; - private ArtifactUuidFix createTestSubject() { - return new ArtifactUuidFix(); - } + @Mock + private TitanDao titanDao; + + @Mock + private TitanVertex vertex; - @Test(expected=NullPointerException.class) - public void testDoFix() throws Exception { - ArtifactUuidFix testSubject; + @Mock + ToscaOperationFacade toscaOperationFacade; + + @Mock + ArtifactCassandraDao artifactCassandraDao; + + @Mock + Service service; + + @Test + public void testDoFixVf() { String fixComponent = ""; String runMode = ""; + String uniqueId = "uniqueId"; boolean result; - - // test 1 - testSubject = createTestSubject(); fixComponent = "vf_only"; - result = testSubject.doFix(fixComponent, runMode); - Assert.assertEquals(false, result); - - // test 2 - testSubject = createTestSubject(); - runMode = "service_vf"; - result = testSubject.doFix(fixComponent, runMode); - Assert.assertEquals(false, result); - - // test 3 - testSubject = createTestSubject(); - runMode = "fix"; - result = testSubject.doFix(fixComponent, runMode); - Assert.assertEquals(false, result); - - // test 4 - testSubject = createTestSubject(); - runMode = "fix"; - result = testSubject.doFix(fixComponent, runMode); - Assert.assertEquals(false, result); - - // test 5 - testSubject = createTestSubject(); - runMode = "fix_only_services"; - result = testSubject.doFix(fixComponent, runMode); - Assert.assertEquals(false, result); + Map hasProps1 = new HashMap<>(); + hasProps1.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + List list = new ArrayList<>(); + GraphVertex graphVertex = new GraphVertex(); + graphVertex.setVertex(vertex); + graphVertex.setUniqueId(uniqueId); + graphVertex.setMetadataProperties(hasProps1); + list.add(graphVertex); + when(titanDao.getByCriteria(VertexTypeEnum.NODE_TYPE, hasProps1)).thenReturn(Either.left(list)); + + Map hasProps2 = new HashMap<>(); + hasProps2.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps2.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF); + hasProps2.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + when(titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps2)).thenReturn(Either.left(list)); + + Map hasProps3 = new HashMap<>(); + hasProps3.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); + hasProps3.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + when(titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps3)).thenReturn(Either.left(list)); + + Map hasProps = new HashMap<>(); + hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF.name()); + Map hasNotProps = new HashMap<>(); + hasNotProps.put(GraphPropertyEnum.IS_DELETED, true); + when(titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps, hasNotProps, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(list)); + Resource resource = new Resource(); + resource.setName(uniqueId); + Map deployArtifact = new HashMap<>(); + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + artifactDefinition.setArtifactType(ArtifactTypeEnum.VF_MODULES_METADATA.getType()); + artifactDefinition.setUniqueId("one.two"); + artifactDefinition.setArtifactUUID("one.two"); + deployArtifact.put("two", artifactDefinition); + resource.setDeploymentArtifacts(deployArtifact); + List groups = new ArrayList<>(); + GroupDefinition groupDefinition = new GroupDefinition(); + groupDefinition.setType(Constants.DEFAULT_GROUP_VF_MODULE); + List artifacts = new ArrayList<>(); + artifacts.add("one.two"); + groupDefinition.setArtifacts(artifacts); + groupDefinition.setArtifactsUuid(artifacts); + groups.add(groupDefinition); + resource.setGroups(groups); + when(toscaOperationFacade.getToscaElement(graphVertex.getUniqueId())).thenReturn(Either.left(resource)); + List serviceList = new ArrayList<>(); + serviceList.add(service); + + result = test.doFix(fixComponent, runMode); + assertEquals(true, result); } @Test - public void testDoFixTosca() throws Exception { - ArtifactUuidFix testSubject; - Map> nodeToFix = null; - Map> vfToFix = null; - Map> serviceToFix = null; + public void testDoFixServiceVf() + { + String fixComponent = "distributed_only"; + String runMode = "service_vf"; + String uniqueId = "uniqueId"; boolean result; - - // default test - testSubject = createTestSubject(); - } - - @Test(expected=NullPointerException.class) - public void testGetVerticesToValidate() throws Exception { - ArtifactUuidFix testSubject; - VertexTypeEnum type = null; - Map hasProps = null; - Map> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getVerticesToValidate(type, hasProps); + Map hasProps = new HashMap<>(); + hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); + hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + hasProps.put(GraphPropertyEnum.DISTRIBUTION_STATUS, DistributionStatusEnum.DISTRIBUTED.name()); + Map hasNotProps = new HashMap<>(); + hasNotProps.put(GraphPropertyEnum.IS_DELETED, true); + Map hasProps1 = new HashMap<>(); + hasProps1.put(GraphPropertyEnum.NAME, "name"); + List list = new ArrayList<>(); + GraphVertex graphVertex = new GraphVertex(); + graphVertex.setUniqueId(uniqueId); + graphVertex.setMetadataProperties(hasProps1); + list.add(graphVertex); + + Map deploymentArtifacts = new HashMap<>(); + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + artifactDefinition.setArtifactType(ArtifactTypeEnum.VF_MODULES_METADATA.name()); + artifactDefinition.setEsId("esID"); + deploymentArtifacts.put("1",artifactDefinition); + List groupInstances = new ArrayList<>(); + GroupInstance groupInstance = new GroupInstance(); + groupInstances.add(groupInstance); + + ComponentInstance componentInstance = new ComponentInstance(); + componentInstance.setDeploymentArtifacts(deploymentArtifacts); + componentInstance.setGroupInstances(groupInstances); + + Service service = new Service(); + service.setUniqueId(uniqueId); + List componentInstances = new ArrayList<>(); + componentInstances.add(componentInstance); + service.setComponentInstances(componentInstances); + + when(titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps, hasNotProps, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(list)); + when(toscaOperationFacade.getToscaElement(ArgumentMatchers.eq(graphVertex.getUniqueId()),any(ComponentParametersView.class))) + .thenReturn(Either.left(service)); + byte[] payload = "value".getBytes(); + + ESArtifactData esArtifactData =new ESArtifactData(); + esArtifactData.setDataAsArray(payload); + Either artifactfromESres = Either.left(esArtifactData); + when(artifactCassandraDao.getArtifact(anyString())).thenReturn(artifactfromESres); + result = test.doFix(fixComponent, runMode); + assertEquals(false, result); } - @Test(expected=NullPointerException.class) - public void testValidateTosca() throws Exception { - ArtifactUuidFix testSubject; - Map> vertices = null; - Map> compToFix = null; - String name = ""; + @Test + public void testDoFixOnly() + { + String runMode = "fix_only_services"; + String fixComponent = ""; boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.validateTosca(vertices, compToFix, name); + Map hasProps1 = new HashMap<>(); + hasProps1.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + List list = new ArrayList<>(); + GraphVertex graphVertex = new GraphVertex(); + graphVertex.setVertex(vertex); + graphVertex.setUniqueId("uniqueId"); + graphVertex.setMetadataProperties(hasProps1); + graphVertex.addMetadataProperty(GraphPropertyEnum.NAME, "name"); + list.add(graphVertex); + Map hasProps = new HashMap<>(); + hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); + Map hasNotProps = new HashMap<>(); + hasNotProps.put(GraphPropertyEnum.IS_DELETED, true); + when(titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps, hasNotProps, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(list)); + result = test.doFix(fixComponent, runMode); + assertEquals(false,result); } } \ No newline at end of file -- cgit 1.2.3-korg