From 48528e9da9e241c59f1628ffda9020a981f939f6 Mon Sep 17 00:00:00 2001 From: shiria Date: Thu, 20 Sep 2018 12:51:32 +0300 Subject: Add support of interface in TOSCA datatypes Move all interface functionality from DataModelUtil class to TOSCA datatype relevant class Change-Id: Ifea22b60e9a71fe024e87f9987a749e9d56aad82 Issue-ID: SDC-1781 Signed-off-by: shiria --- .../sdc/tosca/datatypes/ToscaModelTest.java | 118 ++++----- .../impl/ToscaAnalyzerServiceImplTest.java | 267 +++++++++++++-------- 2 files changed, 224 insertions(+), 161 deletions(-) (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/test/java/org') diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java index 2833cc456d..88e8461299 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java @@ -25,9 +25,35 @@ import java.util.Map; import java.util.Optional; import org.junit.Assert; import org.junit.Test; -import org.onap.sdc.tosca.datatypes.model.*; +import org.onap.sdc.tosca.datatypes.model.ArtifactType; +import org.onap.sdc.tosca.datatypes.model.AttributeDefinition; +import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment; +import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition; +import org.onap.sdc.tosca.datatypes.model.CapabilityFilter; +import org.onap.sdc.tosca.datatypes.model.Constraint; +import org.onap.sdc.tosca.datatypes.model.Directive; +import org.onap.sdc.tosca.datatypes.model.Implementation; +import org.onap.sdc.tosca.datatypes.model.Import; +import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionTemplate; +import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionType; +import org.onap.sdc.tosca.datatypes.model.InterfaceType; +import org.onap.sdc.tosca.datatypes.model.NodeFilter; +import org.onap.sdc.tosca.datatypes.model.NodeTemplate; +import org.onap.sdc.tosca.datatypes.model.NodeType; +import org.onap.sdc.tosca.datatypes.model.OperationDefinition; +import org.onap.sdc.tosca.datatypes.model.OperationDefinitionTemplate; +import org.onap.sdc.tosca.datatypes.model.OperationDefinitionType; +import org.onap.sdc.tosca.datatypes.model.ParameterDefinition; +import org.onap.sdc.tosca.datatypes.model.PropertyDefinition; +import org.onap.sdc.tosca.datatypes.model.PropertyType; import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; -import org.onap.sdc.tosca.datatypes.model.extension.*; +import org.onap.sdc.tosca.datatypes.model.RequirementDefinition; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping; +import org.onap.sdc.tosca.datatypes.model.TopologyTemplate; +import org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignmentExt; +import org.onap.sdc.tosca.datatypes.model.extension.SubstitutionFilter; +import org.onap.sdc.tosca.datatypes.model.extension.SubstitutionMappingExt; import org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt; import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; import org.onap.sdc.tosca.services.YamlUtil; @@ -72,6 +98,7 @@ public class ToscaModelTest { metadata.put("Template_author", "OPENECOMP"); metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, "Test"); metadata.put("Template_version", "1.0.0"); + serviceTemplate.setMetadata(metadata); serviceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0"); serviceTemplate.setDescription("testing desc tosca service template"); @@ -156,13 +183,13 @@ public class ToscaModelTest { nodeType.setRequirements(reqList); - Map capsDef = new HashMap<>(); CapabilityDefinition capdef = new CapabilityDefinition(); capdef.setType("tosca.cap"); List vvSource = new ArrayList<>(); vvSource.add("node1"); vvSource.add("node2"); capdef.setValid_source_types(vvSource); + Map capsDef = new HashMap<>(); capsDef.put("cap1", capdef); nodeType.setCapabilities(capsDef); @@ -172,7 +199,6 @@ public class ToscaModelTest { TopologyTemplate topologyTemplate = new TopologyTemplate(); topologyTemplate.setDescription("topologi template descroption"); - Map inputs = new HashMap<>(); ParameterDefinition paramDef = new ParameterDefinition(); paramDef.setType(PropertyType.STRING.getDisplayName()); paramDef.setDescription("desc"); @@ -187,10 +213,10 @@ public class ToscaModelTest { paramConstraint.add(paramConst1); paramConstraint.add(paramConst2); paramDef.setConstraints(paramConstraint); + Map inputs = new HashMap<>(); inputs.put("inParam1", paramDef); topologyTemplate.setInputs(inputs); - Map nodeTemplates = new HashMap<>(); NodeTemplate nodeTemplate = new NodeTemplate(); nodeTemplate.setType("nodeTypeRef"); List directives = new ArrayList<>(); @@ -204,6 +230,7 @@ public class ToscaModelTest { Map nodeTemplateAtts = new HashMap<>(); nodeTemplateAtts.put("att1", "att1Val"); nodeTemplateAtts.put("att2", "{ get_input: my_mysql_rootpw }"); + Map nodeTemplates = new HashMap<>(); nodeTemplate.setAttributes(nodeTemplateAtts); @@ -215,7 +242,6 @@ public class ToscaModelTest { reqAssOccurrences[0] = 1; reqAssOccurrences[1] = 2; reqAssignment1.setOccurrences(reqAssOccurrences); - NodeFilter reqNodeFilter = new NodeFilter(); List propConstraint1 = new ArrayList<>(); Constraint propConst1 = new Constraint(); propConst1.setGreater_or_equal(9); @@ -232,6 +258,7 @@ public class ToscaModelTest { propsMap.put("propName1", propConstraint1); propsMap.put("propName2", propConstraint2); nodeFilterProp.add(propsMap); + NodeFilter reqNodeFilter = new NodeFilter(); reqNodeFilter.setProperties(nodeFilterProp); reqAssignment1.setNode_filter(reqNodeFilter); @@ -247,7 +274,6 @@ public class ToscaModelTest { nodeTemplate.getRequirements().add(nodeTemplateRequirement1); nodeTemplate.getRequirements().add(nodeTemplateRequirement2); - Map nodeTemplateCapability = new HashMap<>(); CapabilityAssignment capAss = new CapabilityAssignment(); Map capProps = new HashMap<>(); capProps.put("num_cpus", "{ get_input: cpus }"); @@ -255,10 +281,10 @@ public class ToscaModelTest { Map capAtts = new HashMap<>(); capAtts.put("num_cpus", "66"); capAss.setAttributes(capAtts); + Map nodeTemplateCapability = new HashMap<>(); nodeTemplateCapability.put("cap1", capAss); nodeTemplate.setCapabilities(nodeTemplateCapability); - NodeFilter nodeTemplateNodeFilter = new NodeFilter(); List>> nodeFilterProp2 = new ArrayList<>(); Map> propsMap2 = new HashMap<>(); Constraint c1 = new Constraint(); @@ -267,6 +293,7 @@ public class ToscaModelTest { consList.add(c1); propsMap2.put("test1", consList); nodeFilterProp2.add(propsMap2); + NodeFilter nodeTemplateNodeFilter = new NodeFilter(); nodeTemplateNodeFilter.setProperties(nodeFilterProp2); nodeTemplate.setNode_filter(nodeTemplateNodeFilter); nodeTemplates.put("firatNodeTemplate", nodeTemplate); @@ -275,10 +302,10 @@ public class ToscaModelTest { SubstitutionMapping subMap = new SubstitutionMapping(); subMap.setNode_type("myNodeType.node"); Map> mapCapabilities = new HashMap<>(); - List NodeCap = new ArrayList<>(); - NodeCap.add("database"); - NodeCap.add("database_endpoint"); - mapCapabilities.put("database_endpoint", NodeCap); + List nodeCap = new ArrayList<>(); + nodeCap.add("database"); + nodeCap.add("database_endpoint"); + mapCapabilities.put("database_endpoint", nodeCap); subMap.setCapabilities(mapCapabilities); topologyTemplate.setSubstitution_mappings(subMap); serviceTemplate.setTopology_template(topologyTemplate); @@ -291,8 +318,7 @@ public class ToscaModelTest { @Test public void testYamlToServiceTemplateObj() throws IOException { - ServiceTemplate serviceTemplateFromYaml = - getServiceTemplate(BASE_DIR + ST); + ServiceTemplate serviceTemplateFromYaml = getServiceTemplate(BASE_DIR + ST); Assert.assertNotNull(serviceTemplateFromYaml); } @@ -303,7 +329,7 @@ public class ToscaModelTest { InterfaceType expectedInterfaceType = createInterfaceType(); - Map interfaceTypes = DataModelUtil.getInterfaceTypes(serviceTemplateWithOperation); + Map interfaceTypes = serviceTemplateWithOperation.getNormalizeInterfaceTypes(); Assert.assertEquals(1, interfaceTypes.size()); InterfaceType actualInterfaceType = interfaceTypes.get(INTERFACE_ID); Assert.assertEquals(expectedInterfaceType, actualInterfaceType); @@ -316,9 +342,10 @@ public class ToscaModelTest { ServiceTemplate serviceTemplateWithOperation = getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS); OperationDefinition operationDefinition = createOperationDefinition(); - - DataModelUtil.addInterfaceOperation(serviceTemplateWithInterface, INTERFACE_ID, OPERATION_START, - operationDefinition); + InterfaceType normalizeInterfaceType = + serviceTemplateWithInterface.getNormalizeInterfaceTypes().get(INTERFACE_ID); + normalizeInterfaceType.addOperation(OPERATION_START, operationDefinition); + serviceTemplateWithInterface.addInterfaceType(INTERFACE_ID, normalizeInterfaceType); String expectedServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithOperation); String actualServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithInterface); Assert.assertEquals(expectedServiceTemplate, actualServiceTemplate); @@ -330,7 +357,7 @@ public class ToscaModelTest { ServiceTemplate serviceTemplateWithOperation = getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS); InterfaceType interfaceType = createInterfaceType(); - Optional interfaceAsObj = DataModelUtil.convertInterfaceTypeToObj(interfaceType); + Optional interfaceAsObj = interfaceType.convertInterfaceTypeToToscaObj(); Assert.assertTrue(interfaceAsObj.isPresent()); Map interfaceTypes = new HashMap<>(); @@ -345,14 +372,10 @@ public class ToscaModelTest { @Test public void testObjToInterfaceTypeConversion() throws IOException, ReflectiveOperationException { ServiceTemplate serviceTemplateWithOperation = getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS); - Map interfaceTypes = serviceTemplateWithOperation.getInterface_types(); - Object interfaceObj = interfaceTypes.get(INTERFACE_ID); - Optional actualInterfaceType = - DataModelUtil.convertObjToInterfaceType(INTERFACE_ID, interfaceObj); - - Assert.assertTrue(actualInterfaceType.isPresent()); + Map interfaceTypes = serviceTemplateWithOperation.getNormalizeInterfaceTypes(); + InterfaceType actualInterfaceType = interfaceTypes.get(INTERFACE_ID); InterfaceType expectedInterfaceType = createInterfaceType(); - Assert.assertEquals(expectedInterfaceType, actualInterfaceType.get()); + Assert.assertEquals(expectedInterfaceType, actualInterfaceType); } @Test @@ -362,33 +385,22 @@ public class ToscaModelTest { Map interfaces = nodeTypeWithInterface.getInterfaces(); Object interfaceObj = interfaces.get(INTERFACE_ID); - Optional actualInterfaceDefinition = DataModelUtil - .convertObjToInterfaceDefinition( - INTERFACE_ID, interfaceObj, - InterfaceDefinitionType.class); - - Assert.assertTrue(actualInterfaceDefinition.isPresent()); - + InterfaceDefinitionType actualInterfaceDefinition = new InterfaceDefinitionType(interfaceObj); InterfaceDefinitionType expectedInterfaceDefinitionType = createInterfaceDefinitionType(); - Assert.assertEquals(expectedInterfaceDefinitionType, actualInterfaceDefinition.get()); + Assert.assertEquals(expectedInterfaceDefinitionType, actualInterfaceDefinition); } @Test - public void testObjToInterfaceDefinitionTemplateConversion() throws IOException, ReflectiveOperationException { + public void testObjToInterfaceDefinitionTemplateConversion() throws IOException { ServiceTemplate serviceTemplateWithInterfaceDef = getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE_DEF); NodeTemplate nodeTemplateWithInterface = DataModelUtil.getNodeTemplate(serviceTemplateWithInterfaceDef, NODE_TEMPLATE_ID); Map interfaces = nodeTemplateWithInterface.getInterfaces(); Object interfaceObj = interfaces.get(INTERFACE_ID); - Optional actualInterfaceDefinition = DataModelUtil - .convertObjToInterfaceDefinition( - INTERFACE_ID, interfaceObj, - InterfaceDefinitionTemplate.class); - - Assert.assertTrue(actualInterfaceDefinition.isPresent()); + InterfaceDefinitionTemplate actualInterfaceDefinition = new InterfaceDefinitionTemplate(interfaceObj); InterfaceDefinitionTemplate expectedInterfaceDefinitionTemplate = createInterfaceDefinitionTemplate(); - Assert.assertEquals(expectedInterfaceDefinitionTemplate, actualInterfaceDefinition.get()); + Assert.assertEquals(expectedInterfaceDefinitionTemplate, actualInterfaceDefinition); } @Test @@ -416,19 +428,17 @@ public class ToscaModelTest { DataModelUtil.getNodeTemplateRequirements(firstNodeTemplate); Object req1 = nodeTemplateRequirements.get(REQ1); - Assert.assertEquals(true, req1 instanceof org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment); - Assert.assertNotNull(((org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment)req1).getService_filter()); + Assert.assertTrue(req1 instanceof RequirementAssignmentExt); + Assert.assertNotNull(((RequirementAssignmentExt) req1).getService_filter()); List>> properties = - ((org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment) req1).getService_filter() - .getProperties(); + ((RequirementAssignmentExt) req1).getService_filter().getProperties(); Assert.assertNotNull(properties); List vmdNameConstrain = properties.get(0).get(VMD_NAME); Assert.assertNotNull(vmdNameConstrain); Assert.assertNotNull(vmdNameConstrain.get(0).getEqual()); List> capabilities = - ((org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment) req1).getService_filter() - .getCapabilities(); + ((RequirementAssignmentExt) req1).getService_filter().getCapabilities(); Assert.assertNotNull(capabilities); CapabilityFilter capabilityFilter = capabilities.get(0).get(DIRECTOR); Assert.assertNotNull(capabilityFilter); @@ -436,13 +446,11 @@ public class ToscaModelTest { Object req2 = nodeTemplateRequirements.get(REQ2); - Assert.assertEquals(true, req2 instanceof org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment); - Assert.assertNotNull(((org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment)req2).getService_filter()); - Object tosca_id = - ((org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment) req2).getService_filter() - .getTosca_id(); - Assert.assertNotNull(tosca_id); - Assert.assertEquals(SERVICE_FILTER_TOSCA_ID, tosca_id.toString()); + Assert.assertTrue(req2 instanceof RequirementAssignmentExt); + Assert.assertNotNull(((RequirementAssignmentExt) req2).getService_filter()); + Object toscaId = ((RequirementAssignmentExt) req2).getService_filter().getTosca_id(); + Assert.assertNotNull(toscaId); + Assert.assertEquals(SERVICE_FILTER_TOSCA_ID, toscaId.toString()); String serviceTemplateYaml = toscaExtensionYamlUtil.objectToYaml(serviceTemplateWithServiceFilter); diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java index 0f79ed05d6..269f44b28f 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java @@ -16,13 +16,46 @@ package org.openecomp.sdc.tosca.services.impl; -import org.junit.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; -import org.onap.sdc.tosca.datatypes.model.*; +import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition; +import org.onap.sdc.tosca.datatypes.model.CapabilityType; +import org.onap.sdc.tosca.datatypes.model.DataType; +import org.onap.sdc.tosca.datatypes.model.DefinitionOfDataType; +import org.onap.sdc.tosca.datatypes.model.Import; +import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionType; +import org.onap.sdc.tosca.datatypes.model.InterfaceType; +import org.onap.sdc.tosca.datatypes.model.NodeTemplate; +import org.onap.sdc.tosca.datatypes.model.NodeType; +import org.onap.sdc.tosca.datatypes.model.OperationDefinitionType; +import org.onap.sdc.tosca.datatypes.model.ParameterDefinition; +import org.onap.sdc.tosca.datatypes.model.PropertyDefinition; +import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; +import org.onap.sdc.tosca.datatypes.model.RequirementDefinition; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping; +import org.onap.sdc.tosca.datatypes.model.TopologyTemplate; import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.tosca.TestUtil; @@ -30,24 +63,22 @@ import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes; import org.openecomp.sdc.tosca.datatypes.ToscaFlatData; import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; -import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; import org.openecomp.sdc.tosca.services.ToscaConstants; -import java.io.IOException; -import java.io.InputStream; -import java.util.*; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.when; - @RunWith(MockitoJUnitRunner.class) public class ToscaAnalyzerServiceImplTest { - public static final String CAPABILITY_TYPE_A = "capabilityTypeA"; - public static final String CAPABILITY_TYPE_B = "capabilityTypeB"; - public static final String TOSCA_CAPABILITIES_ROOT = "tosca.capabilities.Root"; + private static final String CAPABILITY_TYPE_A = "capabilityTypeA"; + private static final String CAPABILITY_TYPE_B = "capabilityTypeB"; + private static final String TOSCA_CAPABILITIES_ROOT = "tosca.capabilities.Root"; + private static final String CMAUI_IMAGE_EXTEND = "org.openecomp.resource.vfc.nodes.heat.cmaui_image_extend"; + private static final String STANDARD_INTERFACE_KEY = "Standard"; + private static final String TOSCA_LIFECYCLE_STANDARD = "tosca.interfaces.node.lifecycle.Standard"; + private static final String CMAUI_INTERFACE_TEST = + "org.openecomp.resource.vfc.nodes.heat.cmaui_image_interfaceTest"; + private static final String CMAUI_IMAGE_EXTEND2 = "org.openecomp.resource.vfc.nodes.heat.cmaui_image_extend2"; /* Dictionary: @@ -88,7 +119,8 @@ public class ToscaAnalyzerServiceImplTest { public void testGetFlatEntityNotFound() throws Exception { thrown.expect(CoreException.class); thrown.expectMessage( - "Entity Type 'org.openecomp.resource.vfc.notFound' or one of its derivedFrom type hierarchy, is not defined in tosca service model"); + "Entity Type 'org.openecomp.resource.vfc.notFound' or one of its derivedFrom type " + + "hierarchy, is not defined in tosca service model"); ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs( "/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) { @@ -141,12 +173,10 @@ public class ToscaAnalyzerServiceImplTest { List inheritanceHierarchyType = flatData.getInheritanceHierarchyType(); Assert.assertNotNull(inheritanceHierarchyType); Assert.assertEquals(4, inheritanceHierarchyType.size()); - Assert.assertEquals(true, - inheritanceHierarchyType.contains("org.openecomp.resource.vfc.nodes.heat.cmaui_image")); - Assert.assertEquals(true, - inheritanceHierarchyType.contains("org.openecomp.resource.vfc.nodes.heat.nova.Server")); - Assert.assertEquals(true, inheritanceHierarchyType.contains("tosca.nodes.Compute")); - Assert.assertEquals(true, inheritanceHierarchyType.contains("tosca.nodes.Root")); + Assert.assertTrue(inheritanceHierarchyType.contains("org.openecomp.resource.vfc.nodes.heat.cmaui_image")); + Assert.assertTrue(inheritanceHierarchyType.contains("org.openecomp.resource.vfc.nodes.heat.nova.Server")); + Assert.assertTrue(inheritanceHierarchyType.contains("tosca.nodes.Compute")); + Assert.assertTrue(inheritanceHierarchyType.contains("tosca.nodes.Root")); } private void checkNodeTypeFlatEntity(ToscaFlatData flatData) { @@ -168,25 +198,20 @@ public class ToscaAnalyzerServiceImplTest { ServiceTemplate serviceTemplateFromYaml = toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); - ToscaFlatData flatData = toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE, - "org.openecomp.resource.vfc.nodes.heat.cmaui_image_extend", serviceTemplateFromYaml, - toscaServiceModel); + ToscaFlatData flatData = toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE, CMAUI_IMAGE_EXTEND, + serviceTemplateFromYaml, toscaServiceModel); Assert.assertNotNull(flatData); Assert.assertNotNull(flatData.getFlatEntity()); NodeType flatEntity = (NodeType) flatData.getFlatEntity(); Assert.assertNotNull(flatEntity.getInterfaces()); - Object standardInterfaceObj = flatEntity.getInterfaces().get("Standard"); + Object standardInterfaceObj = flatEntity.getInterfaces().get(STANDARD_INTERFACE_KEY); Assert.assertNotNull(standardInterfaceObj); - Optional standardInterface = DataModelUtil - .convertObjToInterfaceDefinition("Standard", - standardInterfaceObj, - InterfaceDefinitionType.class); - Assert.assertEquals(true, standardInterface.isPresent()); - Assert.assertEquals(2, standardInterface.get().getInputs().size()); - Assert.assertEquals(3, standardInterface.get().getOperations().size()); + InterfaceDefinitionType standardInterface = new InterfaceDefinitionType(standardInterfaceObj); + Assert.assertEquals(2, standardInterface.getInputs().size()); + Assert.assertEquals(3, standardInterface.getOperations().size()); OperationDefinitionType createOperation = toscaExtensionYamlUtil.yamlToObject( - toscaExtensionYamlUtil.objectToYaml(standardInterface.get().getOperations().get("create")), + toscaExtensionYamlUtil.objectToYaml(standardInterface.getOperations().get("create")), OperationDefinitionType.class); Assert.assertEquals(2, createOperation.getInputs().size()); @@ -261,11 +286,11 @@ public class ToscaAnalyzerServiceImplTest { Object[] occurences = new Object[] {0, "UNBOUNDED"}; rd.setOccurrences(occurences); - RequirementDefinition rd1 = new RequirementDefinition(); rd.setCapability("tosca.capabilities.network.Bindable"); rd.setNode(null); rd.setRelationship("tosca.relationships.network.BindsTo"); Object[] occurences1 = new Object[] {1, 1}; + RequirementDefinition rd1 = new RequirementDefinition(); rd1.setOccurrences(occurences1); Map nodeTypeRequirementDefinition = new HashMap<>(); @@ -285,8 +310,8 @@ public class ToscaAnalyzerServiceImplTest { List> exposedRequirements = toscaAnalyzerService .calculateExposedRequirements( - nodeTypeRequirementsDefinition, - nodeTemplateRequirementsAssignment); + nodeTypeRequirementsDefinition, + nodeTemplateRequirementsAssignment); Assert.assertEquals(1, exposedRequirements.size()); } @@ -299,11 +324,11 @@ public class ToscaAnalyzerServiceImplTest { Object[] occurences = new Object[] {0, "UNBOUNDED"}; rd.setOccurrences(occurences); - RequirementDefinition rd1 = new RequirementDefinition(); rd.setCapability("tosca.capabilities.network.Bindable"); rd.setNode(null); rd.setRelationship("tosca.relationships.network.BindsTo"); Object[] occurences1 = new Object[] {1, 1}; + RequirementDefinition rd1 = new RequirementDefinition(); rd1.setOccurrences(occurences1); Map nodeTypeRequirementDefinition = new HashMap<>(); @@ -323,8 +348,8 @@ public class ToscaAnalyzerServiceImplTest { List> exposedRequirements = toscaAnalyzerService .calculateExposedRequirements( - nodeTypeRequirementsDefinition, - nodeTemplateRequirementsAssignment); + nodeTypeRequirementsDefinition, + nodeTemplateRequirementsAssignment); Assert.assertEquals(1, exposedRequirements.size()); } @@ -334,11 +359,11 @@ public class ToscaAnalyzerServiceImplTest { CapabilityDefinition cd = new CapabilityDefinition(); cd.setType("tosca.capabilities.Scalable"); nodeTypeCapabilitiesDefinition.put("tosca.capabilities.network.Bindable_pd_server", cd); - Map nodeTemplateRequirementsAssignment = new HashMap<>(); RequirementAssignment ra = new RequirementAssignment(); ra.setCapability("tosca.capabilities.network.Bindable"); ra.setNode("pd_server"); ra.setRelationship("tosca.relationships.network.BindsTo"); + Map nodeTemplateRequirementsAssignment = new HashMap<>(); nodeTemplateRequirementsAssignment.put("binding", ra); Map> fullFilledRequirementsDefinition = new HashMap<>(); fullFilledRequirementsDefinition.put("pd_server", nodeTemplateRequirementsAssignment); @@ -366,17 +391,17 @@ public class ToscaAnalyzerServiceImplTest { NodeTemplate port0 = serviceTemplateFromYaml.getTopology_template().getNode_templates().get("cmaui_port_0"); //Test With Empty requirementId - Assert.assertEquals(false, toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "", ra)); + Assert.assertFalse(toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "", ra)); //Test With valid requirementId - Assert.assertEquals(true, toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "binding", ra)); + Assert.assertTrue(toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "binding", ra)); //Test With invalid requirement assignment RequirementAssignment ra1 = new RequirementAssignment(); ra1.setCapability("tosca.capabilities.network.Bindable1"); ra1.setNode("server_cmaui1"); ra1.setRelationship("tosca.relationships.network.BindsTo1"); - Assert.assertEquals(false, toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "binding", ra1)); + Assert.assertFalse(toscaAnalyzerService.isRequirementExistInNodeTemplate(port0, "binding", ra1)); } } @@ -411,22 +436,23 @@ public class ToscaAnalyzerServiceImplTest { ServiceTemplate emptyServiceTemplate = new ServiceTemplate(); Optional nodeTemplate = toscaAnalyzerService.getNodeTemplateById(emptyServiceTemplate, "test_net222"); - assertEquals(false, nodeTemplate.isPresent()); + assertFalse(nodeTemplate.isPresent()); ServiceTemplate mainServiceTemplate = toscaServiceModel.getServiceTemplates().get(toscaServiceModel.getEntryDefinitionServiceTemplate()); nodeTemplate = toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net"); - assertEquals(true, nodeTemplate.isPresent()); + assertTrue(nodeTemplate.isPresent()); nodeTemplate = toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net222"); - assertEquals(false, nodeTemplate.isPresent()); + assertFalse(nodeTemplate.isPresent()); } @Test public void testGetSubstituteServiceTemplateName() throws Exception { thrown.expect(CoreException.class); thrown.expectMessage( - "Invalid Substitute Node Template invalid2, mandatory map property service_template_filter with mandatory key substitute_service_template must be defined."); + "Invalid Substitute Node Template invalid2, mandatory map property service_template_filter " + + "with mandatory key substitute_service_template must be defined."); Optional substituteServiceTemplateName; @@ -434,28 +460,28 @@ public class ToscaAnalyzerServiceImplTest { toscaServiceModel.getServiceTemplates().get(toscaServiceModel.getEntryDefinitionServiceTemplate()); Optional notSubstitutableNodeTemplate = toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_net"); - assertEquals(true, notSubstitutableNodeTemplate.isPresent()); + assertTrue(notSubstitutableNodeTemplate.isPresent()); if (notSubstitutableNodeTemplate.isPresent()) { substituteServiceTemplateName = toscaAnalyzerService.getSubstituteServiceTemplateName("test_net", notSubstitutableNodeTemplate.get()); - assertEquals(false, substituteServiceTemplateName.isPresent()); + assertFalse(substituteServiceTemplateName.isPresent()); } Optional substitutableNodeTemplate = toscaAnalyzerService.getNodeTemplateById(mainServiceTemplate, "test_nested"); - assertEquals(true, substitutableNodeTemplate.isPresent()); + assertTrue(substitutableNodeTemplate.isPresent()); if (substitutableNodeTemplate.isPresent()) { substituteServiceTemplateName = toscaAnalyzerService.getSubstituteServiceTemplateName("test_nested", substitutableNodeTemplate.get()); - assertEquals(true, substituteServiceTemplateName.isPresent()); + assertTrue(substituteServiceTemplateName.isPresent()); assertEquals("nestedServiceTemplate.yaml", substituteServiceTemplateName.get()); } NodeTemplate invalidSubstitutableNodeTemplate1 = new NodeTemplate(); substituteServiceTemplateName = toscaAnalyzerService.getSubstituteServiceTemplateName("invalid1", invalidSubstitutableNodeTemplate1); - assertEquals(false, substituteServiceTemplateName.isPresent()); + assertFalse(substituteServiceTemplateName.isPresent()); substitutableNodeTemplate.ifPresent(nodeTemplate -> { Object serviceTemplateFilter = @@ -508,12 +534,13 @@ public class ToscaAnalyzerServiceImplTest { ServiceTemplate nestedServiceTemplateFromYaml = toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); - Optional> mappedNodeTemplate = toscaAnalyzerService - .getSubstitutionMappedNodeTemplateByExposedReq( - "NestedServiceTemplateSubstituteTest.yaml", - nestedServiceTemplateFromYaml, - "local_storage_server_cmaui"); - assertEquals(true, mappedNodeTemplate.isPresent()); + Optional> mappedNodeTemplate = + toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq( + "NestedServiceTemplateSubstituteTest.yaml", + nestedServiceTemplateFromYaml, + "local_storage_server_cmaui"); + + assertTrue(mappedNodeTemplate.isPresent()); mappedNodeTemplate.ifPresent(stringNodeTemplateEntry -> { assertEquals("server_cmaui", stringNodeTemplateEntry.getKey()); assertNotNull(stringNodeTemplateEntry.getValue()); @@ -522,7 +549,7 @@ public class ToscaAnalyzerServiceImplTest { mappedNodeTemplate = toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq( "NestedServiceTemplateSubstituteTest.yaml", nestedServiceTemplateFromYaml, "link_cmaui_port_invalid"); - assertEquals(true, mappedNodeTemplate.isPresent()); + assertTrue(mappedNodeTemplate.isPresent()); mappedNodeTemplate.ifPresent(stringNodeTemplateEntry -> { assertEquals("server_cmaui", stringNodeTemplateEntry.getKey()); assertNotNull(stringNodeTemplateEntry.getValue()); @@ -533,7 +560,7 @@ public class ToscaAnalyzerServiceImplTest { mappedNodeTemplate = toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq( toscaServiceModel.getEntryDefinitionServiceTemplate(), mainServiceTemplate, "local_storage_server_cmaui"); - assertEquals(false, mappedNodeTemplate.isPresent()); + assertFalse(mappedNodeTemplate.isPresent()); } } @@ -541,7 +568,8 @@ public class ToscaAnalyzerServiceImplTest { public void invalidSubstitutableMapping() throws Exception { thrown.expect(CoreException.class); thrown.expectMessage( - "Invalid Substitution Service Template invalidMappingServiceTemplate.yaml, missing mandatory file 'Node type' in substitution mapping."); + "Invalid Substitution Service Template invalidMappingServiceTemplate.yaml, " + + "missing mandatory file 'Node type' in substitution mapping."); ServiceTemplate invalidMappingServiceTemplate = new ServiceTemplate(); invalidMappingServiceTemplate.setTopology_template(new TopologyTemplate()); invalidMappingServiceTemplate.getTopology_template().setSubstitution_mappings(new SubstitutionMapping()); @@ -557,13 +585,11 @@ public class ToscaAnalyzerServiceImplTest { emptyReqMapping.getTopology_template().getSubstitution_mappings().setNode_type("temp"); ServiceTemplate mainServiceTemplate = toscaServiceModel.getServiceTemplates().get(toscaServiceModel.getEntryDefinitionServiceTemplate()); - Optional> mappedNodeTemplate = toscaAnalyzerService - .getSubstitutionMappedNodeTemplateByExposedReq( - toscaServiceModel - .getEntryDefinitionServiceTemplate(), - mainServiceTemplate, - "local_storage_server_cmaui"); - assertEquals(false, mappedNodeTemplate.isPresent()); + Optional> mappedNodeTemplate = + toscaAnalyzerService.getSubstitutionMappedNodeTemplateByExposedReq( + toscaServiceModel.getEntryDefinitionServiceTemplate(),mainServiceTemplate, + "local_storage_server_cmaui"); + assertFalse(mappedNodeTemplate.isPresent()); } @Test @@ -594,20 +620,17 @@ public class ToscaAnalyzerServiceImplTest { requirementAssignment.setNode(node); requirementAssignment.setRelationship(relationship); - assertEquals(true, toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node, - relationship)); - assertEquals(true, + assertTrue(toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, capability, node, relationship)); + assertTrue( toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, node, relationship)); - assertEquals(true, toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, null, - relationship)); - assertEquals(true, - toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node, null)); - assertEquals(true, + assertTrue(toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, capability, null, relationship)); + assertTrue(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node, null)); + assertTrue( toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, null, relationship)); - assertEquals(true, - toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, null, null)); - assertEquals(true, - toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, node, null)); + assertTrue(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, null, null)); + assertTrue(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, node, null)); } @@ -622,22 +645,17 @@ public class ToscaAnalyzerServiceImplTest { requirementAssignment.setNode(node); requirementAssignment.setRelationship(relationship); - assertEquals(false, + assertFalse( toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", node, relationship)); - assertEquals(false, + assertFalse( toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", "no", relationship)); - assertEquals(false, - toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", "no", "no")); - assertEquals(false, toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, "no", - relationship)); - assertEquals(false, - toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node, "no")); - assertEquals(false, - toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, "no", "no")); - assertEquals(false, - toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", null, null)); - assertEquals(false, - toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, null, null)); + assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", "no", "no")); + assertFalse(toscaAnalyzerService + .isDesiredRequirementAssignment(requirementAssignment, capability, "no", relationship)); + assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, node, "no")); + assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, capability, "no", "no")); + assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, "no", null, null)); + assertFalse(toscaAnalyzerService.isDesiredRequirementAssignment(requirementAssignment, null, null, null)); } @@ -676,6 +694,42 @@ public class ToscaAnalyzerServiceImplTest { toscaServiceModelMock)); } + @Test + public void interfaceInheritanceNoOperIsTypeTrue() throws IOException { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs( + "/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml")) { + interfaceIsTypeTest(toscaExtensionYamlUtil, CMAUI_IMAGE_EXTEND, yamlFile); + } + } + + private void interfaceIsTypeTest(ToscaExtensionYamlUtil toscaExtensionYamlUtil, String nodeTypeKey, + InputStream yamlFile) { + ServiceTemplate serviceTemplateFromYaml = toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + + ToscaFlatData flatData = toscaAnalyzerService.getFlatEntity(ToscaElementTypes.NODE_TYPE, nodeTypeKey, + serviceTemplateFromYaml, toscaServiceModel); + + Assert.assertNotNull(flatData); + Object standardInterfaceDefinition = + ((NodeType) flatData.getFlatEntity()).getInterfaces().get(STANDARD_INTERFACE_KEY); + InterfaceDefinitionType standardInterfaceDefinitionType = + new InterfaceDefinitionType(standardInterfaceDefinition); + assertTrue(toscaAnalyzerService + .isTypeOf(standardInterfaceDefinitionType, TOSCA_LIFECYCLE_STANDARD, serviceTemplateFromYaml, + toscaServiceModel)); + } + + @Test + public void interfaceInheritanceWithOperIsTypeTrue() throws IOException { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs( + "/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml")) { + interfaceIsTypeTest(toscaExtensionYamlUtil, CMAUI_INTERFACE_TEST, yamlFile); + } + } + + @Test public void shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyAndNdTyDerivedFromRequestedType() { String typeToMatch = ToscaNodeType.CINDER_VOLUME; @@ -765,7 +819,8 @@ public class ToscaAnalyzerServiceImplTest { } @Test - public void shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyAndNotDerivedFromRequestedTypeBut2ndLevelDerivedFromMatch() { + public void + shouldReturnTrueIfNdTmpTypeIsFoundInSrvTmpNdTyAndNotDerivedFromRequestedTypeBut2ndLevelDerivedFromMatch() { String typeToMatch = "A"; when(nodeTemplateMock.getType()).thenReturn(typeToMatch); Map stNodeTypes = new HashMap<>(); @@ -814,8 +869,8 @@ public class ToscaAnalyzerServiceImplTest { anImport.setFile("mainImport"); importMap.put("bla bla", anImport); imports.add(importMap); - ServiceTemplate mainST = new ServiceTemplate(); - mainST.setImports(imports); + ServiceTemplate mainSt = new ServiceTemplate(); + mainSt.setImports(imports); //create searchable service template Map stNodeTypes = new HashMap<>(); @@ -827,11 +882,11 @@ public class ToscaAnalyzerServiceImplTest { // add service templates to tosca service model Map serviceTemplates = toscaServiceModelMock.getServiceTemplates(); - serviceTemplates.put("testMainServiceTemplate", mainST); + serviceTemplates.put("testMainServiceTemplate", mainSt); serviceTemplates.put("mainImport", serviceTemplate); when(toscaServiceModelMock.getServiceTemplates()).thenReturn(serviceTemplates); - assertTrue(toscaAnalyzerService.isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_BLOCK_STORAGE, mainST, + assertTrue(toscaAnalyzerService.isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_BLOCK_STORAGE, mainSt, toscaServiceModelMock)); } @@ -845,8 +900,8 @@ public class ToscaAnalyzerServiceImplTest { anImport.setFile("refToMainImport"); importMap.put("bla bla", anImport); imports.add(importMap); - ServiceTemplate mainST = new ServiceTemplate(); - mainST.setImports(imports); + ServiceTemplate mainSt = new ServiceTemplate(); + mainSt.setImports(imports); //create searchable service template Map stNodeTypes = new HashMap<>(); @@ -863,17 +918,17 @@ public class ToscaAnalyzerServiceImplTest { firstLevelImport.setFile("mainImport"); firstLevelImportsMap.put("bla bla 2", firstLevelImport); firstLevelImports.add(firstLevelImportsMap); - ServiceTemplate firstLevelST = new ServiceTemplate(); - firstLevelST.setImports(firstLevelImports); + ServiceTemplate firstLevelSt = new ServiceTemplate(); + firstLevelSt.setImports(firstLevelImports); // add service templates to tosca service model Map serviceTemplates = toscaServiceModelMock.getServiceTemplates(); - serviceTemplates.put("testMainServiceTemplate", mainST); - serviceTemplates.put("refToMainImport", firstLevelST); + serviceTemplates.put("testMainServiceTemplate", mainSt); + serviceTemplates.put("refToMainImport", firstLevelSt); serviceTemplates.put("mainImport", serviceTemplate); when(toscaServiceModelMock.getServiceTemplates()).thenReturn(serviceTemplates); - assertTrue(toscaAnalyzerService.isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_BLOCK_STORAGE, mainST, + assertTrue(toscaAnalyzerService.isTypeOf(nodeTemplateMock, ToscaNodeType.NATIVE_BLOCK_STORAGE, mainSt, toscaServiceModelMock)); } @@ -913,5 +968,5 @@ public class ToscaAnalyzerServiceImplTest { assertTrue(toscaAnalyzerService .isTypeOf(capabilityDefinition, CAPABILITY_TYPE_B, serviceTemplate, toscaServiceModelMock)); } - } + -- cgit 1.2.3-korg