summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/test')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java1
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperationTest.java (renamed from catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java)541
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java50
3 files changed, 273 insertions, 319 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java
index 2ecb4b444c..0d5614f176 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java
@@ -3,7 +3,6 @@ package org.openecomp.sdc.be.model;
import mockit.Deencapsulation;
import org.junit.Assert;
import org.junit.Test;
-import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest;
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperationTest.java
index 375208d24e..fe2ea209f9 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperationTest.java
@@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue;
import fj.data.Either;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -48,35 +49,27 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application-context-test.xml")
-public class InterfacesOperationTest extends ModelTestBase {
- @Resource
- protected TitanDao titanDao;
-
- @Resource
- private InterfaceOperation interfaceOperation;
-
- @Resource
- protected NodeTypeOperation nodeTypeOperation;
-
- @Resource
- protected TopologyTemplateOperation topologyTemplateOperation;
-
- @Resource
- private ToscaElementLifecycleOperation lifecycleOperation;
+public class InterfaceOperationTest extends ModelTestBase {
private static final String RESOURCE_NAME = "Resource Name";
private static final String RESOURCE_ID = "resourceID";
-
private static final String SERVICE_NAME = "Service Name";
private static final String SERVICE_ID = "serviceID";
-
private final String categoryName = "category";
private final String subcategory = "mycategory";
-
- private GraphVertex ownerVertex;
-
private final Service service = createService();
private final org.openecomp.sdc.be.model.Resource resource = createResource();
+ @Resource
+ protected TitanDao titanDao;
+ @Resource
+ protected NodeTypeOperation nodeTypeOperation;
+ @Resource
+ protected TopologyTemplateOperation topologyTemplateOperation;
+ @Resource
+ private InterfaceOperation interfaceOperation;
+ @Resource
+ private ToscaElementLifecycleOperation lifecycleOperation;
+ private GraphVertex ownerVertex;
@BeforeClass
public static void initInterfacesOperation() {
@@ -96,165 +89,35 @@ public class InterfacesOperationTest extends ModelTestBase {
createTopologyTemplate("firstService");
}
- @After
- public void cleanAfter() {
- GraphTestUtils.clearGraph(titanDao);
- }
-
- @Test
- public void testAddInterface_Service(){testAddInterface(service);}
-
- @Test
- public void testAddInterface_Resource(){testAddInterface(resource);}
-
- @Test
- public void testUpdateInterface_Service(){testUpdateInterface(service);}
-
- @Test
- public void testUpdateInterface_Resource(){testUpdateInterface(resource);}
-
- @Test
- public void testAddInterfaceOperation_Service(){testAddInterfaceOperation(service);}
-
- @Test
- public void testAddInterfaceOperation_Resource(){testAddInterfaceOperation(resource);}
-
- @Test
- public void testUpdateInterfaceOperation_Service(){testUpdateInterfaceOperation(service);}
-
- @Test
- public void testUpdateInterfaceOperation_Resource(){testUpdateInterfaceOperation(resource);}
-
- @Test
- public void testDeleteInterfaceOperation_Service(){testDeleteInterfaceOperation(service);}
-
- @Test
- public void testDeleteInterfaceOperation_Resource(){testDeleteInterfaceOperation(resource);}
-
- @Test
- public void testUpdateInterfaceShouldFailWhenNOtCreatedFirst() {
- Component component = createResource();
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
- interfaceDefinition.setOperationsMap(createMockOperationMap());
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.updateInterface(component.getUniqueId(),
- interfaceDefinition);
- Assert.assertTrue(res.isRight());
- }
-
- private void testAddInterface(Component component) {
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(),
- interfaceDefinition);
- Assert.assertTrue(res.isLeft());
- }
-
- private void testUpdateInterface(Component component) {
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
- interfaceDefinition.setOperationsMap(createMockOperationMap());
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition);
- Assert.assertTrue(res.isLeft());
- InterfaceDefinition value = res.left().value();
- String new_description = "New Description";
- value.setDescription(new_description);
- res = interfaceOperation.updateInterface(component.getUniqueId(), interfaceDefinition);
- assertTrue(res.isLeft());
- assertEquals(new_description,res.left().value().getDescription());
- }
-
- private void testAddInterfaceOperation(Component component) {
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition);
- Assert.assertTrue(res.isLeft());
- InterfaceDefinition value = res.left().value();
- Operation op = createMockOperation();
- Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op);
- assertTrue(addInterfaceOperationRes.isLeft());
- }
-
- private void testUpdateInterfaceOperation(Component component) {
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition);
- Assert.assertTrue(res.isLeft());
- InterfaceDefinition value = res.left().value();
- Operation op = createMockOperation();
- Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op);
- Assert.assertTrue(addInterfaceOperationRes.isLeft());
- Operation resultOp = addInterfaceOperationRes.left().value();
- resultOp.setName("New_Create");
- Either<Operation, StorageOperationStatus> updateInterfaceOperationRes = interfaceOperation.updateInterfaceOperation(component.getUniqueId(), value, resultOp);
- assertTrue(updateInterfaceOperationRes.isLeft());
- assertEquals("New_Create", updateInterfaceOperationRes.left().value().getName());
- }
-
- private void testDeleteInterfaceOperation(Component component) {
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition);
- Assert.assertTrue(res.isLeft());
- InterfaceDefinition value = res.left().value();
- Operation op = createMockOperation();
- Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op);
- Assert.assertTrue(addInterfaceOperationRes.isLeft());
- Operation resultOp = addInterfaceOperationRes.left().value();
- Either<Operation, StorageOperationStatus> deleteInterfaceOperationRes = interfaceOperation.deleteInterfaceOperation(component.getUniqueId(), value, resultOp.getUniqueId());
- assertTrue(deleteInterfaceOperationRes.isLeft());
- }
-
- private InterfaceDefinition buildInterfaceDefinition() {
- InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
- interfaceDefinition.setType("tosca.interfaces.standard");
- interfaceDefinition.setCreationDate(101232L);
- return interfaceDefinition;
- }
-
- private org.openecomp.sdc.be.model.Resource createResource() {
- org.openecomp.sdc.be.model.Resource resource = new org.openecomp.sdc.be.model.Resource();
- resource.setUniqueId(RESOURCE_ID);
- resource.setName(RESOURCE_NAME);
- resource.setDescription("My short description");
- resource.setInterfaces(createMockInterfaceDefinition());
- return resource;
- }
+ private void createUsers() {
+ GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
+ ownerV.setUniqueId("user1");
- private Service createService() {
- Service service = new Service();
- service.setUniqueId(SERVICE_ID);
- service.setName(SERVICE_NAME);
- service.setDescription("My short description");
- service.setInterfaces(createMockInterfaceDefinition());
- return service;
- }
+ Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
+ metadataProperties.put(GraphPropertyEnum.USERID, ownerV.getUniqueId());
+ metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
+ metadataProperties.put(GraphPropertyEnum.NAME, "user1");
+ ownerV.setMetadataProperties(metadataProperties);
+ ownerV.updateMetadataJsonWithCurrentMetadataProperties();
+ ownerV.setJson(new HashMap<>());
+ Either<GraphVertex, TitanOperationStatus> createUserRes = titanDao.createVertex(ownerV);
- private InterfaceDefinition createInterface(String uniqueID, String description, String type, String toscaResourceName,
- Map<String, Operation> op) {
- InterfaceDefinition id = new InterfaceDefinition();
- id.setType(type);
- id.setDescription(description);
- id.setUniqueId(uniqueID);
- id.setToscaResourceName(toscaResourceName);
- id.setOperationsMap(op);
- return id;
- }
+ ownerVertex = createUserRes.left().value();
- private Map<String, InterfaceDefinition> createMockInterfaceDefinition() {
- Map<String, Operation> operationMap = createMockOperationMap();
- Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
- interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1",
- "lifecycle", "tosca", operationMap));
- return interfaceDefinitionMap;
- }
+ GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
+ modifierV.setUniqueId("user2");
- private Map<String, Operation> createMockOperationMap() {
- Map<String, Operation> operationMap = new HashMap<>();
- operationMap.put("op1", createMockOperation());
- return operationMap;
- }
+ metadataProperties = new HashMap<>();
+ metadataProperties.put(GraphPropertyEnum.USERID, modifierV.getUniqueId());
+ metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
+ metadataProperties.put(GraphPropertyEnum.NAME, "user2");
+ modifierV.setMetadataProperties(metadataProperties);
+ modifierV.updateMetadataJsonWithCurrentMetadataProperties();
+ modifierV.setJson(new HashMap<>());
+ createUserRes = titanDao.createVertex(modifierV);
+ createUserRes.left().value();
- private Operation createMockOperation() {
- Operation operation = new Operation();
- operation.setDefinition(false);
- operation.setName("create");
- operation.setUniqueId("op1");
- return operation;
+ lifecycleOperation.findUser(ownerVertex.getUniqueId());
}
private void createResourceCategory() {
@@ -265,7 +128,8 @@ public class InterfacesOperationTest extends ModelTestBase {
metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_CATEGORY.getName());
metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
- metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
+ metadataProperties
+ .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
cat.setMetadataProperties(metadataProperties);
cat.updateMetadataJsonWithCurrentMetadataProperties();
@@ -276,13 +140,15 @@ public class InterfacesOperationTest extends ModelTestBase {
metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, subCatId);
metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_SUBCATEGORY.getName());
metadataProperties.put(GraphPropertyEnum.NAME, subcategory);
- metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory));
+ metadataProperties
+ .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory));
subCat.setMetadataProperties(metadataProperties);
subCat.updateMetadataJsonWithCurrentMetadataProperties();
Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
Either<GraphVertex, TitanOperationStatus> subCatRes = titanDao.createVertex(subCat);
- titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
+ titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(),
+ EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
}
private void createServiceCategory() {
@@ -293,32 +159,64 @@ public class InterfacesOperationTest extends ModelTestBase {
metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.SERVICE_CATEGORY.getName());
metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
- metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
+ metadataProperties
+ .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
cat.setMetadataProperties(metadataProperties);
cat.updateMetadataJsonWithCurrentMetadataProperties();
titanDao.createVertex(cat);
}
- private void createTopologyTemplate(String name) {
- TopologyTemplate service = new TopologyTemplate();
+ private void createRootNodeType() {
+ NodeType vf = new NodeType();
String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
- service.setUniqueId(uniqueId);
- service.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
- service.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), name);
- service.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
- service.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
- service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
- service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
+ vf.setUniqueId(uniqueId);
+ vf.setComponentType(ComponentTypeEnum.RESOURCE);
+ vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
+ vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), "root");
+ vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
+ vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "1.0");
+ vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VFC.name());
+ vf.getMetadata()
+ .put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name());
+ vf.getMetadata().put(JsonPresentationFields.TOSCA_RESOURCE_NAME.getPresentation(), "root");
+ vf.getMetadata().put(JsonPresentationFields.HIGHEST_VERSION.getPresentation(), true);
+
List<CategoryDefinition> categories = new ArrayList<>();
CategoryDefinition cat = new CategoryDefinition();
categories.add(cat);
cat.setName(categoryName);
- service.setCategories(categories);
+ List<SubCategoryDefinition> subCategories = new ArrayList<>();
+ SubCategoryDefinition subCat = new SubCategoryDefinition();
+ subCat.setName(subcategory);
+ subCategories.add(subCat);
+ cat.setSubcategories(subCategories);
+ vf.setCategories(categories);
- service.setComponentType(ComponentTypeEnum.SERVICE);
- Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service);
- Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createRes.left().value().getUniqueId());
+ List<String> derivedFrom = new ArrayList<>();
+ vf.setDerivedFrom(derivedFrom);
+
+ Map<String, PropertyDataDefinition> properties = new HashMap<>();
+ PropertyDataDefinition prop1 = new PropertyDataDefinition();
+ prop1.setName("derived1");
+ prop1.setDefaultValue("deriveddef1");
+ properties.put("derived1", prop1);
+
+ PropertyDataDefinition prop2 = new PropertyDataDefinition();
+ prop2.setUniqueId("derived2");
+ prop2.setName("deriveddef2");
+ properties.put("derived2", prop2);
+ PropertyDataDefinition prop3 = new PropertyDataDefinition();
+ prop3.setName("derived3");
+ prop3.setDefaultValue("deriveddef3");
+ properties.put("derived3", prop3);
+
+ vf.setProperties(properties);
+ vf.setComponentType(ComponentTypeEnum.RESOURCE);
+ Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
+
+ Either<GraphVertex, TitanOperationStatus> getNodeTyeRes =
+ titanDao.getVertexById(createVFRes.left().value().getUniqueId());
getNodeTyeRes.left().value();
}
@@ -347,11 +245,6 @@ public class InterfacesOperationTest extends ModelTestBase {
vf.setDerivedFrom(derivedFrom);
vf.setComponentType(ComponentTypeEnum.RESOURCE);
- Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
-
- Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
-
- GraphVertex vfVertex = getNodeTyeRes.left().value();
List<PropertyDataDefinition> addProperties = new ArrayList<>();
PropertyDataDefinition prop11 = new PropertyDataDefinition();
@@ -365,22 +258,30 @@ public class InterfacesOperationTest extends ModelTestBase {
prop22.setDefaultValue("def22");
addProperties.add(prop22);
- StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
- assertSame(status, StorageOperationStatus.OK);
+ Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
+ Either<GraphVertex, TitanOperationStatus> getNodeTyeRes =
+ titanDao.getVertexById(createVFRes.left().value().getUniqueId());
+ GraphVertex vfVertex = getNodeTyeRes.left().value();
+ StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES,
+ VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
+ assertSame(StorageOperationStatus.OK, status);
PropertyDataDefinition prop33 = new PropertyDataDefinition();
prop33.setName("prop33");
prop33.setDefaultValue("def33");
- status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME);
- assertSame(status, StorageOperationStatus.OK);
+ status = nodeTypeOperation
+ .addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES,
+ prop33, JsonPresentationFields.NAME);
+ assertSame(StorageOperationStatus.OK, status);
PropertyDataDefinition prop44 = new PropertyDataDefinition();
prop44.setName("prop44");
prop44.setDefaultValue("def44");
- status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
- assertSame(status, StorageOperationStatus.OK);
+ status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES,
+ VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
+ assertSame(StorageOperationStatus.OK, status);
PropertyDataDefinition capProp = new PropertyDataDefinition();
capProp.setName("capProp");
@@ -392,96 +293,200 @@ public class InterfacesOperationTest extends ModelTestBase {
Map<String, MapDataDefinition> capProps = new HashMap<>();
capProps.put("capName", dataToCreate);
- nodeTypeOperation.associateElementToData(
- vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
+ nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
+ EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
List<String> pathKeys = new ArrayList<>();
pathKeys.add("capName");
capProp.setDefaultValue("BBBB");
- nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME);
+ nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES,
+ VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME);
}
- private void createRootNodeType() {
- NodeType vf = new NodeType();
+ private void createTopologyTemplate(String name) {
+ TopologyTemplate service = new TopologyTemplate();
String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
- vf.setUniqueId(uniqueId);
- vf.setComponentType(ComponentTypeEnum.RESOURCE);
- vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
- vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), "root");
- vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
- vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "1.0");
- vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VFC.name());
- vf.getMetadata().put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name());
- vf.getMetadata().put(JsonPresentationFields.TOSCA_RESOURCE_NAME.getPresentation(), "root");
- vf.getMetadata().put(JsonPresentationFields.HIGHEST_VERSION.getPresentation(), true);
-
+ service.setUniqueId(uniqueId);
+ service.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
+ service.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), name);
+ service.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
+ service.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
+ service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
+ service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
List<CategoryDefinition> categories = new ArrayList<>();
CategoryDefinition cat = new CategoryDefinition();
categories.add(cat);
cat.setName(categoryName);
- List<SubCategoryDefinition> subCategories = new ArrayList<>();
- SubCategoryDefinition subCat = new SubCategoryDefinition();
- subCat.setName(subcategory);
- subCategories.add(subCat);
- cat.setSubcategories(subCategories);
- vf.setCategories(categories);
+ service.setCategories(categories);
- List<String> derivedFrom = new ArrayList<>();
- vf.setDerivedFrom(derivedFrom);
+ service.setComponentType(ComponentTypeEnum.SERVICE);
+ Either<TopologyTemplate, StorageOperationStatus> createRes =
+ topologyTemplateOperation.createTopologyTemplate(service);
+ Either<GraphVertex, TitanOperationStatus> getNodeTyeRes =
+ titanDao.getVertexById(createRes.left().value().getUniqueId());
- Map<String, PropertyDataDefinition> properties = new HashMap<>();
- PropertyDataDefinition prop1 = new PropertyDataDefinition();
- prop1.setName("derived1");
- prop1.setDefaultValue("deriveddef1");
- properties.put("derived1", prop1);
+ getNodeTyeRes.left().value();
+ }
- PropertyDataDefinition prop2 = new PropertyDataDefinition();
- prop2.setUniqueId("derived2");
- prop2.setName("deriveddef2");
- properties.put("derived2", prop2);
+ @After
+ public void cleanAfter() {
+ GraphTestUtils.clearGraph(titanDao);
+ }
- PropertyDataDefinition prop3 = new PropertyDataDefinition();
- prop3.setName("derived3");
- prop3.setDefaultValue("deriveddef3");
- properties.put("derived3", prop3);
+ @Test
+ public void testAddInterface_Service() {
+ testAddSingleInterface(service);
+ }
- vf.setProperties(properties);
- vf.setComponentType(ComponentTypeEnum.RESOURCE);
- Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
+ private void testAddSingleInterface(Component component) {
+ InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1");
+ Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation
+ .addInterfaces(component.getUniqueId(),
+ Collections.singletonList(
+ interfaceDefinition));
+ Assert.assertTrue(res.isLeft());
+ Assert.assertEquals("1", res.left().value().get(0).getUniqueId());
+ }
- Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
- getNodeTyeRes.left().value();
+ private InterfaceDefinition buildInterfaceDefinition(String uniqueId) {
+ InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType("tosca.interfaces.standard");
+ interfaceDefinition.setUniqueId(uniqueId);
+ interfaceDefinition.setOperationsMap(createMockOperationMap());
+ return interfaceDefinition;
}
- private void createUsers() {
- GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
- ownerV.setUniqueId("user1");
+ private Map<String, Operation> createMockOperationMap() {
+ Map<String, Operation> operationMap = new HashMap<>();
+ operationMap.put("op1", createMockOperation());
+ return operationMap;
+ }
- Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
- metadataProperties.put(GraphPropertyEnum.USERID, ownerV.getUniqueId());
- metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
- metadataProperties.put(GraphPropertyEnum.NAME, "user1");
- ownerV.setMetadataProperties(metadataProperties);
- ownerV.updateMetadataJsonWithCurrentMetadataProperties();
- ownerV.setJson(new HashMap<>());
- Either<GraphVertex, TitanOperationStatus> createUserRes = titanDao.createVertex(ownerV);
+ private Operation createMockOperation() {
+ Operation operation = new Operation();
+ operation.setDefinition(false);
+ operation.setName("create");
+ operation.setUniqueId("op1");
+ return operation;
+ }
- ownerVertex = createUserRes.left().value();
+ @Test
+ public void testAddInterface_Resource() {
+ testAddMultipleInterface(resource);
+ }
- GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
- modifierV.setUniqueId("user2");
+ private void testAddMultipleInterface(Component component) {
+ InterfaceDefinition interfaceDefinition1 = buildInterfaceDefinition("1");
+ InterfaceDefinition interfaceDefinition2 = buildInterfaceDefinition("2");
+ List<InterfaceDefinition> interfaceDefinitions = new ArrayList<>();
+ interfaceDefinitions.add(interfaceDefinition1);
+ interfaceDefinitions.add(interfaceDefinition2);
+ Either<List<InterfaceDefinition>, StorageOperationStatus> res =
+ interfaceOperation.addInterfaces(component.getUniqueId(), interfaceDefinitions);
+ Assert.assertTrue(res.isLeft());
+ Assert.assertEquals(2, res.left().value().size());
+ }
- metadataProperties = new HashMap<>();
- metadataProperties.put(GraphPropertyEnum.USERID, modifierV.getUniqueId());
- metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
- metadataProperties.put(GraphPropertyEnum.NAME, "user2");
- modifierV.setMetadataProperties(metadataProperties);
- modifierV.updateMetadataJsonWithCurrentMetadataProperties();
- modifierV.setJson(new HashMap<>());
- createUserRes = titanDao.createVertex(modifierV);
- createUserRes.left().value();
+ @Test
+ public void testUpdateInterface_Service() {
+ testUpdateInterface(service);
+ }
- lifecycleOperation.findUser(ownerVertex.getUniqueId());
+ private void testUpdateInterface(Component component) {
+ InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1");
+ Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation
+ .addInterfaces(component.getUniqueId(),
+ Collections.singletonList(
+ interfaceDefinition));
+ Assert.assertTrue(res.isLeft());
+ List<InterfaceDefinition> value = res.left().value();
+ InterfaceDefinition createdInterfaceDef = value.get(0);
+ String newDescription = "New Description";
+ createdInterfaceDef.setDescription(newDescription);
+ res = interfaceOperation
+ .updateInterfaces(component.getUniqueId(), Collections.singletonList(createdInterfaceDef));
+ assertTrue(res.isLeft());
+ assertEquals(newDescription, res.left().value().get(0).getDescription());
+ }
+
+ @Test
+ public void testUpdateInterface_Resource() {
+ testUpdateInterface(resource);
+ }
+
+ @Test
+ public void testDeleteInterface_Service() {
+ testDeleteInterface(service);
+ }
+
+ private void testDeleteInterface(Component component) {
+ InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1");
+ Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation
+ .addInterfaces(component.getUniqueId(),
+ Collections.singletonList(
+ interfaceDefinition));
+ Assert.assertTrue(res.isLeft());
+ List<InterfaceDefinition> value = res.left().value();
+ Either<String, StorageOperationStatus> deleteInterfaceOperationRes =
+ interfaceOperation.deleteInterface(component.getUniqueId(), value.get(0).getUniqueId());
+ assertTrue(deleteInterfaceOperationRes.isLeft());
+ }
+
+ @Test
+ public void testDeleteInterface_Resource() {
+ testDeleteInterface(resource);
+ }
+
+ @Test
+ public void testUpdateInterfaceShouldFailWhenNOtCreatedFirst() {
+ Component component = createResource();
+ InterfaceDefinition interfaceDefinition = buildInterfaceDefinitionWithoutOperation();
+ interfaceDefinition.setOperationsMap(createMockOperationMap());
+ Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation.updateInterfaces(
+ component.getUniqueId(), Collections.singletonList(interfaceDefinition));
+ Assert.assertTrue(res.isRight());
+ }
+
+ private InterfaceDefinition buildInterfaceDefinitionWithoutOperation() {
+ InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType("tosca.interfaces.standard");
+ return interfaceDefinition;
+ }
+
+ private org.openecomp.sdc.be.model.Resource createResource() {
+ org.openecomp.sdc.be.model.Resource resource = new org.openecomp.sdc.be.model.Resource();
+ resource.setUniqueId(RESOURCE_ID);
+ resource.setName(RESOURCE_NAME);
+ resource.setDescription("My short description");
+ resource.setInterfaces(createMockInterfaceDefinition());
+ return resource;
+ }
+
+ private Service createService() {
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+ service.setName(SERVICE_NAME);
+ service.setDescription("My short description");
+ service.setInterfaces(createMockInterfaceDefinition());
+ return service;
+ }
+
+ private Map<String, InterfaceDefinition> createMockInterfaceDefinition() {
+ Map<String, Operation> operationMap = createMockOperationMap();
+ Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
+ interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1", "lifecycle", "tosca", operationMap));
+ return interfaceDefinitionMap;
+ }
+
+ private InterfaceDefinition createInterface(String uniqueId, String description, String type,
+ String toscaResourceName, Map<String, Operation> op) {
+ InterfaceDefinition id = new InterfaceDefinition();
+ id.setType(type);
+ id.setDescription(description);
+ id.setUniqueId(uniqueId);
+ id.setToscaResourceName(toscaResourceName);
+ id.setOperationsMap(op);
+ return id;
}
@After
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java
deleted file mode 100644
index fbf01bc91d..0000000000
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.openecomp.sdc.be.model.jsontitan.utils;
-
-import org.junit.Test;
-import org.openecomp.sdc.be.model.InterfaceDefinition;
-import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.Resource;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-public class InterfaceUtilsTest {
-
- private InterfaceUtils createTestSubject() {
- return new InterfaceUtils();
- }
-
-
- @Test
- public void testGetInterfaceDefinitionFromToscaName() throws Exception {
- Collection<InterfaceDefinition> interfaces = null;
- String resourceName = "";
- Optional<InterfaceDefinition> result;
-
- // default test
- result = InterfaceUtils.getInterfaceDefinitionFromToscaName(interfaces, resourceName);
- }
-
-
- @Test
- public void testGetInterfaceDefinitionListFromToscaName() throws Exception {
- Collection<InterfaceDefinition> interfaces = null;
- String resourceName = "";
- Collection<InterfaceDefinition> result;
-
- // default test
- result = InterfaceUtils.getInterfaceDefinitionListFromToscaName(interfaces, resourceName);
- }
-
-
- @Test
- public void testCreateInterfaceToscaResourceName() throws Exception {
- String resourceName = "";
- String result;
-
- // default test
- result = InterfaceUtils.createInterfaceToscaResourceName(resourceName);
- }
-} \ No newline at end of file