X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-be-plugins%2Fetsi-nfv-nsd-csar-plugin%2Fsrc%2Ftest%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fplugins%2Fetsi%2Fnfv%2Fnsd%2Fgenerator%2FNsDescriptorGeneratorImplTest.java;h=7ad43db45b04772eff36daa6c0daa3ed6ff1b8c7;hb=28e1a54e6074f50dcc06f7ea4eb3943ad873b448;hp=69d9b0fd756ca42f8324945363de97ca1e105d23;hpb=280149632b48dfabd4c12719d1ff391414bbd02f;p=sdc.git diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java index 69d9b0fd75..7ad43db45b 100644 --- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java +++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java @@ -26,6 +26,10 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNull.notNullValue; import static org.hamcrest.core.IsNull.nullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.mock; @@ -40,6 +44,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -59,6 +64,7 @@ import org.openecomp.sdc.be.tosca.model.ToscaNodeType; import org.openecomp.sdc.be.tosca.model.ToscaProperty; import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraint; import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintValidValues; +import org.openecomp.sdc.be.tosca.model.ToscaRequirement; import org.openecomp.sdc.be.tosca.model.ToscaTemplate; import org.openecomp.sdc.be.tosca.model.ToscaTemplateCapability; import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate; @@ -70,6 +76,9 @@ class NsDescriptorGeneratorImplTest { private static final String VNFD_AMF_NODE_NAME = "vnfd_amf"; private static final String VIRTUAL_LINK_REQUIREMENT_NAME = "virtual_link"; + private static final String VIRTUAL_BINDING_REQUIREMENT_NAME = "virtual_binding"; + private static final String DOT = "."; + private static final String PREFIX = "VNF"; private final ObjectProvider toscaTemplateYamlGeneratorProvider = new ObjectProvider<>() { @Override public ToscaTemplateYamlGenerator getObject(Object... args) { @@ -98,7 +107,7 @@ class NsDescriptorGeneratorImplTest { @BeforeEach void setUp() { setUpConfigurationMock(); - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); nsDescriptorGenerator = new NsDescriptorGeneratorImpl(toscaExportHandler, toscaTemplateYamlGeneratorProvider); } @@ -119,6 +128,7 @@ class NsDescriptorGeneratorImplTest { } @Test + @SuppressWarnings("unchecked") void testGenerate() throws IOException, NsdException { //given final Component component = mock(Component.class); @@ -142,24 +152,36 @@ class NsDescriptorGeneratorImplTest { componentToscaTopologyTemplate.setNode_templates(nodeTemplateMap); final SubstitutionMapping substitutionMapping = mock(SubstitutionMapping.class); Map requirements = new HashMap<>(); - String[] requirementAssignment = {"VNF1", VIRTUAL_LINK_REQUIREMENT_NAME}; - requirements.put(VIRTUAL_LINK_REQUIREMENT_NAME, requirementAssignment); + String[] requirementAssignmentVl = {"VNF1", PREFIX + DOT + VIRTUAL_LINK_REQUIREMENT_NAME}; + requirements.put("VNF1" + DOT + VIRTUAL_LINK_REQUIREMENT_NAME, requirementAssignmentVl); when(substitutionMapping.getRequirements()).thenReturn(requirements); Map capabilities = new HashMap<>(); String[] capabilitiesAssignment = {"VNF1", "capability1"}; capabilities.put("capability", capabilitiesAssignment); when(substitutionMapping.getCapabilities()).thenReturn(capabilities); componentToscaTopologyTemplate.setSubstitution_mappings(substitutionMapping); + + Map inputs = new HashMap<>(); + inputs.put("invariant_id", new ToscaProperty()); + inputs.put("other_property", new ToscaProperty()); + componentToscaTopologyTemplate.setInputs(inputs ); final ToscaTemplate componentInterfaceToscaTemplate = new ToscaTemplate(""); final String designerPropertyValue = "designerValue"; final String versionPropertyValue = "versionValue"; final String namePropertyValue = "nameValue"; final String invariantIdPropertyValue = "invariantIdValue"; + final String otherPropertyValue = "otherValue"; final ToscaNodeType interfaceToscaNodeType = createDefaultInterfaceToscaNodeType(designerPropertyValue, versionPropertyValue, - namePropertyValue, invariantIdPropertyValue); + namePropertyValue, invariantIdPropertyValue, otherPropertyValue); + List> interfaceNodeTypeRequirements = new ArrayList<>(); + Map interfaceNodeTypeRequirementMap = new HashMap<>(); + interfaceNodeTypeRequirementMap.put("VNF1" + DOT + VIRTUAL_LINK_REQUIREMENT_NAME, mock(ToscaRequirement.class)); + interfaceNodeTypeRequirementMap.put("VNF1" + DOT + VIRTUAL_BINDING_REQUIREMENT_NAME, mock(ToscaRequirement.class)); + interfaceNodeTypeRequirements.add(interfaceNodeTypeRequirementMap); + interfaceToscaNodeType.setRequirements(interfaceNodeTypeRequirements); final String nsNodeTypeName = "nsNodeTypeName"; componentInterfaceToscaTemplate.setNode_types(ImmutableMap.of(nsNodeTypeName, interfaceToscaNodeType)); - when(toscaExportHandler.convertToToscaTemplate(component)).thenReturn(Either.left(componentToscaTemplate)); + when(toscaExportHandler.convertToToscaTemplate(component, false)).thenReturn(Either.left(componentToscaTemplate)); when(toscaExportHandler.convertInterfaceNodeType(any(), any(), any(), any(), anyBoolean())) .thenReturn(Either.left(componentInterfaceToscaTemplate)); final List vnfDescriptorList = new ArrayList<>(); @@ -177,32 +199,53 @@ class NsDescriptorGeneratorImplTest { assertThat("Nsd name should be as expected", nsd.getName(), is(namePropertyValue)); assertThat("Nsd invariantId should be as expected", nsd.getInvariantId(), is(invariantIdPropertyValue)); final Map toscaTemplateYaml = readYamlAsMap(nsd.getContents()); - @SuppressWarnings("unchecked") final Map topologyTemplate = (Map) toscaTemplateYaml.get("topology_template"); + final Map topologyTemplate = (Map) toscaTemplateYaml.get("topology_template"); assertThat("topology_template should not be empty", topologyTemplate, is(not(anEmptyMap()))); - @SuppressWarnings("unchecked") final Map substitutionMappings = (Map) topologyTemplate + final Map substitutionMappings = (Map) topologyTemplate .get("substitution_mappings"); assertThat("substitution_mappings should not be empty", substitutionMappings, is(not(anEmptyMap()))); assertThat("substitution_mappings->node_type should not be null", substitutionMappings.get("node_type"), is(notNullValue())); assertThat("substitution_mappings->node_type should be as expected", substitutionMappings.get("node_type"), is(nsNodeTypeName)); final Map> subMappingRequirements = (Map>) substitutionMappings.get("requirements"); - assertThat(subMappingRequirements.get(VIRTUAL_LINK_REQUIREMENT_NAME).get(0), is("VNF1")); - assertThat(subMappingRequirements.get(VIRTUAL_LINK_REQUIREMENT_NAME).get(1), is(VIRTUAL_LINK_REQUIREMENT_NAME)); + assertThat(subMappingRequirements.get("VNF1" + DOT + VIRTUAL_LINK_REQUIREMENT_NAME).get(0), is("VNF1")); + assertThat(subMappingRequirements.get("VNF1" + DOT + VIRTUAL_LINK_REQUIREMENT_NAME).get(1), is(VIRTUAL_LINK_REQUIREMENT_NAME)); + assertEquals(1, subMappingRequirements.size()); final Map> subMappingCapabilities = (Map>) substitutionMappings.get("capabilities"); - assertThat(subMappingCapabilities.get("capability").get(0), is("VNF1")); - assertThat(subMappingCapabilities.get("capability").get(1), is("capability1")); - @SuppressWarnings("unchecked") final Map nodeTemplates = (Map) topologyTemplate.get("node_templates"); - @SuppressWarnings("unchecked") final Map nodeTemplate = (Map) nodeTemplates.get(VNFD_AMF_NODE_NAME); - assertThat("capabilities should be null", nodeTemplate.get("capabilities"), is(nullValue())); + assertNull(subMappingCapabilities); + + final Map topologyInputs = (Map) topologyTemplate.get("inputs"); + assertTrue(topologyInputs.containsKey("other_property")); + assertEquals(1, topologyInputs.size()); + + final Map nodeTemplates = (Map) ((Map) topologyTemplate.get("node_templates")); + final Map nodeTemplateVnfd = (Map) ((Map) nodeTemplates.get(VNFD_AMF_NODE_NAME)); + final Map nodeTemplateProperties = (Map) ((Map) nodeTemplateVnfd.get("properties")); + assertTrue(nodeTemplateProperties.containsKey("will_not_be_excluded")); + + final Map nodeType = (Map) ((Map) toscaTemplateYaml.get("node_types")).get(nsNodeTypeName); + assertTrue(((List>)nodeType.get("requirements")).get(0).containsKey("VNF1" + DOT + VIRTUAL_LINK_REQUIREMENT_NAME)); + assertFalse(((List>)nodeType.get("requirements")).get(0).containsKey("VNF1" + DOT + VIRTUAL_BINDING_REQUIREMENT_NAME)); + + assertEquals(5, ((Map)nodeType.get("properties")).size()); + for (final Entry property: ((Map)nodeType.get("properties")).entrySet()) { + if (property.getKey().equals("other_property")) { + assertNull(property.getValue().get("constraints")); + } else { + assertEquals(1, ((List)property.getValue().get("constraints")).size()); + } + } + } private ToscaNodeType createDefaultInterfaceToscaNodeType(final String designerPropertyValue, final String versionPropertyValue, - final String namePropertyValue, final String invariantIdPropertyValue) { + final String namePropertyValue, final String invariantIdPropertyValue, String otherPropertyValue) { final ToscaNodeType interfaceToscaNodeType = new ToscaNodeType(); final Map propertyMap = new HashMap<>(); propertyMap.put("designer", createToscaProperty(designerPropertyValue)); propertyMap.put("version", createToscaProperty(versionPropertyValue)); propertyMap.put("name", createToscaProperty(namePropertyValue)); propertyMap.put("invariant_id", createToscaProperty(invariantIdPropertyValue)); + propertyMap.put("other_property", createToscaProperty(otherPropertyValue)); interfaceToscaNodeType.setProperties(propertyMap); return interfaceToscaNodeType; } @@ -215,8 +258,7 @@ class NsDescriptorGeneratorImplTest { private ToscaProperty createToscaProperty(final String value) { final ToscaProperty toscaProperty = new ToscaProperty(); - final ToscaPropertyConstraint toscaPropertyConstraint = new ToscaPropertyConstraintValidValues(ImmutableList.of(value)); - toscaProperty.setConstraints(ImmutableList.of(toscaPropertyConstraint)); + toscaProperty.setDefaultp(value); return toscaProperty; }