From: Sindhuri.A Date: Fri, 26 Oct 2018 13:33:28 +0000 (+0530) Subject: UT-TopologyTemplateOperation X-Git-Tag: 1.3.2~18 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=d26e62a53f86e70f7a3475c82a39be6b41ee5e7a;p=sdc.git UT-TopologyTemplateOperation Add UT for catalog model TopologyTemplateOperation class Issue-ID: SDC-1775 Change-Id: I4962899dd946edcdeeb2d58c867a9b8d3a1904df Signed-off-by: Sindhuri.A --- diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java index 6193c5d6b9..8bb252ea12 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java @@ -2,6 +2,8 @@ package org.openecomp.sdc.be.model.jsontitan.operations; import com.thinkaurelius.titan.core.TitanVertex; import fj.data.Either; +import org.apache.tinkerpop.gremlin.structure.Direction; +import org.apache.tinkerpop.gremlin.structure.Edge; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -12,17 +14,26 @@ import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty; +import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.model.DistributionStatusEnum; import org.openecomp.sdc.be.model.PolicyDefinition; +import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -68,14 +79,14 @@ public class TopologyTemplateOperationTest { StorageOperationStatus storageOperationStatus = topologyTemplateOperation.updateToscaDataDeepElementsBlockToToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, new MapCapabilityProperty(), ""); assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.NOT_FOUND); } - + @Test public void addPolicyToToscaElementSuccessTest(){ TitanOperationStatus status = TitanOperationStatus.OK; StorageOperationStatus result = addPolicyToToscaElementWithStatus(status); assertThat(result).isEqualTo(StorageOperationStatus.OK); } - + @Test public void addPolicyToToscaElementFailureTest(){ TitanOperationStatus status = TitanOperationStatus.ALREADY_EXIST; @@ -83,6 +94,48 @@ public class TopologyTemplateOperationTest { assertThat(result).isEqualTo(StorageOperationStatus.ENTITY_ALREADY_EXISTS); } + @Test + public void testAssociateOrAddCalcCapReqToComponent() { + StorageOperationStatus result; + GraphVertex graphVertex = new GraphVertex(); + Map calcRequirements = new HashMap<>(); + Map calcCapabilty = new HashMap<>(); + Map calCapabilitiesProps = new HashMap<>(); + addPolicyToToscaElementWithStatus(TitanOperationStatus.OK); + result = topologyTemplateOperation.associateOrAddCalcCapReqToComponent(graphVertex, calcRequirements, calcCapabilty, calCapabilitiesProps); + assertEquals(StorageOperationStatus.OK, result); + } + + @Test + public void testUpdateDistributionStatus() { + Either result; + String uniqueId = "uniqueId"; + User user = new User(); + String userId = "userId"; + user.setUserId(userId); + Iterator edgeIterator = new Iterator() { + @Override + public boolean hasNext() { + return false; + } + + @Override + public Edge next() { + return null; + } + }; + GraphVertex graphVertex = Mockito.mock(GraphVertex.class); + TitanVertex titanVertex = Mockito.mock(TitanVertex.class); + when(graphVertex.getVertex()).thenReturn(titanVertex); + when(titanVertex.edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name())).thenReturn(edgeIterator); + when(titanDao.getVertexByPropertyAndLabel(GraphPropertyEnum.USERID, userId, VertexTypeEnum.USER, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(graphVertex)); + when(titanDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.left(graphVertex)); + when(titanDao.createEdge(graphVertex, graphVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null)).thenReturn(TitanOperationStatus.OK); + when(titanDao.updateVertex(graphVertex)).thenReturn(Either.left(graphVertex)); + result = topologyTemplateOperation.updateDistributionStatus(uniqueId, user, DistributionStatusEnum.DISTRIBUTED); + assertThat(result.isLeft()); + } + @SuppressWarnings("unchecked") private StorageOperationStatus addPolicyToToscaElementWithStatus(TitanOperationStatus status) { GraphVertex componentV = new GraphVertex(); @@ -104,5 +157,5 @@ public class TopologyTemplateOperationTest { when(titanDao.createEdge(any(TitanVertex.class), any(TitanVertex.class), any(EdgeLabelEnum.class), any(HashMap.class))).thenReturn(status); return topologyTemplateOperation.addPolicyToToscaElement(componentV, policy, counter); } - + }