summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSindhuri.A <arcot.sindhuri@huawei.com>2018-10-26 19:03:28 +0530
committerMichael Lando <michael.lando@intl.att.com>2018-10-29 18:10:25 +0000
commitd26e62a53f86e70f7a3475c82a39be6b41ee5e7a (patch)
tree8fc0edc3289e8942628757c110b67b73e86d5aad
parenteaefd11b8d0e3cedd50fca90c1deb85034581157 (diff)
UT-TopologyTemplateOperation
Add UT for catalog model TopologyTemplateOperation class Issue-ID: SDC-1775 Change-Id: I4962899dd946edcdeeb2d58c867a9b8d3a1904df Signed-off-by: Sindhuri.A <arcot.sindhuri@huawei.com>
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java59
1 files changed, 56 insertions, 3 deletions
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<String, MapListRequirementDataDefinition> calcRequirements = new HashMap<>();
+ Map<String, MapListCapabilityDataDefinition> calcCapabilty = new HashMap<>();
+ Map<String, MapCapabilityProperty> calCapabilitiesProps = new HashMap<>();
+ addPolicyToToscaElementWithStatus(TitanOperationStatus.OK);
+ result = topologyTemplateOperation.associateOrAddCalcCapReqToComponent(graphVertex, calcRequirements, calcCapabilty, calCapabilitiesProps);
+ assertEquals(StorageOperationStatus.OK, result);
+ }
+
+ @Test
+ public void testUpdateDistributionStatus() {
+ Either<GraphVertex, StorageOperationStatus> result;
+ String uniqueId = "uniqueId";
+ User user = new User();
+ String userId = "userId";
+ user.setUserId(userId);
+ Iterator<Edge> edgeIterator = new Iterator<Edge>() {
+ @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);
}
-
+
}