UT-TopologyTemplateOperation 10/71310/3
authorSindhuri.A <arcot.sindhuri@huawei.com>
Fri, 26 Oct 2018 13:33:28 +0000 (19:03 +0530)
committerMichael Lando <michael.lando@intl.att.com>
Mon, 29 Oct 2018 18:10:25 +0000 (18:10 +0000)
Add UT for catalog model TopologyTemplateOperation class

Issue-ID: SDC-1775

Change-Id: I4962899dd946edcdeeb2d58c867a9b8d3a1904df
Signed-off-by: Sindhuri.A <arcot.sindhuri@huawei.com>
catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java

index 6193c5d..8bb252e 100644 (file)
@@ -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);
     }
-    
+
 }