From c0d03886fbf71cbc843e9a7c7d47221ae4f8d2eb Mon Sep 17 00:00:00 2001 From: Pavel Aharoni Date: Mon, 21 Aug 2017 21:37:17 +0300 Subject: [SDC-243] sdc-tosca for port mirroring Change-Id: I9fc74a79a6fd5c6f4bafc4767b78241c3ebcc021 Signed-off-by: Pavel Aharoni --- pom.xml | 4 +- .../sdc/tosca/parser/api/ISdcCsarHelper.java | 73 ++++++++-- .../sdc/tosca/parser/impl/SdcCsarHelperImpl.java | 121 ++++++++++++---- .../openecomp/sdc/tosca/parser/impl/SdcTypes.java | 2 +- .../openecomp/sdc/impl/ToscaParserGroupTest.java | 2 +- .../sdc/impl/ToscaParserMetadataTest.java | 35 +++++ .../sdc/impl/ToscaParserNodeTemplateTest.java | 21 +++ .../sdc/impl/ToscaParserReqAndCapTest.java | 97 +++++++++++++ .../sdc/impl/ToscaParserSubsMappingsTest.java | 154 ++++++++++----------- src/test/resources/csars/service-sunny-flow.csar | Bin 45194 -> 45199 bytes 10 files changed, 394 insertions(+), 115 deletions(-) create mode 100644 src/test/java/org/openecomp/sdc/impl/ToscaParserReqAndCapTest.java diff --git a/pom.xml b/pom.xml index 280ef10..3ccca61 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ sdc-tosca SDC Tosca Parser SDC Tosca Parser JAR file for use by consumers - 1.1.34-SNAPSHOT + 1.1.50-SNAPSHOT jar @@ -97,7 +97,7 @@ org.openecomp.sdc.jtosca jtosca - 1.1.3-SNAPSHOT + 1.1.10-SNAPSHOT diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java index 06a66c6..df9e47d 100644 --- a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java +++ b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java @@ -25,8 +25,7 @@ import java.util.Map; import org.apache.commons.lang3.tuple.Pair; import org.openecomp.sdc.tosca.parser.impl.FilterType; import org.openecomp.sdc.tosca.parser.impl.SdcTypes; -import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.*; import org.openecomp.sdc.toscaparser.api.elements.Metadata; import org.openecomp.sdc.toscaparser.api.parameters.Input; @@ -203,17 +202,29 @@ public interface ISdcCsarHelper { public String getServiceSubstitutionMappingsTypeName(); /** - * Get the CSAR service metadata - * @return - the service metadata object. + * Get service Metadata object.
+ * This object represents the "metadata" section of a CSAR service. + * @return - the service Metadata object. */ public Metadata getServiceMetadata(); /** * Get the CSAR service metadata as map. * @return - the service metadata object as Map. + * @deprecated This function is deprecated since its not tosca compliant.
+ * Tosca defines the Metadata section as map of string (not map of object).
+ * This function is targeted to be removed as part of 1802.
+ * Please use {@link #getServiceMetadataAllProperties() getServiceMetadataAllProperties()}. */ + @Deprecated public Map getServiceMetadataProperties(); + /** + * Get the CSAR service metadata as map + * @return - the service metadata object as Map + */ + public Map getServiceMetadataAllProperties(); + /** * Get all VFC node templates from a specified VF. * @param vfCustomizationId - customizationUuid of the VF node template. @@ -326,7 +337,8 @@ public interface ISdcCsarHelper { * port_fe_oam={ip_requirements#ip_count_required#count=2, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4, subnetpoolid="subnet_2", network_role_tag="Mobility_OAM_protected"}}

* @param vfc - VFC node template to look for CP-related props. * @return map CP node template name to a map of full path to a property on this CP - value of this property on this CP. - * @deprecated This function is deprecated since its flattened form doesn't provide solution for cp properties of type List. + * @deprecated This function is deprecated since its flattened form doesn't provide solution for cp properties of type List. + * Will be removed in 1802. */ @Deprecated public Map> getCpPropertiesFromVfc(NodeTemplate vfc); @@ -367,9 +379,9 @@ public interface ISdcCsarHelper { public List getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType); /** - * Get all node templates by sdcType for this CSAR service. + * Get all node templates by SDC type enum for this CSAR service. * - * @param sdcType - the SDC type of the node. + * @param sdcType - the SDC type of the node (for example, CP, VF...). * @return service node templates of this SDC type. */ public List getServiceNodeTemplateBySdcType(SdcTypes sdcType); @@ -394,4 +406,49 @@ public interface ISdcCsarHelper { * @return return list of children node templates for node template. */ public List getNodeTemplateChildren(NodeTemplate nodeTemplate); -} + + /** + * Get node template on service level by node template name. + * @param nodeName - the name of the node template. + * @return service-level node template with this name, or null if no such node template was found. + */ + public NodeTemplate getServiceNodeTemplateByNodeName(String nodeName); + + /** + * Get node template Metadata object.
+ * This object represents the "metadata" section of node template. + * @param nt - Node template to get its Metadata object. + * @return Metadata for this node template, or null if not found. + */ + public Metadata getNodeTemplateMetadata(NodeTemplate nt); + + /** + * Get CapabilityAssignments object for this node template.
+ * This should be an entry point function for working with capability assignments of node template.
+ * This object allows filtering capability assignments objects.
+ * @param nt - Node Template to get its capability assignments. + * @return CapabilitiesAssignments that contains list of capability assignments for the node template.
+ * If none found, an empty list will be returned. + */ + public CapabilityAssignments getCapabilitiesOf(NodeTemplate nt); + + /** + * Get RequirementAssignments object for this node template.
+ * This should be an entry point function for working with requirement assignments of node template.
+ * This object allows filtering requirement assignments objects.
+ * @param nt - Node Template to get its requirement assignments. + * @return RequirementAssignments that contains list of requirement assignments for the node template. + * If none found, an empty list will be returned. + */ + public RequirementAssignments getRequirementsOf(NodeTemplate nt); + + /** + * Get any property leaf value for capability by full path separated by #. + * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for a capability assignment. + * @param capability - capability assignment where the property should be looked up. + * @param pathToPropertyLeafValue - the full path of the required property. + * @return the leaf value as String, or null if there's no such property, or it's not a leaf. + */ + public String getCapabilityPropertyLeafValue(CapabilityAssignment capability, String pathToPropertyLeafValue); + +} \ No newline at end of file diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java index bfbbeee..c320f63 100644 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java +++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java @@ -27,14 +27,11 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.toscaparser.api.CapabilityAssignments; import org.openecomp.sdc.tosca.parser.utils.GeneralUtility; +import org.openecomp.sdc.toscaparser.api.RequirementAssignments; import org.openecomp.sdc.tosca.parser.utils.SdcToscaUtility; -import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.toscaparser.api.Property; -import org.openecomp.sdc.toscaparser.api.SubstitutionMappings; -import org.openecomp.sdc.toscaparser.api.TopologyTemplate; -import org.openecomp.sdc.toscaparser.api.ToscaTemplate; +import org.openecomp.sdc.toscaparser.api.*; import org.openecomp.sdc.toscaparser.api.elements.Metadata; import org.openecomp.sdc.toscaparser.api.elements.NodeType; import org.openecomp.sdc.toscaparser.api.functions.Function; @@ -398,10 +395,18 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { @Override //Sunny flow - covered with UT public Map getServiceMetadataProperties() { - if (toscaTemplate.getMetaData()==null){ + if (toscaTemplate.getMetaData() == null){ return null; } - return toscaTemplate.getMetaData().getPropertyMap(); + return new HashMap<>(toscaTemplate.getMetaData().getAllProperties()); + } + + @Override + public Map getServiceMetadataAllProperties() { + if (toscaTemplate.getMetaData() == null){ + return null; + } + return toscaTemplate.getMetaData().getAllProperties(); } @Override @@ -509,32 +514,37 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { @SuppressWarnings("unchecked") public List> getNodeTemplatePairsByReqName( List listOfReqNodeTemplates, List listOfCapNodeTemplates, String reqName) { - if (listOfReqNodeTemplates == null || listOfCapNodeTemplates == null || reqName == null) { - //TODO error message + + if (listOfReqNodeTemplates == null) { + log.error("getNodeTemplatePairsByReqName - listOfReqNodeTemplates is null"); + return new ArrayList<>(); + } + + if (listOfCapNodeTemplates == null) { + log.error("getNodeTemplatePairsByReqName - listOfCapNodeTemplates is null"); + return new ArrayList<>(); + } + + if (GeneralUtility.isEmptyString(reqName)) { + log.error("getNodeTemplatePairsByReqName - reqName is null or empty"); return new ArrayList<>(); } List> pairsList = new ArrayList<>(); - if (listOfReqNodeTemplates != null) { - for (NodeTemplate reqNodeTemplate : listOfReqNodeTemplates) { - List requirements = reqNodeTemplate.getRequirements(); - for (Object reqEntry : requirements) { - LinkedHashMap reqEntryHash = (LinkedHashMap) reqEntry; - Map reqEntryMap = (Map) reqEntryHash.get(reqName); - if (reqEntryMap != null) { - Object node = reqEntryMap.get("node"); - if (node != null) { - String nodeString = (String) node; - Optional findFirst = listOfCapNodeTemplates.stream().filter(x -> x.getName().equals(nodeString)).findFirst(); - if (findFirst.isPresent()) { - pairsList.add(new ImmutablePair(reqNodeTemplate, findFirst.get())); - } - } + for (NodeTemplate reqNodeTemplate : listOfReqNodeTemplates) { + List requirements = reqNodeTemplate.getRequirements().getRequirementsByName(reqName).getAll(); + for (RequirementAssignment reqEntry : requirements) { + String node = reqEntry.getNodeTemplateName(); + if (node != null) { + Optional findFirst = listOfCapNodeTemplates.stream().filter(x -> x.getName().equals(node)).findFirst(); + if (findFirst.isPresent()) { + pairsList.add(new ImmutablePair(reqNodeTemplate, findFirst.get())); } } } } + return pairsList; } @@ -729,6 +739,67 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { return new ArrayList<>(); } + @Override + public NodeTemplate getServiceNodeTemplateByNodeName(String nodeName) { + if (GeneralUtility.isEmptyString(nodeName)) { + log.error("getServiceNodeTemplateByNodeName - nodeName - is null or empty"); + return null; + } + + List nodeTemplates = getServiceNodeTemplates(); + Optional findFirst = nodeTemplates.stream().filter(nt -> nt.getName().equals(nodeName)).findFirst(); + + return findFirst.isPresent() ? findFirst.get() : null; + } + + @Override + public Metadata getNodeTemplateMetadata(NodeTemplate nt) { + if (nt == null) { + log.error("getNodeTemplateMetadata - nt (node template) - is null"); + return null; + } + + return nt.getMetaData(); + } + + @Override + public CapabilityAssignments getCapabilitiesOf(NodeTemplate nt) { + if (nt == null) { + log.error("getCapabilitiesOf - nt (node template) - is null"); + return null; + } + + return nt.getCapabilities(); + } + + @Override + public RequirementAssignments getRequirementsOf(NodeTemplate nt) { + if (nt == null) { + log.error("getRequirementsOf - nt (node template) - is null"); + return null; + } + + return nt.getRequirements(); + } + + @Override + public String getCapabilityPropertyLeafValue(CapabilityAssignment capability, String pathToPropertyLeafValue) { + if (capability == null) { + log.error("getCapabilityPropertyLeafValue - capability is null"); + return null; + } + + if (GeneralUtility.isEmptyString(pathToPropertyLeafValue)) { + log.error("getCapabilityPropertyLeafValue - pathToPropertyLeafValue is null or empty"); + return null; + } + + String[] split = getSplittedPath(pathToPropertyLeafValue); + LinkedHashMap properties = capability.getProperties(); + Object property = processProperties(split, properties); + return property == null || property instanceof Function ? null : String.valueOf(property); + } + /************************************* helper functions ***********************************/ private boolean isVNFType(NodeTemplate nt) { return nt.getType().endsWith("VnfConfiguration"); diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java index 9f885f4..5dc9101 100644 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java +++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java @@ -25,7 +25,7 @@ import java.util.List; public enum SdcTypes { - CP, VL, VF, VFC, PNF, SERVICE, CVFC; + CP, VL, VF, VFC, PNF, SERVICE, CVFC, SERVICE_PROXY, CONFIGURATION; public static List complexTypes = Arrays.asList(VF, PNF, SERVICE, CVFC); diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java index d7321d1..8435c12 100644 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java @@ -20,7 +20,7 @@ public class ToscaParserGroupTest extends SdcToscaParserBasicTest{ for (Group group : vfModulesByVf){ assertTrue(group.getName().startsWith("fdnt1")); assertNotNull(group.getMetadata()); - assertNotNull(group.getMetadata().getValue("vfModuleCustomizationUUID")); + assertNotNull(group.getMetadata().getValue("vfModuleModelCustomizationUUID")); } } diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java index cd80f3a..70bd9c9 100644 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java @@ -1,8 +1,10 @@ package org.openecomp.sdc.impl; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; import org.testng.annotations.Test; import org.openecomp.sdc.toscaparser.api.elements.Metadata; +import java.util.List; import java.util.Map; import static org.testng.Assert.assertEquals; @@ -81,4 +83,37 @@ public class ToscaParserMetadataTest extends SdcToscaParserBasicTest { assertEquals(metadata.get("namingPolicy"),"test"); } //endregion + + //region getServiceMetadataAllProperties + @Test + public void testNullServiceMetadataAllPropertiesMap() { + Map metadata = rainyCsarHelperSingleVf.getServiceMetadataAllProperties(); + assertNull(metadata); + } + + @Test + public void testServiceMetadataAllPropertiesMap() { + Map metadata = fdntCsarHelper.getServiceMetadataAllProperties(); + assertNotNull(metadata); + assertEquals(metadata.size(),9); + assertEquals(metadata.get("namingPolicy"),"test"); + } + //endregion + + //region getNodeTemplateMetadata + @Test + public void testGetNodeTemplateMetadata() { + List vfs = fdntCsarHelper.getServiceVfList(); + Metadata metadata = fdntCsarHelper.getNodeTemplateMetadata(vfs.get(0)); + assertNotNull(metadata); + assertEquals("VF", metadata.getValue("type")); + assertEquals("1.0", metadata.getValue("version")); + } + + @Test + public void testGetNodeTemplateMetadataByNull() { + Metadata metadata = fdntCsarHelper.getNodeTemplateMetadata(null); + assertNull(metadata); + } + //endregion } diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java index 80bf1b9..dc0fa70 100644 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java @@ -729,6 +729,27 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { } } + //region getServiceNodeTemplateByNodeName + @Test + public void testGetServiceNodeTemplateByRealNodeName() { + NodeTemplate nodeTemplate = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); + assertNotNull(nodeTemplate); + assertEquals(nodeTemplate.getName(), "FDNT 1"); + assertEquals(nodeTemplate.getMetaData().getValue("type"), "VF"); + } + + @Test + public void testGetServiceNodeTemplateByNullNodeName() { + NodeTemplate nodeTemplate = fdntCsarHelper.getServiceNodeTemplateByNodeName(null); + assertNull(nodeTemplate); + } + + @Test + public void testGetServiceNodeTemplateByDummyNodeName() { + NodeTemplate nodeTemplate = fdntCsarHelper.getServiceNodeTemplateByNodeName("dummy"); + assertNull(nodeTemplate); + } + //endregion //region resolve get_input @Test public void testResolveGetInputForComplexTypeAndList() { diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserReqAndCapTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserReqAndCapTest.java new file mode 100644 index 0000000..797aa54 --- /dev/null +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserReqAndCapTest.java @@ -0,0 +1,97 @@ +package org.openecomp.sdc.impl; + +import org.openecomp.sdc.tosca.parser.impl.SdcTypes; +import org.openecomp.sdc.toscaparser.api.CapabilityAssignment; +import org.openecomp.sdc.toscaparser.api.CapabilityAssignments; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.RequirementAssignments; +import org.testng.annotations.Test; + +import java.util.List; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +public class ToscaParserReqAndCapTest extends SdcToscaParserBasicTest { + + //region getCapabilitiesOf + @Test + public void testGetCapabilitiesOfNodeTemplate() { + List vfs = fdntCsarHelper.getServiceVfList(); + CapabilityAssignments capabilityAssignments = fdntCsarHelper.getCapabilitiesOf(vfs.get(0)); + assertNotNull(capabilityAssignments); + assertEquals(13, capabilityAssignments.getAll().size()); + assertNotNull(capabilityAssignments.getCapabilityByName("DNT_FW_RHRG.binding_DNT_FW_INT_DNS_TRUSTED_RVMI")); + assertEquals(6, capabilityAssignments.getCapabilitiesByType("tosca.capabilities.network.Bindable").getAll().size()); + } + + @Test + public void testGetCapabilitiesOfNull() { + CapabilityAssignments capabilityAssignments = fdntCsarHelper.getCapabilitiesOf(null); + assertNull(capabilityAssignments); + } + //endregion + + //region getRequirementsOf + @Test + public void testGetRequirementsOfNodeTemplate() { + List vfs = fdntCsarHelper.getServiceVfList(); + List cps = fdntCsarHelper.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); + RequirementAssignments requirementAssignments = fdntCsarHelper.getRequirementsOf(cps.get(0)); + assertNotNull(requirementAssignments); + assertEquals(1, requirementAssignments.getAll().size()); + assertEquals("DNT_FW_RHRG", requirementAssignments.getRequirementsByName("binding").getAll().get(0).getNodeTemplateName()); + } + + @Test + public void testGetRequirementsOfNull() { + RequirementAssignments requirementAssignments = fdntCsarHelper.getRequirementsOf(null); + assertNull(requirementAssignments); + } + //endregion + + //region getCapabilityPropertyLeafValue + @Test + public void testGetCapabilityPropertyLeafValue() { + NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); + CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER"); + assertNotNull(capabilityAssignment); + String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "max_instances#type"); + assertEquals("integer", propValue); + } + + @Test + public void testGetCapabilityHierarchyPropertyLeafValue() { + NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); + CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.endpoint_DNT_FW_SERVER"); + assertNotNull(capabilityAssignment); + String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "ports#entry_schema#type"); + assertEquals("PortSpec", propValue); + } + + @Test + public void testGetCapabilityDummyPropertyLeafValue() { + NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); + CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER"); + assertNotNull(capabilityAssignment); + String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "dummy"); + assertNull(propValue); + } + + @Test + public void testGetCapabilityNullPropertyLeafValue() { + NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); + CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER"); + assertNotNull(capabilityAssignment); + String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, null); + assertNull(propValue); + } + + @Test + public void testGetNullCapabilityPropertyLeafValue() { + String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(null, "max_instances#type"); + assertNull(propValue); + } + //endregion +} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java index 6461a92..7570ced 100644 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java @@ -3,15 +3,13 @@ package org.openecomp.sdc.impl; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.toscaparser.api.Capability; +import org.openecomp.sdc.toscaparser.api.CapabilityAssignment; import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.RequirementAssignment; import org.openecomp.sdc.toscaparser.api.elements.CapabilityTypeDef; //import org.testng.ReporterConfig.Property; import org.testng.annotations.Test; @@ -38,81 +36,81 @@ public class ToscaParserSubsMappingsTest extends SdcToscaParserBasicTest { //Added by QA - Check for Capabilities in VF level (Capabilities QTY and Names). //@Test // - BUG 283369 - public void testCapabilitiesofVFNames_QTY() throws SdcToscaParserException { - List serviceVfList = fdntCsarHelper.getServiceVfList(); - String sName = serviceVfList.get(0).getName(); - assertEquals(sName,fdntCsarHelper_Data.get("FDNT").get("VF Name").get(0)); - LinkedHashMap lCapabilitys = serviceVfList.get(0).getCapabilities(); - List CPkeys = new ArrayList<>(lCapabilitys.keySet()); - List CapabilitiesNames = new ArrayList(CPkeys.size()); - - for (int i = 0; i < CPkeys.size(); i++) { - - Capability cCp = lCapabilitys.get(CPkeys.get(i)); - - CapabilitiesNames.add(cCp.getName()); - - assertEquals(CPkeys.get(i).toLowerCase(), CapabilitiesNames.get(i).toLowerCase());// Compare keys to values, Should it be checked as Case sensitive???? - - //System.out.println(String.format("Value of key: %s , Value of capability: %s", keys.get(i).toLowerCase(), Capabilities.get(i).toLowerCase())); - //System.out.println(String.format("Value of key: %s , Value of capability: %s", ActualValues.get(i).toLowerCase(), Capabilities.get(i).toLowerCase())); - //System.out.println(String.format("*******%d*******",i)); - } - - for (int i = 0; i < CPkeys.size(); i++) { - assertEquals(true, CapabilitiesNames.stream().map(String::toLowerCase).collect(Collectors.toList()).contains(fdntCsarHelper_Data.get("FDNT").get("capabilities").get(i).toLowerCase())); // Compare capabilities predefined list to actual one. - } - - assertEquals(fdntCsarHelper_Data.get("FDNT").get("capabilities").size(), CapabilitiesNames.size()); // Compare capabilities qty expected vs actual - } +// public void testCapabilitiesofVFNames_QTY() throws SdcToscaParserException { +// List serviceVfList = fdntCsarHelper.getServiceVfList(); +// String sName = serviceVfList.get(0).getName(); +// assertEquals(sName,fdntCsarHelper_Data.get("FDNT").get("VF Name").get(0)); +// Map lCapabilitys = serviceVfList.get(0).getCapabilities().getAll(); +// List CPkeys = new ArrayList<>(lCapabilitys.keySet()); +// List CapabilitiesNames = new ArrayList(CPkeys.size()); +// +// for (int i = 0; i < CPkeys.size(); i++) { +// +// CapabilityAssignment cCp = lCapabilitys.get(CPkeys.get(i)); +// +// CapabilitiesNames.add(cCp.getName()); +// +// assertEquals(CPkeys.get(i).toLowerCase(), CapabilitiesNames.get(i).toLowerCase());// Compare keys to values, Should it be checked as Case sensitive???? +// +// //System.out.println(String.format("Value of key: %s , Value of capability: %s", keys.get(i).toLowerCase(), Capabilities.get(i).toLowerCase())); +// //System.out.println(String.format("Value of key: %s , Value of capability: %s", ActualValues.get(i).toLowerCase(), Capabilities.get(i).toLowerCase())); +// //System.out.println(String.format("*******%d*******",i)); +// } +// +// for (int i = 0; i < CPkeys.size(); i++) { +// assertEquals(true, CapabilitiesNames.stream().map(String::toLowerCase).collect(Collectors.toList()).contains(fdntCsarHelper_Data.get("FDNT").get("capabilities").get(i).toLowerCase())); // Compare capabilities predefined list to actual one. +// } +// +// assertEquals(fdntCsarHelper_Data.get("FDNT").get("capabilities").size(), CapabilitiesNames.size()); // Compare capabilities qty expected vs actual +// } //Added by QA - Check for Capabilities in VF level (Capabilities Types and Properties). //@Test - public void testCapabilitiesofVFTypes_Properties() throws SdcToscaParserException { - List serviceVfList = fdntCsarHelper.getServiceVfList(); - String sName = serviceVfList.get(0).getName(); - assertEquals(sName,fdntCsarHelper_Data.get("FDNT").get("VF Name").get(0)); - LinkedHashMap lCapabilitys = serviceVfList.get(0).getCapabilities(); - - List CPkeys = new ArrayList<>(lCapabilitys.keySet()); - List CPPropkeys = new ArrayList<>(lCapabilitys.keySet()); - List CapabilitiesTypes = new ArrayList(CPkeys.size()); - - //int iKeysSize = keys.size(); //for debug - - for (int i = 0; i < CPkeys.size(); i++) { - - Capability cCp = lCapabilitys.get(CPkeys.get(i)); - CapabilityTypeDef CpDef = cCp.getDefinition(); - CapabilitiesTypes.add(CpDef.getType()); - - //LinkedHashMap lProperties = cCp.getDefinition().getProperties(); - LinkedHashMap lPropertiesR = cCp.getProperties(); - - List CP_Propkeys = new ArrayList<>(lPropertiesR.keySet()); - - for (int j = 0; j < CP_Propkeys.size(); j++) { - - Property p = lPropertiesR.get(CP_Propkeys.get(j)); - - if(p != null){ - String sPType = p.getType(); - Boolean bPRequired = p.isRequired(); - - System.out.println(sPType + " " + bPRequired); - - } - - } - - } - - for (int i = 0; i < CPkeys.size(); i++) { - - } - - assertEquals(fdntCsarHelper_Data.get("FDNT").get("capabilitiesTypes").size(), CapabilitiesTypes.size()); // Compare capabilities qty expected vs actual - } +// public void testCapabilitiesofVFTypes_Properties() throws SdcToscaParserException { +// List serviceVfList = fdntCsarHelper.getServiceVfList(); +// String sName = serviceVfList.get(0).getName(); +// assertEquals(sName,fdntCsarHelper_Data.get("FDNT").get("VF Name").get(0)); +// Map lCapabilitys = serviceVfList.get(0).getCapabilities().getAll(); +// +// List CPkeys = new ArrayList<>(lCapabilitys.keySet()); +// List CPPropkeys = new ArrayList<>(lCapabilitys.keySet()); +// List CapabilitiesTypes = new ArrayList(CPkeys.size()); +// +// //int iKeysSize = keys.size(); //for debug +// +// for (int i = 0; i < CPkeys.size(); i++) { +// +// CapabilityAssignment cCp = lCapabilitys.get(CPkeys.get(i)); +// CapabilityTypeDef CpDef = cCp.getDefinition(); +// CapabilitiesTypes.add(CpDef.getType()); +// +// //LinkedHashMap lProperties = cCp.getDefinition().getProperties(); +// LinkedHashMap lPropertiesR = cCp.getProperties(); +// +// List CP_Propkeys = new ArrayList<>(lPropertiesR.keySet()); +// +// for (int j = 0; j < CP_Propkeys.size(); j++) { +// +// Property p = lPropertiesR.get(CP_Propkeys.get(j)); +// +// if(p != null){ +// String sPType = p.getType(); +// Boolean bPRequired = p.isRequired(); +// +// System.out.println(sPType + " " + bPRequired); +// +// } +// +// } +// +// } +// +// for (int i = 0; i < CPkeys.size(); i++) { +// +// } +// +// assertEquals(fdntCsarHelper_Data.get("FDNT").get("capabilitiesTypes").size(), CapabilitiesTypes.size()); // Compare capabilities qty expected vs actual +// } //@Test // - BUG 283387 public void testRequirmentsofVF() throws SdcToscaParserException { @@ -122,7 +120,7 @@ public class ToscaParserSubsMappingsTest extends SdcToscaParserBasicTest { List ActualReqsValues = new ArrayList<>(Arrays.asList( )); - ArrayList lRequirements = serviceVfList.get(0).getRequirements(); + List lRequirements = serviceVfList.get(0).getRequirements().getAll(); assertEquals(fdntCsarHelper_Data.get("FDNT").get("requirements").size(),lRequirements.size()); // diff --git a/src/test/resources/csars/service-sunny-flow.csar b/src/test/resources/csars/service-sunny-flow.csar index ef6d03e..48eb59b 100644 Binary files a/src/test/resources/csars/service-sunny-flow.csar and b/src/test/resources/csars/service-sunny-flow.csar differ -- cgit 1.2.3-korg