aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
authorSindhuri.A <arcot.sindhuri@huawei.com>2018-11-16 19:26:33 +0530
committerTal Gitelman <tal.gitelman@att.com>2018-11-19 17:27:41 +0000
commitaeda7a05caa864a935ccd02028f0bba5801d6736 (patch)
tree2f1868067cd8ce7698656588af11466403cbdd08 /catalog-model/src
parentc46afec3bec649979b1753a057e9639f90306f5f (diff)
UT-enhance NodeTemplateOperationTest4
UT for catalog model NodeTemplateOperation class Issue-ID: SDC-1775 Change-Id: Ib7907643e19264d94bda7cf04f4ad72b410eac42 Signed-off-by: Sindhuri.A <arcot.sindhuri@huawei.com> (cherry picked from commit 9884dc7f6323217b71f29797c155e24d68069162)
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperationTest.java203
1 files changed, 106 insertions, 97 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperationTest.java
index febf1297cc..bddebea630 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperationTest.java
@@ -31,20 +31,26 @@ package org.openecomp.sdc.be.model.jsontitan.operations;
import com.google.common.collect.Lists;
import fj.data.Either;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
-import org.openecomp.sdc.be.config.Configuration;
+import org.mockito.junit.MockitoJUnitRunner;
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.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.*;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
@@ -56,9 +62,11 @@ import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
+@RunWith(MockitoJUnitRunner.class)
public class NodeTemplateOperationTest extends ModelTestBase {
private final static String COMPONENT_ID = "componentId";
@@ -79,9 +87,15 @@ public class NodeTemplateOperationTest extends ModelTestBase {
private static RequirementDataDefinition requirement;
private static RequirementCapabilityRelDef relation;
- private static TitanDao titanDao;
+ @InjectMocks
private static NodeTemplateOperation operation;
+ @Mock
+ private static TitanDao titanDao;
+
+ @Mock
+ private static TopologyTemplateOperation topologyTemplateOperation;
+
@BeforeClass
public static void setup() {
init();
@@ -152,79 +166,27 @@ public class NodeTemplateOperationTest extends ModelTestBase {
assertTrue(result.isRight());
assertSame(result.right().value(), StorageOperationStatus.NOT_FOUND);
}
-
- private static void buildRequirementDataDefinition() {
- buildRequirement();
- fulfilledRequirement = new HashMap<>();
- MapListRequirementDataDefinition mapListRequirementDataDefinition = new MapListRequirementDataDefinition();
- mapListRequirementDataDefinition.add(requirement.getCapability(), requirement);
- fulfilledRequirement.put(FROM_INSTANCE_ID, mapListRequirementDataDefinition);
-
- }
-
- private static void buildRequirement() {
- requirement = new RequirementDataDefinition();
- requirement.setOwnerId(REQUIREMENT_OWNER_ID);
- requirement.setUniqueId(REQUIREMENT_UID);
- requirement.setName(REQUIREMENT_NAME);
- requirement.setRelationship(RELATIONSHIP_TYPE);
- }
-
- private static void buildCapabiltyDataDefinition() {
- buildCapability();
- fulfilledCapability = new HashMap<>();
- MapListCapabilityDataDefinition mapListCapabiltyDataDefinition = new MapListCapabilityDataDefinition();
- mapListCapabiltyDataDefinition.add(capability.getType(), capability);
- fulfilledCapability.put(TO_INSTANCE_ID, mapListCapabiltyDataDefinition);
- }
-
- private static void buildCapability() {
- capability = new CapabilityDataDefinition();
- capability.setOwnerId(CAPABILITY_OWNER_ID);
- capability.setUniqueId(CAPABILITY_UID);
- capability.setName(CAPABILITY_NAME);
- }
-
- private static void buildRelation() {
- relation = new RequirementCapabilityRelDef();
- CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
- RelationshipInfo relationInfo = new RelationshipInfo();
- relationInfo.setId(RELATION_ID);
- relationship.setRelation(relationInfo);
-
- relation.setRelationships(Lists.newArrayList(relationship));
- relation.setToNode(TO_INSTANCE_ID);
- relation.setFromNode(FROM_INSTANCE_ID);
-
- relationInfo.setCapabilityOwnerId(CAPABILITY_OWNER_ID);
- relationInfo.setCapabilityUid(CAPABILITY_UID);
- relationInfo.setCapability(CAPABILITY_NAME);
- relationInfo.setRequirementOwnerId(REQUIREMENT_OWNER_ID);
- relationInfo.setRequirementUid(REQUIREMENT_UID);
- relationInfo.setRequirement(REQUIREMENT_NAME);
- RelationshipImpl relationshipImpl = new RelationshipImpl();
- relationshipImpl.setType(RELATIONSHIP_TYPE);
- relationInfo.setRelationships(relationshipImpl);
- }
+ @Test
+ public void testUpdateCIMetadataOfTopologyTemplate() {
+ Either<ImmutablePair<TopologyTemplate, String>, StorageOperationStatus> result;
+ String id = "id";
+ TopologyTemplate container = new TopologyTemplate();
+ ToscaElement toscaElement = new TopologyTemplate();
+ toscaElement.setResourceType(ResourceTypeEnum.VF);
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setName(id);
+ componentInstance.setComponentUid(id);
+ container.setUniqueId(id);
+ GraphVertex graphVertex = new GraphVertex();
+ when(titanDao.getVertexById(container.getUniqueId(), JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.left(graphVertex));
+ when(titanDao.updateVertex(graphVertex)).thenReturn(Either.left(graphVertex));
+ when(topologyTemplateOperation.getToscaElement(anyString())).thenReturn(Either.left(toscaElement));
- private boolean isBelongingRequirement(RelationshipInfo relationshipInfo, RequirementDataDefinition req) {
- return req.getRelationship().equals(relationshipInfo.getRelationship().getType()) &&
- req.getName().equals(relationshipInfo.getRequirement()) &&
- req.getUniqueId().equals(relationshipInfo.getRequirementUid()) &&
- req.getOwnerId().equals(relationshipInfo.getRequirementOwnerId());
+ result = operation.updateComponentInstanceMetadataOfTopologyTemplate(container, toscaElement, componentInstance);
+ assertTrue(result.isLeft());
}
- private boolean isBelongingCapability(RelationshipInfo relationshipInfo, CapabilityDataDefinition cap) {
- return cap.getName().equals(relationshipInfo.getCapability()) &&
- cap.getUniqueId().equals(relationshipInfo.getCapabilityUid()) &&
- cap.getOwnerId().equals(relationshipInfo.getCapabilityOwnerId());
- }
-
- private NodeTemplateOperation createTestSubject() {
- return operation;
- }
-
@Test
public void testGetDefaultHeatTimeout() {
Integer result;
@@ -235,7 +197,6 @@ public class NodeTemplateOperationTest extends ModelTestBase {
@Test
public void testPrepareInstDeploymentArtifactPerInstance() {
- NodeTemplateOperation testSubject;
Map<String, Object> deploymentResourceArtifacts = new HashMap<>();
Map<String, ArtifactDataDefinition> deploymentArtifacts = new HashMap<>();
ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
@@ -251,15 +212,11 @@ public class NodeTemplateOperationTest extends ModelTestBase {
String envType = "VfHeatEnv";
MapArtifactDataDefinition result;
- testSubject = createTestSubject();
-
- result = testSubject.prepareInstDeploymentArtifactPerInstance(deploymentArtifacts, componentInstanceId, user,
+ result = operation.prepareInstDeploymentArtifactPerInstance(deploymentArtifacts, componentInstanceId, user,
envType);
Assert.assertEquals(2, result.getMapToscaDataDefinition().size());
}
-
-
@Test
public void testCreateCapPropertyKey() throws Exception {
String key = "";
@@ -270,10 +227,8 @@ public class NodeTemplateOperationTest extends ModelTestBase {
result = NodeTemplateOperation.createCapPropertyKey(key, instanceId);
}
-
@Test
public void testPrepareCalculatedCapabiltyForNodeType() {
- NodeTemplateOperation testSubject;
Map<String, ListCapabilityDataDefinition> capabilities = new HashMap<>();
ListCapabilityDataDefinition listCapDataDefinition = new ListCapabilityDataDefinition();
List<CapabilityDataDefinition> listToscaDataDefinition = new ArrayList<>();
@@ -285,16 +240,12 @@ public class NodeTemplateOperationTest extends ModelTestBase {
ComponentInstance componentInstance = createCompInstance();
MapListCapabilityDataDefinition result;
- // test 1
- testSubject = createTestSubject();
- result = testSubject.prepareCalculatedCapabiltyForNodeType(capabilities, componentInstance);
+ result = operation.prepareCalculatedCapabiltyForNodeType(capabilities, componentInstance);
Assert.assertEquals(1, result.getMapToscaDataDefinition().size());
}
-
@Test
public void testPrepareCalculatedReqForNodeType() {
- NodeTemplateOperation testSubject;
Map<String, ListRequirementDataDefinition> requirements = new HashMap<>();
ListRequirementDataDefinition listReqDataDef = new ListRequirementDataDefinition();
List<RequirementDataDefinition> listToscaDataDefinition = new ArrayList<>();
@@ -306,41 +257,31 @@ public class NodeTemplateOperationTest extends ModelTestBase {
ComponentInstance componentInstance = createCompInstance();
MapListRequirementDataDefinition result;
- // test 1
- testSubject = createTestSubject();
- result = testSubject.prepareCalculatedRequirementForNodeType(requirements, componentInstance);
+ result = operation.prepareCalculatedRequirementForNodeType(requirements, componentInstance);
Assert.assertEquals(1, result.getMapToscaDataDefinition().size());
}
@Test
public void testAddGroupInstancesToComponentInstance() throws Exception {
- NodeTemplateOperation testSubject;
Component containerComponent = null;
ComponentInstanceDataDefinition componentInstance = null;
List<GroupDefinition> groups = null;
Map<String, List<ArtifactDefinition>> groupInstancesArtifacts = null;
StorageOperationStatus result;
- // test 1
- testSubject = createTestSubject();
- groupInstancesArtifacts = null;
- result = testSubject.addGroupInstancesToComponentInstance(containerComponent, componentInstance, groups,
+ result = operation.addGroupInstancesToComponentInstance(containerComponent, componentInstance, groups,
groupInstancesArtifacts);
Assert.assertEquals(StorageOperationStatus.OK, result);
}
@Test
public void testGenerateCustomizationUUIDOnInstanceGroup() throws Exception {
- NodeTemplateOperation testSubject;
String componentId = "";
String instanceId = "";
List<String> groupInstances = null;
StorageOperationStatus result;
- // test 1
- testSubject = createTestSubject();
- groupInstances = null;
- result = testSubject.generateCustomizationUUIDOnInstanceGroup(componentId, instanceId, groupInstances);
+ result = operation.generateCustomizationUUIDOnInstanceGroup(componentId, instanceId, groupInstances);
Assert.assertEquals(StorageOperationStatus.OK, result);
}
@@ -352,4 +293,72 @@ public class NodeTemplateOperationTest extends ModelTestBase {
componentInstance.setName(id);
return componentInstance;
}
+ private static void buildRequirementDataDefinition() {
+ buildRequirement();
+ fulfilledRequirement = new HashMap<>();
+ MapListRequirementDataDefinition mapListRequirementDataDefinition = new MapListRequirementDataDefinition();
+ mapListRequirementDataDefinition.add(requirement.getCapability(), requirement);
+ fulfilledRequirement.put(FROM_INSTANCE_ID, mapListRequirementDataDefinition);
+
+ }
+
+ private static void buildRequirement() {
+ requirement = new RequirementDataDefinition();
+ requirement.setOwnerId(REQUIREMENT_OWNER_ID);
+ requirement.setUniqueId(REQUIREMENT_UID);
+ requirement.setName(REQUIREMENT_NAME);
+ requirement.setRelationship(RELATIONSHIP_TYPE);
+ }
+
+ private static void buildCapabiltyDataDefinition() {
+ buildCapability();
+ fulfilledCapability = new HashMap<>();
+ MapListCapabilityDataDefinition mapListCapabiltyDataDefinition = new MapListCapabilityDataDefinition();
+ mapListCapabiltyDataDefinition.add(capability.getType(), capability);
+ fulfilledCapability.put(TO_INSTANCE_ID, mapListCapabiltyDataDefinition);
+ }
+
+ private static void buildCapability() {
+ capability = new CapabilityDataDefinition();
+ capability.setOwnerId(CAPABILITY_OWNER_ID);
+ capability.setUniqueId(CAPABILITY_UID);
+ capability.setName(CAPABILITY_NAME);
+ }
+
+ private static void buildRelation() {
+
+ relation = new RequirementCapabilityRelDef();
+ CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
+ RelationshipInfo relationInfo = new RelationshipInfo();
+ relationInfo.setId(RELATION_ID);
+ relationship.setRelation(relationInfo);
+
+ relation.setRelationships(Lists.newArrayList(relationship));
+ relation.setToNode(TO_INSTANCE_ID);
+ relation.setFromNode(FROM_INSTANCE_ID);
+
+ relationInfo.setCapabilityOwnerId(CAPABILITY_OWNER_ID);
+ relationInfo.setCapabilityUid(CAPABILITY_UID);
+ relationInfo.setCapability(CAPABILITY_NAME);
+ relationInfo.setRequirementOwnerId(REQUIREMENT_OWNER_ID);
+ relationInfo.setRequirementUid(REQUIREMENT_UID);
+ relationInfo.setRequirement(REQUIREMENT_NAME);
+ RelationshipImpl relationshipImpl = new RelationshipImpl();
+ relationshipImpl.setType(RELATIONSHIP_TYPE);
+ relationInfo.setRelationships(relationshipImpl);
+ }
+
+ private boolean isBelongingRequirement(RelationshipInfo relationshipInfo, RequirementDataDefinition req) {
+ return req.getRelationship().equals(relationshipInfo.getRelationship().getType()) &&
+ req.getName().equals(relationshipInfo.getRequirement()) &&
+ req.getUniqueId().equals(relationshipInfo.getRequirementUid()) &&
+ req.getOwnerId().equals(relationshipInfo.getRequirementOwnerId());
+ }
+
+ private boolean isBelongingCapability(RelationshipInfo relationshipInfo, CapabilityDataDefinition cap) {
+ return cap.getName().equals(relationshipInfo.getCapability()) &&
+ cap.getUniqueId().equals(relationshipInfo.getCapabilityUid()) &&
+ cap.getOwnerId().equals(relationshipInfo.getCapabilityOwnerId());
+ }
+
}