From 4cea23f8111aa3d3532ec8d74351eccbf0ac44a5 Mon Sep 17 00:00:00 2001 From: Yuli Shlosberg Date: Tue, 6 Mar 2018 17:57:45 +0200 Subject: update SDC-TOSCA package names Change-Id: I496713bcf2551f3b5c7f629f89ffcb8b1954b489 Issue-ID: SDC-951 Signed-off-by: Yuli Shlosberg --- .../sdc/tosca/parser/api/ConformanceLevel.java | 25 + .../onap/sdc/tosca/parser/api/ISdcCsarHelper.java | 454 ++++++++++ .../org/onap/sdc/tosca/parser/api/Version.java | 48 + .../sdc/tosca/parser/config/Configuration.java | 16 + .../tosca/parser/config/ConfigurationManager.java | 124 +++ .../tosca/parser/config/ErrorConfiguration.java | 46 + .../onap/sdc/tosca/parser/config/ErrorInfo.java | 59 ++ .../parser/config/JToscaValidationIssueInfo.java | 31 + .../config/JtoscaValidationIssueConfiguration.java | 52 ++ .../tosca/parser/config/SdcToscaParserErrors.java | 31 + .../parser/exceptions/SdcToscaParserException.java | 20 + .../org/onap/sdc/tosca/parser/impl/FilterType.java | 26 + .../parser/impl/JToscaValidationIssueType.java | 6 + .../sdc/tosca/parser/impl/SdcCsarHelperImpl.java | 908 +++++++++++++++++++ .../sdc/tosca/parser/impl/SdcPropertyNames.java | 109 +++ .../tosca/parser/impl/SdcToscaParserFactory.java | 203 +++++ .../org/onap/sdc/tosca/parser/impl/SdcTypes.java | 46 + .../sdc/tosca/parser/utils/GeneralUtility.java | 53 ++ .../sdc/tosca/parser/utils/SdcToscaUtility.java | 19 + .../tosca/parser/utils/YamlToObjectConverter.java | 126 +++ .../sdc/tosca/parser/api/ConformanceLevel.java | 25 - .../sdc/tosca/parser/api/ISdcCsarHelper.java | 454 ---------- .../openecomp/sdc/tosca/parser/api/Version.java | 48 - .../sdc/tosca/parser/config/Configuration.java | 16 - .../tosca/parser/config/ConfigurationManager.java | 124 --- .../tosca/parser/config/ErrorConfiguration.java | 46 - .../sdc/tosca/parser/config/ErrorInfo.java | 59 -- .../parser/config/JToscaValidationIssueInfo.java | 31 - .../config/JtoscaValidationIssueConfiguration.java | 52 -- .../tosca/parser/config/SdcToscaParserErrors.java | 31 - .../parser/exceptions/SdcToscaParserException.java | 20 - .../sdc/tosca/parser/impl/FilterType.java | 26 - .../parser/impl/JToscaValidationIssueType.java | 6 - .../sdc/tosca/parser/impl/SdcCsarHelperImpl.java | 912 ------------------- .../sdc/tosca/parser/impl/SdcPropertyNames.java | 109 --- .../tosca/parser/impl/SdcToscaParserFactory.java | 199 ----- .../openecomp/sdc/tosca/parser/impl/SdcTypes.java | 46 - .../sdc/tosca/parser/utils/GeneralUtility.java | 53 -- .../sdc/tosca/parser/utils/SdcToscaUtility.java | 19 - .../tosca/parser/utils/YamlToObjectConverter.java | 126 --- .../org/onap/sdc/impl/SdcToscaParserBasicTest.java | 149 ++++ .../sdc/impl/ToscaParserConfigurationTest.java | 63 ++ .../sdc/impl/ToscaParserErrorHandlingTest.java | 143 +++ .../onap/sdc/impl/ToscaParserGeneralUtilTest.java | 23 + .../org/onap/sdc/impl/ToscaParserGroupTest.java | 115 +++ .../org/onap/sdc/impl/ToscaParserMetadataTest.java | 235 +++++ .../onap/sdc/impl/ToscaParserNodeTemplateTest.java | 972 +++++++++++++++++++++ .../onap/sdc/impl/ToscaParserReqAndCapTest.java | 273 ++++++ .../onap/sdc/impl/ToscaParserServiceInputTest.java | 77 ++ .../onap/sdc/impl/ToscaParserSubsMappingsTest.java | 129 +++ .../sdc/impl/ToscaParserValidationIssueTest.java | 93 ++ src/test/java/org/onap/sdc/impl/myTest.java | 41 + .../sdc/impl/SdcToscaParserBasicTest.java | 150 ---- .../sdc/impl/ToscaParserConfigurationTest.java | 63 -- .../sdc/impl/ToscaParserErrorHandlingTest.java | 143 --- .../sdc/impl/ToscaParserGeneralUtilTest.java | 23 - .../openecomp/sdc/impl/ToscaParserGroupTest.java | 116 --- .../sdc/impl/ToscaParserMetadataTest.java | 234 ----- .../sdc/impl/ToscaParserNodeTemplateTest.java | 972 --------------------- .../sdc/impl/ToscaParserReqAndCapTest.java | 273 ------ .../sdc/impl/ToscaParserServiceInputTest.java | 77 -- .../sdc/impl/ToscaParserSubsMappingsTest.java | 130 --- .../sdc/impl/ToscaParserValidationIssueTest.java | 96 -- src/test/java/org/openecomp/sdc/impl/myTest.java | 42 - 64 files changed, 4715 insertions(+), 4721 deletions(-) create mode 100644 src/main/java/org/onap/sdc/tosca/parser/api/ConformanceLevel.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/api/Version.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/config/Configuration.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/config/ConfigurationManager.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/config/ErrorConfiguration.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/config/ErrorInfo.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/config/JToscaValidationIssueInfo.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/config/JtoscaValidationIssueConfiguration.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/config/SdcToscaParserErrors.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/exceptions/SdcToscaParserException.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/impl/FilterType.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/impl/JToscaValidationIssueType.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/impl/SdcToscaParserFactory.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/impl/SdcTypes.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/utils/GeneralUtility.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/utils/SdcToscaUtility.java create mode 100644 src/main/java/org/onap/sdc/tosca/parser/utils/YamlToObjectConverter.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/api/ConformanceLevel.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/api/Version.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/config/Configuration.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/config/JToscaValidationIssueInfo.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/config/JtoscaValidationIssueConfiguration.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/impl/FilterType.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/impl/JToscaValidationIssueType.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcPropertyNames.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/utils/SdcToscaUtility.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/utils/YamlToObjectConverter.java create mode 100644 src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java create mode 100644 src/test/java/org/onap/sdc/impl/ToscaParserConfigurationTest.java create mode 100644 src/test/java/org/onap/sdc/impl/ToscaParserErrorHandlingTest.java create mode 100644 src/test/java/org/onap/sdc/impl/ToscaParserGeneralUtilTest.java create mode 100644 src/test/java/org/onap/sdc/impl/ToscaParserGroupTest.java create mode 100644 src/test/java/org/onap/sdc/impl/ToscaParserMetadataTest.java create mode 100644 src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java create mode 100644 src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java create mode 100644 src/test/java/org/onap/sdc/impl/ToscaParserServiceInputTest.java create mode 100644 src/test/java/org/onap/sdc/impl/ToscaParserSubsMappingsTest.java create mode 100644 src/test/java/org/onap/sdc/impl/ToscaParserValidationIssueTest.java create mode 100644 src/test/java/org/onap/sdc/impl/myTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/ToscaParserReqAndCapTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/ToscaParserValidationIssueTest.java delete mode 100644 src/test/java/org/openecomp/sdc/impl/myTest.java (limited to 'src') diff --git a/src/main/java/org/onap/sdc/tosca/parser/api/ConformanceLevel.java b/src/main/java/org/onap/sdc/tosca/parser/api/ConformanceLevel.java new file mode 100644 index 0000000..4b4d646 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/api/ConformanceLevel.java @@ -0,0 +1,25 @@ +package org.onap.sdc.tosca.parser.api; + +public class ConformanceLevel { + + private String minVersion; + private String maxVersion; + + public String getMaxVersion() { + return maxVersion; + } + + public void setMaxVersion(String maxVersion) { + this.maxVersion = maxVersion; + } + + public String getMinVersion() { + return minVersion; + } + + public void setMinVersion(String minVersion) { + this.minVersion = minVersion; + } + + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java b/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java new file mode 100644 index 0000000..76798d5 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java @@ -0,0 +1,454 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.sdc.tosca.parser.api; + + +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.Pair; +import org.onap.sdc.tosca.parser.impl.SdcTypes; +import org.onap.sdc.tosca.parser.impl.FilterType; +import org.onap.sdc.toscaparser.api.*; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.sdc.toscaparser.api.parameters.Input; + + +public interface ISdcCsarHelper { + + /** + * Get all node templates by node_type for this CSAR service. + * + * @param nodeType - the TOSCA type of the node. + * @return service node templates of this type. + */ + public List getServiceNodeTemplatesByType(String nodeType); + + /** + * Get all node templates for this CSAR service. + * + * @return service node templates. + */ + public List getServiceNodeTemplates(); + + /** + * Get groups of a VF with type "org.onap.groups.VfModule". + * + * @param vfCustomizationUuid - customizationUuid of VF instance. + * @return list of vfModule groups. + */ + public List getVfModulesByVf(String vfCustomizationUuid); + + + /** + * Get any property leaf value for node template by full path separated by #.
+ * For example, for node template with this property:

+ * network_assignments:
+   ecomp_generated_network_assignment: true
+   is_shared_network: false
+   is_external_network: false
+   ipv4_subnet_default_assignments:
+     use_ipv4: true
+     ip_network_address_plan: 1.2.3.4
+     dhcp_enabled: true
+     ip_version: 4
+     cidr_mask: 24
+     min_subnets_count: 1
+   ipv6_subnet_default_assignments:
+     use_ipv6: false

+ + * calling
+ * getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignments#use_ipv6")
+ * will return "false". + * @param nodeTemplate - nodeTemplate 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 getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String pathToPropertyLeafValue); + + /** + * Get any property leaf value for node template by full path separated by #.
+ * For example, for node template with this property:

+ * network_assignments:
+   ecomp_generated_network_assignment: true
+   is_shared_network: false
+   is_external_network: false
+   ipv4_subnet_default_assignments:
+     use_ipv4: true
+     ip_network_address_plan: 1.2.3.4
+     dhcp_enabled: true
+     ip_version: 4
+     cidr_mask: 24
+     min_subnets_count: 1
+   ipv6_subnet_default_assignments:
+     use_ipv6: false

+ + * calling
+ * getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignments#use_ipv6")
+ * will return "false". + * @param nodeTemplate - nodeTemplate where the property should be looked up. + * @param pathToPropertyLeafValue - the full path of the required property. + * @return the leaf value as Object, or null if there's no such property. It's up to the caller to cast it to a proper type. + */ + public Object getNodeTemplatePropertyAsObject(NodeTemplate nodeTemplate, String pathToPropertyLeafValue); + + /** + * Get any property leaf value for a group definition by full path separated by #. + * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for a group. + * @param group - group where the property should be looked up. + * @param propertyName - the name 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 getGroupPropertyLeafValue(Group group, String propertyName); + + /** + * Get any property value for a group definition by full path separated by #. + * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for a group. + * @param group - group where the property should be looked up. + * @param propertyName - the name of the required property. + * @return the leaf value as Object, or null if there's no such property. It's up to the caller to cast it to a proper type. + */ + public Object getGroupPropertyAsObject(Group group, String propertyName); + + /** + * Get all VL node templates of the CSAR service. + * @return - all VL node templates. + */ + public List getServiceVlList(); + + /** + * Get all VF node templates of the CSAR service. + * @return - all VF node templates. + */ + public List getServiceVfList(); + + + /** + * + * Get a property from a metadata object.
+ * This is just sugaring method, same as calling metadata.getMetadataPropertyValue(metadataPropertyName).
+ * + * For metadata object representing the below:

+ * + * metadata:
+   invariantUUID: 4598a404-00e1-42a6-8767-0bda343e2066
+   UUID: e17940d6-42f8-4989-bad0-31de5addc619
+   customizationUUID: 83d086b2-a861-4d3b-aa84-3bfbb9b2ec20
+   version: '0.1'
+   name: vIPR_ATM
+   description: vIPR_ATM
+   type: VF
+   category: category1
+   subcategory: subCategory1

+ + calling
+ getMetadataPropertyValue(metadata,"invariantUUID")
+ will return "4598a404-00e1-42a6-8767-0bda343e2066". + + * @param metadata - metadata object. + * @param metadataPropertyName - the name of the metadata property. + * @return metadata property value + */ + public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName); + + + /** + * Get input leaf value for the CSAR service, by full path separated by #.
+ * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for an input full path. + * The expected format is "input_name#default[optionally #rest_of_path]" + * @param inputLeafValuePath by full path separated by #. + * @return input leaf value for the service. + */ + public String getServiceInputLeafValueOfDefault(String inputLeafValuePath); + + /** + * Get input leaf value for the CSAR service, by full path separated by #.
+ * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for an input full path. + * The expected format is "input_name#default[optionally #rest_of_path]" + * @param inputLeafValuePath by full path separated by #. + * @return input value for the service as Object. It's up to the caller to cast it to a proper type. + */ + public Object getServiceInputLeafValueOfDefaultAsObject(String inputLeafValuePath); + + /** + * Get the type name of the CSAR service's substitution mappings element.
+ * + * For the below:

+ * + * substitution_mappings:
+   type: org.onap.services.ViprATM
+ + calling
+ getServiceSubstitutionMappingsTypeName()
+ will return "org.onap.services.ViprATM" + * @return - the type name of the CSAR service's substitution mappings element + */ + public String getServiceSubstitutionMappingsTypeName(); + + /** + * 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. + * @return all VFC node templates from a specified VF + */ + public List getVfcListByVf(String vfCustomizationId); + + /** + * Get all CP node templates from a specified VF. + * @param vfCustomizationId - customizationUuid of the VF node template. + * @return all CP node templates from a specified VF + */ + public List getCpListByVf(String vfCustomizationId); + + /** + * Get all members of this group definition.
+ * + * For example, for this group definition:

+ * + * ViprAtm..vIPR-ATM-Base..module-0:
+   type: org.onap.groups.VfModule
+   .................
+   members: [vIPR_ATM_Ha_Two, vIPR_ATM_Ha_One, vIPR_ATM_OAM_SG, vIPR_ATM_HA_TWO_SG, vIPR_ATM_HA_ONE_SG]

+ + calling
+ getMembersOfVfModule(NoteTemplate vfNodeTemplate, Group group)
+ will return List of the following Node templates in the vfNodeTemplate: "vIPR_ATM_Ha_Two, vIPR_ATM_Ha_One, vIPR_ATM_OAM_SG, vIPR_ATM_HA_TWO_SG, vIPR_ATM_HA_ONE_SG"
+ * @param vf - VF to return the node templates from. + * @param vfModule - group to return the members from. + * @return node templates from vf with the names as in members section. + * + */ + public List getMembersOfVfModule(NodeTemplate vf, Group vfModule); + + + /** + * Get list of node template pairs, where for each pair,
+ * the left node template in pair has requirement with name reqName,
+ * which should be satisfied with respective capability by the right node template in pair.
+ * + * For example, if we have the below two node templates in the vIPR VF:

+ * + * oam_extCP:
+   type: org.onap.resources.cp.extCP
+   requirements:
+     - virtualBinding: vipr_atm_firewall

+ * + * vipr_atm_firewall:
+   type: org.onap.resources.vfc.ViprAtm.abstract.nodes.heat.vipr_atm
+ ........

+ * + + * calling
+ * getNodeTemplatePairsByReqName(getCpListByVf(viprCustomUuid), getVfcListByVf(viprCustomUuid), "virtualBinding")
+ * will return a list with one Pair - where left element of pair will be "oam_extCP" node template,
+ * and right element will be "vipr_atm_firewall" node template.
+ * + * @param listOfReqNodeTemplates - list of node templates in which the "reqName" requirement should be looked. + * @param listOfCapNodeTemplates - list of node templates in which the capability matching the "reqName" requirement should be looked. + * @param reqName - the name of a requirement definition to match by. + * @return pairs of node templates according to described above. + */ + public List> getNodeTemplatePairsByReqName(List listOfReqNodeTemplates, List listOfCapNodeTemplates, String reqName); + + /** + * Get all allotted node templates from this service. + * @return all allotted node templates from this service. + */ + public List getAllottedResources(); + + /** + * Get node_type of a node template.
+ * + * For this node template:
+ * + * vipr_atm_firewall:
+   type: org.onap.resources.vfc.ViprAtm.abstract.nodes.heat.vipr_atm
+ ........

+ * + * the function will return "org.onap.resources.vfc.ViprAtm.abstract.nodes.heat.vipr_atm" + * + * @param nodeTemplate - node template object + * @return - node type string. + */ + public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate); + + /** + * Get the CSAR service inputs list. + * @return - the service inputs list. + */ + public List getServiceInputs(); + + + /** + * Get the conformance level of this CSAR.
+ * The conformance level value of the CSAR is located in csar.meta file at the top level of the CSAR file.
+ * For 1707 CSARs, the conformance level is 3.0. + * @return the conformance level of the CSAR. + */ + public String getConformanceLevel(); + + + /** + * Get the map of CP-related props from a VFC node template.
+ * Let's say there are 5 CPs related to this VFC. Then the output will look like this:

+ * {port_fe1_sigtran={ip_requirements#ip_count_required#count=1, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4, subnetpoolid="subnet_1", network_role_tag="SIGNET_vrf_B1_direct"},
+ * port_fe_cluster={ip_requirements#ip_count_required#count=2, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4},
+ * port_fe_slan={ip_requirements#ip_count_required#count=1, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4},
+ * port_fe_interce={ip_requirements#ip_count_required#count=1, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4},
+ * 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. + * Will be removed in 1802. + */ + @Deprecated + public Map> getCpPropertiesFromVfc(NodeTemplate vfc); + + /** + * Get the map of CP-related props from a VFC node template.
+ * Let's say there are 2 CPs (ports) related to this VFC. Then the output will look like this:

+ * {port_fe_sigtran={ip_requirements={ip_count_required: {count: 1}, dhcp_enabled: true, ip_version: 4}, subnetpoolid: "subnet_1", network_role_tag: "SIGNET_vrf_B1_direct"}
+ * port_fe_cluster={ip_requirements={ip_count_required: {count: 2}, dhcp_enabled: true, ip_version: 4}}
+ * @param vfc - VFC node template to look for CP-related props. + * @return map CP node template name to a map of property name - property value as object. + */ + public Map> getCpPropertiesFromVfcAsObject(NodeTemplate vfc); + + /** + * Get customization UUID of a node template + * @param nt - node template + * @return customization UUID of a node template. + */ + public String getNodeTemplateCustomizationUuid(NodeTemplate nt); + + /** + * Filter Node Template property values by equals/contains operator and a pattern + * @param nodeTemplate Node Template to filter its properties + * @param filterType filter type - equals or contains + * @param pattern value to filter with it + * @return Map full path to a property mapped to property value filtered by type and pattern + */ + public Map filterNodeTemplatePropertiesByValue(NodeTemplate nodeTemplate, FilterType filterType, String pattern); + + /** + * Get all node templates by sdcType for parent Node Template. + * + * @param parentNodeTemplate - parent node template + * @param sdcType - the SDC type of the node. + * @return node templates of this SDC type. + */ + public List getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType); + + /** + * Get all node templates by SDC type enum for this CSAR service. + * + * @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); + + /** + * Get all node templates for this CSAR service. + * @param vfCustomizationUuid - the Customization UUID of the node. + * @return VNF Configuration Node Template. + */ + public NodeTemplate getVnfConfig(String vfCustomizationUuid); + + /** + * Check if Node Template has Topology Template + * @param nodeTemplate - Node Template to check + * @return true if node template has topology template, false if not. + */ + public boolean hasTopology(NodeTemplate nodeTemplate); + + /** + * Get children node templates for node template. + * @param nodeTemplate - Node Template to get its children + * @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/onap/sdc/tosca/parser/api/Version.java b/src/main/java/org/onap/sdc/tosca/parser/api/Version.java new file mode 100644 index 0000000..c485b18 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/api/Version.java @@ -0,0 +1,48 @@ +package org.onap.sdc.tosca.parser.api; + +public class Version implements Comparable { + + private String version; + + public final String get() { + return this.version; + } + + public Version(String version) { + if(version == null) + throw new IllegalArgumentException("Version can not be null"); + if(!version.matches("[0-9]+(\\.[0-9]+)*")) + throw new IllegalArgumentException("Invalid version format"); + this.version = version; + } + + @Override public int compareTo(Version that) { + if(that == null) + return 1; + String[] thisParts = this.get().split("\\."); + String[] thatParts = that.get().split("\\."); + int length = Math.max(thisParts.length, thatParts.length); + for(int i = 0; i < length; i++) { + int thisPart = i < thisParts.length ? + Integer.parseInt(thisParts[i]) : 0; + int thatPart = i < thatParts.length ? + Integer.parseInt(thatParts[i]) : 0; + if(thisPart < thatPart) + return -1; + if(thisPart > thatPart) + return 1; + } + return 0; + } + + @Override public boolean equals(Object that) { + if(this == that) + return true; + if(that == null) + return false; + if(this.getClass() != that.getClass()) + return false; + return this.compareTo((Version) that) == 0; + } + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/config/Configuration.java b/src/main/java/org/onap/sdc/tosca/parser/config/Configuration.java new file mode 100644 index 0000000..7135b6b --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/config/Configuration.java @@ -0,0 +1,16 @@ +package org.onap.sdc.tosca.parser.config; + +import org.onap.sdc.tosca.parser.api.ConformanceLevel; + +public class Configuration { + + private ConformanceLevel conformanceLevel; + + public ConformanceLevel getConformanceLevel() { + return conformanceLevel; + } + + public void setConformanceLevel(ConformanceLevel conformanceLevel) { + this.conformanceLevel = conformanceLevel; + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/config/ConfigurationManager.java b/src/main/java/org/onap/sdc/tosca/parser/config/ConfigurationManager.java new file mode 100644 index 0000000..e0b9dc8 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/config/ConfigurationManager.java @@ -0,0 +1,124 @@ +package org.onap.sdc.tosca.parser.config; + +import com.google.common.base.Charsets; +import com.google.common.io.Resources; +import org.onap.sdc.tosca.parser.utils.YamlToObjectConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + + +public class ConfigurationManager { + + private static Logger log = LoggerFactory.getLogger(ConfigurationManager.class.getName()); + + private static final String CONFIGURATION_DIR = "config/"; + private static volatile ConfigurationManager instance; + + + Map configurations = new HashMap(); + + private ConfigurationManager() { + initialConfigObjectsFromFiles(); + } + + private void initialConfigObjectsFromFiles() { + loadConfigurationClass(ErrorConfiguration.class); + loadConfigurationClass(Configuration.class); + loadConfigurationClass(JtoscaValidationIssueConfiguration.class); + } + + private void loadConfigurationClass(Class clazz) { + T object = getObjectFromYaml(clazz); + configurations.put(clazz.getSimpleName(), object); + } + + private void loadConfigurationClass(Class clazz, String fileName) { + T object = getObjectFromYaml(clazz,fileName); + configurations.put(clazz.getSimpleName(), object); + } + + public static T getObjectFromYaml(Class className) { + return getObjectFromYaml(className, null); + } + + public static T getObjectFromYaml(Class className, String fileName) { + + + String configFileName = fileName != null ? fileName : calculateFileName(className); ; + + URL url = Resources.getResource(CONFIGURATION_DIR + configFileName); + String configFileContents = null; + try { + configFileContents = Resources.toString(url, Charsets.UTF_8); + } catch (IOException e) { + log.error("ConfigurationManager - Failed to load configuration file {}", configFileName, e); + } + YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter(); + T object = yamlToObjectConverter.convertFromString(configFileContents, className); + + return object; + } + + + public static ConfigurationManager getInstance() { + if (instance == null) { + synchronized (ConfigurationManager.class) { + if (instance == null) { + instance = new ConfigurationManager(); + } + } + } + return instance; + } + + private static String calculateFileName(Class className) { + + String[] words = className.getSimpleName().split("(?=\\p{Upper})"); + + StringBuilder builder = new StringBuilder(); + + // There cannot be a null value returned from "split" - words != null is + // redundant + // if (words != null) { + boolean isFirst = true; + for (int i = 0; i < words.length; i++) { + + String word = words[i]; + if (word != null && !word.isEmpty()) { + if (!isFirst) { + builder.append("-"); + } else { + isFirst = false; + } + builder.append(words[i].toLowerCase()); + } + } + return builder.toString() + ".yaml"; + + /* + * } else { return className.getSimpleName().toLowerCase() + Constants.YAML_SUFFIX; } + */ + + } + + public ErrorConfiguration getErrorConfiguration() { + return (ErrorConfiguration) configurations.get((ErrorConfiguration.class.getSimpleName())); + } + public JtoscaValidationIssueConfiguration getJtoscaValidationIssueConfiguration() { + return (JtoscaValidationIssueConfiguration) configurations.get((JtoscaValidationIssueConfiguration.class.getSimpleName())); + } + public void setJtoscaValidationIssueConfiguration(String fileName) { + loadConfigurationClass(JtoscaValidationIssueConfiguration.class, fileName); + } + public Configuration getConfiguration() { + return (Configuration) configurations.get((Configuration.class.getSimpleName())); + } + public void setErrorConfiguration(String fileName) { + loadConfigurationClass(ErrorConfiguration.class, fileName); + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/config/ErrorConfiguration.java b/src/main/java/org/onap/sdc/tosca/parser/config/ErrorConfiguration.java new file mode 100644 index 0000000..1b1f2e2 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/config/ErrorConfiguration.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.tosca.parser.config; + +import java.util.Map; + +public class ErrorConfiguration { + + private Map errors; + + public Map getErrors() { + return errors; + } + + public void setErrors(Map errors) { + this.errors = errors; + } + + public ErrorInfo getErrorInfo(String key) { + ErrorInfo clone = null; + ErrorInfo other = errors.get(key); + if (other != null) { + clone = new ErrorInfo(); + clone.cloneData(other); + } + return clone; + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/config/ErrorInfo.java b/src/main/java/org/onap/sdc/tosca/parser/config/ErrorInfo.java new file mode 100644 index 0000000..52a92c4 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/config/ErrorInfo.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.tosca.parser.config; + +public class ErrorInfo { + + private String code; + private String message; + private boolean failOnError; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean getFailOnError() { + return failOnError; + } + + public void setFailOnError(boolean failOnError) { + this.failOnError = failOnError; + } + + public void cloneData(ErrorInfo other) { + this.code = other.getCode(); + this.message = other.getMessage(); + this.failOnError = other.getFailOnError(); + } + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/config/JToscaValidationIssueInfo.java b/src/main/java/org/onap/sdc/tosca/parser/config/JToscaValidationIssueInfo.java new file mode 100644 index 0000000..0e76b29 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/config/JToscaValidationIssueInfo.java @@ -0,0 +1,31 @@ +package org.onap.sdc.tosca.parser.config; + +public class JToscaValidationIssueInfo { + + private String issueType; + private String sinceCsarConformanceLevel; + + public JToscaValidationIssueInfo() {} + + public String getIssueType() { + return issueType; + } + + public void setIssueType(String issueType) { + this.issueType = issueType; + } + + public String getSinceCsarConformanceLevel() { + return sinceCsarConformanceLevel; + } + + public void setSinceCsarConformanceLevel(String sinceCsarConformanceLevel) { + this.sinceCsarConformanceLevel = sinceCsarConformanceLevel; + } + + public void cloneData(JToscaValidationIssueInfo other) { + this.issueType = other.getIssueType(); + this.sinceCsarConformanceLevel = other.getSinceCsarConformanceLevel(); + } + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/config/JtoscaValidationIssueConfiguration.java b/src/main/java/org/onap/sdc/tosca/parser/config/JtoscaValidationIssueConfiguration.java new file mode 100644 index 0000000..55912e6 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/config/JtoscaValidationIssueConfiguration.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.tosca.parser.config; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class JtoscaValidationIssueConfiguration { + + private Map> validationIssues; + + public Map> getValidationIssues() { + return validationIssues; + } + + public void setValidationIssues(Map> validationIssues) { + this.validationIssues = validationIssues; + } + + public List getJtoscaValidationIssueInfo(String key) { + List clone = new ArrayList<>(); + List other = validationIssues.get(key); + if (other != null) { + for (JToscaValidationIssueInfo item: other) { + JToscaValidationIssueInfo cloneitem = new JToscaValidationIssueInfo(); + cloneitem.cloneData(item); + clone.add(cloneitem); + } + } + return clone; + } + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/config/SdcToscaParserErrors.java b/src/main/java/org/onap/sdc/tosca/parser/config/SdcToscaParserErrors.java new file mode 100644 index 0000000..730142c --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/config/SdcToscaParserErrors.java @@ -0,0 +1,31 @@ +package org.onap.sdc.tosca.parser.config; + +import java.util.EnumMap; +import java.util.Map; + +import org.onap.sdc.toscaparser.api.utils.JToscaErrorCodes; + +public enum SdcToscaParserErrors { + + BAD_FORMAT, CONFORMANCE_LEVEL_ERROR, FILE_NOT_FOUND, GENERAL_ERROR; + + private static final Map JTOSCA_ERRORS = + new EnumMap(JToscaErrorCodes.class) {{ + + put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR); + + put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND); + //CSAR contents problems + put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT); + put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT); + put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT); + put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT); + put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT); + put(JToscaErrorCodes.INVALID_CSAR_FORMAT, BAD_FORMAT); + }}; + + public static SdcToscaParserErrors getSdcErrorByJToscaError(JToscaErrorCodes jToscaErrorCode) { + return JTOSCA_ERRORS.get(jToscaErrorCode); + } + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/exceptions/SdcToscaParserException.java b/src/main/java/org/onap/sdc/tosca/parser/exceptions/SdcToscaParserException.java new file mode 100644 index 0000000..5576750 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/exceptions/SdcToscaParserException.java @@ -0,0 +1,20 @@ +package org.onap.sdc.tosca.parser.exceptions; + +public class SdcToscaParserException extends Exception { + + private static final long serialVersionUID = 626014844866501196L; + private String code; + + public SdcToscaParserException(String string, String code) { + super(string); + this.code = code; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/FilterType.java b/src/main/java/org/onap/sdc/tosca/parser/impl/FilterType.java new file mode 100644 index 0000000..09c3c5c --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/impl/FilterType.java @@ -0,0 +1,26 @@ +package org.onap.sdc.tosca.parser.impl; + +public enum FilterType { + + CONTAINS("contains"){ + @Override + public boolean isMatch(String value, String pattern) { + return value.contains(pattern); + } + }, + EQUALS("equals"){ + @Override + public boolean isMatch(String value, String pattern) { + return value.equals(pattern); + } + }; + + String filterName; + + FilterType(String name) { + this.filterName = name; + } + + public abstract boolean isMatch(String value, String pattern); + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/JToscaValidationIssueType.java b/src/main/java/org/onap/sdc/tosca/parser/impl/JToscaValidationIssueType.java new file mode 100644 index 0000000..fb13867 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/impl/JToscaValidationIssueType.java @@ -0,0 +1,6 @@ +package org.onap.sdc.tosca.parser.impl; + +public enum JToscaValidationIssueType { + CRITICAL, + WARNING +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java new file mode 100644 index 0000000..0c42a4f --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java @@ -0,0 +1,908 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.tosca.parser.impl; + +import java.util.*; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.config.ConfigurationManager; +import org.onap.sdc.tosca.parser.utils.GeneralUtility; +import org.onap.sdc.tosca.parser.utils.SdcToscaUtility; +import org.onap.sdc.toscaparser.api.*; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.sdc.toscaparser.api.elements.NodeType; +import org.onap.sdc.toscaparser.api.functions.Function; +import org.onap.sdc.toscaparser.api.parameters.Input; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdcCsarHelperImpl implements ISdcCsarHelper { + + private static final String PATH_DELIMITER = "#"; + private static final String CUSTOMIZATION_UUID = "customizationUUID"; + private ToscaTemplate toscaTemplate; + private ConfigurationManager configurationManager; + private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName()); + + public SdcCsarHelperImpl(ToscaTemplate toscaTemplate) { + this.toscaTemplate = toscaTemplate; + } + + public SdcCsarHelperImpl(ToscaTemplate toscaTemplate, ConfigurationManager configurationManager) { + this.toscaTemplate = toscaTemplate; + this.configurationManager = configurationManager; + } + + @Override + //Sunny flow - covered with UT, flat and nested + public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) { + if (nodeTemplate == null) { + log.error("getNodeTemplatePropertyLeafValue - nodeTemplate is null"); + return null; + } + if (GeneralUtility.isEmptyString(leafValuePath)) { + log.error("getNodeTemplatePropertyLeafValue - leafValuePath is null or empty"); + return null; + } + String[] split = getSplittedPath(leafValuePath); + LinkedHashMap properties = nodeTemplate.getProperties(); + Object property = processProperties(split, properties); + return property == null || property instanceof Function ? null : String.valueOf(property); + } + + @Override + public Object getNodeTemplatePropertyAsObject(NodeTemplate nodeTemplate, String leafValuePath) { + if (nodeTemplate == null) { + log.error("getNodeTemplatePropertyAsObject - nodeTemplate is null"); + return null; + } + if (GeneralUtility.isEmptyString(leafValuePath)) { + log.error("getNodeTemplatePropertyAsObject - leafValuePath is null or empty"); + return null; + } + String[] split = getSplittedPath(leafValuePath); + LinkedHashMap properties = nodeTemplate.getProperties(); + return processProperties(split, properties); + } + + public Map> getCpPropertiesFromVfcAsObject(NodeTemplate vfc) { + if (vfc == null) { + log.error("getCpPropertiesFromVfc - vfc is null"); + return new HashMap<>(); + } + + String presetProperty = "_ip_requirements"; + Map> cps = new HashMap<>(); + + Map props = vfc.getProperties(); + if (props != null) { + // find all port names by pre-set property (ip_requirements) + for (Map.Entry entry : props.entrySet()) { + if (entry.getKey().endsWith(presetProperty)) { + String portName = entry.getKey().replaceAll(presetProperty, ""); + cps.put(portName, new HashMap<>()); + } + } + + if (cps.size() > 0) { + // ports found - find all their properties + for (String portName : cps.keySet()) { + for (Map.Entry property: props.entrySet()) { + if (property.getKey().startsWith(portName)) { + String portProperty = property.getKey().replaceFirst(portName + "_", ""); + if (property.getValue() != null) { + cps.get(portName).put(portProperty, property.getValue().getValue()); + } + } + } + } + } + } + + return cps; + } + + public Map> getCpPropertiesFromVfc(NodeTemplate vfc) { + + if (vfc == null) { + log.error("getCpPropertiesFromVfc - vfc is null"); + return new HashMap<>(); + } + + String presetProperty = "_ip_requirements"; + Map> cps = new HashMap<>(); + + Map props = vfc.getProperties(); + if (props != null) { + // find all port names by pre-set property (ip_requirements) + for (Map.Entry entry : props.entrySet()) { + if (entry.getKey().endsWith(presetProperty)) { + String portName = entry.getKey().replaceAll(presetProperty, ""); + cps.put(portName, new HashMap<>()); + } + } + + if (cps.size() > 0) { + // ports found - find all their properties + for (String portName : cps.keySet()) { + for (Map.Entry property: props.entrySet()) { + if (property.getKey().startsWith(portName)) { + Map portPaths = new HashMap<>(); + String portProperty = property.getKey().replaceFirst(portName + "_", ""); + buildPathMappedToValue(portProperty, property.getValue().getValue(), portPaths); + + cps.get(portName).putAll(portPaths); + } + } + } + } + } + + return cps; + } + + @SuppressWarnings("unchecked") + private void buildPathMappedToValue(String path, Object property, Map pathsMap) { + if (property instanceof Map) { + for (Map.Entry item : ((Map) property).entrySet()) { + if (item.getValue() instanceof Map || item.getValue() instanceof List) { + buildPathMappedToValue(path + PATH_DELIMITER + item.getKey(), item.getValue(), pathsMap); + } else { + pathsMap.put(path + PATH_DELIMITER + item.getKey(), item.getValue()); + } + } + } else if (property instanceof List) { + for (Object item: (List)property) { + buildPathMappedToValue(path, item, pathsMap); + } + } else { + pathsMap.put(path, property); + } + + } + + @Override + //Sunny flow - covered with UT + public List getServiceVlList() { + List serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VL); + return serviceVlList; + } + + @Override + //Sunny flow - covered with UT + public List getServiceVfList() { + List serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VF); + return serviceVfList; + } + + @Override + //Sunny flow - covered with UT + public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName) { + if (GeneralUtility.isEmptyString(metadataPropertyName)) { + log.error("getMetadataPropertyValue - the metadataPropertyName is null or empty"); + return null; + } + if (metadata == null) { + log.error("getMetadataPropertyValue - the metadata is null"); + return null; + } + String metadataPropertyValue = metadata.getValue(metadataPropertyName); + return metadataPropertyValue; + } + + + @Override + //Sunny flow - covered with UT + public List getServiceNodeTemplatesByType(String nodeType) { + if (GeneralUtility.isEmptyString(nodeType)) { + log.error("getServiceNodeTemplatesByType - nodeType - is null or empty"); + return new ArrayList<>(); + } + + List res = new ArrayList<>(); + List nodeTemplates = toscaTemplate.getNodeTemplates(); + for (NodeTemplate nodeTemplate : nodeTemplates) { + if (nodeType.equals(nodeTemplate.getTypeDefinition().getType())) { + res.add(nodeTemplate); + } + } + + return res; + } + + + @Override + public List getServiceNodeTemplates() { + List nodeTemplates = toscaTemplate.getNodeTemplates(); + return nodeTemplates; + } + + @Override + //Sunny flow - covered with UT + public List getVfcListByVf(String vfCustomizationId) { + if (GeneralUtility.isEmptyString(vfCustomizationId)) { + log.error("getVfcListByVf - vfCustomizationId - is null or empty"); + return new ArrayList<>(); + } + + List serviceVfList = getServiceVfList(); + NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId); + List vfcs = getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC); + vfcs.addAll(getNodeTemplateBySdcType(vfInstance, SdcTypes.CVFC)); + + return vfcs; + } + + @Override + //Sunny flow - covered with UT + public List getVfModulesByVf(String vfCustomizationUuid) { + List serviceVfList = getServiceVfList(); + NodeTemplate nodeTemplateByCustomizationUuid = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid); + if (nodeTemplateByCustomizationUuid != null) { + /*SubstitutionMappings substitutionMappings = nodeTemplateByCustomizationUuid.getSubstitutionMappings(); + if (substitutionMappings != null){ + List groups = substitutionMappings.getGroups(); + if (groups != null){ + List collect = groups.stream().filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType())).collect(Collectors.toList()); + log.debug("getVfModulesByVf - VfModules are {}", collect); + return collect; + } + }*/ + String name = nodeTemplateByCustomizationUuid.getName(); + String normaliseComponentInstanceName = SdcToscaUtility.normaliseComponentInstanceName(name); + List serviceLevelGroups = toscaTemplate.getTopologyTemplate().getGroups(); + log.debug("getVfModulesByVf - VF node template name {}, normalized name {}. Searching groups on service level starting with VF normalized name...", name, normaliseComponentInstanceName); + if (serviceLevelGroups != null) { + List collect = serviceLevelGroups + .stream() + .filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType()) && x.getName().startsWith(normaliseComponentInstanceName)) + .collect(Collectors.toList()); + return collect; + } + } + return new ArrayList<>(); + } + + @Override + //Sunny flow - covered with UT + public String getServiceInputLeafValueOfDefault(String inputLeafValuePath) { + if (GeneralUtility.isEmptyString(inputLeafValuePath)) { + log.error("getServiceInputLeafValueOfDefault - inputLeafValuePath is null or empty"); + return null; + } + + String[] split = getSplittedPath(inputLeafValuePath); + if (split.length < 2 || !split[1].equals("default")) { + log.error("getServiceInputLeafValue - inputLeafValuePath should be of format #default[optionally #] "); + return null; + } + + List inputs = toscaTemplate.getInputs(); + if (inputs != null) { + Optional findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst(); + if (findFirst.isPresent()) { + Input input = findFirst.get(); + Object current = input.getDefault(); + Object property = iterateProcessPath(2, current, split); + return property == null || property instanceof Function? null : String.valueOf(property); + } + } + log.error("getServiceInputLeafValue - value not found"); + return null; + } + + @Override + public Object getServiceInputLeafValueOfDefaultAsObject(String inputLeafValuePath) { + if (GeneralUtility.isEmptyString(inputLeafValuePath)) { + log.error("getServiceInputLeafValueOfDefaultAsObject - inputLeafValuePath is null or empty"); + return null; + } + + String[] split = getSplittedPath(inputLeafValuePath); + if (split.length < 2 || !split[1].equals("default")) { + log.error("getServiceInputLeafValueOfDefaultAsObject - inputLeafValuePath should be of format #default[optionally #] "); + return null; + } + + List inputs = toscaTemplate.getInputs(); + if (inputs != null) { + Optional findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst(); + if (findFirst.isPresent()) { + Input input = findFirst.get(); + Object current = input.getDefault(); + return iterateProcessPath(2, current, split); + } + } + log.error("getServiceInputLeafValueOfDefaultAsObject - value not found"); + return null; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + private Object iterateProcessPath(Integer index, Object current, String[] split) { + if (current == null) { + log.error("iterateProcessPath - this input has no default"); + return null; + } + if (split.length > index) { + for (int i = index; i < split.length; i++) { + if (current instanceof Map) { + current = ((Map) current).get(split[i]); + } else if (current instanceof List) { + current = ((List) current).get(0); + i--; + } + else { + log.error("iterateProcessPath - found an unexpected leaf where expected to find a complex type"); + return null; + } + } + } + if (current != null) { + return current; + } + log.error("iterateProcessPath - Path not Found"); + return null; + } + + private String[] getSplittedPath(String inputLeafValuePath) { + return inputLeafValuePath.split(PATH_DELIMITER); + } + + + @Override + //Sunny flow - covered with UT + public String getServiceSubstitutionMappingsTypeName() { + SubstitutionMappings substitutionMappings = toscaTemplate.getTopologyTemplate().getSubstitutionMappings(); + if (substitutionMappings == null) { + log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings defined"); + return null; + } + + NodeType nodeType = substitutionMappings.getNodeDefinition(); + if (nodeType == null) { + log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings node defined"); + return null; + } + + return nodeType.getType(); + } + + @Override + //Sunny flow - covered with UT + public Metadata getServiceMetadata() { + return toscaTemplate.getMetaData(); + } + + @Override + //Sunny flow - covered with UT + public Map getServiceMetadataProperties() { + if (toscaTemplate.getMetaData() == null){ + return null; + } + return new HashMap<>(toscaTemplate.getMetaData().getAllProperties()); + } + + @Override + public Map getServiceMetadataAllProperties() { + if (toscaTemplate.getMetaData() == null){ + return null; + } + return toscaTemplate.getMetaData().getAllProperties(); + } + + @Override + //Sunny flow - covered with UT + public List getServiceInputs() { + return toscaTemplate.getInputs(); + } + + @Override + //Sunny flow - covered with UT + public String getGroupPropertyLeafValue(Group group, String leafValuePath) { + if (group == null) { + log.error("getGroupPropertyLeafValue - group is null"); + return null; + } + + if (GeneralUtility.isEmptyString(leafValuePath)) { + log.error("getGroupPropertyLeafValue - leafValuePath is null or empty"); + return null; + } + + String[] split = getSplittedPath(leafValuePath); + LinkedHashMap properties = group.getProperties(); + Object property = processProperties(split, properties); + return property == null || property instanceof Function? null : String.valueOf(property); + } + + @Override + public Object getGroupPropertyAsObject(Group group, String leafValuePath) { + if (group == null) { + log.error("getGroupPropertyAsObject - group is null"); + return null; + } + + if (GeneralUtility.isEmptyString(leafValuePath)) { + log.error("getGroupPropertyAsObject - leafValuePath is null or empty"); + return null; + } + + String[] split = getSplittedPath(leafValuePath); + LinkedHashMap properties = group.getProperties(); + return processProperties(split, properties); + } + + @Override + //Sunny flow - covered with UT + public List getCpListByVf(String vfCustomizationId) { + List cpList = new ArrayList<>(); + if (GeneralUtility.isEmptyString(vfCustomizationId)) { + log.error("getCpListByVf vfCustomizationId string is empty"); + return cpList; + } + + List serviceVfList = getServiceVfList(); + if (serviceVfList == null || serviceVfList.size() == 0) { + log.error("getCpListByVf Vfs not exist for vfCustomizationId {}", vfCustomizationId); + return cpList; + } + NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId); + if (vfInstance == null) { + log.debug("getCpListByVf vf list is null"); + return cpList; + } + cpList = getNodeTemplateBySdcType(vfInstance, SdcTypes.CP); + if (cpList == null || cpList.size() == 0) + log.debug("getCpListByVf cps not exist for vfCustomizationId {}", vfCustomizationId); + return cpList; + } + + @Override + //Sunny flow - covered with UT + public List getMembersOfVfModule(NodeTemplate vf, Group serviceLevelVfModule) { + if (vf == null) { + log.error("getMembersOfVfModule - vf is null"); + return new ArrayList<>(); + } + + if (serviceLevelVfModule == null || serviceLevelVfModule.getMetadata() == null || serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID) == null) { + log.error("getMembersOfVfModule - vfModule or its metadata is null. Cannot match a VF group based on invariantUuid from missing metadata."); + return new ArrayList<>(); + } + + + SubstitutionMappings substitutionMappings = vf.getSubMappingToscaTemplate(); + if (substitutionMappings != null) { + List groups = substitutionMappings.getGroups(); + if (groups != null) { + Optional findFirst = groups + .stream() + .filter(x -> (x.getMetadata() != null && serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID).equals(x.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)))).findFirst(); + if (findFirst.isPresent()) { + List members = findFirst.get().getMembers(); + if (members != null) { + List collect = substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(Collectors.toList()); + return collect; + } + } + } + } + return new ArrayList<>(); + } + + @Override + //Sunny flow - covered with UT + @SuppressWarnings("unchecked") + public List> getNodeTemplatePairsByReqName( + List listOfReqNodeTemplates, List listOfCapNodeTemplates, String reqName) { + + 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<>(); + + 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; + } + + @Override + //Sunny flow - covered with UT + //TODO constant strings + public List getAllottedResources() { + List nodeTemplates = null; + nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates(); + if (nodeTemplates.isEmpty()) { + log.error("getAllottedResources nodeTemplates not exist"); + } + nodeTemplates = nodeTemplates.stream().filter( + x -> x.getMetaData() != null && x.getMetaData().getValue("category").equals("Allotted Resource")) + .collect(Collectors.toList()); + if (nodeTemplates.isEmpty()) { + log.debug("getAllottedResources - allotted resources not exist"); + } else { + } + + return nodeTemplates; + } + + @Override + //Sunny flow - covered with UT + public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate) { + if (nodeTemplate == null) { + + log.error("getTypeOfNodeTemplate nodeTemplate is null"); + return null; + } + return nodeTemplate.getTypeDefinition().getType(); + } + + /** + * This methdd is returning the csarConformanceLevel for input CSAR + * When csarConformanceLevel is configured with failOnError as False in Error Configuration; it + * assigns the default value to csarConformanceLevel which is the max level provided in + * Configuration file + * @return csarConformanceLevel + */ + @Override + public String getConformanceLevel() { + LinkedHashMap csarMeta = toscaTemplate.getMetaProperties("csar.meta"); + if (csarMeta == null){ + log.warn("No csar.meta file is found in CSAR - this file should hold the conformance level of the CSAR. This might be OK for older CSARs."); + if (configurationManager != null && !configurationManager.getErrorConfiguration() + .getErrorInfo("CONFORMANCE_LEVEL_ERROR").getFailOnError()){ + String csarConLevel = configurationManager.getConfiguration().getConformanceLevel().getMaxVersion(); + log.warn("csarConformanceLevel is not found in input csar; defaulting to max version {}" , csarConLevel); + return csarConLevel; + } + else { + log.warn("csarConformanceLevel is not found in input csar; returning null as no defaults defined in error configuration"); + return null; + } + } + + Object conformanceLevel = csarMeta.get("SDC-TOSCA-Definitions-Version"); + if (conformanceLevel != null){ + String confLevelStr = conformanceLevel.toString(); + log.debug("CSAR conformance level is {}", confLevelStr); + return confLevelStr; + } else { + log.error("Invalid csar.meta file - no entry found for SDC-TOSCA-Definitions-Version key. This entry should hold the conformance level."); + return null; + } + } + + + @Override + public String getNodeTemplateCustomizationUuid(NodeTemplate nt) { + String res = null; + if (nt != null && nt.getMetaData() != null){ + res = nt.getMetaData().getValue(CUSTOMIZATION_UUID); + } else { + log.error("Node template or its metadata is null"); + } + return res; + } + + public List getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType) { + return getNodeTemplateBySdcType(parentNodeTemplate, sdcType, false); + } + + private List getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType, boolean isVNF) { + + if (parentNodeTemplate == null) { + log.error("getNodeTemplateBySdcType - nodeTemplate is null or empty"); + return new ArrayList<>(); + } + + if (sdcType == null) { + log.error("getNodeTemplateBySdcType - sdcType is null or empty"); + return new ArrayList<>(); + } + + SubstitutionMappings substitutionMappings = parentNodeTemplate.getSubMappingToscaTemplate(); + + if (substitutionMappings != null) { + List nodeTemplates = substitutionMappings.getNodeTemplates(); + if (nodeTemplates != null && nodeTemplates.size() > 0) { + if (sdcType.equals(SdcTypes.VFC) && isVNF) { + return nodeTemplates.stream() + .filter(x -> (x.getMetaData() != null && + sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && isVNFType(x)) + .collect(Collectors.toList()); + } + else { + return nodeTemplates.stream() + .filter(x -> (x.getMetaData() != null && + sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && !isVNFType(x)) + .collect(Collectors.toList()); + } + } + else { + log.debug("getNodeTemplateBySdcType - SubstitutionMappings' node Templates not exist"); + } + } else + log.debug("getNodeTemplateBySdcType - SubstitutionMappings not exist"); + + return new ArrayList<>(); + } + + public Map filterNodeTemplatePropertiesByValue(NodeTemplate nodeTemplate, FilterType filterType, String pattern) { + Map filterMap = new HashMap<>(); + + if (nodeTemplate == null) { + log.error("filterNodeTemplatePropertiesByValue nodeTemplate is null"); + return filterMap; + } + + if (filterType == null) { + log.error("filterNodeTemplatePropertiesByValue filterType is null"); + return filterMap; + } + + if (GeneralUtility.isEmptyString(pattern)) { + log.error("filterNodeTemplatePropertiesByValue pattern string is empty"); + return filterMap; + } + + Map ntProperties = nodeTemplate.getProperties(); + + if (ntProperties != null && ntProperties.size() > 0) { + + for (Property current : ntProperties.values()) { + filterProperties(current.getValue(), current.getName(), filterType, pattern, filterMap); + } + } + + log.trace("filterNodeTemplatePropertiesByValue - filterMap value: {}", filterMap); + + return filterMap; + } + + public NodeTemplate getVnfConfig(String vfCustomizationUuid) { + + if (GeneralUtility.isEmptyString(vfCustomizationUuid)) { + log.error("getVnfConfig - vfCustomizationId - is null or empty"); + return null; + } + + List serviceVfList = getServiceVfList(); + NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid); + NodeTemplate vnfConfig = getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC, true).stream().findAny().orElse(null); + return vnfConfig; + } + + @Override + public boolean hasTopology(NodeTemplate nodeTemplate) { + if (nodeTemplate == null) { + log.error("hasTopology - nodeTemplate - is null"); + return false; + } + + if (nodeTemplate.getMetaData() != null) { + String type = nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE); + log.debug("hasTopology - node template {} is a {} type", nodeTemplate.getName(), type); + return SdcTypes.isComplex(type); + } + + return false; + } + + @Override + public List getNodeTemplateChildren(NodeTemplate nodeTemplate) { + if (nodeTemplate == null) { + log.error("getNodeTemplateChildren - nodeTemplate - is null"); + return new ArrayList<>(); + } + + SubstitutionMappings substitutionMappings = nodeTemplate.getSubMappingToscaTemplate(); + if (substitutionMappings != null) { + List nodeTemplates = substitutionMappings.getNodeTemplates(); + if (nodeTemplates != null && nodeTemplates.size() > 0) { + + return nodeTemplates.stream() + .filter(x -> !isVNFType(x)) + .collect(Collectors.toList()); + } + else { + log.debug("getNodeTemplateChildren - SubstitutionMappings' node Templates not exist"); + } + } else + log.debug("getNodeTemplateChildren - SubstitutionMappings not exist"); + + 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"); + } + + @SuppressWarnings("unchecked") + private Map filterProperties(Object property, String path, FilterType filterType, String pattern, Map filterMap) { + + if (property instanceof Map) { + for (Map.Entry item: ((Map) property).entrySet()) { + String itemPath = path + PATH_DELIMITER + item.getKey(); + filterProperties(item.getValue(), itemPath, filterType, pattern, filterMap); + } + } else if (property instanceof List) { + for (Object item: (List)property) { + filterProperties(item, path, filterType, pattern, filterMap); + } + } else { + if (filterType.isMatch(property.toString(), pattern)) { + filterMap.put(path, property.toString()); + } + } + + return filterMap; + } + + public List getServiceNodeTemplateBySdcType(SdcTypes sdcType) { + if (sdcType == null) { + log.error("getServiceNodeTemplateBySdcType - sdcType is null or empty"); + return new ArrayList<>(); + } + + TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate(); + return getNodeTemplateBySdcType(topologyTemplate, sdcType); + } + + + /************************************* helper functions ***********************************/ + private List getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, SdcTypes sdcType) { + if (sdcType == null) { + log.error("getNodeTemplateBySdcType - sdcType is null or empty"); + return new ArrayList<>(); + } + + if (topologyTemplate == null) { + log.error("getNodeTemplateBySdcType - topologyTemplate is null"); + return new ArrayList<>(); + } + + List nodeTemplates = topologyTemplate.getNodeTemplates(); + + if (nodeTemplates != null && nodeTemplates.size() > 0) + return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList()); + + log.debug("getNodeTemplateBySdcType - topologyTemplate's nodeTemplates not exist"); + return new ArrayList<>(); + } + + //Assumed to be unique property for the list + private NodeTemplate getNodeTemplateByCustomizationUuid(List nodeTemplates, String customizationId) { + if (customizationId != null) { + Optional findFirst = nodeTemplates.stream().filter(x -> (x.getMetaData() != null && customizationId.equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)))).findFirst(); + return findFirst.isPresent() ? findFirst.get() : null; + } + else { + log.error("getNodeTemplateByCustomizationUuid - customizationId is null"); + return null; + } + } + + private Object processProperties(String[] split, LinkedHashMap properties) { + Optional> findFirst = properties.entrySet().stream().filter(x -> x.getKey().equals(split[0])).findFirst(); + if (findFirst.isPresent()) { + Property property = findFirst.get().getValue(); + Object current = property.getValue(); + return iterateProcessPath(1, current, split); + } + String propName = (split != null && split.length > 0 ? split[0] : null); + log.error("processProperties - property {} not found", propName); + return null; + } + + + + + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java new file mode 100644 index 0000000..7235593 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.tosca.parser.impl; + +public class SdcPropertyNames { + public static String PROPERTY_NAME_INVARIANTUUID = "invariantUUID"; + public static String PROPERTY_NAME_UUID = "UUID"; + public static String PROPERTY_NAME_CUSTOMIZATIONUUID = "customizationUUID"; + public static String PROPERTY_NAME_VERSION = "version"; + + //Groups metadata + public static String PROPERTY_NAME_VFMODULEMODELINVARIANTUUID = "vfModuleModelInvariantUUID"; + public static String PROPERTY_NAME_VFMODULEMODELUUID = "vfModuleModelUUID"; + public static String PROPERTY_NAME_VFMODULECUSTOMIZATIONUUID = "vfModuleCustomizationUUID"; + public static String PROPERTY_NAME_VFMODULEMODELVERSION = "vfModuleModelVersion"; + public static String PROPERTY_NAME_VFMODULEMODELNAME = "vfModuleModelName"; + + //Groups properties + public static String PROPERTY_NAME_VFMODULETYPE = "vf_module_type"; + public static String PROPERTY_NAME_VFMODULELABEL = "vf_module_label"; + public static String PROPERTY_NAME_MINVFMODULEINSTANCES = "min_vf_module_instances"; + public static String PROPERTY_NAME_MAXVFMODULEINSTANCES = "max_vf_module_instances"; + public static String PROPERTY_NAME_INITIALCOUNT = "initial_count"; + + + public static String PROPERTY_NAME_DESCRIPTION = "description"; + public static String PROPERTY_NAME_TYPE = "type"; + public static String PROPERTY_NAME_CATEGORY = "category"; + public static String PROPERTY_NAME_SUBCATEGORY = "subcategory"; + public static String PROPERTY_NAME_RESOURCEVENDOR = "resourceVendor"; + public static String PROPERTY_NAME_RESOURCEVENDORRELEASE = "resourceVendorRelease"; + //VFC + public static String PROPERTY_NAME_NFCCODE = "nfc_code"; + public static String PROPERTY_NAME_VMTYPETAG = "vm_type_tag"; + public static String PROPERTY_NAME_VMTYPE = "vm_type"; + public static String PROPERTY_NAME_VFCNAMING_ECOMPGENERATEDNAMING="vfc_naming#ecomp_generated_naming"; + public static String PROPERTY_NAME_VFCNAMING_NAMINGPOLICY="vfc_naming#naming_policy"; + //VF + public static String PROPERTY_NAME_NFTYPE = "nf_type"; + public static String PROPERTY_NAME_NFROLE = "nf_role"; + public static String PROPERTY_NAME_NFFUNCTION = "nf_function"; + public static String PROPERTY_NAME_NFCODE = "nf_code"; + public static String PROPERTY_NAME_MININSTANCES = "min_instances"; + public static String PROPERTY_NAME_MAXINSTANCES = "max_instances"; + public static String PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT = "availability_zone_max_count"; + public static String PROPERTY_NAME_AVAILABILITYZONECOUNT = "availability_zone_count"; + public static String PROPERTY_NAME_NAME = "name"; + public static String PROPERTY_NAME_VNFECOMPNAMING_ECOMPGENERATEDNAMING="vnf_ecomp_naming#ecomp_generated_naming"; + public static String PROPERTY_NAME_VNFECOMPNAMING_NAMINGPOLICY="vnf_ecomp_naming#naming_policy"; + public static String PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS = "ecomp_generated_vm_assignments"; + //Service + public static String PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING="service_naming#default#ecomp_generated_naming"; + public static String PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY="service_naming#default#naming_policy"; + //VL + public static String PROPERTY_NAME_NETWORKTYPE="network_type"; + public static String PROPERTY_NAME_NETWORKROLE="network_role"; + public static String PROPERTY_NAME_NETWORKROLETAG="network_role_tag"; + public static String PROPERTY_NAME_NETWORKTECHNOLOGY="network_technology"; + public static String PROPERTY_NAME_NETWORKSCOPE="network_scope"; + public static String PROPERTY_NAME_NETWORKECOMPNAMING_ECOMPGENERATEDNAMING="network_ecomp_naming#ecomp_generated_naming"; + public static String PROPERTY_NAME_NETWORKECOMPNAMING_NAMINGPOLICY="network_ecomp_naming#naming_policy"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_ISSHAREDNETWORK="network_assignments#is_shared_network"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_ISEXTERNALNETWORK="network_assignments#is_external_network"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_ECOMPGENERATEDNETWORKASSIGNMENT="network_assignments#ecomp_generated_network_assignment"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_USEIPV4="network_assignments#ipv4_subnet_default_assignments#use_ipv4"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPNETWORKADDRESSPLAN="network_assignments#ipv4_subnet_default_assignments#ip_network_address_plan"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_DHCPENABLED="network_assignments#ipv4_subnet_default_assignments#dhcp_enabled"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPVERSION="network_assignments#ipv4_subnet_default_assignments#ip_version"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_CIDRMASK="network_assignments#ipv4_subnet_default_assignments#cidr_mask"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT="network_assignments#ipv4_subnet_default_assignments#min_subnets_count"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_USEIPV6="network_assignments#ipv6_subnet_default_assignments#use_ipv6"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPNETWORKADDRESSPLAN="network_assignments#ipv6_subnet_default_assignments#ip_network_address_plan"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_DHCPENABLED="network_assignments#ipv6_subnet_default_assignments#dhcp_enabled"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPVERSION="network_assignments#ipv6_subnet_default_assignments#ip_version"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_CIDRMASK="network_assignments#ipv6_subnet_default_assignments#cidr_mask"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT="network_assignments#ipv6_subnet_default_assignments#min_subnets_count"; + + /*public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_ISPROVIDERNETWORK="network_assignments#provider_network#is_provider_network"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_PHYSICALNETWORKNAME="network_assignments#provider_network#physical_network_name"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_NUMA="network_assignments#provider_network#numa"; + public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_PNICINSTANCE="network_assignments#provider_network#pnic_instance"; + */ + + public static String PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK="provider_network#is_provider_network"; + public static String PROPERTY_NAME_PROVIDERNETWORK_PHYSICALNETWORKNAME="provider_network#physical_network_name"; + public static String PROPERTY_NAME_PROVIDERNETWORK_NUMA="provider_network#numa"; + public static String PROPERTY_NAME_PROVIDERNETWORK_PNICINSTANCE="provider_network#pnic_instance"; + + public static String PROPERTY_NAME_NETWORKFLOWS_ISBOUNDTOVPN="network_flows#is_bound_to_vpn"; + public static String PROPERTY_NAME_NETWORKFLOWS_VPNBINDING="network_flows#vpn_binding"; +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcToscaParserFactory.java b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcToscaParserFactory.java new file mode 100644 index 0000000..bc8d1b1 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcToscaParserFactory.java @@ -0,0 +1,203 @@ +package org.onap.sdc.tosca.parser.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.sdc.tosca.parser.api.ConformanceLevel; +import org.onap.sdc.tosca.parser.config.ConfigurationManager; +import org.onap.sdc.tosca.parser.config.ErrorInfo; +import org.onap.sdc.tosca.parser.config.JToscaValidationIssueInfo; +import org.onap.sdc.tosca.parser.config.SdcToscaParserErrors; +import org.onap.sdc.tosca.parser.utils.GeneralUtility; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.config.*; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.toscaparser.api.ToscaTemplate; +import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue; +import org.onap.sdc.toscaparser.api.common.JToscaException; +import org.onap.sdc.toscaparser.api.utils.JToscaErrorCodes; +import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdcToscaParserFactory { + private static Logger log = LoggerFactory.getLogger(SdcToscaParserFactory.class.getName()); + + private static ConfigurationManager configurationManager; + private static volatile SdcToscaParserFactory instance; + private List criticalExceptions = new ArrayList<>(); + private List warningExceptions = new ArrayList<>(); + private List notAnalyzadExceptions = new ArrayList<>(); + private SdcToscaParserFactory() {} + + /** + * Get an SdcToscaParserFactory instance. + * @return SdcToscaParserFactory instance. + */ + public static SdcToscaParserFactory getInstance() { + if (instance == null) { + synchronized (SdcToscaParserFactory.class) { + if (instance == null) { + instance = new SdcToscaParserFactory(); + configurationManager = ConfigurationManager.getInstance(); + } + } + } + return instance; + } + + public static void setConfigurationManager(ConfigurationManager configurationManager) { + SdcToscaParserFactory.configurationManager = configurationManager; + } + + /** + * Get an ISdcCsarHelper object for this CSAR file. + * + * @param csarPath - the absolute path to CSAR file. + * @return ISdcCsarHelper object. + * @throws SdcToscaParserException - in case the path or CSAR are invalid. + */ + public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws SdcToscaParserException { + return init(csarPath, true); + } + + /** + * Get an ISdcCsarHelper object for this CSAR file. + * + * @param csarPath - the absolute path to CSAR file. + * @param resolveGetInput - resolve get_input properties + * @return ISdcCsarHelper object. + * @throws SdcToscaParserException - in case the path or CSAR are invalid. + */ + public ISdcCsarHelper getSdcCsarHelper(String csarPath, boolean resolveGetInput) throws SdcToscaParserException { + return init(csarPath, resolveGetInput); + } + + private ISdcCsarHelper init(String csarPath, boolean resolveGetInput) throws SdcToscaParserException { + synchronized (SdcToscaParserFactory.class) { + ToscaTemplate tosca = null; + try { + tosca = new ToscaTemplate(csarPath, null, true, null, resolveGetInput); + } catch (JToscaException e) { + throwSdcToscaParserException(e); + } + SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(tosca, configurationManager); + String cSarConformanceLevel = sdcCsarHelperImpl.getConformanceLevel(); + validateCsarVersion(cSarConformanceLevel); + try { + handleErrorsByTypes(csarPath, cSarConformanceLevel); + } catch (JToscaException e) { + throwSdcToscaParserException(e); + } + return sdcCsarHelperImpl; + } + } + + private void handleErrorsByTypes(String csarPath, String cSarConformanceLevel) throws JToscaException { + clearValidationIssuesLists(); + for(JToscaValidationIssue toscaValidationIssue : ThreadLocalsHolder.getCollector().getValidationIssues().values()){ + List issueInfos = configurationManager.getJtoscaValidationIssueConfiguration().getValidationIssues().get(toscaValidationIssue.getCode()); + if(issueInfos != null && !issueInfos.isEmpty()){ + JToscaValidationIssueInfo issueInfo = null; + issueInfo = issueInfos.stream() + .filter(i-> isMatchConformanceLevel(cSarConformanceLevel,i.getSinceCsarConformanceLevel())) + .max((i1,i2) -> GeneralUtility.conformanceLevelCompare(i1.getSinceCsarConformanceLevel(), i2.getSinceCsarConformanceLevel()) ) + .orElse(null); + + if(issueInfo != null){ + switch (JToscaValidationIssueType.valueOf(issueInfo.getIssueType())) { + case CRITICAL: + criticalExceptions.add(toscaValidationIssue); + break; + case WARNING: + warningExceptions.add(toscaValidationIssue); + break; + default: + break; + } + }else{ + notAnalyzadExceptions.add(toscaValidationIssue); + } + }else{//notAnalyzed + notAnalyzadExceptions.add(toscaValidationIssue); + } + } + logErrors(csarPath); + } + + private void clearValidationIssuesLists(){ + notAnalyzadExceptions.clear(); + criticalExceptions.clear(); + warningExceptions.clear(); + } + + private void logErrors(String inputPath) throws JToscaException{ + //Warnings + int warningsCount = warningExceptions.size(); + if (warningsCount > 0) { + log.warn("####################################################################################################"); + log.warn("CSAR Warnings found! CSAR name - {}", inputPath); + log.warn("ToscaTemplate - verifyTemplate - {} Parsing Warning{} occurred...", warningsCount, (warningsCount > 1 ? "s" : "")); + for (JToscaValidationIssue info : warningExceptions) { + log.warn("JTosca Exception [{}]: {}. CSAR name - {}", info.getCode(),info.getMessage(), inputPath); + } + log.warn("####################################################################################################"); + } + //Criticals + int criticalsCount = criticalExceptions.size(); + if (criticalsCount > 0) { + log.error("####################################################################################################"); + log.error("ToscaTemplate - verifyTemplate - {} Parsing Critical{} occurred...", criticalsCount, (criticalsCount > 1 ? "s" : "")); + for (JToscaValidationIssue info : criticalExceptions) { + log.error("JTosca Exception [{}]: {}. CSAR name - {}", info.getCode(),info.getMessage(), inputPath); + } + throw new JToscaException(String.format("CSAR Validation Failed. CSAR name - {}. Please check logs for details.", inputPath), JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR.getValue()); + } + } + public List getCriticalExceptions() { + return criticalExceptions; + } + + public List getWarningExceptions() { + return warningExceptions; + } + + public List getNotAnalyzadExceptions() { + return notAnalyzadExceptions; + } + + + private void validateCsarVersion(String cSarVersion) throws SdcToscaParserException { + ConformanceLevel level = configurationManager.getConfiguration().getConformanceLevel(); + String minVersion = level.getMinVersion(); + String maxVersion = level.getMaxVersion(); + if (cSarVersion != null) { + if ((GeneralUtility.conformanceLevelCompare(cSarVersion, minVersion) < 0) || (GeneralUtility.conformanceLevelCompare(cSarVersion, maxVersion) > 0)) { + throwConformanceLevelException(minVersion, maxVersion); + } + } else { + throwConformanceLevelException(minVersion, maxVersion); + } + } + + private boolean isMatchConformanceLevel(String ValidationIssueVersion, String cSarVersion){ + if (ValidationIssueVersion != null && cSarVersion != null) { + if ((GeneralUtility.conformanceLevelCompare(ValidationIssueVersion, cSarVersion) >= 0)) { + return true; + } + } + return false; + } + private void throwConformanceLevelException(String minVersion, String maxVersion) throws SdcToscaParserException { + ErrorInfo errorInfo = configurationManager.getErrorConfiguration().getErrorInfo(SdcToscaParserErrors.CONFORMANCE_LEVEL_ERROR.toString()); + throw new SdcToscaParserException(String.format(errorInfo.getMessage(), minVersion, maxVersion), errorInfo.getCode()); + } + + private void throwSdcToscaParserException(JToscaException e) throws SdcToscaParserException { + ErrorInfo errorInfo = configurationManager.getErrorConfiguration().getErrorInfo(SdcToscaParserErrors.getSdcErrorByJToscaError(JToscaErrorCodes.getByCode(e.getCode())).toString()); + throw new SdcToscaParserException(errorInfo.getMessage(), errorInfo.getCode()); + } + + + +} \ No newline at end of file diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcTypes.java b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcTypes.java new file mode 100644 index 0000000..9daf0ef --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcTypes.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.tosca.parser.impl; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public enum SdcTypes { + + CP("CP"), VL("VL"), VF("VF"), CR("CR"), VFC("VFC"), PNF("PNF"), SERVICE("Service"), CVFC("CVFC"), SERVICE_PROXY("Service Proxy"), CONFIGURATION("Configuration"); + + private String value; + + private static List complexTypes = Arrays.asList(VF, PNF, CR, SERVICE, CVFC).stream().map(SdcTypes::getValue).collect(Collectors.toList()); + + private SdcTypes(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static boolean isComplex(String sdcType) { + return complexTypes.contains(sdcType); + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/utils/GeneralUtility.java b/src/main/java/org/onap/sdc/tosca/parser/utils/GeneralUtility.java new file mode 100644 index 0000000..cddccd3 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/utils/GeneralUtility.java @@ -0,0 +1,53 @@ +package org.onap.sdc.tosca.parser.utils; + +import java.util.Arrays; + +public class GeneralUtility { + + public static boolean isEmptyString(String str) { + return str == null || str.trim().isEmpty(); + } + + + /** + * Compares two version strings. + *

+ * Use this instead of String.compareTo() for a non-lexicographical + * comparison that works for version strings. e.g. "1.10".compareTo("1.6"). + * + * @param str1 a string of ordinal numbers separated by decimal points. + * @param str2 a string of ordinal numbers separated by decimal points. + * @return The result is a negative integer if str1 is _numerically_ less than str2. + * The result is a positive integer if str1 is _numerically_ greater than str2. + * The result is zero if the strings are _numerically_ equal. + * It does not work if "1.10" is supposed to be equal to "1.10.0". + */ + public static int conformanceLevelCompare(String str1, String str2) { + String[] vals1 = str1.split("\\."); + String[] vals2 = str2.split("\\."); + int i = 0; + // set index to first non-equal ordinal or length of shortest version string + while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) { + i++; + } + // compare first non-equal ordinal number + if (i < vals1.length && i < vals2.length) { + int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i])); + return Integer.signum(diff); + } + //in case of 0 after the . e.g: "3" = "3.0" or "3.0.0.0" = "3.0" + str2 = str2.substring(i).replace(".", ""); + str1 = str1.substring(i).replace(".", ""); + if ((!(str1.equals(""))) && Integer.valueOf(str1) == 0){ + vals1 = Arrays.copyOf(vals1, i); + } + if ((!(str2.equals(""))) && Integer.valueOf(str2) == 0){ + vals2 = Arrays.copyOf(vals2, i); + } + + // the strings are equal or one string is a substring of the other + // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4" + return Integer.signum(vals1.length - vals2.length); + } + +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/utils/SdcToscaUtility.java b/src/main/java/org/onap/sdc/tosca/parser/utils/SdcToscaUtility.java new file mode 100644 index 0000000..57f4187 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/utils/SdcToscaUtility.java @@ -0,0 +1,19 @@ +package org.onap.sdc.tosca.parser.utils; + +import java.util.regex.Pattern; + +public class SdcToscaUtility { + + public final static Pattern COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+"); + + public static String normaliseComponentInstanceName(String name) { + String normalizedName = name.toLowerCase(); + normalizedName = COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" "); + String[] split = normalizedName.split(" "); + StringBuffer sb = new StringBuffer(); + for (String splitElement : split) { + sb.append(splitElement); + } + return sb.toString(); + } +} diff --git a/src/main/java/org/onap/sdc/tosca/parser/utils/YamlToObjectConverter.java b/src/main/java/org/onap/sdc/tosca/parser/utils/YamlToObjectConverter.java new file mode 100644 index 0000000..89963d8 --- /dev/null +++ b/src/main/java/org/onap/sdc/tosca/parser/utils/YamlToObjectConverter.java @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.tosca.parser.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; + +public class YamlToObjectConverter { + + private static Logger log = LoggerFactory + .getLogger(YamlToObjectConverter.class.getName()); + + private static HashMap yamls = new HashMap(); + + private static Yaml defaultYaml = new Yaml(); + + private static Yaml getYamlByClassName(Class className) { + + Yaml yaml = yamls.get(className.getName()); + if (yaml == null) { + yaml = defaultYaml; + } + + return yaml; + } + + public T convert(String dirPath, Class className, + String configFileName) { + + T config = null; + + try { + + String fullFileName = dirPath + File.separator + configFileName; + + config = convert(fullFileName, className); + + } catch (Exception e) { + log.error("Failed to convert yaml file " + configFileName + + " to object.", e); + } + + return config; + } + + public T convert(String fullFileName, Class className) { + + T config = null; + + Yaml yaml = getYamlByClassName(className); + + InputStream in = null; + try { + + File f = new File(fullFileName); + if (false == f.exists()) { + log.warn("The file " + fullFileName + + " cannot be found. Ignore reading configuration."); + return null; + } + in = Files.newInputStream(Paths.get(fullFileName)); + + config = yaml.loadAs(in, className); + + // System.out.println(config.toString()); + } catch (Exception e) { + log.error("Failed to convert yaml file " + fullFileName + + " to object.", e); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + return config; + } + + public T convertFromString(String yamlContents, Class className) { + + T config = null; + Yaml yaml = new Yaml(); + try { + Object data = yaml.load(yamlContents); + // convert it manually with jackson instead of using snakeyaml auto converter, + // because of problematic complex objects like JtoscaValidationIssueConfiguration + ObjectMapper mapper = new ObjectMapper(); + config = mapper.convertValue(data, className); + } catch (Exception e){ + log.error("Failed to convert YAML {} to object." , yamlContents, e); + } + + return config; + } +} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/api/ConformanceLevel.java b/src/main/java/org/openecomp/sdc/tosca/parser/api/ConformanceLevel.java deleted file mode 100644 index a026938..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/api/ConformanceLevel.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.openecomp.sdc.tosca.parser.api; - -public class ConformanceLevel { - - private String minVersion; - private String maxVersion; - - public String getMaxVersion() { - return maxVersion; - } - - public void setMaxVersion(String maxVersion) { - this.maxVersion = maxVersion; - } - - public String getMinVersion() { - return minVersion; - } - - public void setMinVersion(String minVersion) { - this.minVersion = minVersion; - } - - -} 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 deleted file mode 100644 index df9e47d..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java +++ /dev/null @@ -1,454 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * sdc-distribution-client - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.openecomp.sdc.tosca.parser.api; - - -import java.util.List; -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.*; -import org.openecomp.sdc.toscaparser.api.elements.Metadata; -import org.openecomp.sdc.toscaparser.api.parameters.Input; - - -public interface ISdcCsarHelper { - - /** - * Get all node templates by node_type for this CSAR service. - * - * @param nodeType - the TOSCA type of the node. - * @return service node templates of this type. - */ - public List getServiceNodeTemplatesByType(String nodeType); - - /** - * Get all node templates for this CSAR service. - * - * @return service node templates. - */ - public List getServiceNodeTemplates(); - - /** - * Get groups of a VF with type "org.openecomp.groups.VfModule". - * - * @param vfCustomizationUuid - customizationUuid of VF instance. - * @return list of vfModule groups. - */ - public List getVfModulesByVf(String vfCustomizationUuid); - - - /** - * Get any property leaf value for node template by full path separated by #.
- * For example, for node template with this property:

- * network_assignments:
-   ecomp_generated_network_assignment: true
-   is_shared_network: false
-   is_external_network: false
-   ipv4_subnet_default_assignments:
-     use_ipv4: true
-     ip_network_address_plan: 1.2.3.4
-     dhcp_enabled: true
-     ip_version: 4
-     cidr_mask: 24
-     min_subnets_count: 1
-   ipv6_subnet_default_assignments:
-     use_ipv6: false

- - * calling
- * getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignments#use_ipv6")
- * will return "false". - * @param nodeTemplate - nodeTemplate 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 getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String pathToPropertyLeafValue); - - /** - * Get any property leaf value for node template by full path separated by #.
- * For example, for node template with this property:

- * network_assignments:
-   ecomp_generated_network_assignment: true
-   is_shared_network: false
-   is_external_network: false
-   ipv4_subnet_default_assignments:
-     use_ipv4: true
-     ip_network_address_plan: 1.2.3.4
-     dhcp_enabled: true
-     ip_version: 4
-     cidr_mask: 24
-     min_subnets_count: 1
-   ipv6_subnet_default_assignments:
-     use_ipv6: false

- - * calling
- * getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignments#use_ipv6")
- * will return "false". - * @param nodeTemplate - nodeTemplate where the property should be looked up. - * @param pathToPropertyLeafValue - the full path of the required property. - * @return the leaf value as Object, or null if there's no such property. It's up to the caller to cast it to a proper type. - */ - public Object getNodeTemplatePropertyAsObject(NodeTemplate nodeTemplate, String pathToPropertyLeafValue); - - /** - * Get any property leaf value for a group definition by full path separated by #. - * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for a group. - * @param group - group where the property should be looked up. - * @param propertyName - the name 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 getGroupPropertyLeafValue(Group group, String propertyName); - - /** - * Get any property value for a group definition by full path separated by #. - * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for a group. - * @param group - group where the property should be looked up. - * @param propertyName - the name of the required property. - * @return the leaf value as Object, or null if there's no such property. It's up to the caller to cast it to a proper type. - */ - public Object getGroupPropertyAsObject(Group group, String propertyName); - - /** - * Get all VL node templates of the CSAR service. - * @return - all VL node templates. - */ - public List getServiceVlList(); - - /** - * Get all VF node templates of the CSAR service. - * @return - all VF node templates. - */ - public List getServiceVfList(); - - - /** - * - * Get a property from a metadata object.
- * This is just sugaring method, same as calling metadata.getMetadataPropertyValue(metadataPropertyName).
- * - * For metadata object representing the below:

- * - * metadata:
-   invariantUUID: 4598a404-00e1-42a6-8767-0bda343e2066
-   UUID: e17940d6-42f8-4989-bad0-31de5addc619
-   customizationUUID: 83d086b2-a861-4d3b-aa84-3bfbb9b2ec20
-   version: '0.1'
-   name: vIPR_ATM
-   description: vIPR_ATM
-   type: VF
-   category: category1
-   subcategory: subCategory1

- - calling
- getMetadataPropertyValue(metadata,"invariantUUID")
- will return "4598a404-00e1-42a6-8767-0bda343e2066". - - * @param metadata - metadata object. - * @param metadataPropertyName - the name of the metadata property. - * @return metadata property value - */ - public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName); - - - /** - * Get input leaf value for the CSAR service, by full path separated by #.
- * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for an input full path. - * The expected format is "input_name#default[optionally #rest_of_path]" - * @param inputLeafValuePath by full path separated by #. - * @return input leaf value for the service. - */ - public String getServiceInputLeafValueOfDefault(String inputLeafValuePath); - - /** - * Get input leaf value for the CSAR service, by full path separated by #.
- * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for an input full path. - * The expected format is "input_name#default[optionally #rest_of_path]" - * @param inputLeafValuePath by full path separated by #. - * @return input value for the service as Object. It's up to the caller to cast it to a proper type. - */ - public Object getServiceInputLeafValueOfDefaultAsObject(String inputLeafValuePath); - - /** - * Get the type name of the CSAR service's substitution mappings element.
- * - * For the below:

- * - * substitution_mappings:
-   type: org.openecomp.services.ViprATM
- - calling
- getServiceSubstitutionMappingsTypeName()
- will return "org.openecomp.services.ViprATM" - * @return - the type name of the CSAR service's substitution mappings element - */ - public String getServiceSubstitutionMappingsTypeName(); - - /** - * 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. - * @return all VFC node templates from a specified VF - */ - public List getVfcListByVf(String vfCustomizationId); - - /** - * Get all CP node templates from a specified VF. - * @param vfCustomizationId - customizationUuid of the VF node template. - * @return all CP node templates from a specified VF - */ - public List getCpListByVf(String vfCustomizationId); - - /** - * Get all members of this group definition.
- * - * For example, for this group definition:

- * - * ViprAtm..vIPR-ATM-Base..module-0:
-   type: org.openecomp.groups.VfModule
-   .................
-   members: [vIPR_ATM_Ha_Two, vIPR_ATM_Ha_One, vIPR_ATM_OAM_SG, vIPR_ATM_HA_TWO_SG, vIPR_ATM_HA_ONE_SG]

- - calling
- getMembersOfVfModule(NoteTemplate vfNodeTemplate, Group group)
- will return List of the following Node templates in the vfNodeTemplate: "vIPR_ATM_Ha_Two, vIPR_ATM_Ha_One, vIPR_ATM_OAM_SG, vIPR_ATM_HA_TWO_SG, vIPR_ATM_HA_ONE_SG"
- * @param vf - VF to return the node templates from. - * @param vfModule - group to return the members from. - * @return node templates from vf with the names as in members section. - * - */ - public List getMembersOfVfModule(NodeTemplate vf, Group vfModule); - - - /** - * Get list of node template pairs, where for each pair,
- * the left node template in pair has requirement with name reqName,
- * which should be satisfied with respective capability by the right node template in pair.
- * - * For example, if we have the below two node templates in the vIPR VF:

- * - * oam_extCP:
-   type: org.openecomp.resources.cp.extCP
-   requirements:
-     - virtualBinding: vipr_atm_firewall

- * - * vipr_atm_firewall:
-   type: org.openecomp.resources.vfc.ViprAtm.abstract.nodes.heat.vipr_atm
- ........

- * - - * calling
- * getNodeTemplatePairsByReqName(getCpListByVf(viprCustomUuid), getVfcListByVf(viprCustomUuid), "virtualBinding")
- * will return a list with one Pair - where left element of pair will be "oam_extCP" node template,
- * and right element will be "vipr_atm_firewall" node template.
- * - * @param listOfReqNodeTemplates - list of node templates in which the "reqName" requirement should be looked. - * @param listOfCapNodeTemplates - list of node templates in which the capability matching the "reqName" requirement should be looked. - * @param reqName - the name of a requirement definition to match by. - * @return pairs of node templates according to described above. - */ - public List> getNodeTemplatePairsByReqName(List listOfReqNodeTemplates, List listOfCapNodeTemplates, String reqName); - - /** - * Get all allotted node templates from this service. - * @return all allotted node templates from this service. - */ - public List getAllottedResources(); - - /** - * Get node_type of a node template.
- * - * For this node template:
- * - * vipr_atm_firewall:
-   type: org.openecomp.resources.vfc.ViprAtm.abstract.nodes.heat.vipr_atm
- ........

- * - * the function will return "org.openecomp.resources.vfc.ViprAtm.abstract.nodes.heat.vipr_atm" - * - * @param nodeTemplate - node template object - * @return - node type string. - */ - public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate); - - /** - * Get the CSAR service inputs list. - * @return - the service inputs list. - */ - public List getServiceInputs(); - - - /** - * Get the conformance level of this CSAR.
- * The conformance level value of the CSAR is located in csar.meta file at the top level of the CSAR file.
- * For 1707 CSARs, the conformance level is 3.0. - * @return the conformance level of the CSAR. - */ - public String getConformanceLevel(); - - - /** - * Get the map of CP-related props from a VFC node template.
- * Let's say there are 5 CPs related to this VFC. Then the output will look like this:

- * {port_fe1_sigtran={ip_requirements#ip_count_required#count=1, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4, subnetpoolid="subnet_1", network_role_tag="SIGNET_vrf_B1_direct"},
- * port_fe_cluster={ip_requirements#ip_count_required#count=2, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4},
- * port_fe_slan={ip_requirements#ip_count_required#count=1, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4},
- * port_fe_interce={ip_requirements#ip_count_required#count=1, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4},
- * 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. - * Will be removed in 1802. - */ - @Deprecated - public Map> getCpPropertiesFromVfc(NodeTemplate vfc); - - /** - * Get the map of CP-related props from a VFC node template.
- * Let's say there are 2 CPs (ports) related to this VFC. Then the output will look like this:

- * {port_fe_sigtran={ip_requirements={ip_count_required: {count: 1}, dhcp_enabled: true, ip_version: 4}, subnetpoolid: "subnet_1", network_role_tag: "SIGNET_vrf_B1_direct"}
- * port_fe_cluster={ip_requirements={ip_count_required: {count: 2}, dhcp_enabled: true, ip_version: 4}}
- * @param vfc - VFC node template to look for CP-related props. - * @return map CP node template name to a map of property name - property value as object. - */ - public Map> getCpPropertiesFromVfcAsObject(NodeTemplate vfc); - - /** - * Get customization UUID of a node template - * @param nt - node template - * @return customization UUID of a node template. - */ - public String getNodeTemplateCustomizationUuid(NodeTemplate nt); - - /** - * Filter Node Template property values by equals/contains operator and a pattern - * @param nodeTemplate Node Template to filter its properties - * @param filterType filter type - equals or contains - * @param pattern value to filter with it - * @return Map full path to a property mapped to property value filtered by type and pattern - */ - public Map filterNodeTemplatePropertiesByValue(NodeTemplate nodeTemplate, FilterType filterType, String pattern); - - /** - * Get all node templates by sdcType for parent Node Template. - * - * @param parentNodeTemplate - parent node template - * @param sdcType - the SDC type of the node. - * @return node templates of this SDC type. - */ - public List getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType); - - /** - * Get all node templates by SDC type enum for this CSAR service. - * - * @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); - - /** - * Get all node templates for this CSAR service. - * @param vfCustomizationUuid - the Customization UUID of the node. - * @return VNF Configuration Node Template. - */ - public NodeTemplate getVnfConfig(String vfCustomizationUuid); - - /** - * Check if Node Template has Topology Template - * @param nodeTemplate - Node Template to check - * @return true if node template has topology template, false if not. - */ - public boolean hasTopology(NodeTemplate nodeTemplate); - - /** - * Get children node templates for node template. - * @param nodeTemplate - Node Template to get its children - * @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/api/Version.java b/src/main/java/org/openecomp/sdc/tosca/parser/api/Version.java deleted file mode 100644 index 473e3a8..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/api/Version.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.openecomp.sdc.tosca.parser.api; - -public class Version implements Comparable { - - private String version; - - public final String get() { - return this.version; - } - - public Version(String version) { - if(version == null) - throw new IllegalArgumentException("Version can not be null"); - if(!version.matches("[0-9]+(\\.[0-9]+)*")) - throw new IllegalArgumentException("Invalid version format"); - this.version = version; - } - - @Override public int compareTo(Version that) { - if(that == null) - return 1; - String[] thisParts = this.get().split("\\."); - String[] thatParts = that.get().split("\\."); - int length = Math.max(thisParts.length, thatParts.length); - for(int i = 0; i < length; i++) { - int thisPart = i < thisParts.length ? - Integer.parseInt(thisParts[i]) : 0; - int thatPart = i < thatParts.length ? - Integer.parseInt(thatParts[i]) : 0; - if(thisPart < thatPart) - return -1; - if(thisPart > thatPart) - return 1; - } - return 0; - } - - @Override public boolean equals(Object that) { - if(this == that) - return true; - if(that == null) - return false; - if(this.getClass() != that.getClass()) - return false; - return this.compareTo((Version) that) == 0; - } - -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/Configuration.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/Configuration.java deleted file mode 100644 index 1d00d14..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/config/Configuration.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.openecomp.sdc.tosca.parser.config; - -import org.openecomp.sdc.tosca.parser.api.ConformanceLevel; - -public class Configuration { - - private ConformanceLevel conformanceLevel; - - public ConformanceLevel getConformanceLevel() { - return conformanceLevel; - } - - public void setConformanceLevel(ConformanceLevel conformanceLevel) { - this.conformanceLevel = conformanceLevel; - } -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java deleted file mode 100644 index f2fc903..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.openecomp.sdc.tosca.parser.config; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; -import org.openecomp.sdc.tosca.parser.utils.YamlToObjectConverter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - - -public class ConfigurationManager { - - private static Logger log = LoggerFactory.getLogger(ConfigurationManager.class.getName()); - - private static final String CONFIGURATION_DIR = "config/"; - private static volatile ConfigurationManager instance; - - - Map configurations = new HashMap(); - - private ConfigurationManager() { - initialConfigObjectsFromFiles(); - } - - private void initialConfigObjectsFromFiles() { - loadConfigurationClass(ErrorConfiguration.class); - loadConfigurationClass(Configuration.class); - loadConfigurationClass(JtoscaValidationIssueConfiguration.class); - } - - private void loadConfigurationClass(Class clazz) { - T object = getObjectFromYaml(clazz); - configurations.put(clazz.getSimpleName(), object); - } - - private void loadConfigurationClass(Class clazz, String fileName) { - T object = getObjectFromYaml(clazz,fileName); - configurations.put(clazz.getSimpleName(), object); - } - - public static T getObjectFromYaml(Class className) { - return getObjectFromYaml(className, null); - } - - public static T getObjectFromYaml(Class className, String fileName) { - - - String configFileName = fileName != null ? fileName : calculateFileName(className); ; - - URL url = Resources.getResource(CONFIGURATION_DIR + configFileName); - String configFileContents = null; - try { - configFileContents = Resources.toString(url, Charsets.UTF_8); - } catch (IOException e) { - log.error("ConfigurationManager - Failed to load configuration file {}", configFileName, e); - } - YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter(); - T object = yamlToObjectConverter.convertFromString(configFileContents, className); - - return object; - } - - - public static ConfigurationManager getInstance() { - if (instance == null) { - synchronized (ConfigurationManager.class) { - if (instance == null) { - instance = new ConfigurationManager(); - } - } - } - return instance; - } - - private static String calculateFileName(Class className) { - - String[] words = className.getSimpleName().split("(?=\\p{Upper})"); - - StringBuilder builder = new StringBuilder(); - - // There cannot be a null value returned from "split" - words != null is - // redundant - // if (words != null) { - boolean isFirst = true; - for (int i = 0; i < words.length; i++) { - - String word = words[i]; - if (word != null && !word.isEmpty()) { - if (!isFirst) { - builder.append("-"); - } else { - isFirst = false; - } - builder.append(words[i].toLowerCase()); - } - } - return builder.toString() + ".yaml"; - - /* - * } else { return className.getSimpleName().toLowerCase() + Constants.YAML_SUFFIX; } - */ - - } - - public ErrorConfiguration getErrorConfiguration() { - return (ErrorConfiguration) configurations.get((ErrorConfiguration.class.getSimpleName())); - } - public JtoscaValidationIssueConfiguration getJtoscaValidationIssueConfiguration() { - return (JtoscaValidationIssueConfiguration) configurations.get((JtoscaValidationIssueConfiguration.class.getSimpleName())); - } - public void setJtoscaValidationIssueConfiguration(String fileName) { - loadConfigurationClass(JtoscaValidationIssueConfiguration.class, fileName); - } - public Configuration getConfiguration() { - return (Configuration) configurations.get((Configuration.class.getSimpleName())); - } - public void setErrorConfiguration(String fileName) { - loadConfigurationClass(ErrorConfiguration.class, fileName); - } -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java deleted file mode 100644 index 59e8c6d..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.tosca.parser.config; - -import java.util.Map; - -public class ErrorConfiguration { - - private Map errors; - - public Map getErrors() { - return errors; - } - - public void setErrors(Map errors) { - this.errors = errors; - } - - public ErrorInfo getErrorInfo(String key) { - ErrorInfo clone = null; - ErrorInfo other = errors.get(key); - if (other != null) { - clone = new ErrorInfo(); - clone.cloneData(other); - } - return clone; - } -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java deleted file mode 100644 index 34983ef..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.tosca.parser.config; - -public class ErrorInfo { - - private String code; - private String message; - private boolean failOnError; - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean getFailOnError() { - return failOnError; - } - - public void setFailOnError(boolean failOnError) { - this.failOnError = failOnError; - } - - public void cloneData(ErrorInfo other) { - this.code = other.getCode(); - this.message = other.getMessage(); - this.failOnError = other.getFailOnError(); - } - -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/JToscaValidationIssueInfo.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/JToscaValidationIssueInfo.java deleted file mode 100644 index 31ab0a0..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/config/JToscaValidationIssueInfo.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.openecomp.sdc.tosca.parser.config; - -public class JToscaValidationIssueInfo { - - private String issueType; - private String sinceCsarConformanceLevel; - - public JToscaValidationIssueInfo() {} - - public String getIssueType() { - return issueType; - } - - public void setIssueType(String issueType) { - this.issueType = issueType; - } - - public String getSinceCsarConformanceLevel() { - return sinceCsarConformanceLevel; - } - - public void setSinceCsarConformanceLevel(String sinceCsarConformanceLevel) { - this.sinceCsarConformanceLevel = sinceCsarConformanceLevel; - } - - public void cloneData(JToscaValidationIssueInfo other) { - this.issueType = other.getIssueType(); - this.sinceCsarConformanceLevel = other.getSinceCsarConformanceLevel(); - } - -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/JtoscaValidationIssueConfiguration.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/JtoscaValidationIssueConfiguration.java deleted file mode 100644 index ff13251..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/config/JtoscaValidationIssueConfiguration.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.tosca.parser.config; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class JtoscaValidationIssueConfiguration { - - private Map> validationIssues; - - public Map> getValidationIssues() { - return validationIssues; - } - - public void setValidationIssues(Map> validationIssues) { - this.validationIssues = validationIssues; - } - - public List getJtoscaValidationIssueInfo(String key) { - List clone = new ArrayList<>(); - List other = validationIssues.get(key); - if (other != null) { - for (JToscaValidationIssueInfo item: other) { - JToscaValidationIssueInfo cloneitem = new JToscaValidationIssueInfo(); - cloneitem.cloneData(item); - clone.add(cloneitem); - } - } - return clone; - } - -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java deleted file mode 100644 index ce84a9c..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.openecomp.sdc.tosca.parser.config; - -import java.util.EnumMap; -import java.util.Map; - -import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes; - -public enum SdcToscaParserErrors { - - BAD_FORMAT, CONFORMANCE_LEVEL_ERROR, FILE_NOT_FOUND, GENERAL_ERROR; - - private static final Map JTOSCA_ERRORS = - new EnumMap(JToscaErrorCodes.class) {{ - - put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR); - - put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND); - //CSAR contents problems - put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT); - put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT); - put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT); - put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT); - put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT); - put(JToscaErrorCodes.INVALID_CSAR_FORMAT, BAD_FORMAT); - }}; - - public static SdcToscaParserErrors getSdcErrorByJToscaError(JToscaErrorCodes jToscaErrorCode) { - return JTOSCA_ERRORS.get(jToscaErrorCode); - } - -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java b/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java deleted file mode 100644 index a7fd99d..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.openecomp.sdc.tosca.parser.exceptions; - -public class SdcToscaParserException extends Exception { - - private static final long serialVersionUID = 626014844866501196L; - private String code; - - public SdcToscaParserException(String string, String code) { - super(string); - this.code = code; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/FilterType.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/FilterType.java deleted file mode 100644 index 0f7810f..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/FilterType.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.openecomp.sdc.tosca.parser.impl; - -public enum FilterType { - - CONTAINS("contains"){ - @Override - public boolean isMatch(String value, String pattern) { - return value.contains(pattern); - } - }, - EQUALS("equals"){ - @Override - public boolean isMatch(String value, String pattern) { - return value.equals(pattern); - } - }; - - String filterName; - - FilterType(String name) { - this.filterName = name; - } - - public abstract boolean isMatch(String value, String pattern); - -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/JToscaValidationIssueType.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/JToscaValidationIssueType.java deleted file mode 100644 index 1e68c51..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/JToscaValidationIssueType.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.openecomp.sdc.tosca.parser.impl; - -public enum JToscaValidationIssueType { - CRITICAL, - WARNING -} 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 deleted file mode 100644 index 901b315..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java +++ /dev/null @@ -1,912 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * sdc-distribution-client - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.tosca.parser.impl; - -import java.util.*; -import java.util.Map.Entry; -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.tosca.parser.config.ConfigurationManager; -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.*; -import org.openecomp.sdc.toscaparser.api.elements.Metadata; -import org.openecomp.sdc.toscaparser.api.elements.NodeType; -import org.openecomp.sdc.toscaparser.api.functions.Function; -import org.openecomp.sdc.toscaparser.api.parameters.Input; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID; - -public class SdcCsarHelperImpl implements ISdcCsarHelper { - - private static final String PATH_DELIMITER = "#"; - private static final String CUSTOMIZATION_UUID = "customizationUUID"; - private ToscaTemplate toscaTemplate; - private ConfigurationManager configurationManager; - private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName()); - - public SdcCsarHelperImpl(ToscaTemplate toscaTemplate) { - this.toscaTemplate = toscaTemplate; - } - - public SdcCsarHelperImpl(ToscaTemplate toscaTemplate, ConfigurationManager configurationManager) { - this.toscaTemplate = toscaTemplate; - this.configurationManager = configurationManager; - } - - @Override - //Sunny flow - covered with UT, flat and nested - public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) { - if (nodeTemplate == null) { - log.error("getNodeTemplatePropertyLeafValue - nodeTemplate is null"); - return null; - } - if (GeneralUtility.isEmptyString(leafValuePath)) { - log.error("getNodeTemplatePropertyLeafValue - leafValuePath is null or empty"); - return null; - } - String[] split = getSplittedPath(leafValuePath); - LinkedHashMap properties = nodeTemplate.getProperties(); - Object property = processProperties(split, properties); - return property == null || property instanceof Function ? null : String.valueOf(property); - } - - @Override - public Object getNodeTemplatePropertyAsObject(NodeTemplate nodeTemplate, String leafValuePath) { - if (nodeTemplate == null) { - log.error("getNodeTemplatePropertyAsObject - nodeTemplate is null"); - return null; - } - if (GeneralUtility.isEmptyString(leafValuePath)) { - log.error("getNodeTemplatePropertyAsObject - leafValuePath is null or empty"); - return null; - } - String[] split = getSplittedPath(leafValuePath); - LinkedHashMap properties = nodeTemplate.getProperties(); - return processProperties(split, properties); - } - - public Map> getCpPropertiesFromVfcAsObject(NodeTemplate vfc) { - if (vfc == null) { - log.error("getCpPropertiesFromVfc - vfc is null"); - return new HashMap<>(); - } - - String presetProperty = "_ip_requirements"; - Map> cps = new HashMap<>(); - - Map props = vfc.getProperties(); - if (props != null) { - // find all port names by pre-set property (ip_requirements) - for (Map.Entry entry : props.entrySet()) { - if (entry.getKey().endsWith(presetProperty)) { - String portName = entry.getKey().replaceAll(presetProperty, ""); - cps.put(portName, new HashMap<>()); - } - } - - if (cps.size() > 0) { - // ports found - find all their properties - for (String portName : cps.keySet()) { - for (Map.Entry property: props.entrySet()) { - if (property.getKey().startsWith(portName)) { - String portProperty = property.getKey().replaceFirst(portName + "_", ""); - if (property.getValue() != null) { - cps.get(portName).put(portProperty, property.getValue().getValue()); - } - } - } - } - } - } - - return cps; - } - - public Map> getCpPropertiesFromVfc(NodeTemplate vfc) { - - if (vfc == null) { - log.error("getCpPropertiesFromVfc - vfc is null"); - return new HashMap<>(); - } - - String presetProperty = "_ip_requirements"; - Map> cps = new HashMap<>(); - - Map props = vfc.getProperties(); - if (props != null) { - // find all port names by pre-set property (ip_requirements) - for (Map.Entry entry : props.entrySet()) { - if (entry.getKey().endsWith(presetProperty)) { - String portName = entry.getKey().replaceAll(presetProperty, ""); - cps.put(portName, new HashMap<>()); - } - } - - if (cps.size() > 0) { - // ports found - find all their properties - for (String portName : cps.keySet()) { - for (Map.Entry property: props.entrySet()) { - if (property.getKey().startsWith(portName)) { - Map portPaths = new HashMap<>(); - String portProperty = property.getKey().replaceFirst(portName + "_", ""); - buildPathMappedToValue(portProperty, property.getValue().getValue(), portPaths); - - cps.get(portName).putAll(portPaths); - } - } - } - } - } - - return cps; - } - - @SuppressWarnings("unchecked") - private void buildPathMappedToValue(String path, Object property, Map pathsMap) { - if (property instanceof Map) { - for (Map.Entry item : ((Map) property).entrySet()) { - if (item.getValue() instanceof Map || item.getValue() instanceof List) { - buildPathMappedToValue(path + PATH_DELIMITER + item.getKey(), item.getValue(), pathsMap); - } else { - pathsMap.put(path + PATH_DELIMITER + item.getKey(), item.getValue()); - } - } - } else if (property instanceof List) { - for (Object item: (List)property) { - buildPathMappedToValue(path, item, pathsMap); - } - } else { - pathsMap.put(path, property); - } - - } - - @Override - //Sunny flow - covered with UT - public List getServiceVlList() { - List serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VL); - return serviceVlList; - } - - @Override - //Sunny flow - covered with UT - public List getServiceVfList() { - List serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VF); - return serviceVfList; - } - - @Override - //Sunny flow - covered with UT - public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName) { - if (GeneralUtility.isEmptyString(metadataPropertyName)) { - log.error("getMetadataPropertyValue - the metadataPropertyName is null or empty"); - return null; - } - if (metadata == null) { - log.error("getMetadataPropertyValue - the metadata is null"); - return null; - } - String metadataPropertyValue = metadata.getValue(metadataPropertyName); - return metadataPropertyValue; - } - - - @Override - //Sunny flow - covered with UT - public List getServiceNodeTemplatesByType(String nodeType) { - if (GeneralUtility.isEmptyString(nodeType)) { - log.error("getServiceNodeTemplatesByType - nodeType - is null or empty"); - return new ArrayList<>(); - } - - List res = new ArrayList<>(); - List nodeTemplates = toscaTemplate.getNodeTemplates(); - for (NodeTemplate nodeTemplate : nodeTemplates) { - if (nodeType.equals(nodeTemplate.getTypeDefinition().getType())) { - res.add(nodeTemplate); - } - } - - return res; - } - - - @Override - public List getServiceNodeTemplates() { - List nodeTemplates = toscaTemplate.getNodeTemplates(); - return nodeTemplates; - } - - @Override - //Sunny flow - covered with UT - public List getVfcListByVf(String vfCustomizationId) { - if (GeneralUtility.isEmptyString(vfCustomizationId)) { - log.error("getVfcListByVf - vfCustomizationId - is null or empty"); - return new ArrayList<>(); - } - - List serviceVfList = getServiceVfList(); - NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId); - List vfcs = getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC); - vfcs.addAll(getNodeTemplateBySdcType(vfInstance, SdcTypes.CVFC)); - - return vfcs; - } - - @Override - //Sunny flow - covered with UT - public List getVfModulesByVf(String vfCustomizationUuid) { - List serviceVfList = getServiceVfList(); - NodeTemplate nodeTemplateByCustomizationUuid = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid); - if (nodeTemplateByCustomizationUuid != null) { - /*SubstitutionMappings substitutionMappings = nodeTemplateByCustomizationUuid.getSubstitutionMappings(); - if (substitutionMappings != null){ - List groups = substitutionMappings.getGroups(); - if (groups != null){ - List collect = groups.stream().filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType())).collect(Collectors.toList()); - log.debug("getVfModulesByVf - VfModules are {}", collect); - return collect; - } - }*/ - String name = nodeTemplateByCustomizationUuid.getName(); - String normaliseComponentInstanceName = SdcToscaUtility.normaliseComponentInstanceName(name); - List serviceLevelGroups = toscaTemplate.getTopologyTemplate().getGroups(); - log.debug("getVfModulesByVf - VF node template name {}, normalized name {}. Searching groups on service level starting with VF normalized name...", name, normaliseComponentInstanceName); - if (serviceLevelGroups != null) { - List collect = serviceLevelGroups - .stream() - .filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType()) && x.getName().startsWith(normaliseComponentInstanceName)) - .collect(Collectors.toList()); - return collect; - } - } - return new ArrayList<>(); - } - - @Override - //Sunny flow - covered with UT - public String getServiceInputLeafValueOfDefault(String inputLeafValuePath) { - if (GeneralUtility.isEmptyString(inputLeafValuePath)) { - log.error("getServiceInputLeafValueOfDefault - inputLeafValuePath is null or empty"); - return null; - } - - String[] split = getSplittedPath(inputLeafValuePath); - if (split.length < 2 || !split[1].equals("default")) { - log.error("getServiceInputLeafValue - inputLeafValuePath should be of format #default[optionally #] "); - return null; - } - - List inputs = toscaTemplate.getInputs(); - if (inputs != null) { - Optional findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst(); - if (findFirst.isPresent()) { - Input input = findFirst.get(); - Object current = input.getDefault(); - Object property = iterateProcessPath(2, current, split); - return property == null || property instanceof Function? null : String.valueOf(property); - } - } - log.error("getServiceInputLeafValue - value not found"); - return null; - } - - @Override - public Object getServiceInputLeafValueOfDefaultAsObject(String inputLeafValuePath) { - if (GeneralUtility.isEmptyString(inputLeafValuePath)) { - log.error("getServiceInputLeafValueOfDefaultAsObject - inputLeafValuePath is null or empty"); - return null; - } - - String[] split = getSplittedPath(inputLeafValuePath); - if (split.length < 2 || !split[1].equals("default")) { - log.error("getServiceInputLeafValueOfDefaultAsObject - inputLeafValuePath should be of format #default[optionally #] "); - return null; - } - - List inputs = toscaTemplate.getInputs(); - if (inputs != null) { - Optional findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst(); - if (findFirst.isPresent()) { - Input input = findFirst.get(); - Object current = input.getDefault(); - return iterateProcessPath(2, current, split); - } - } - log.error("getServiceInputLeafValueOfDefaultAsObject - value not found"); - return null; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - private Object iterateProcessPath(Integer index, Object current, String[] split) { - if (current == null) { - log.error("iterateProcessPath - this input has no default"); - return null; - } - if (split.length > index) { - for (int i = index; i < split.length; i++) { - if (current instanceof Map) { - current = ((Map) current).get(split[i]); - } else if (current instanceof List) { - current = ((List) current).get(0); - i--; - } - else { - log.error("iterateProcessPath - found an unexpected leaf where expected to find a complex type"); - return null; - } - } - } - if (current != null) { - return current; - } - log.error("iterateProcessPath - Path not Found"); - return null; - } - - private String[] getSplittedPath(String inputLeafValuePath) { - return inputLeafValuePath.split(PATH_DELIMITER); - } - - - @Override - //Sunny flow - covered with UT - public String getServiceSubstitutionMappingsTypeName() { - SubstitutionMappings substitutionMappings = toscaTemplate.getTopologyTemplate().getSubstitutionMappings(); - if (substitutionMappings == null) { - log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings defined"); - return null; - } - - NodeType nodeType = substitutionMappings.getNodeDefinition(); - if (nodeType == null) { - log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings node defined"); - return null; - } - - return nodeType.getType(); - } - - @Override - //Sunny flow - covered with UT - public Metadata getServiceMetadata() { - return toscaTemplate.getMetaData(); - } - - @Override - //Sunny flow - covered with UT - public Map getServiceMetadataProperties() { - if (toscaTemplate.getMetaData() == null){ - return null; - } - return new HashMap<>(toscaTemplate.getMetaData().getAllProperties()); - } - - @Override - public Map getServiceMetadataAllProperties() { - if (toscaTemplate.getMetaData() == null){ - return null; - } - return toscaTemplate.getMetaData().getAllProperties(); - } - - @Override - //Sunny flow - covered with UT - public List getServiceInputs() { - return toscaTemplate.getInputs(); - } - - @Override - //Sunny flow - covered with UT - public String getGroupPropertyLeafValue(Group group, String leafValuePath) { - if (group == null) { - log.error("getGroupPropertyLeafValue - group is null"); - return null; - } - - if (GeneralUtility.isEmptyString(leafValuePath)) { - log.error("getGroupPropertyLeafValue - leafValuePath is null or empty"); - return null; - } - - String[] split = getSplittedPath(leafValuePath); - LinkedHashMap properties = group.getProperties(); - Object property = processProperties(split, properties); - return property == null || property instanceof Function? null : String.valueOf(property); - } - - @Override - public Object getGroupPropertyAsObject(Group group, String leafValuePath) { - if (group == null) { - log.error("getGroupPropertyAsObject - group is null"); - return null; - } - - if (GeneralUtility.isEmptyString(leafValuePath)) { - log.error("getGroupPropertyAsObject - leafValuePath is null or empty"); - return null; - } - - String[] split = getSplittedPath(leafValuePath); - LinkedHashMap properties = group.getProperties(); - return processProperties(split, properties); - } - - @Override - //Sunny flow - covered with UT - public List getCpListByVf(String vfCustomizationId) { - List cpList = new ArrayList<>(); - if (GeneralUtility.isEmptyString(vfCustomizationId)) { - log.error("getCpListByVf vfCustomizationId string is empty"); - return cpList; - } - - List serviceVfList = getServiceVfList(); - if (serviceVfList == null || serviceVfList.size() == 0) { - log.error("getCpListByVf Vfs not exist for vfCustomizationId {}", vfCustomizationId); - return cpList; - } - NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId); - if (vfInstance == null) { - log.debug("getCpListByVf vf list is null"); - return cpList; - } - cpList = getNodeTemplateBySdcType(vfInstance, SdcTypes.CP); - if (cpList == null || cpList.size() == 0) - log.debug("getCpListByVf cps not exist for vfCustomizationId {}", vfCustomizationId); - return cpList; - } - - @Override - //Sunny flow - covered with UT - public List getMembersOfVfModule(NodeTemplate vf, Group serviceLevelVfModule) { - if (vf == null) { - log.error("getMembersOfVfModule - vf is null"); - return new ArrayList<>(); - } - - if (serviceLevelVfModule == null || serviceLevelVfModule.getMetadata() == null || serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID) == null) { - log.error("getMembersOfVfModule - vfModule or its metadata is null. Cannot match a VF group based on invariantUuid from missing metadata."); - return new ArrayList<>(); - } - - - SubstitutionMappings substitutionMappings = vf.getSubMappingToscaTemplate(); - if (substitutionMappings != null) { - List groups = substitutionMappings.getGroups(); - if (groups != null) { - Optional findFirst = groups - .stream() - .filter(x -> (x.getMetadata() != null && serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID).equals(x.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)))).findFirst(); - if (findFirst.isPresent()) { - List members = findFirst.get().getMembers(); - if (members != null) { - List collect = substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(Collectors.toList()); - return collect; - } - } - } - } - return new ArrayList<>(); - } - - @Override - //Sunny flow - covered with UT - @SuppressWarnings("unchecked") - public List> getNodeTemplatePairsByReqName( - List listOfReqNodeTemplates, List listOfCapNodeTemplates, String reqName) { - - 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<>(); - - 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; - } - - @Override - //Sunny flow - covered with UT - //TODO constant strings - public List getAllottedResources() { - List nodeTemplates = null; - nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates(); - if (nodeTemplates.isEmpty()) { - log.error("getAllottedResources nodeTemplates not exist"); - } - nodeTemplates = nodeTemplates.stream().filter( - x -> x.getMetaData() != null && x.getMetaData().getValue("category").equals("Allotted Resource")) - .collect(Collectors.toList()); - if (nodeTemplates.isEmpty()) { - log.debug("getAllottedResources - allotted resources not exist"); - } else { - } - - return nodeTemplates; - } - - @Override - //Sunny flow - covered with UT - public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate) { - if (nodeTemplate == null) { - - log.error("getTypeOfNodeTemplate nodeTemplate is null"); - return null; - } - return nodeTemplate.getTypeDefinition().getType(); - } - - /** - * This methdd is returning the csarConformanceLevel for input CSAR - * When csarConformanceLevel is configured with failOnError as False in Error Configuration; it - * assigns the default value to csarConformanceLevel which is the max level provided in - * Configuration file - * @return csarConformanceLevel - */ - @Override - public String getConformanceLevel() { - LinkedHashMap csarMeta = toscaTemplate.getMetaProperties("csar.meta"); - if (csarMeta == null){ - log.warn("No csar.meta file is found in CSAR - this file should hold the conformance level of the CSAR. This might be OK for older CSARs."); - if (configurationManager != null && !configurationManager.getErrorConfiguration() - .getErrorInfo("CONFORMANCE_LEVEL_ERROR").getFailOnError()){ - String csarConLevel = configurationManager.getConfiguration().getConformanceLevel().getMaxVersion(); - log.warn("csarConformanceLevel is not found in input csar; defaulting to max version {}" , csarConLevel); - return csarConLevel; - } - else { - log.warn("csarConformanceLevel is not found in input csar; returning null as no defaults defined in error configuration"); - return null; - } - } - - Object conformanceLevel = csarMeta.get("SDC-TOSCA-Definitions-Version"); - if (conformanceLevel != null){ - String confLevelStr = conformanceLevel.toString(); - log.debug("CSAR conformance level is {}", confLevelStr); - return confLevelStr; - } else { - log.error("Invalid csar.meta file - no entry found for SDC-TOSCA-Definitions-Version key. This entry should hold the conformance level."); - return null; - } - } - - - @Override - public String getNodeTemplateCustomizationUuid(NodeTemplate nt) { - String res = null; - if (nt != null && nt.getMetaData() != null){ - res = nt.getMetaData().getValue(CUSTOMIZATION_UUID); - } else { - log.error("Node template or its metadata is null"); - } - return res; - } - - public List getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType) { - return getNodeTemplateBySdcType(parentNodeTemplate, sdcType, false); - } - - private List getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType, boolean isVNF) { - - if (parentNodeTemplate == null) { - log.error("getNodeTemplateBySdcType - nodeTemplate is null or empty"); - return new ArrayList<>(); - } - - if (sdcType == null) { - log.error("getNodeTemplateBySdcType - sdcType is null or empty"); - return new ArrayList<>(); - } - - SubstitutionMappings substitutionMappings = parentNodeTemplate.getSubMappingToscaTemplate(); - - if (substitutionMappings != null) { - List nodeTemplates = substitutionMappings.getNodeTemplates(); - if (nodeTemplates != null && nodeTemplates.size() > 0) { - if (sdcType.equals(SdcTypes.VFC) && isVNF) { - return nodeTemplates.stream() - .filter(x -> (x.getMetaData() != null && - sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && isVNFType(x)) - .collect(Collectors.toList()); - } - else { - return nodeTemplates.stream() - .filter(x -> (x.getMetaData() != null && - sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && !isVNFType(x)) - .collect(Collectors.toList()); - } - } - else { - log.debug("getNodeTemplateBySdcType - SubstitutionMappings' node Templates not exist"); - } - } else - log.debug("getNodeTemplateBySdcType - SubstitutionMappings not exist"); - - return new ArrayList<>(); - } - - public Map filterNodeTemplatePropertiesByValue(NodeTemplate nodeTemplate, FilterType filterType, String pattern) { - Map filterMap = new HashMap<>(); - - if (nodeTemplate == null) { - log.error("filterNodeTemplatePropertiesByValue nodeTemplate is null"); - return filterMap; - } - - if (filterType == null) { - log.error("filterNodeTemplatePropertiesByValue filterType is null"); - return filterMap; - } - - if (GeneralUtility.isEmptyString(pattern)) { - log.error("filterNodeTemplatePropertiesByValue pattern string is empty"); - return filterMap; - } - - Map ntProperties = nodeTemplate.getProperties(); - - if (ntProperties != null && ntProperties.size() > 0) { - - for (Property current : ntProperties.values()) { - filterProperties(current.getValue(), current.getName(), filterType, pattern, filterMap); - } - } - - log.trace("filterNodeTemplatePropertiesByValue - filterMap value: {}", filterMap); - - return filterMap; - } - - public NodeTemplate getVnfConfig(String vfCustomizationUuid) { - - if (GeneralUtility.isEmptyString(vfCustomizationUuid)) { - log.error("getVnfConfig - vfCustomizationId - is null or empty"); - return null; - } - - List serviceVfList = getServiceVfList(); - NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid); - NodeTemplate vnfConfig = getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC, true).stream().findAny().orElse(null); - return vnfConfig; - } - - @Override - public boolean hasTopology(NodeTemplate nodeTemplate) { - if (nodeTemplate == null) { - log.error("hasTopology - nodeTemplate - is null"); - return false; - } - - if (nodeTemplate.getMetaData() != null) { - String type = nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE); - log.debug("hasTopology - node template {} is a {} type", nodeTemplate.getName(), type); - return SdcTypes.isComplex(type); - } - - return false; - } - - @Override - public List getNodeTemplateChildren(NodeTemplate nodeTemplate) { - if (nodeTemplate == null) { - log.error("getNodeTemplateChildren - nodeTemplate - is null"); - return new ArrayList<>(); - } - - SubstitutionMappings substitutionMappings = nodeTemplate.getSubMappingToscaTemplate(); - if (substitutionMappings != null) { - List nodeTemplates = substitutionMappings.getNodeTemplates(); - if (nodeTemplates != null && nodeTemplates.size() > 0) { - - return nodeTemplates.stream() - .filter(x -> !isVNFType(x)) - .collect(Collectors.toList()); - } - else { - log.debug("getNodeTemplateChildren - SubstitutionMappings' node Templates not exist"); - } - } else - log.debug("getNodeTemplateChildren - SubstitutionMappings not exist"); - - 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"); - } - - @SuppressWarnings("unchecked") - private Map filterProperties(Object property, String path, FilterType filterType, String pattern, Map filterMap) { - - if (property instanceof Map) { - for (Map.Entry item: ((Map) property).entrySet()) { - String itemPath = path + PATH_DELIMITER + item.getKey(); - filterProperties(item.getValue(), itemPath, filterType, pattern, filterMap); - } - } else if (property instanceof List) { - for (Object item: (List)property) { - filterProperties(item, path, filterType, pattern, filterMap); - } - } else { - if (filterType.isMatch(property.toString(), pattern)) { - filterMap.put(path, property.toString()); - } - } - - return filterMap; - } - - public List getServiceNodeTemplateBySdcType(SdcTypes sdcType) { - if (sdcType == null) { - log.error("getServiceNodeTemplateBySdcType - sdcType is null or empty"); - return new ArrayList<>(); - } - - TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate(); - return getNodeTemplateBySdcType(topologyTemplate, sdcType); - } - - - /************************************* helper functions ***********************************/ - private List getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, SdcTypes sdcType) { - if (sdcType == null) { - log.error("getNodeTemplateBySdcType - sdcType is null or empty"); - return new ArrayList<>(); - } - - if (topologyTemplate == null) { - log.error("getNodeTemplateBySdcType - topologyTemplate is null"); - return new ArrayList<>(); - } - - List nodeTemplates = topologyTemplate.getNodeTemplates(); - - if (nodeTemplates != null && nodeTemplates.size() > 0) - return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList()); - - log.debug("getNodeTemplateBySdcType - topologyTemplate's nodeTemplates not exist"); - return new ArrayList<>(); - } - - //Assumed to be unique property for the list - private NodeTemplate getNodeTemplateByCustomizationUuid(List nodeTemplates, String customizationId) { - if (customizationId != null) { - Optional findFirst = nodeTemplates.stream().filter(x -> (x.getMetaData() != null && customizationId.equals(x.getMetaData().getValue(PROPERTY_NAME_CUSTOMIZATIONUUID)))).findFirst(); - return findFirst.isPresent() ? findFirst.get() : null; - } - else { - log.error("getNodeTemplateByCustomizationUuid - customizationId is null"); - return null; - } - } - - private Object processProperties(String[] split, LinkedHashMap properties) { - Optional> findFirst = properties.entrySet().stream().filter(x -> x.getKey().equals(split[0])).findFirst(); - if (findFirst.isPresent()) { - Property property = findFirst.get().getValue(); - Object current = property.getValue(); - return iterateProcessPath(1, current, split); - } - String propName = (split != null && split.length > 0 ? split[0] : null); - log.error("processProperties - property {} not found", propName); - return null; - } - - - - - -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcPropertyNames.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcPropertyNames.java deleted file mode 100644 index 7d34c6f..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcPropertyNames.java +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * sdc-distribution-client - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.tosca.parser.impl; - -public class SdcPropertyNames { - public static String PROPERTY_NAME_INVARIANTUUID = "invariantUUID"; - public static String PROPERTY_NAME_UUID = "UUID"; - public static String PROPERTY_NAME_CUSTOMIZATIONUUID = "customizationUUID"; - public static String PROPERTY_NAME_VERSION = "version"; - - //Groups metadata - public static String PROPERTY_NAME_VFMODULEMODELINVARIANTUUID = "vfModuleModelInvariantUUID"; - public static String PROPERTY_NAME_VFMODULEMODELUUID = "vfModuleModelUUID"; - public static String PROPERTY_NAME_VFMODULECUSTOMIZATIONUUID = "vfModuleCustomizationUUID"; - public static String PROPERTY_NAME_VFMODULEMODELVERSION = "vfModuleModelVersion"; - public static String PROPERTY_NAME_VFMODULEMODELNAME = "vfModuleModelName"; - - //Groups properties - public static String PROPERTY_NAME_VFMODULETYPE = "vf_module_type"; - public static String PROPERTY_NAME_VFMODULELABEL = "vf_module_label"; - public static String PROPERTY_NAME_MINVFMODULEINSTANCES = "min_vf_module_instances"; - public static String PROPERTY_NAME_MAXVFMODULEINSTANCES = "max_vf_module_instances"; - public static String PROPERTY_NAME_INITIALCOUNT = "initial_count"; - - - public static String PROPERTY_NAME_DESCRIPTION = "description"; - public static String PROPERTY_NAME_TYPE = "type"; - public static String PROPERTY_NAME_CATEGORY = "category"; - public static String PROPERTY_NAME_SUBCATEGORY = "subcategory"; - public static String PROPERTY_NAME_RESOURCEVENDOR = "resourceVendor"; - public static String PROPERTY_NAME_RESOURCEVENDORRELEASE = "resourceVendorRelease"; - //VFC - public static String PROPERTY_NAME_NFCCODE = "nfc_code"; - public static String PROPERTY_NAME_VMTYPETAG = "vm_type_tag"; - public static String PROPERTY_NAME_VMTYPE = "vm_type"; - public static String PROPERTY_NAME_VFCNAMING_ECOMPGENERATEDNAMING="vfc_naming#ecomp_generated_naming"; - public static String PROPERTY_NAME_VFCNAMING_NAMINGPOLICY="vfc_naming#naming_policy"; - //VF - public static String PROPERTY_NAME_NFTYPE = "nf_type"; - public static String PROPERTY_NAME_NFROLE = "nf_role"; - public static String PROPERTY_NAME_NFFUNCTION = "nf_function"; - public static String PROPERTY_NAME_NFCODE = "nf_code"; - public static String PROPERTY_NAME_MININSTANCES = "min_instances"; - public static String PROPERTY_NAME_MAXINSTANCES = "max_instances"; - public static String PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT = "availability_zone_max_count"; - public static String PROPERTY_NAME_AVAILABILITYZONECOUNT = "availability_zone_count"; - public static String PROPERTY_NAME_NAME = "name"; - public static String PROPERTY_NAME_VNFECOMPNAMING_ECOMPGENERATEDNAMING="vnf_ecomp_naming#ecomp_generated_naming"; - public static String PROPERTY_NAME_VNFECOMPNAMING_NAMINGPOLICY="vnf_ecomp_naming#naming_policy"; - public static String PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS = "ecomp_generated_vm_assignments"; - //Service - public static String PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING="service_naming#default#ecomp_generated_naming"; - public static String PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY="service_naming#default#naming_policy"; - //VL - public static String PROPERTY_NAME_NETWORKTYPE="network_type"; - public static String PROPERTY_NAME_NETWORKROLE="network_role"; - public static String PROPERTY_NAME_NETWORKROLETAG="network_role_tag"; - public static String PROPERTY_NAME_NETWORKTECHNOLOGY="network_technology"; - public static String PROPERTY_NAME_NETWORKSCOPE="network_scope"; - public static String PROPERTY_NAME_NETWORKECOMPNAMING_ECOMPGENERATEDNAMING="network_ecomp_naming#ecomp_generated_naming"; - public static String PROPERTY_NAME_NETWORKECOMPNAMING_NAMINGPOLICY="network_ecomp_naming#naming_policy"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_ISSHAREDNETWORK="network_assignments#is_shared_network"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_ISEXTERNALNETWORK="network_assignments#is_external_network"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_ECOMPGENERATEDNETWORKASSIGNMENT="network_assignments#ecomp_generated_network_assignment"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_USEIPV4="network_assignments#ipv4_subnet_default_assignments#use_ipv4"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPNETWORKADDRESSPLAN="network_assignments#ipv4_subnet_default_assignments#ip_network_address_plan"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_DHCPENABLED="network_assignments#ipv4_subnet_default_assignments#dhcp_enabled"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPVERSION="network_assignments#ipv4_subnet_default_assignments#ip_version"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_CIDRMASK="network_assignments#ipv4_subnet_default_assignments#cidr_mask"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT="network_assignments#ipv4_subnet_default_assignments#min_subnets_count"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_USEIPV6="network_assignments#ipv6_subnet_default_assignments#use_ipv6"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPNETWORKADDRESSPLAN="network_assignments#ipv6_subnet_default_assignments#ip_network_address_plan"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_DHCPENABLED="network_assignments#ipv6_subnet_default_assignments#dhcp_enabled"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPVERSION="network_assignments#ipv6_subnet_default_assignments#ip_version"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_CIDRMASK="network_assignments#ipv6_subnet_default_assignments#cidr_mask"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT="network_assignments#ipv6_subnet_default_assignments#min_subnets_count"; - - /*public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_ISPROVIDERNETWORK="network_assignments#provider_network#is_provider_network"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_PHYSICALNETWORKNAME="network_assignments#provider_network#physical_network_name"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_NUMA="network_assignments#provider_network#numa"; - public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_PNICINSTANCE="network_assignments#provider_network#pnic_instance"; - */ - - public static String PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK="provider_network#is_provider_network"; - public static String PROPERTY_NAME_PROVIDERNETWORK_PHYSICALNETWORKNAME="provider_network#physical_network_name"; - public static String PROPERTY_NAME_PROVIDERNETWORK_NUMA="provider_network#numa"; - public static String PROPERTY_NAME_PROVIDERNETWORK_PNICINSTANCE="provider_network#pnic_instance"; - - public static String PROPERTY_NAME_NETWORKFLOWS_ISBOUNDTOVPN="network_flows#is_bound_to_vpn"; - public static String PROPERTY_NAME_NETWORKFLOWS_VPNBINDING="network_flows#vpn_binding"; -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java deleted file mode 100644 index 9fc59f2..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java +++ /dev/null @@ -1,199 +0,0 @@ -package org.openecomp.sdc.tosca.parser.impl; - -import java.util.ArrayList; -import java.util.List; - -import org.openecomp.sdc.tosca.parser.api.ConformanceLevel; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.config.*; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.tosca.parser.utils.GeneralUtility; -import org.openecomp.sdc.toscaparser.api.ToscaTemplate; -import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue; -import org.openecomp.sdc.toscaparser.api.common.JToscaException; -import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes; -import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdcToscaParserFactory { - private static Logger log = LoggerFactory.getLogger(SdcToscaParserFactory.class.getName()); - - private static ConfigurationManager configurationManager; - private static volatile SdcToscaParserFactory instance; - private List criticalExceptions = new ArrayList<>(); - private List warningExceptions = new ArrayList<>(); - private List notAnalyzadExceptions = new ArrayList<>(); - private SdcToscaParserFactory() {} - - /** - * Get an SdcToscaParserFactory instance. - * @return SdcToscaParserFactory instance. - */ - public static SdcToscaParserFactory getInstance() { - if (instance == null) { - synchronized (SdcToscaParserFactory.class) { - if (instance == null) { - instance = new SdcToscaParserFactory(); - configurationManager = ConfigurationManager.getInstance(); - } - } - } - return instance; - } - - public static void setConfigurationManager(ConfigurationManager configurationManager) { - SdcToscaParserFactory.configurationManager = configurationManager; - } - - /** - * Get an ISdcCsarHelper object for this CSAR file. - * - * @param csarPath - the absolute path to CSAR file. - * @return ISdcCsarHelper object. - * @throws SdcToscaParserException - in case the path or CSAR are invalid. - */ - public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws SdcToscaParserException { - return init(csarPath, true); - } - - /** - * Get an ISdcCsarHelper object for this CSAR file. - * - * @param csarPath - the absolute path to CSAR file. - * @param resolveGetInput - resolve get_input properties - * @return ISdcCsarHelper object. - * @throws SdcToscaParserException - in case the path or CSAR are invalid. - */ - public ISdcCsarHelper getSdcCsarHelper(String csarPath, boolean resolveGetInput) throws SdcToscaParserException { - return init(csarPath, resolveGetInput); - } - - private ISdcCsarHelper init(String csarPath, boolean resolveGetInput) throws SdcToscaParserException { - synchronized (SdcToscaParserFactory.class) { - ToscaTemplate tosca = null; - try { - tosca = new ToscaTemplate(csarPath, null, true, null, resolveGetInput); - } catch (JToscaException e) { - throwSdcToscaParserException(e); - } - SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(tosca, configurationManager); - String cSarConformanceLevel = sdcCsarHelperImpl.getConformanceLevel(); - validateCsarVersion(cSarConformanceLevel); - try { - handleErrorsByTypes(csarPath, cSarConformanceLevel); - } catch (JToscaException e) { - throwSdcToscaParserException(e); - } - return sdcCsarHelperImpl; - } - } - - private void handleErrorsByTypes(String csarPath, String cSarConformanceLevel) throws JToscaException { - clearValidationIssuesLists(); - for(JToscaValidationIssue toscaValidationIssue : ThreadLocalsHolder.getCollector().getValidationIssues().values()){ - List issueInfos = configurationManager.getJtoscaValidationIssueConfiguration().getValidationIssues().get(toscaValidationIssue.getCode()); - if(issueInfos != null && !issueInfos.isEmpty()){ - JToscaValidationIssueInfo issueInfo = null; - issueInfo = issueInfos.stream() - .filter(i-> isMatchConformanceLevel(cSarConformanceLevel,i.getSinceCsarConformanceLevel())) - .max((i1,i2) -> GeneralUtility.conformanceLevelCompare(i1.getSinceCsarConformanceLevel(), i2.getSinceCsarConformanceLevel()) ) - .orElse(null); - - if(issueInfo != null){ - switch (JToscaValidationIssueType.valueOf(issueInfo.getIssueType())) { - case CRITICAL: - criticalExceptions.add(toscaValidationIssue); - break; - case WARNING: - warningExceptions.add(toscaValidationIssue); - break; - default: - break; - } - }else{ - notAnalyzadExceptions.add(toscaValidationIssue); - } - }else{//notAnalyzed - notAnalyzadExceptions.add(toscaValidationIssue); - } - } - logErrors(csarPath); - } - - private void clearValidationIssuesLists(){ - notAnalyzadExceptions.clear(); - criticalExceptions.clear(); - warningExceptions.clear(); - } - - private void logErrors(String inputPath) throws JToscaException{ - //Warnings - int warningsCount = warningExceptions.size(); - if (warningsCount > 0) { - log.warn("####################################################################################################"); - log.warn("CSAR Warnings found! CSAR name - {}", inputPath); - log.warn("ToscaTemplate - verifyTemplate - {} Parsing Warning{} occurred...", warningsCount, (warningsCount > 1 ? "s" : "")); - for (JToscaValidationIssue info : warningExceptions) { - log.warn("JTosca Exception [{}]: {}. CSAR name - {}", info.getCode(),info.getMessage(), inputPath); - } - log.warn("####################################################################################################"); - } - //Criticals - int criticalsCount = criticalExceptions.size(); - if (criticalsCount > 0) { - log.error("####################################################################################################"); - log.error("ToscaTemplate - verifyTemplate - {} Parsing Critical{} occurred...", criticalsCount, (criticalsCount > 1 ? "s" : "")); - for (JToscaValidationIssue info : criticalExceptions) { - log.error("JTosca Exception [{}]: {}. CSAR name - {}", info.getCode(),info.getMessage(), inputPath); - } - throw new JToscaException(String.format("CSAR Validation Failed. CSAR name - {}. Please check logs for details.", inputPath), JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR.getValue()); - } - } - public List getCriticalExceptions() { - return criticalExceptions; - } - - public List getWarningExceptions() { - return warningExceptions; - } - - public List getNotAnalyzadExceptions() { - return notAnalyzadExceptions; - } - - - private void validateCsarVersion(String cSarVersion) throws SdcToscaParserException { - ConformanceLevel level = configurationManager.getConfiguration().getConformanceLevel(); - String minVersion = level.getMinVersion(); - String maxVersion = level.getMaxVersion(); - if (cSarVersion != null) { - if ((GeneralUtility.conformanceLevelCompare(cSarVersion, minVersion) < 0) || (GeneralUtility.conformanceLevelCompare(cSarVersion, maxVersion) > 0)) { - throwConformanceLevelException(minVersion, maxVersion); - } - } else { - throwConformanceLevelException(minVersion, maxVersion); - } - } - - private boolean isMatchConformanceLevel(String ValidationIssueVersion, String cSarVersion){ - if (ValidationIssueVersion != null && cSarVersion != null) { - if ((GeneralUtility.conformanceLevelCompare(ValidationIssueVersion, cSarVersion) >= 0)) { - return true; - } - } - return false; - } - private void throwConformanceLevelException(String minVersion, String maxVersion) throws SdcToscaParserException { - ErrorInfo errorInfo = configurationManager.getErrorConfiguration().getErrorInfo(SdcToscaParserErrors.CONFORMANCE_LEVEL_ERROR.toString()); - throw new SdcToscaParserException(String.format(errorInfo.getMessage(), minVersion, maxVersion), errorInfo.getCode()); - } - - private void throwSdcToscaParserException(JToscaException e) throws SdcToscaParserException { - ErrorInfo errorInfo = configurationManager.getErrorConfiguration().getErrorInfo(SdcToscaParserErrors.getSdcErrorByJToscaError(JToscaErrorCodes.getByCode(e.getCode())).toString()); - throw new SdcToscaParserException(errorInfo.getMessage(), errorInfo.getCode()); - } - - - -} \ No newline at end of file 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 deleted file mode 100644 index aeb4ee0..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * sdc-distribution-client - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.tosca.parser.impl; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public enum SdcTypes { - - CP("CP"), VL("VL"), VF("VF"), CR("CR"), VFC("VFC"), PNF("PNF"), SERVICE("Service"), CVFC("CVFC"), SERVICE_PROXY("Service Proxy"), CONFIGURATION("Configuration"); - - private String value; - - private static List complexTypes = Arrays.asList(VF, PNF, CR, SERVICE, CVFC).stream().map(SdcTypes::getValue).collect(Collectors.toList()); - - private SdcTypes(String value) { - this.value = value; - } - - public String getValue() { - return value; - } - - public static boolean isComplex(String sdcType) { - return complexTypes.contains(sdcType); - } -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java b/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java deleted file mode 100644 index 84150f6..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.openecomp.sdc.tosca.parser.utils; - -import java.util.Arrays; - -public class GeneralUtility { - - public static boolean isEmptyString(String str) { - return str == null || str.trim().isEmpty(); - } - - - /** - * Compares two version strings. - *

- * Use this instead of String.compareTo() for a non-lexicographical - * comparison that works for version strings. e.g. "1.10".compareTo("1.6"). - * - * @param str1 a string of ordinal numbers separated by decimal points. - * @param str2 a string of ordinal numbers separated by decimal points. - * @return The result is a negative integer if str1 is _numerically_ less than str2. - * The result is a positive integer if str1 is _numerically_ greater than str2. - * The result is zero if the strings are _numerically_ equal. - * It does not work if "1.10" is supposed to be equal to "1.10.0". - */ - public static int conformanceLevelCompare(String str1, String str2) { - String[] vals1 = str1.split("\\."); - String[] vals2 = str2.split("\\."); - int i = 0; - // set index to first non-equal ordinal or length of shortest version string - while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) { - i++; - } - // compare first non-equal ordinal number - if (i < vals1.length && i < vals2.length) { - int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i])); - return Integer.signum(diff); - } - //in case of 0 after the . e.g: "3" = "3.0" or "3.0.0.0" = "3.0" - str2 = str2.substring(i).replace(".", ""); - str1 = str1.substring(i).replace(".", ""); - if ((!(str1.equals(""))) && Integer.valueOf(str1) == 0){ - vals1 = Arrays.copyOf(vals1, i); - } - if ((!(str2.equals(""))) && Integer.valueOf(str2) == 0){ - vals2 = Arrays.copyOf(vals2, i); - } - - // the strings are equal or one string is a substring of the other - // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4" - return Integer.signum(vals1.length - vals2.length); - } - -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/utils/SdcToscaUtility.java b/src/main/java/org/openecomp/sdc/tosca/parser/utils/SdcToscaUtility.java deleted file mode 100644 index 77f7d55..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/utils/SdcToscaUtility.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.openecomp.sdc.tosca.parser.utils; - -import java.util.regex.Pattern; - -public class SdcToscaUtility { - - public final static Pattern COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+"); - - public static String normaliseComponentInstanceName(String name) { - String normalizedName = name.toLowerCase(); - normalizedName = COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" "); - String[] split = normalizedName.split(" "); - StringBuffer sb = new StringBuffer(); - for (String splitElement : split) { - sb.append(splitElement); - } - return sb.toString(); - } -} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/utils/YamlToObjectConverter.java b/src/main/java/org/openecomp/sdc/tosca/parser/utils/YamlToObjectConverter.java deleted file mode 100644 index 926b155..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/utils/YamlToObjectConverter.java +++ /dev/null @@ -1,126 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * sdc-distribution-client - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.tosca.parser.utils; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yaml.snakeyaml.Yaml; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashMap; - -public class YamlToObjectConverter { - - private static Logger log = LoggerFactory - .getLogger(YamlToObjectConverter.class.getName()); - - private static HashMap yamls = new HashMap(); - - private static Yaml defaultYaml = new Yaml(); - - private static Yaml getYamlByClassName(Class className) { - - Yaml yaml = yamls.get(className.getName()); - if (yaml == null) { - yaml = defaultYaml; - } - - return yaml; - } - - public T convert(String dirPath, Class className, - String configFileName) { - - T config = null; - - try { - - String fullFileName = dirPath + File.separator + configFileName; - - config = convert(fullFileName, className); - - } catch (Exception e) { - log.error("Failed to convert yaml file " + configFileName - + " to object.", e); - } - - return config; - } - - public T convert(String fullFileName, Class className) { - - T config = null; - - Yaml yaml = getYamlByClassName(className); - - InputStream in = null; - try { - - File f = new File(fullFileName); - if (false == f.exists()) { - log.warn("The file " + fullFileName - + " cannot be found. Ignore reading configuration."); - return null; - } - in = Files.newInputStream(Paths.get(fullFileName)); - - config = yaml.loadAs(in, className); - - // System.out.println(config.toString()); - } catch (Exception e) { - log.error("Failed to convert yaml file " + fullFileName - + " to object.", e); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - return config; - } - - public T convertFromString(String yamlContents, Class className) { - - T config = null; - Yaml yaml = new Yaml(); - try { - Object data = yaml.load(yamlContents); - // convert it manually with jackson instead of using snakeyaml auto converter, - // because of problematic complex objects like JtoscaValidationIssueConfiguration - ObjectMapper mapper = new ObjectMapper(); - config = mapper.convertValue(data, className); - } catch (Exception e){ - log.error("Failed to convert YAML {} to object." , yamlContents, e); - } - - return config; - } -} diff --git a/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java b/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java new file mode 100644 index 0000000..39f5190 --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java @@ -0,0 +1,149 @@ +package org.onap.sdc.impl; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.onap.sdc.toscaparser.api.common.JToscaException; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; + +public abstract class SdcToscaParserBasicTest { + + public static final String VF_CUSTOMIZATION_UUID = "56179cd8-de4a-4c38-919b-bbc4452d2d73"; + static SdcToscaParserFactory factory; + static ISdcCsarHelper rainyCsarHelperSingleVf; + static ISdcCsarHelper rainyCsarHelperMultiVfs; + static ISdcCsarHelper fdntCsarHelper; + static ISdcCsarHelper fdntCsarHelperWithInputs; + static ISdcCsarHelper nfodCsarHlper; + static ISdcCsarHelper ipAssignCsarHelper; + static ISdcCsarHelper nestedVfcCsarHlper; + static ISdcCsarHelper nfodNEWCsarHlper; + static ISdcCsarHelper QAServiceForToscaParserTests; + static ISdcCsarHelper resolveGetInputCsar; + static ISdcCsarHelper resolveGetInputCsarFalse; + static ISdcCsarHelper resolveGetInputCsarQA; + static ISdcCsarHelper resolveReqsCapsCsarQA; + static ISdcCsarHelper portMirroring; + static ISdcCsarHelper csarHelperServiceWithCrs; + + + static Map>> fdntCsarHelper_Data; + + @BeforeSuite + public static void init() throws SdcToscaParserException, JToscaException, IOException { + + factory = SdcToscaParserFactory.getInstance(); + fdntCsarHelper = getCsarHelper("csars/service-sunny-flow.csar", false); + rainyCsarHelperMultiVfs = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar", false); + rainyCsarHelperSingleVf = getCsarHelper("csars/service-ServiceFdnt-csar.csar", false); + fdntCsarHelperWithInputs = getCsarHelper("csars/service-ServiceFdnt-with-get-input.csar", false); + nfodCsarHlper = getCsarHelper("csars/service-NfodService-csar.csar", false); + ipAssignCsarHelper = getCsarHelper("csars/service-Ipassignservice-csar.csar", false); + nestedVfcCsarHlper = getCsarHelper("csars/service-nested-vfc-csar.csar", false); + nfodNEWCsarHlper = getCsarHelper("csars/service-Nfod2images-csar.csar", false); + resolveGetInputCsar = getCsarHelper("csars/service-resolve-get-input-csar.csar"); + resolveGetInputCsarFalse = getCsarHelper("csars/service-resolve-get-input-csar.csar",false); + resolveGetInputCsarQA = getCsarHelper("csars/service-resolve-get-input-csar_QA.csar"); + QAServiceForToscaParserTests = getCsarHelper("csars/service-ServiceForToscaParserTests-csar.csar"); + resolveReqsCapsCsarQA = getCsarHelper("csars/service-sunny-flow2.csar"); + portMirroring = getCsarHelper("csars/service-PortMirroring.csar"); + csarHelperServiceWithCrs = getCsarHelper("csars/service-CrTestService-csar.csar"); + + fdntCsarHelper_Data = new HashMap>>(){ + { + HashMap> FDNT ; + + FDNT = new HashMap>(); + FDNT.put("VF Name", Arrays.asList("FDNT 1")); + FDNT.put("capabilities", Arrays.asList( + "dnt_fw_rhrg.binding_DNT_FW_INT_DNS_TRUSTED_RVMI", + "dnt_fw_rhrg.host_DNT_FW_SERVER", + "dnt_fw_rhrg.binding_DNT_FW_CORE_DIRECT_RVMI", + "dnt_fw_rhrg.scalable_DNT_FW_SERVER", + "dnt_fw_rhrg.endpoint_DNT_FW_SERVER", + "dnt_fw_rhrg.binding_DNT_FW_INTERNET_DNS_DIRECT_RVMI", + "dnt_fw_rhrg.os_DNT_FW_SERVER", + "dnt_fw_rhrg.feature", + "dnt_fw_rhrg.binding_DNT_FW_OAM_PROTECTED_RVMI", + "dnt_fw_rhrg.binding_DNT_FW_SERVER", + "dnt_fw_rhrg.binding_DNT_FW_NIMBUS_HSL_RVMI", + "dnt_fw_rsg_si_1.feature")); + FDNT.put("requirements", Arrays.asList( + "DNT_FW_RSG_SI_1.dependency", + "DNT_FW_RHRG.dependency", + "DNT_FW_RHRG.link_DNT_FW_INTERNET_DNS_DIRECT_RVMI", + "DNT_FW_RHRG.link_DNT_FW_CORE_DIRECT_RVMI", + "DNT_FW_RHRG.link_DNT_FW_OAM_PROTECTED_RVMI", + "DNT_FW_RHRG.link_DNT_FW_INT_DNS_TRUSTED_RVMI", + "DNT_FW_RHRG.link_DNT_FW_NIMBUS_HSL_RVMI", + "DNT_FW_RSG_SI_1.port", + "DNT_FW_RHRG.local_storage_DNT_FW_SERVER")); + FDNT.put("capabilitiesTypes", Arrays.asList( + "tosca.capabilities.network.Bindable", + "tosca.capabilities.OperatingSystem", + "tosca.capabilities.network.Bindable", + "tosca.capabilities.Scalable", + "tosca.capabilities.Endpoint.Admin", + "tosca.capabilities.network.Bindable", + "tosca.capabilities.network.Bindable", + "tosca.capabilities.network.Bindable", + "tosca.capabilities.Node", + "tosca.capabilities.Container", + "tosca.nodes.SoftwareComponent", + "tosca.capabilities.network.Bindable")); + FDNT.put("capabilityProperties", Arrays.asList( + "dnt_fw_rhrg.binding_DNT_FW_INT_DNS_TRUSTED_RVMI:none", + "dnt_fw_rhrg.host_DNT_FW_SERVER:num_cpus,integer,false;", + "dnt_fw_rhrg.binding_DNT_FW_CORE_DIRECT_RVMI", + "dnt_fw_rhrg.scalable_DNT_FW_SERVER", + "dnt_fw_rhrg.endpoint_DNT_FW_SERVER", + "dnt_fw_rhrg.binding_DNT_FW_INTERNET_DNS_DIRECT_RVMI", + "dnt_fw_rhrg.os_DNT_FW_SERVER", + "dnt_fw_rhrg.feature", + "dnt_fw_rhrg.binding_DNT_FW_OAM_PROTECTED_RVMI", + "dnt_fw_rhrg.binding_DNT_FW_SERVER", + "dnt_fw_rhrg.binding_DNT_FW_NIMBUS_HSL_RVMI", + "dnt_fw_rsg_si_1.feature")); + + + put("FDNT", FDNT); + } + }; + }; + + protected static ISdcCsarHelper getCsarHelper(String path) throws SdcToscaParserException { + System.out.println("Parsing CSAR "+path+"..."); + String fileStr1 = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile(); + File file1 = new File(fileStr1); + ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath()); + return sdcCsarHelper; + } + + protected static ISdcCsarHelper getCsarHelper(String path, boolean resolveGetInput) throws SdcToscaParserException { + System.out.println("Parsing CSAR "+path+"..."); + String fileStr1 = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile(); + File file1 = new File(fileStr1); + ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath(), resolveGetInput); + return sdcCsarHelper; + } + + @BeforeMethod + public void setupTest(Method method) { + System.out.println("#### Starting Test " + method.getName() + " ###########"); + } + + @AfterMethod + public void tearDown(Method method){ + System.out.println("#### Ended test " + method.getName() + " ###########"); + } +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserConfigurationTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserConfigurationTest.java new file mode 100644 index 0000000..6c0455b --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserConfigurationTest.java @@ -0,0 +1,63 @@ +package org.onap.sdc.impl; + +import org.onap.sdc.tosca.parser.config.ErrorConfiguration; +import org.onap.sdc.tosca.parser.config.JtoscaValidationIssueConfiguration; +import org.testng.annotations.Test; +import org.onap.sdc.tosca.parser.config.Configuration; +import org.onap.sdc.tosca.parser.config.ConfigurationManager; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest { + + @Test + public void testConfigurationConformanceLevel() { + Configuration config = ConfigurationManager.getInstance().getConfiguration(); + assertNotNull(config); + assertNotNull(config.getConformanceLevel()); + assertNotNull(config.getConformanceLevel().getMaxVersion()); + assertNotNull(config.getConformanceLevel().getMinVersion()); + } + + + @Test + public void testErrorConfigurations() { + ErrorConfiguration errorConfig = ConfigurationManager.getInstance().getErrorConfiguration(); + assertNotNull(errorConfig); + assertNotNull(errorConfig.getErrors()); + } + + @Test + public void testSetErrorConfiguration() { + ConfigurationManager configurationManager = ConfigurationManager.getInstance(); + try { + configurationManager.setErrorConfiguration("error-configuration-test.yaml"); + ErrorConfiguration errorConfig = configurationManager.getErrorConfiguration(); + assertEquals(false, + errorConfig.getErrorInfo("CONFORMANCE_LEVEL_ERROR").getFailOnError()); + assertEquals(true, errorConfig.getErrorInfo("FILE_NOT_FOUND").getFailOnError()); + } + finally { + // Reset the configuration for other tests + configurationManager.setErrorConfiguration("error-configuration.yaml"); + } + } + + @Test + public void testSetJtoscaValidationIssueConfiguration() { + ConfigurationManager configurationManager = ConfigurationManager.getInstance(); + try { + configurationManager.setJtoscaValidationIssueConfiguration( + "jtosca-validation-issue-configuration-test.yaml"); + JtoscaValidationIssueConfiguration issueConfig = configurationManager + .getJtoscaValidationIssueConfiguration(); + assertNotNull(issueConfig); + } + finally { + // Reset the configuration for other tests + configurationManager.setJtoscaValidationIssueConfiguration + ("jtosca-validation-issue-configuration.yaml"); + } + } +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserErrorHandlingTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserErrorHandlingTest.java new file mode 100644 index 0000000..d022a1a --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserErrorHandlingTest.java @@ -0,0 +1,143 @@ +package org.onap.sdc.impl; + +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +import java.io.File; + +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.toscaparser.api.utils.JToscaErrorCodes; + + +/*put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR); + +put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND); +//CSAR contents problems +put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT); +put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT); +put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT); +put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT); +put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT); + + MISSING_META_FILE("JT1001"), +/* INVALID_META_YAML_CONTENT("JT1002"), +/* ENTRY_DEFINITION_NOT_DEFINED("JT1003"), +/* MISSING_ENTRY_DEFINITION_FILE("JT1004"), +/* GENERAL_ERROR("JT1005"), +/* PATH_NOT_VALID("JT1006"), +/* CSAR_TOSCA_VALIDATION_ERROR("JT1007"); + +*/ + +/* + * + * # Errors +errors: + FILE_NOT_FOUND: { + code: TP0001, + message: "Error: CSAR file not found." + } + BAD_FORMAT: { + code: TP0002, + message: "Error: CSAR file bad format. Check the log for details." + } + CONFORMANCE_LEVEL_ERROR: { + code: TP0003, + message: "Error: CSAR version is unsupported. Parser supports versions %s to %s." + } + GENERAL_ERROR: { + code: TP0004, + message: "Error: an unexpected internal error occured." + } + * + */ + +public class ToscaParserErrorHandlingTest extends SdcToscaParserBasicTest { + + + @Test + public void testMissingMetadata(){ + String csarPath = "csars/service-missing-meta-file.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + + @Test + public void testInvalidYamlContentMeta(){ + String csarPath = "csars/service-invalid-yaml-content-meta.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testEntryDefinitionNotDefined(){ + String csarPath = "csars/service-entry-definition-not-defined.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testMissingEntryDefinitionFile(){ + String csarPath = "csars/service-missing-entry-definition.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + //@Test - PA - there are currently no critical erros in JTosca + public void tesValidationError(){ + String csarPath = "csars/service-invalid-input-args.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testInValidConformanceLevelError(){ + String csarPath = "csars/service-invalid-conformence-level.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0003"); + } + + @Test + public void testFileNotFound(){ + Throwable captureThrowable = captureThrowable("csars/XXX.csar"); + testThrowable(captureThrowable, "TP0001"); + } + + @Test + public void testInvalidCsarFormat(){ + String csarPath = "csars/csar-invalid-zip.zip"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + private static void testThrowable(Throwable captureThrowable, String expectedCode) { + assertNotNull(captureThrowable); + assertTrue(captureThrowable instanceof SdcToscaParserException, "Error thrown is of type "+captureThrowable.getClass().getSimpleName()); + assertEquals(((SdcToscaParserException)captureThrowable).getCode(), expectedCode); + } + + public static Throwable captureThrowable(String csarPath) { + Throwable result = null; + try { + factory.getSdcCsarHelper(csarPath); + } catch( Throwable throwable ) { + result = throwable; + } + return result; + } +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserGeneralUtilTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserGeneralUtilTest.java new file mode 100644 index 0000000..d4ad73d --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserGeneralUtilTest.java @@ -0,0 +1,23 @@ +package org.onap.sdc.impl; + +import org.testng.annotations.Test; +import org.onap.sdc.tosca.parser.utils.GeneralUtility; + +import static org.testng.Assert.assertTrue; + +public class ToscaParserGeneralUtilTest extends SdcToscaParserBasicTest { + + @Test + public void testVersionCompare() { + assertTrue(GeneralUtility.conformanceLevelCompare("2", "3.0") < 0); + assertTrue(GeneralUtility.conformanceLevelCompare("0.5", "0.5") == 0); + assertTrue(GeneralUtility.conformanceLevelCompare("0.5", "0.6") < 0); + assertTrue(GeneralUtility.conformanceLevelCompare("1.5", "2.6") < 0); + assertTrue(GeneralUtility.conformanceLevelCompare("0.2", "0.1") > 0); + assertTrue(GeneralUtility.conformanceLevelCompare("2", "1.15") > 0); + assertTrue(GeneralUtility.conformanceLevelCompare("2", "2.0.0") == 0); + assertTrue(GeneralUtility.conformanceLevelCompare("2.0", "2.0.0.0") == 0); + assertTrue(GeneralUtility.conformanceLevelCompare("2.", "2.0.0.0") == 0); + assertTrue(GeneralUtility.conformanceLevelCompare("2.0", "2.0.0.2") < 0); + } +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserGroupTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserGroupTest.java new file mode 100644 index 0000000..540236c --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserGroupTest.java @@ -0,0 +1,115 @@ +package org.onap.sdc.impl; + +import org.testng.annotations.Test; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.toscaparser.api.Group; +import org.onap.sdc.toscaparser.api.elements.Metadata; + +import java.util.List; + +import static org.testng.Assert.*; + +public class ToscaParserGroupTest extends SdcToscaParserBasicTest{ + + //region getVfModulesByVf + @Test + public void testVfModulesFromVf(){ + List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + assertEquals(2, vfModulesByVf.size()); + for (Group group : vfModulesByVf){ + assertTrue(group.getName().startsWith("fdnt1")); + assertNotNull(group.getMetadata()); + assertNotNull(group.getMetadata().getValue("vfModuleModelCustomizationUUID")); + } + } + + @Test + public void testGetGroupMetadata(){ + List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + boolean found = false; + for (Group group : vfModulesByVf){ + if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")){ + found = true; + Metadata metadata = group.getMetadata(); + assertNotNull(metadata); + assertEquals("b458f4ef-ede2-403d-9605-d08c9398b6ee", metadata.getValue("vfModuleModelCustomizationUUID")); + } + } + assertTrue(found); + } + + @Test + public void testGetGroupEmptyMetadata(){ + List vfModulesByVf = rainyCsarHelperMultiVfs.getVfModulesByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"); + boolean found = false; + for (Group group : vfModulesByVf){ + if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")){ + found = true; + Metadata metadata = group.getMetadata(); + assertNull(metadata); + } + } + assertTrue(found); + } + + @Test + public void testGetVfModuleNonExisitingVf() { + List vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf("dummy"); + assertNotNull(vfModulesByVf); + assertEquals(0, vfModulesByVf.size()); + } + + @Test + public void testGetVfModuleNullVf() { + List vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf(null); + assertNotNull(vfModulesByVf); + assertEquals(0, vfModulesByVf.size()); + } + //endregion + + //region getGroupPropertyLeafValue + @Test + public void testGroupFlatProperty() throws SdcToscaParserException { + List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + String volumeGroup = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "volume_group"); + assertEquals("false", volumeGroup); + } + +// @Test +// public void testGroupFlatGetInputProperty() throws SdcToscaParserException { +// List vfModulesByVf = fdntCsarHelperWithInputs.getVfModulesByVf(VF_CUSTOMIZATION_UUID); +// String volumeGroup = fdntCsarHelperWithInputs.getGroupPropertyLeafValue(vfModulesByVf.get(1), "volume_group"); +// assertEquals("false", volumeGroup); +// } + + @Test + public void testGroupPropertyLeafValueByNullProperty() { + List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), null); + assertNull(groupProperty); + } + + @Test + public void testGroupPropertyLeafValueByDummyProperty() { + List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "XXX"); + assertNull(groupProperty); + } + + @Test + public void testGroupPropertyLeafValueByNullGroup() { + String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(null, "volume_group"); + assertNull(groupProperty); + } + //endregion + + //region getGroupPropertyAsObject + @Test + public void testGetGroupPropertyAsObject() { + List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + Object volumeGroup = fdntCsarHelper.getGroupPropertyAsObject(vfModulesByVf.get(0), "volume_group"); + assertEquals(false, volumeGroup); + } + //getGroupPropertyAsObject + +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserMetadataTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserMetadataTest.java new file mode 100644 index 0000000..8487dec --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserMetadataTest.java @@ -0,0 +1,235 @@ +package org.onap.sdc.impl; + +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.config.ConfigurationManager; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.testng.annotations.Test; + +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +public class ToscaParserMetadataTest extends SdcToscaParserBasicTest { + + //region getServiceMetadata + @Test + public void testGetServiceMetadata() { + Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata(); + assertNotNull(serviceMetadata); + assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", serviceMetadata.getValue("invariantUUID")); + assertEquals("Service FDNT", serviceMetadata.getValue("name")); + assertEquals("true", String.valueOf(serviceMetadata.getValue("serviceEcompNaming"))); + } + + @Test + public void testServiceMetadata() { + Metadata metadata = rainyCsarHelperSingleVf.getServiceMetadata(); + assertNull(metadata); + } + //endregion + + //region getMetadataPropertyValue + @Test + public void testGetMetadataProperty(){ + Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata(); + String metadataPropertyValue = fdntCsarHelper.getMetadataPropertyValue(serviceMetadata, "invariantUUID"); + assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", metadataPropertyValue); + } + + @Test + public void testGetNullMetadataPropertyValue() { + String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(null, "XXX"); + assertNull(value); + } + + @Test + public void testGetMetadataByNullPropertyValue() { + Metadata metadata = rainyCsarHelperMultiVfs.getServiceMetadata(); + String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(metadata, null); + assertNull(value); + } + + @Test + public void testGetMetadataByEmptyPropertyValue() { + Metadata metadata = rainyCsarHelperMultiVfs.getServiceMetadata(); + String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(metadata, ""); + assertNull(value); + } + //endregion + + @Test + public void GetServiceNodeTemplateMetadataTypeCR() { + NodeTemplate nodeTemplate = csarHelperServiceWithCrs.getServiceNodeTemplateByNodeName("chaya best cr 0"); + Metadata nodeTemplateMetadata = csarHelperServiceWithCrs.getNodeTemplateMetadata(nodeTemplate); + assertNotNull(nodeTemplateMetadata); + assertEquals(nodeTemplateMetadata.getValue("resourceVendorModelNumber"), ""); + assertEquals(nodeTemplateMetadata.getValue("type"), "CR"); + assertEquals(nodeTemplateMetadata.getValue("name"), "chaya best cr"); + assertEquals(nodeTemplateMetadata.getValue("version"), "0.1"); + } + + //region getConformanceLevel + @Test + public void testSunnyGetConformanceLevel() { + String conformanceLevel = fdntCsarHelper.getConformanceLevel(); + assertNotNull(conformanceLevel); + assertEquals("3.0", conformanceLevel); + } + //endregion + + //region getServiceMetadataProperties + @Test + public void testNullServiceMetadataPropertiesMap() { + Map metadata = rainyCsarHelperSingleVf.getServiceMetadataProperties(); + assertNull(metadata); + } + + @Test + public void testServiceMetadataPropertiesMap() { + Map metadata = fdntCsarHelper.getServiceMetadataProperties(); + assertNotNull(metadata); + assertEquals(metadata.size(),9); + 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 + + //QA tests region for US 319197 -port mirroring + + //getNodeTemplateMetadata (All Types) + @Test + public void GetServiceNodeTemplateMetadataTypeVF() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("VF_1_V_port_1 0"); + Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); + assertNotNull(nodeTemplateMetadata); + assertEquals(nodeTemplateMetadata.getValue("resourceVendorRelease"), "12-12-12"); + assertEquals(nodeTemplateMetadata.getValue("type"), "VF"); + } + + @Test + public void GetServiceNodeTemplateMetadataTypeVL() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtVL 0"); + Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); + assertNotNull(nodeTemplateMetadata); + assertEquals(nodeTemplateMetadata.getValue("resourceVendorRelease"), "1.0.0.wd03"); + assertEquals(nodeTemplateMetadata.getValue("type"), "VL"); + } + + @Test + public void GetServiceNodeTemplateMetadataTypeCP() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtCP 0"); + Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); + assertNotNull(nodeTemplateMetadata); + assertEquals(nodeTemplateMetadata.getValue("UUID"), "7a883088-5cab-4bfb-8d55-307d3ffd0758"); + assertEquals(nodeTemplateMetadata.getValue("type"), "CP"); + } + + @Test + public void GetServiceNodeTemplateMetadataTypePNF() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("PNF TEST 0"); + Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); + assertNotNull(nodeTemplateMetadata); + assertEquals(nodeTemplateMetadata.getValue("resourceVendorModelNumber"), ""); + assertEquals(nodeTemplateMetadata.getValue("type"), "PNF"); + } + + //QA end region for US 319197 -port mirroring + + // Added by QA //region getServiceMetadataAllProperties + + @Test + public void testGetAllMetadataProperties() { + Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata(); + assertNotNull(serviceMetadata); + Map allProperties = serviceMetadata.getAllProperties(); + assertNotNull(allProperties); + String invariantUUID = allProperties.get("invariantUUID"); + String UUID = allProperties.get("UUID"); + String name = allProperties.get("name"); + String description = allProperties.get("description"); + String type = allProperties.get("type"); + String category = allProperties.get("category"); + String ecompGeneratedNaming = allProperties.get("ecompGeneratedNaming"); + String namingPolicy = allProperties.get("namingPolicy"); + String serviceEcompNaming = allProperties.get("serviceEcompNaming"); + + assertEquals(invariantUUID, "78c72999-1003-4a35-8534-bbd7d96fcae3"); + assertEquals(UUID, "edd0a9f7-d084-4423-8461-a2eff4cb3eb6"); + assertEquals(name, "Service FDNT"); + assertEquals(description, "Service FDNT"); + assertEquals(type, "Service"); + assertEquals(category, "Network L1-3"); + assertEquals(ecompGeneratedNaming, "true"); + assertEquals(namingPolicy, "test"); + assertEquals(serviceEcompNaming, "true"); + } + //endregion + + @Test + public void testCSARMissingConformanceLevelWithCustomErrorConfig() throws + SdcToscaParserException { + + ConfigurationManager configurationManager = ConfigurationManager.getInstance(); + try { + configurationManager.setErrorConfiguration("error-configuration-test.yaml"); + factory.setConfigurationManager(configurationManager); + ISdcCsarHelper missingCSARMetaCsarCustomConfig = getCsarHelper + ("csars/service-missing-csar-meta-file.csar"); + String conformanceLevel = missingCSARMetaCsarCustomConfig.getConformanceLevel(); + assertNotNull(conformanceLevel); + assertEquals(conformanceLevel, configurationManager.getConfiguration().getConformanceLevel() + .getMaxVersion()); + } + finally { + configurationManager.setErrorConfiguration("error-configuration.yaml"); + factory.setConfigurationManager(configurationManager); + } + + } + + @Test(expectedExceptions = SdcToscaParserException.class) + public void testCSARMissingConformanceLevelWithDefaultErrorConfig() throws + SdcToscaParserException { + ISdcCsarHelper missingCSARMetaCsarDefaultConfig = getCsarHelper("csars/service-missing-csar-meta-file.csar"); + missingCSARMetaCsarDefaultConfig.getConformanceLevel(); + } + +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java new file mode 100644 index 0000000..0692ebe --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java @@ -0,0 +1,972 @@ +package org.onap.sdc.impl; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import java.util.*; +import static org.hamcrest.CoreMatchers.is; + +import com.google.common.collect.ImmutableMap; +import org.apache.commons.lang3.tuple.Pair; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.FilterType; +import org.onap.sdc.tosca.parser.impl.SdcTypes; +import org.onap.sdc.toscaparser.api.Group; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Property; +import org.testng.annotations.Test; + +import fj.data.fingertrees.Node; + +public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { + + //region getServiceVfList + @Test + public void testNumberOfVfSunnyFlow() throws SdcToscaParserException { + List serviceVfList = fdntCsarHelper.getServiceVfList(); + assertNotNull(serviceVfList); + assertEquals(2, serviceVfList.size()); + } + + @Test + public void testGetNodeTemplateCustomizationUuid(){ + List serviceVfList = fdntCsarHelper.getServiceVfList(); + boolean found = false; + for (NodeTemplate nt : serviceVfList){ + if (nt.getName().equals("FDNT 1")){ + found = true; + assertEquals(fdntCsarHelper.getNodeTemplateCustomizationUuid(nt), "56179cd8-de4a-4c38-919b-bbc4452d2d73"); + } + } + assertTrue(found); + } + + @Test + public void testSingleVFWithNotMetadata() throws SdcToscaParserException { + //If there is no metadata on VF level - There is no VF's because the type is taken from metadata values. + List serviceVfList = rainyCsarHelperSingleVf.getServiceVfList(); + assertNotNull(serviceVfList); + assertEquals(0, serviceVfList.size()); + } + //endregion + + //region getNodeTemplatePropertyLeafValue + @Test + public void testNodeTemplateFlatProperty() throws SdcToscaParserException { + List serviceVfList = fdntCsarHelper.getServiceVfList(); + assertEquals("2", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "availability_zone_max_count")); + assertEquals("3", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "max_instances")); + assertEquals("some code", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_naming_code")); + } + + @Test + public void testNodeTemplateFlatFunctionProperty() throws SdcToscaParserException { + List serviceVfList = fdntCsarHelperWithInputs.getServiceVfList(); + assertEquals(null, fdntCsarHelperWithInputs.getNodeTemplatePropertyLeafValue(serviceVfList.get(1), "target_network_role")); + } + + @Test + public void testNodeTemplateNestedFunctionProperty() throws SdcToscaParserException { + List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + assertEquals(null, ipAssignCsarHelper.getNodeTemplatePropertyLeafValue(vfcs.get(0), "port_pd01_port_ip_requirements#ip_count_required#count")); + } + + @Test + public void testNodeTemplateNestedProperty() throws SdcToscaParserException { + List serviceVlList = fdntCsarHelper.getServiceVlList(); + NodeTemplate nodeTemplate = serviceVlList.get(0); + //System.out.println("node template " + nodeTemplate.toString()); + assertEquals("24", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#cidr_mask")); + assertEquals("7a6520b-9982354-ee82992c-105720", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_flows#vpn_binding")); + } + + @Test + public void testNodeTemplateNestedPropertyFromInput() throws SdcToscaParserException { + List serviceVfList = fdntCsarHelper.getServiceVfList(); + NodeTemplate nodeTemplate = serviceVfList.get(0); + //System.out.println("node template " + nodeTemplate.toString()); + assertEquals("true", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming#ecomp_generated_naming")); + assertEquals("FDNT_instance_VF_2", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming#naming_policy")); + } + + @Test + public void testNodeTemplateNestedPropertyNotExists() throws SdcToscaParserException { + List serviceVfList = fdntCsarHelper.getServiceVfList(); + String nodeTemplatePropertyLeafValue = fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_role#nf_naming#kuku"); + assertNull(nodeTemplatePropertyLeafValue); + } + + @Test + public void testNodeTemplateFlatPropertyByNotFoundProperty() throws SdcToscaParserException { + List serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList(); + String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "XXXX"); + assertNull(nodeTemplatePropertyLeafValue); + } + + @Test + public void testNodeTemplateFlatPropertyByNullProperty() throws SdcToscaParserException { + List serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList(); + String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), null); + assertNull(nodeTemplatePropertyLeafValue); + } + + @Test + public void testNodeTemplateFlatPropertyByNullNodeTemplate() throws SdcToscaParserException { + String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(null, "availability_zone_max_count"); + assertNull(nodeTemplatePropertyLeafValue); + } + //endregion + + //region getServiceVlList + @Test + public void testServiceVl() { + List vlList = fdntCsarHelper.getServiceVlList(); + assertEquals(1, vlList.size()); + assertEquals("exVL", vlList.get(0).getName()); + } + + @Test + public void testNumberOfVLRainyFlow() throws SdcToscaParserException { + List serviceVlList = rainyCsarHelperMultiVfs.getServiceVlList(); + assertNotNull(serviceVlList); + assertEquals(0, serviceVlList.size()); + } + //endregion + + //region getServiceNodeTemplatesByType + @Test + public void testServiceNodeTemplatesByType() throws SdcToscaParserException { + List serviceVfList = fdntCsarHelper.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Fdnt"); + assertNotNull(serviceVfList); + assertEquals(1, serviceVfList.size()); + } + + @Test + public void testServiceNodeTemplatesByNull() { + List nodeTemplates = rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType(null); + assertNotNull(nodeTemplates); + assertEquals(0, nodeTemplates.size()); + } + + @Test + public void testServiceNodeTemplatesByNotFoundProperty() { + List nodeTemplates = rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType("XXX"); + assertNotNull(nodeTemplates); + assertEquals(0, nodeTemplates.size()); + } + //endregion + + //region getTypeOfNodeTemplate + @Test + public void testGetTypeOfNodeTemplate() { + List serviceVfList = fdntCsarHelper.getServiceVfList(); + String typeOfNodeTemplate = fdntCsarHelper.getTypeOfNodeTemplate(serviceVfList.get(0)); + assertEquals("org.openecomp.resource.vf.Fdnt", typeOfNodeTemplate); + } + + @Test + public void testGetTypeOfNullNodeTemplate() { + String typeOfNodeTemplate = rainyCsarHelperMultiVfs.getTypeOfNodeTemplate(null); + assertNull(typeOfNodeTemplate); + } + //endregion + + //region getAllottedResources + @Test + public void testGetAllottedResources() { + List allottedResources = fdntCsarHelper.getAllottedResources(); + assertEquals(1, allottedResources.size()); + } + + @Test + public void testGetAllottedResourcesZero() { + List allottedResources = rainyCsarHelperMultiVfs.getAllottedResources(); + assertNotNull(allottedResources); + assertEquals(0, allottedResources.size()); + } + //endregion + + //region getVfcListByVf + @Test + public void testGetVfcFromVf() { + List vfcListByVf = fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID); + assertEquals(2, vfcListByVf.size()); + } + + @Test + public void testVfcListByNull() { + List vfcList = rainyCsarHelperMultiVfs.getVfcListByVf(null); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + + @Test + public void testVfcListByNotFoundProperty() { + List vfcList = rainyCsarHelperMultiVfs.getVfcListByVf("XXX"); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + //endregion + + //region getCpListByVf + @Test + public void testGetCpFromVf() { + List cpListByVf = fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID); + assertEquals(1, cpListByVf.size()); + NodeTemplate nodeTemplate = cpListByVf.get(0); + assertEquals("DNT_PORT", nodeTemplate.getName()); + } + + @Test + public void testGetCpFromVfByNullId() { + List cpListByVf = rainyCsarHelperMultiVfs.getCpListByVf(null); + assertNotNull(cpListByVf); + assertEquals(0, cpListByVf.size()); + } + + @Test + public void testGetCpFromVfXxx() { + List cpListByVf = rainyCsarHelperMultiVfs.getCpListByVf("XXXXX"); + assertNotNull(cpListByVf); + assertEquals(0, cpListByVf.size()); + } + //endregion + + //region getNodeTemplatePairsByReqName + @Test + public void testGetNodeTemplatePairsByReqName() { + List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(1, nodeTemplatePairsByReqName.size()); + Pair pair = nodeTemplatePairsByReqName.get(0); + NodeTemplate cp = pair.getLeft(); + NodeTemplate vfc = pair.getRight(); + assertEquals("DNT_PORT", cp.getName()); + assertEquals("DNT_FW_RHRG", vfc.getName()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithNullVF() { + List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + null, fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithEmptyVF() { + List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + new ArrayList<>(), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithNullCap() { + List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), null, "binding"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithEmptyCap() { + List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), new ArrayList<>(), "binding"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithNullReq() { + List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), null); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithDummyReq() { + + List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "XXX"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + //endregion + + //region getMembersOfVfModule + @Test + public void testGetMembersOfVfModule() { + NodeTemplate vf = fdntCsarHelper.getServiceVfList().get(0); + List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + assertEquals(2, vfModulesByVf.size()); + for (Group group : vfModulesByVf) { + List membersOfVfModule = fdntCsarHelper.getMembersOfVfModule(vf, group); + assertNotNull(membersOfVfModule); + if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")) { + assertEquals(1, membersOfVfModule.size()); + NodeTemplate nodeTemplate = membersOfVfModule.get(0); + assertEquals("DNT_FW_RSG_SI_1", nodeTemplate.getName()); + } else { + assertEquals("fdnt1..Fdnt..mod_vmsi_dnt_fw_parent..module-1", group.getName()); + assertEquals(1, membersOfVfModule.size()); + NodeTemplate nodeTemplate = membersOfVfModule.get(0); + assertEquals("DNT_FW_RHRG", nodeTemplate.getName()); + } + } + } + + @Test + public void testMembersOfVfModuleByNullVf() { + List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + List nodeTemplates = fdntCsarHelper.getMembersOfVfModule(null, vfModulesByVf.get(0)); + assertNotNull(nodeTemplates); + assertEquals(0, nodeTemplates.size()); + } + + @Test + public void testMembersOfVfModuleByNullGroup() { + List serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList(); + List nodeTemplates = rainyCsarHelperMultiVfs.getMembersOfVfModule(serviceVfList.get(0), null); + assertNotNull(nodeTemplates); + assertEquals(0, nodeTemplates.size()); + } + //endregion + + //region getCpPropertiesFromVfc + @Test + public void testGetCpPropertiesFromVfc() { + List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + boolean isChecked = false; + + for (NodeTemplate vfc: vfcs) { + + if(vfc.getName().equalsIgnoreCase("abstract_pd_server")) + { + isChecked = true; + Map> cps = ipAssignCsarHelper.getCpPropertiesFromVfcAsObject(vfc); + + assertEquals(2,cps.size()); + Map pd01 = cps.get("port_pd01_port"); + assertEquals(5, pd01.size()); + + Map firstIpRequirements = (Map) ((List)pd01.get("ip_requirements")).get(0); + Map secondIpRequirements = (Map) ((List)pd01.get("ip_requirements")).get(1); + + assertEquals("subnet_role_4", firstIpRequirements.get("subnet_role")); + assertEquals(4, firstIpRequirements.get("ip_version")); + assertEquals(true, ((Map) firstIpRequirements.get("ip_count_required")).get("is_required")); + assertEquals("get_input:node_count", ((Map) firstIpRequirements.get("ip_count_required")).get("count").toString()); + assertEquals(false, ((Map)((Map)pd01.get("mac_requirements")).get("mac_count_required")).get("is_required")); + assertEquals("test_subnetpoolid", pd01.get("subnetpoolid")); + assertEquals("oam", pd01.get("network_role_tag")); + assertEquals(6, secondIpRequirements.get("ip_version")); + } + + } + assertTrue(isChecked); + } + + @Test + public void testGetCpPropertiesFromVfcForNullVFC() { + Map> cps = ipAssignCsarHelper.getCpPropertiesFromVfcAsObject(null); + assertNotNull(cps); + assertEquals(0, cps.size()); + } + //endregion + + //region getNodeTemplatePropertyAsObject + @Test + public void testGetNodeTemplatePropertyAsObject() { + List serviceVfList = fdntCsarHelper.getServiceVfList(); + assertEquals("2", fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "availability_zone_max_count")); + assertEquals(3, fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "max_instances")); + assertEquals("some code", fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "nf_naming_code")); + } + //endregion + + //region getServiceNodeTemplates + @Test + public void testServiceNodeTemplates() throws SdcToscaParserException { + List serviceVfList = fdntCsarHelper.getServiceNodeTemplates(); + assertNotNull(serviceVfList); + assertEquals(3, serviceVfList.size()); + assertEquals(serviceVfList.get(2).getName(), "exVL"); + } + //endregion + + //region filterNodeTemplatePropertiesByValue + @Test + public void testFilterNodeTemplatePropertiesByContains() { + List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + boolean isChecked = false; + for (NodeTemplate vfc: vfcs) { + if(vfc.getName().equalsIgnoreCase("abstract_pd_server")) + { + isChecked = true; + Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfc, FilterType.CONTAINS, "get_input"); + + assertEquals(7, filteredInputs.size()); + assertEquals("get_input:availabilityzone_name", filteredInputs.get("compute_pd_server_availability_zone")); + assertEquals("get_input:[pd_server_names, 0]", filteredInputs.get("compute_pd_server_name")); + assertEquals("get_input:node_count", filteredInputs.get("port_pd01_port_ip_requirements#ip_count_required#count")); + + break; + } + + } + assertTrue(isChecked); + } + + @Test + public void testFilterNodeTemplatePropertiesByDummyContains() { + List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), FilterType.CONTAINS, "dummy"); + assertNotNull(filteredInputs); + assertEquals(0, filteredInputs.size()); + } + + @Test + public void testFilterNodeTemplatePropertiesByEquals() { + List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + boolean isChecked = false; + for (NodeTemplate vfc: vfcs) { + if(vfc.getName().equalsIgnoreCase("abstract_pd_server")) + { + isChecked = true; + Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfc, FilterType.EQUALS, "oam"); + + assertEquals(2, filteredInputs.size()); + assertEquals("oam", filteredInputs.get("port_pd02_port_network_role_tag")); + assertEquals("oam", filteredInputs.get("port_pd01_port_network_role_tag")); + break; + } + + } + assertTrue(isChecked); + } + + @Test + public void testFilterNodeTemplatePropertiesByDummyEquals() { + List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), FilterType.EQUALS, "dummy"); + assertNotNull(filteredInputs); + assertEquals(0, filteredInputs.size()); + } + + @Test + public void testFilterNodeTemplatePropertiesByNullFilterType() { + List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), null, "ddc"); + assertNotNull(filteredInputs); + assertEquals(0, filteredInputs.size()); + } + + @Test + public void testFilterNodeTemplatePropertiesByNullPattern() { + List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), FilterType.EQUALS, null); + assertNotNull(filteredInputs); + assertEquals(0, filteredInputs.size()); + } + + @Test + public void testFilterNodeTemplatePropertiesByNullVfc() { + Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(null, FilterType.EQUALS, "ddc"); + assertNotNull(filteredInputs); + assertEquals(0, filteredInputs.size()); + } + //endregion + + //region getServiceNodeTemplateBySdcType + @Test + public void testServiceNodeTemplateBySdcType() { + List serviceVfList = fdntCsarHelper.getServiceNodeTemplateBySdcType(SdcTypes.VF); + assertNotNull(serviceVfList); + assertEquals(serviceVfList.size(), 2); + assertEquals(serviceVfList.get(0).getName(), "FDNT 1"); + } + + @Test + public void testServiceNodeTemplateBySdcTypeServiceProxy() { + List serviceProxies = portMirroring.getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY); + assertNotNull(serviceProxies); + assertEquals(serviceProxies.size(), 2); + } + + @Test + public void testServiceNodeTemplateByNullSdcType() { + List serviceVfList = fdntCsarHelper.getServiceNodeTemplateBySdcType(null); + assertNotNull(serviceVfList); + assertEquals(serviceVfList.size(), 0); + } + //endregion + + //region getNodeTemplateBySdcType + @Test + public void testNodeTemplateBySdcType() { + List vfList = fdntCsarHelper.getServiceVfList(); + List vfcList = fdntCsarHelper.getNodeTemplateBySdcType(vfList.get(0), SdcTypes.VFC); + assertNotNull(vfcList); + assertEquals(2, vfcList.size()); + assertEquals("DNT_FW_RSG_SI_1", vfcList.get(0).getName()); + } + + @Test + public void testNodeTemplateByNullSdcType() { + List vfList = fdntCsarHelper.getServiceVfList(); + List vfcList = fdntCsarHelper.getNodeTemplateBySdcType(vfList.get(0), null); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + + @Test + public void testNodeTemplateBySdcTypeNullNT() { + List vfcList = fdntCsarHelper.getNodeTemplateBySdcType(null, SdcTypes.VFC); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + //endregion + + //region getVnfConfig + @Test + public void testGetVnfConfig() { + NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); + assertNotNull(vnfConfig); + assertEquals("vnfConfiguration", vnfConfig.getMetaData().getValue("name")); + } + + @Test + public void testGetVnfConfigByNonFoundVNF() { + NodeTemplate vnfConfig = ipAssignCsarHelper.getVnfConfig("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + assertNull(vnfConfig); + } + + @Test + public void testGetVnfConfigByDummyUUID() { + NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig("XXX"); + assertNull(vnfConfig); + } + + @Test + public void testGetVnfConfigByNullUUID() { + NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig(null); + assertNull(vnfConfig); + } + + @Test + public void testGetVfcTypWithoutVnf() { + List vfcList = nfodCsarHlper.getVfcListByVf("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); + assertNotNull(vfcList); + assertEquals(2, vfcList.size()); + } + //endregion + + //region nested vfc + @Test + public void testNestedVfcByExistCvfc() { + List vfcList = nestedVfcCsarHlper.getVfcListByVf("71389f8b-8671-4a43-a991-59fb621d3615"); + assertNotNull(vfcList); + assertEquals(vfcList.size(), 2); + assertEquals("VFC1 DUMMY", vfcList.get(0).getName()); + assertEquals("VF_VNF", vfcList.get(1).getName()); + } + + @Test + public void testNestedVfcByNullVf() { + List vfcList = nestedVfcCsarHlper.getVfcListByVf(null); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + + @Test + public void testNestedVfcByDummyVf() { + List vfcList = nestedVfcCsarHlper.getVfcListByVf("dummy"); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + //endregion + + //region hasTopology + @Test + public void testHasTopologyByVF() { + List vfList = nestedVfcCsarHlper.getServiceVfList(); + boolean hasTopology = nestedVfcCsarHlper.hasTopology(vfList.get(0)); + assertEquals(true, hasTopology); + } + + @Test + public void testHasTopologyByCVFC() { + List vfcList = nestedVfcCsarHlper.getVfcListByVf("71389f8b-8671-4a43-a991-59fb621d3615"); + boolean hasTopology = nestedVfcCsarHlper.hasTopology(vfcList.get(1)); + assertEquals(true, hasTopology); + } + + @Test + public void testHasTopologyByVL() { + List serviceVlList = fdntCsarHelper.getServiceVlList(); + boolean hasTopology = fdntCsarHelper.hasTopology(serviceVlList.get(0)); + assertEquals(false, hasTopology); + } + + @Test + public void testHasTopologyByNull() { + boolean hasTopology = fdntCsarHelper.hasTopology(null); + assertEquals(false, hasTopology); + } + //endregion + + //region getNodeTemplateChildren + @Test + public void testGetNodeTemplatesListOfNodeTemplateByVF() { + List vfList = fdntCsarHelper.getServiceVfList(); + List children = fdntCsarHelper.getNodeTemplateChildren(vfList.get(0)); + assertNotNull(children); + assertEquals(3, children.size()); + + children.sort(Comparator.comparing(NodeTemplate::getName)); + + assertEquals("DNT_FW_RSG_SI_1", children.get(1).getName()); + assertEquals("VFC", children.get(1).getMetaData().getValue("type")); + assertEquals("DNT_PORT", children.get(2).getName()); + assertEquals("CP", children.get(2).getMetaData().getValue("type")); + } + + @Test + public void testGetNodeTemplatesListOfNodeTemplateByVFC() { + List vfList = nestedVfcCsarHlper.getServiceVfList(); + List vfChildren = nestedVfcCsarHlper.getNodeTemplateChildren(vfList.get(0)); + assertNotNull(vfChildren); + assertEquals(vfChildren.size(), 2); + vfChildren.sort(Comparator.comparing(NodeTemplate::getName)); + assertEquals("VFC1 DUMMY", vfChildren.get(0).getName()); + assertEquals("VF_VNF", vfChildren.get(1).getName()); + assertEquals("CVFC", vfChildren.get(1).getMetaData().getValue("type")); + + + List vfcChildren = nestedVfcCsarHlper.getNodeTemplateChildren(vfChildren.get(1)); + assertNotNull(vfcChildren); + assertEquals(vfcChildren.size(), 3); + vfcChildren.sort(Comparator.comparing(NodeTemplate::getName)); + assertEquals("Test NIC 02_wan_port", vfcChildren.get(0).getName()); + assertEquals("Test NIC_wan_port", vfcChildren.get(1).getName()); + assertEquals("VF", vfcChildren.get(2).getName()); + } + + @Test + public void testGetNodeTemplatesListOfNodeTemplateByNull() { + List children = fdntCsarHelper.getNodeTemplateChildren(null); + assertNotNull(children); + assertEquals(0, children.size()); + } + //endregion + + // added by QA + // Get specific VNF properties + @Test + public void testGetVnfConfigGetProperties() { + NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); + assertNotNull(vnfConfig); + assertEquals("vnfConfiguration", vnfConfig.getMetaData().getValue("name")); + + String manufacturer_reference_number = nfodCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#ATT_part_12345_for_FortiGate-VM00#vendor_info#manufacturer_reference_number"); + String num_cpus = nfodCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#ATT_part_67890_for_FortiGate-VM01#compute_flavor#num_cpus"); + String sp_part_number = nfodCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#ATT_part_67890_for_FortiGate-VM01#sp_part_number"); + + assertEquals("FortiGate-VM00",manufacturer_reference_number); + assertEquals("10",num_cpus); + assertEquals("ATT_part_67890_for_FortiGate-VM01",sp_part_number); + } + + // added by QA + // Check that get vnfconfiguration not return as VFC + @Test + public void testGetVfcTypWithoutVnfCheckNames() { + List vfcList = nfodCsarHlper.getVfcListByVf("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); + assertNotNull(vfcList); + assertEquals(2, vfcList.size()); + for (int i = 0; i < vfcList.size(); i++) { + + String Name= vfcList.get(i).getName(); + + assertEquals(false, Name.equals("vFW_VNF_Configuration")); + + } + } + + @Test + public void testNewGetVnfConfigGetProperties() { + NodeTemplate vnfConfig = nfodNEWCsarHlper.getVnfConfig("a6587663-b27f-4e88-8a86-604604302ce6"); + assertNotNull(vnfConfig); + assertEquals("vnfConfiguration", vnfConfig.getMetaData().getValue("name")); + + //Deployment flavor 1 + String manufacturer_reference_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#123456#vendor_info#manufacturer_reference_number"); + String num_cpus = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#123456#compute_flavor#num_cpus"); + String sp_part_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#123456#sp_part_number"); + + assertEquals("234567",manufacturer_reference_number); + assertEquals("2",num_cpus); + assertEquals("123456",sp_part_number); + + //Deployment flavor 2 + manufacturer_reference_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#FG_partNumbereJqQjUkteF1#vendor_info#manufacturer_reference_number"); + num_cpus = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#FG_partNumbereJqQjUkteF1#compute_flavor#num_cpus"); + sp_part_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#FG_partNumbereJqQjUkteF1#sp_part_number"); + + assertEquals("EP_manufacturerReferenceNumberkbAiqZZNzx1",manufacturer_reference_number); + assertEquals("1",num_cpus); + assertEquals("FG_partNumbereJqQjUkteF1",sp_part_number); + } + + // added by QA + // Check that get vnfconfiguration not return as VFC + @Test + public void testNewGetVfcTypWithoutVnfCheckNames() { + List vfcList = nfodNEWCsarHlper.getVfcListByVf("a6587663-b27f-4e88-8a86-604604302ce6"); + assertNotNull(vfcList); + assertEquals(1, vfcList.size()); + for (int i = 0; i < vfcList.size(); i++) { + + String Name= vfcList.get(i).getName(); + + assertEquals(false, Name.equals("name_6GkVrOjnGp1_VNF_Configuration")); + } + } + + //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() { + //port_pd01_port_ip_requirements is of type list + //This test covers: + // 1) "default" resolving + // 2) complex type resolving + // 3) List access resolving + List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_ip_requirements"); + assertTrue(propertyAsObject instanceof ArrayList); + assertEquals(2, ((ArrayList) propertyAsObject).size()); + //port_pd01_port_ip_requirements: + //- get_input: [ip_requirements, 0] + //- get_input: [ip_requirements, 1] + assertEquals("subnet_role_4", ((Map) ((ArrayList) propertyAsObject).get(0)).get("subnet_role")); + assertEquals("subnet_role_6", ((Map) ((ArrayList) propertyAsObject).get(1)).get("subnet_role")); + } + + @Test + public void testResolveGetInputForPrimitiveTypeString() { + //This test covers "default" resolving of primitive - as Object + List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_network_role_tag"); + assertEquals("oam", propertyAsObject); + } + + @Test + public void testResolveGetInputForPrimitiveTypeInteger() { + //This test covers "default" resolving of primitive - as String + List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + String propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyLeafValue(vfcs.get(0), "port_pd01_port_order"); + assertEquals("1", propertyAsObject); + } + + @Test + public void testResolveGetInputForMap() { + //This test covers "default" resolving of primitive - as Map + List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd02_port_ip_requirements#ip_count_required"); + assertTrue(propertyAsObject instanceof Map); + assertEquals(false, ((Map)propertyAsObject).get("is_required")); + } + + @Test + public void testResolveGetInputForAllHierarchy() { + //This test covers "default" resolving from service level + List vfs = resolveGetInputCsar.getServiceVfList(); + Object vfPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfs.get(0), "vm_count"); + assertEquals(2, vfPropertyAsObject); + //This test covers property assignment resolving on VFI level (service template), from Vf level + List vfcs = resolveGetInputCsar.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.VFC); + Object vfcPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "my_count"); + assertEquals(2, vfcPropertyAsObject); //takes it from upper level (VF) property + } + + @Test + public void testResolveGetInputNoDefValueInnerLevel() { + //This test covers resolving when no "default" value is supplied to the input - should be null - VF/VFCI level + List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + String propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyLeafValue(vfcs.get(0), "index_value"); + assertNull(propertyAsObject); + + } + + @Test + public void testResolveGetInputNoDefValueServiceLevel() { + //This test covers resolving when no "default" value is supplied to the input - should be null - Service/VFI level + List vfs = resolveGetInputCsar.getServiceVfList(); + Object vfPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfs.get(0), "port_order"); + assertNull(vfPropertyAsObject); + + } + //endregion + + // region Added by QA - Continue with testings of resolve get_input + + @Test + public void testResolveGetInputForComplexTypeAndListWithFalseValue() + { + List vfcs = resolveGetInputCsarFalse.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_ip_requirements"); + assertTrue(propertyAsObject instanceof ArrayList); + assertEquals(2, ((ArrayList) propertyAsObject).size()); + assertEquals("get_input:[ip_requirements, 0]", ((ArrayList) propertyAsObject).get(0).toString()); + assertEquals("get_input:[ip_requirements, 1]", ((ArrayList) propertyAsObject).get(1).toString()); + } + + @Test + public void testResolveGetInputForPrimitiveTypeStringWithFalseValue() { + List vfcs = resolveGetInputCsarFalse.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_network_role_tag"); + assertEquals("get_input:role_tag_oam", propertyAsObject.toString()); + } + + @Test + public void testResolveGetInputForPrimitiveTypeListWithFalseValue() { + List vfcs = resolveGetInputCsarFalse.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_name"); + assertEquals("[get_input:[pd_server_names, 0]]", propertyAsObject.toString()); + } + + //@Test // Maybe a bug here.... need to check with Esti - Mait was sent. + public void testResolveGetInputForPrimitiveTypeList() { + List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_name"); + assertEquals("\"ZRDM1MOGX01MPD001\"", propertyAsObject.toString()); + } + + @Test + public void testResolveGetInputForPrimitiveNullValue() { + List vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + @SuppressWarnings("unchecked") + ListpropertyAsObject = (List) resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_availability_zone"); + assertNull(propertyAsObject.get(0)); + } + @Test + public void testResolveGetInputForPrimitiveIPValue() { + List vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Object propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "vm_image_name"); + assertEquals("107.239.36.5", propertyAsObject.toString()); + } + + //QA region getServiceNodeTemplateByNodeName tests + + @Test + public void getServiceNodeTemplateByNodeNameTypeVF() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("VF_1_V_port_1 0"); + assertNotNull(nodeTemplate); + assertEquals(nodeTemplate.getName(), "VF_1_V_port_1 0"); + assertEquals(nodeTemplate.getMetaData().getValue("type"), "VF"); + } + + @Test + public void getServiceNodeTemplateByNodeNameTypeVL() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtVL 0"); + assertNotNull(nodeTemplate); + assertEquals(nodeTemplate.getName(), "ExtVL 0"); + assertEquals(nodeTemplate.getMetaData().getValue("type"), "VL"); + } + + @Test + public void getServiceNodeTemplateByNodeNameTypeCP() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtCP 0"); + assertNotNull(nodeTemplate); + assertEquals(nodeTemplate.getName(), "ExtCP 0"); + assertEquals(nodeTemplate.getMetaData().getValue("type"), "CP"); + } + + @Test + public void getServiceNodeTemplateByNodeNameTypePNF() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("PNF TEST 0"); + assertNotNull(nodeTemplate); + assertEquals(nodeTemplate.getName(), "PNF TEST 0"); + assertEquals(nodeTemplate.getMetaData().getValue("type"), "PNF"); + } + + //QA region getServiceNodeTemplateBySdcType tests + + @Test + public void getServiceNodeTemplateBySdcType_VF() { + List vfList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Vf1VPort1"); + assertEquals(2, vfList.size()); + assertEquals("VF_1_V_port_1", vfList.get(0).getMetaData().getValue("name")); + } + // endregion Added by QA - Continue with testings of resolve get_input + + + @Test + public void testResolveGetInputArrayStructure() { + List vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Object propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_name"); + assertEquals( ((ArrayList)propertyAsObject).get(0).toString(), "\"ZRDM1MOGX01MPD001\""); + propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_ip_requirements"); + assertEquals( ((ArrayList)propertyAsObject).get(1), null); + } + + @Test + public void testServiceNodeTemplateByCRType() { + List serviceCRList = csarHelperServiceWithCrs.getServiceNodeTemplateBySdcType(SdcTypes.CR); + assertNotNull(serviceCRList); + assertEquals(serviceCRList.size(), 2); + assertEquals(serviceCRList.get(0).getName(), "chaya best cr 1"); + assertEquals(serviceCRList.get(0).getType(), "org.openecomp.resource.cr.ChayaBestCr"); + assertEquals(serviceCRList.get(1).getName(), "chaya best cr 0"); + assertEquals(serviceCRList.get(1).getType(), "org.openecomp.resource.cr.ChayaBestCr"); + } + + @Test + public void testGetCPOfCRNodeTemplate() { + NodeTemplate nodeTemplate = csarHelperServiceWithCrs.getServiceNodeTemplateByNodeName("chaya best cr 0"); + List crCpChildren = csarHelperServiceWithCrs.getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CP); + assertEquals(crCpChildren.get(0).getName(), "ContrailPort 0"); + assertEquals(crCpChildren.get(0).getMetaData().getValue("type"), SdcTypes.CP.name()); + } + + @Test + public void testServiceCRInstanceProps() { + List serviceCrList = csarHelperServiceWithCrs.getServiceNodeTemplateBySdcType(SdcTypes.CR); + assertNotNull(serviceCrList); + NodeTemplate crTemplate = serviceCrList.get(0); + assertNotNull(crTemplate); + assertEquals(crTemplate.getPropertyValue("nf_naming").toString(), ImmutableMap.of("ecomp_generated_naming", "true").toString()); + assertEquals(crTemplate.getPropertyValue("contrailport0_virtual_network"), "chaya"); + } + + +} + + diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java new file mode 100644 index 0000000..75f8962 --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java @@ -0,0 +1,273 @@ +package org.onap.sdc.impl; + +import org.onap.sdc.tosca.parser.impl.SdcTypes; +import org.onap.sdc.toscaparser.api.CapabilityAssignments; +import org.onap.sdc.toscaparser.api.CapabilityAssignment; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.RequirementAssignments; +import org.onap.sdc.toscaparser.api.elements.Metadata; +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 + + //QA tests region for US 319197 -port mirroring- + + //get-CapabilitiesOf (All Types) + @Test + public void getServiceNodeTemplateCapabilitiesOfTypeVF() { + List serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF); + CapabilityAssignments capabilitiesOfVF = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVfList.get(0)); + assertEquals(capabilitiesOfVF.getAll().size(),12); + assertNotNull(capabilitiesOfVF.getCapabilityByName("neutronport0.network.incoming.packets.rate")); + } + + @Test + public void getServiceNodeTemplateCapabilitiesOfTypeExVL() { + List serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL"); + CapabilityAssignments capabilitiesOfExtVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceExtVlList.get(0)); + assertEquals(capabilitiesOfExtVL.getAll().size(),2); + assertNotNull(capabilitiesOfExtVL.getCapabilityByName("virtual_linkable").getProperties()); + } + + @Test + public void getServiceNodeTemplateCapabilitiesOfTypeVL() { + List serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network"); + CapabilityAssignments capabilitiesOfVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVlList.get(0)); + assertEquals(capabilitiesOfVL.getAll().size(),2); + assertNotNull(capabilitiesOfVL.getCapabilityByName("link").getProperties()); + } + + @Test + public void getServiceNodeTemplateCapabilitiesOfTypeCP() { + List serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); + CapabilityAssignments capabilitiesOfCP = QAServiceForToscaParserTests.getCapabilitiesOf(serviceCpList.get(0)); + assertEquals(capabilitiesOfCP.getAll().size(),2); + assertNotNull(capabilitiesOfCP.getCapabilityByName("internal_connectionPoint")); + } + + @Test + public void getServiceNodeTemplateCapabilitiesOfTypePNF() { + List servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF); + CapabilityAssignments capabilitiesOfPnf = QAServiceForToscaParserTests.getCapabilitiesOf(servicePnfs.get(0)); + assertEquals(capabilitiesOfPnf.getAll().size(),1); + assertNotNull(capabilitiesOfPnf.getCapabilityByName("feature")); + } + + //get-RequirementsOf (All Types)----------------------------- + + @Test + public void getServiceNodeTemplateRequirementsOfTypeVF() { + List serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF); + RequirementAssignments requirementsOfVF = QAServiceForToscaParserTests.getRequirementsOf(serviceVfList.get(6)); + assertEquals(requirementsOfVF.getAll().size(),3); +// RequirementAssignments requirementsByName = + assertEquals(requirementsOfVF.getRequirementsByName("dependency").getAll().size(),2 ); + //check that API return empty list if requirement property not exist. + assertEquals(requirementsOfVF.getRequirementsByName("blabla").getAll().size(),0); + } + + @Test + public void getServiceNodeTemplateRequirementsOfTypeExVL() { + List serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL"); + RequirementAssignments requirementsOfExtVL = QAServiceForToscaParserTests.getRequirementsOf(serviceExtVlList.get(0)); + assertEquals(requirementsOfExtVL.getAll().size(),1); + } + + @Test + public void getServiceNodeTemplateRequirementsOfTypeVL() { + List serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network"); + RequirementAssignments requirementsOfVL = QAServiceForToscaParserTests.getRequirementsOf(serviceVlList.get(1)); + assertEquals(requirementsOfVL.getAll().size(),2); + assertNotNull(requirementsOfVL.getRequirementsByName("dependency")); + } + + @Test + public void getServiceNodeTemplateRequirementsOfTypeCP() { + List serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); + RequirementAssignments requirementsOfCP = QAServiceForToscaParserTests.getRequirementsOf(serviceCpList.get(0)); + assertEquals(requirementsOfCP.getAll().size(),2); + assertEquals(requirementsOfCP.getRequirementsByName("virtualBinding").getAll().size(),1); + } + + @Test + public void getServiceNodeTemplateRequirementsOfTypePNF() { + List servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF); + RequirementAssignments requirementsOfPnf = QAServiceForToscaParserTests.getRequirementsOf(servicePnfs.get(0)); + assertEquals(requirementsOfPnf.getAll().size(),2); + assertNotNull(requirementsOfPnf.getRequirementsByName("feature")); + } + + //QA end region for US 319197 -port mirroring + + // Added by QA CapabilityAssignments + @Test + public void testGetCapabilitiesByType() { + List vfs = resolveGetInputCsarQA.getServiceVfList(); + CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); + assertNotNull(capabilityAssignments); + CapabilityAssignments capabilitiesByType = capabilityAssignments.getCapabilitiesByType("tosca.capabilities.Scalable"); + int capsQty = capabilitiesByType.getAll().size(); + assertEquals(1, capsQty); + CapabilityAssignment capabilityByName = capabilitiesByType.getCapabilityByName("abstract_pd_server.scalable_pd_server"); + assertNotNull(capabilityByName); + } + + @Test + public void testGetCapabilityByName() { + List vfs = resolveGetInputCsarQA.getServiceVfList(); + CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); + assertNotNull(capabilityAssignments); + CapabilityAssignment capabilityByName = capabilityAssignments.getCapabilityByName("abstract_pd_server.disk.iops_pd_server"); + assertNotNull(capabilityByName); + String capName = capabilityByName.getName(); + assertEquals(capName, "abstract_pd_server.disk.iops_pd_server"); + } + + @Test + public void testGetCapabilitiesGetAll() { + List vfs = resolveGetInputCsarQA.getServiceVfList(); + CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); + assertNotNull(capabilityAssignments); + int capsAssignmentSize = capabilityAssignments.getAll().size(); + assertEquals(65, capsAssignmentSize); + } + + // Added by QA RequirementsAssignments + @Test + public void testGetRequirementsByName() { + List vfs = resolveReqsCapsCsarQA.getServiceVfList(); + List cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); + RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0)); + assertNotNull(requirementAssignments); + assertEquals(2, requirementAssignments.getAll().size()); + assertEquals("DNT_FW_RHRG2", requirementAssignments.getRequirementsByName("binding").getAll().get(1).getNodeTemplateName()); + + } + + @Test + public void testRequirementAssignmentGetNodeGetCapability() { + List vfs = resolveReqsCapsCsarQA.getServiceVfList(); + List cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); + RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0)); + assertNotNull(requirementAssignments); + String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName(); + String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName(); + assertEquals(nodeTemplateName, "DNT_FW_RHRG"); + assertNull(capabilityName); + } + + + @Test + public void testRequirementAssignmentGetCapability() { + List cps = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); + RequirementAssignments requirementAssignments = QAServiceForToscaParserTests.getRequirementsOf(cps.get(0)); + assertNotNull(requirementAssignments); + String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName(); + String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName(); + assertEquals(nodeTemplateName, "ExtVL 0"); + assertEquals(capabilityName,"tosca.capabilities.network.Linkable"); + } + + @Test + public void testGetCapabilityProperties() { + List vfs = fdntCsarHelper.getServiceVfList(); + List cps = fdntCsarHelper.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); + CapabilityAssignments capabilityAssignments = cps.get(0).getCapabilities(); + assertNotNull(capabilityAssignments); + assertEquals(12, capabilityAssignments.getAll().size()); + CapabilityAssignment xxxCapability = capabilityAssignments.getCapabilityByName("xxx"); + //GetInput property - resolved in any case + String getInputProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "DeploymentFlavor"); + assertEquals("{aaa=bbb}", getInputProp); + //Simple property + String simpleProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "distribution"); + assertEquals("rhel", simpleProp); + } + +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserServiceInputTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserServiceInputTest.java new file mode 100644 index 0000000..b11487f --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserServiceInputTest.java @@ -0,0 +1,77 @@ +package org.onap.sdc.impl; + +import org.testng.annotations.Test; +import org.onap.sdc.toscaparser.api.parameters.Input; + +import java.util.List; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +public class ToscaParserServiceInputTest extends SdcToscaParserBasicTest { + + //region getServiceInputs + @Test + public void testGetServiceInputs(){ + List serviceInputs = fdntCsarHelper.getServiceInputs(); + assertNotNull(serviceInputs); + assertEquals(1, serviceInputs.size()); + } + + @Test + public void testServiceInputs() { + List inputs = rainyCsarHelperSingleVf.getServiceInputs(); + assertNotNull(inputs); + assertEquals(0, inputs.size()); + } + //endregion + + //region getServiceInputLeafValueOfDefault + @Test + public void testGetServiceInputLeafValue(){ + String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default"); + assertEquals("test service naming", serviceInputLeafValue); + } + +// @Test +// public void testGetServiceInputLeafValueWithGetInput(){ +// String serviceInputLeafValue = fdntCsarHelperWithInputs.getServiceInputLeafValueOfDefault("my_input#default"); +// assertEquals(null, serviceInputLeafValue); +// } + + @Test + public void testGetServiceInputLeafValueNotExists(){ + String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default#kuku"); + assertNull(serviceInputLeafValue); + } + + @Test + public void testGetServiceInputLeafValueNull(){ + String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault(null); + assertNull(serviceInputLeafValue); + } + //endregion + + //region getServiceInputLeafValueOfDefaultAsObject + @Test + public void testGetServiceInputLeafValueOfDefaultAsObject() { + Object serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default"); + assertEquals("test service naming", serviceInputLeafValue); + } + + @Test + public void testGetServiceComplexInputLeafValueOfDefault() { + String serviceInputLeafValue = fdntCsarHelperWithInputs.getServiceInputLeafValueOfDefault("complex_input#default#ipv4_subnet_default_assignment#cidr_mask"); + assertEquals(serviceInputLeafValue, "24"); + } + + @Test + public void testGetServiceDummyComplexInputLeafValueOfDefault() { + String serviceInputLeafValue = fdntCsarHelperWithInputs.getServiceInputLeafValueOfDefault("complex_input#default#ipv4_subnet_default_assignment#XXX"); + assertNull(serviceInputLeafValue); + } + + + //endregion +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserSubsMappingsTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserSubsMappingsTest.java new file mode 100644 index 0000000..cbd8e8a --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserSubsMappingsTest.java @@ -0,0 +1,129 @@ +package org.onap.sdc.impl; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.util.*; + +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.toscaparser.api.CapabilityAssignment; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.RequirementAssignment; +import org.onap.sdc.toscaparser.api.elements.CapabilityTypeDef; +//import org.testng.ReporterConfig.Property; +import org.testng.annotations.Test; +import org.onap.sdc.toscaparser.api.Property; + +//import static org.junit.Assert.assertEquals; +//import static org.junit.Assert.assertNull; + +public class ToscaParserSubsMappingsTest extends SdcToscaParserBasicTest { + + //region getServiceSubstitutionMappingsTypeName + @Test + public void testGetServiceSubstitutionMappingsTypeName() { + String serviceSubstitutionMappingsTypeName = fdntCsarHelper.getServiceSubstitutionMappingsTypeName(); + assertEquals("org.openecomp.service.ServiceFdnt", serviceSubstitutionMappingsTypeName); + } + + @Test + public void testServiceSubstitutionMappingsTypeName() { + String substitutionMappingsTypeName = rainyCsarHelperMultiVfs.getServiceSubstitutionMappingsTypeName(); + assertNull(substitutionMappingsTypeName); + } + //endregion + + //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)); +// 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)); +// 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 { + List serviceVfList = fdntCsarHelper.getServiceVfList(); + String sName = serviceVfList.get(0).getName(); + assertEquals(sName,"FDNT 1"); + + List ActualReqsValues = new ArrayList<>(Arrays.asList( )); + + List lRequirements = serviceVfList.get(0).getRequirements().getAll(); + + assertEquals(fdntCsarHelper_Data.get("FDNT").get("requirements").size(),lRequirements.size()); // + + // Continue from here after bug is fixed ! ! ! ! - Test the Requirements values + } + +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserValidationIssueTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserValidationIssueTest.java new file mode 100644 index 0000000..0fc42f7 --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserValidationIssueTest.java @@ -0,0 +1,93 @@ +package org.onap.sdc.impl; + +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.config.ConfigurationManager; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; + +import static org.testng.Assert.assertEquals; + +public class ToscaParserValidationIssueTest extends SdcToscaParserBasicTest { + protected static ConfigurationManager configurationManager = ConfigurationManager.getInstance(); + + @BeforeClass + public void loadJtoscaValidationIssueConfiguration() throws IOException { + //load the tests dedicated configuration + configurationManager.setJtoscaValidationIssueConfiguration( "jtosca-validation-issue-configuration-test.yaml"); + factory.setConfigurationManager(configurationManager); + } + + @AfterClass + public void loadJtoscaValidationIssueOriginalConfiguration() throws IOException { + //load the tests dedicated configuration + configurationManager.setJtoscaValidationIssueConfiguration("jtosca-validation-issue-configuration.yaml"); + factory.setConfigurationManager(configurationManager); + + } + + + @Test + public void testNoValidationIssues() throws SdcToscaParserException { + ISdcCsarHelper rainyCsarHelper = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar");//conformance level 3.0 + + //List notAnalyzedReport = factory.getNotAnalyzadExceptions(); + //assertEquals( notAnalyzedReport.size(),0); + List warningsReport = factory.getWarningExceptions(); + assertEquals( warningsReport.size(),0); + List criticalsReport = factory.getCriticalExceptions(); + assertEquals( criticalsReport.size(),0); + } + @Test + public void testGetLowSinceConformanceLevel() throws SdcToscaParserException { + ISdcCsarHelper fdntCsarHelperWithInputs = getCsarHelper("csars/service-NfodService-csar.csar");//conformance level 3.0 + //Service level + + List notAnalyzedReport = factory.getNotAnalyzadExceptions(); + assertEquals( notAnalyzedReport.size(),10); + //JE003 high CL 4.0 + assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE003")).collect(Collectors.toList()).size(), 2); + assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE235")).collect(Collectors.toList()).size(), 7); + assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE236")).collect(Collectors.toList()).size(), 1); + List warningsReport = factory.getWarningExceptions(); + assertEquals( warningsReport.size(),14); + assertEquals( warningsReport.stream().filter(w->w.getCode().equals("JE006")).collect(Collectors.toList()).size(), 13); + //JE004 low CL 2.0 + assertEquals( warningsReport.stream().filter(w->w.getCode().equals("JE004")).collect(Collectors.toList()).size(), 1); + List criticalsReport = factory.getCriticalExceptions(); + assertEquals( criticalsReport.size(),0); + } + + @Test(expectedExceptions = SdcToscaParserException.class) + public void testCriticalIssueThrowsSdcToscaParserException() throws SdcToscaParserException { + getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0 + } + + @Test + public void testMultiSinceConformanceLevelIssues() { + try { + ISdcCsarHelper Nfod2images = getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0 + } catch (SdcToscaParserException e) { + System.out.println("SdcToscaParserException is caught here - this is WAD in this specific test."); + } + List notAnalyzedReport = factory.getNotAnalyzadExceptions(); + assertEquals(3, notAnalyzedReport.size()); + List warningsReport = factory.getWarningExceptions(); + assertEquals( 0, warningsReport.size()); + List criticalsReport = factory.getCriticalExceptions(); + assertEquals( 22, criticalsReport.size()); + //JE006 multy values sinceCsarConformanceLevel + assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE006")).collect + (Collectors.toList()).size(), 18); + assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE003")).collect + (Collectors.toList()).size(), 4); + } + + +} diff --git a/src/test/java/org/onap/sdc/impl/myTest.java b/src/test/java/org/onap/sdc/impl/myTest.java new file mode 100644 index 0000000..4833f6f --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/myTest.java @@ -0,0 +1,41 @@ +package org.onap.sdc.impl; + +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.testng.annotations.Test; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; + +import java.io.File; + +import static org.onap.sdc.impl.SdcToscaParserBasicTest.getCsarHelper; + +public class myTest { + + static SdcToscaParserFactory factory; + static ISdcCsarHelper fdntCsarHelper; + + @Test + public void testNoValidationIssues() throws SdcToscaParserException { + + +// factory = SdcToscaParserFactory.getInstance(); +// fdntCsarHelper = getCsarHelper("csars/service-Oren1-csar-4.csar"); +// +// +// List serviceNodeTemplatesByType = fdntCsarHelper.getServiceNodeTemplatesByType("org.openecomp.nodes.ForwardingPath"); +// +// String target_range = fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceNodeTemplatesByType.get(0), "target_range"); + + } + + + protected static ISdcCsarHelper getCsarHelper(String path) throws SdcToscaParserException { + System.out.println("Parsing CSAR "+path+"..."); + String fileStr1 = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile(); + File file1 = new File(fileStr1); + ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath()); + return sdcCsarHelper; + } + +} diff --git a/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java b/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java deleted file mode 100644 index 1695671..0000000 --- a/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.openecomp.sdc.impl; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.openecomp.sdc.toscaparser.api.common.JToscaException; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeSuite; - -public abstract class SdcToscaParserBasicTest { - - public static final String VF_CUSTOMIZATION_UUID = "56179cd8-de4a-4c38-919b-bbc4452d2d73"; - static SdcToscaParserFactory factory; - static ISdcCsarHelper rainyCsarHelperSingleVf; - static ISdcCsarHelper rainyCsarHelperMultiVfs; - static ISdcCsarHelper fdntCsarHelper; - static ISdcCsarHelper fdntCsarHelperWithInputs; - static ISdcCsarHelper nfodCsarHlper; - static ISdcCsarHelper ipAssignCsarHelper; - static ISdcCsarHelper nestedVfcCsarHlper; - static ISdcCsarHelper nfodNEWCsarHlper; - static ISdcCsarHelper QAServiceForToscaParserTests; - static ISdcCsarHelper resolveGetInputCsar; - static ISdcCsarHelper resolveGetInputCsarFalse; - static ISdcCsarHelper resolveGetInputCsarQA; - static ISdcCsarHelper resolveReqsCapsCsarQA; - static ISdcCsarHelper portMirroring; - static ISdcCsarHelper csarHelperServiceWithCrs; - - - static Map>> fdntCsarHelper_Data; - - @BeforeSuite - public static void init() throws SdcToscaParserException, JToscaException, IOException { - - factory = SdcToscaParserFactory.getInstance(); - fdntCsarHelper = getCsarHelper("csars/service-sunny-flow.csar", false); - rainyCsarHelperMultiVfs = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar", false); - rainyCsarHelperSingleVf = getCsarHelper("csars/service-ServiceFdnt-csar.csar", false); - fdntCsarHelperWithInputs = getCsarHelper("csars/service-ServiceFdnt-with-get-input.csar", false); - nfodCsarHlper = getCsarHelper("csars/service-NfodService-csar.csar", false); - ipAssignCsarHelper = getCsarHelper("csars/service-Ipassignservice-csar.csar", false); - nestedVfcCsarHlper = getCsarHelper("csars/service-nested-vfc-csar.csar", false); - nfodNEWCsarHlper = getCsarHelper("csars/service-Nfod2images-csar.csar", false); - resolveGetInputCsar = getCsarHelper("csars/service-resolve-get-input-csar.csar"); - resolveGetInputCsarFalse = getCsarHelper("csars/service-resolve-get-input-csar.csar",false); - resolveGetInputCsarQA = getCsarHelper("csars/service-resolve-get-input-csar_QA.csar"); - QAServiceForToscaParserTests = getCsarHelper("csars/service-ServiceForToscaParserTests-csar.csar"); - resolveReqsCapsCsarQA = getCsarHelper("csars/service-sunny-flow2.csar"); - portMirroring = getCsarHelper("csars/service-PortMirroring.csar"); - csarHelperServiceWithCrs = getCsarHelper("csars/service-CrTestService-csar.csar"); - - fdntCsarHelper_Data = new HashMap>>(){ - { - HashMap> FDNT ; - - FDNT = new HashMap>(); - FDNT.put("VF Name", Arrays.asList("FDNT 1")); - FDNT.put("capabilities", Arrays.asList( - "dnt_fw_rhrg.binding_DNT_FW_INT_DNS_TRUSTED_RVMI", - "dnt_fw_rhrg.host_DNT_FW_SERVER", - "dnt_fw_rhrg.binding_DNT_FW_CORE_DIRECT_RVMI", - "dnt_fw_rhrg.scalable_DNT_FW_SERVER", - "dnt_fw_rhrg.endpoint_DNT_FW_SERVER", - "dnt_fw_rhrg.binding_DNT_FW_INTERNET_DNS_DIRECT_RVMI", - "dnt_fw_rhrg.os_DNT_FW_SERVER", - "dnt_fw_rhrg.feature", - "dnt_fw_rhrg.binding_DNT_FW_OAM_PROTECTED_RVMI", - "dnt_fw_rhrg.binding_DNT_FW_SERVER", - "dnt_fw_rhrg.binding_DNT_FW_NIMBUS_HSL_RVMI", - "dnt_fw_rsg_si_1.feature")); - FDNT.put("requirements", Arrays.asList( - "DNT_FW_RSG_SI_1.dependency", - "DNT_FW_RHRG.dependency", - "DNT_FW_RHRG.link_DNT_FW_INTERNET_DNS_DIRECT_RVMI", - "DNT_FW_RHRG.link_DNT_FW_CORE_DIRECT_RVMI", - "DNT_FW_RHRG.link_DNT_FW_OAM_PROTECTED_RVMI", - "DNT_FW_RHRG.link_DNT_FW_INT_DNS_TRUSTED_RVMI", - "DNT_FW_RHRG.link_DNT_FW_NIMBUS_HSL_RVMI", - "DNT_FW_RSG_SI_1.port", - "DNT_FW_RHRG.local_storage_DNT_FW_SERVER")); - FDNT.put("capabilitiesTypes", Arrays.asList( - "tosca.capabilities.network.Bindable", - "tosca.capabilities.OperatingSystem", - "tosca.capabilities.network.Bindable", - "tosca.capabilities.Scalable", - "tosca.capabilities.Endpoint.Admin", - "tosca.capabilities.network.Bindable", - "tosca.capabilities.network.Bindable", - "tosca.capabilities.network.Bindable", - "tosca.capabilities.Node", - "tosca.capabilities.Container", - "tosca.nodes.SoftwareComponent", - "tosca.capabilities.network.Bindable")); - FDNT.put("capabilityProperties", Arrays.asList( - "dnt_fw_rhrg.binding_DNT_FW_INT_DNS_TRUSTED_RVMI:none", - "dnt_fw_rhrg.host_DNT_FW_SERVER:num_cpus,integer,false;", - "dnt_fw_rhrg.binding_DNT_FW_CORE_DIRECT_RVMI", - "dnt_fw_rhrg.scalable_DNT_FW_SERVER", - "dnt_fw_rhrg.endpoint_DNT_FW_SERVER", - "dnt_fw_rhrg.binding_DNT_FW_INTERNET_DNS_DIRECT_RVMI", - "dnt_fw_rhrg.os_DNT_FW_SERVER", - "dnt_fw_rhrg.feature", - "dnt_fw_rhrg.binding_DNT_FW_OAM_PROTECTED_RVMI", - "dnt_fw_rhrg.binding_DNT_FW_SERVER", - "dnt_fw_rhrg.binding_DNT_FW_NIMBUS_HSL_RVMI", - "dnt_fw_rsg_si_1.feature")); - - - put("FDNT", FDNT); - } - }; - }; - - protected static ISdcCsarHelper getCsarHelper(String path) throws SdcToscaParserException { - System.out.println("Parsing CSAR "+path+"..."); - String fileStr1 = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile(); - File file1 = new File(fileStr1); - ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath()); - return sdcCsarHelper; - } - - protected static ISdcCsarHelper getCsarHelper(String path, boolean resolveGetInput) throws SdcToscaParserException { - System.out.println("Parsing CSAR "+path+"..."); - String fileStr1 = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile(); - File file1 = new File(fileStr1); - ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath(), resolveGetInput); - return sdcCsarHelper; - } - - @BeforeMethod - public void setupTest(Method method) { - System.out.println("#### Starting Test " + method.getName() + " ###########"); - } - - @AfterMethod - public void tearDown(Method method){ - System.out.println("#### Ended test " + method.getName() + " ###########"); - } -} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java deleted file mode 100644 index b57522d..0000000 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.openecomp.sdc.impl; - -import org.openecomp.sdc.tosca.parser.config.ErrorConfiguration; -import org.openecomp.sdc.tosca.parser.config.JtoscaValidationIssueConfiguration; -import org.testng.annotations.Test; -import org.openecomp.sdc.tosca.parser.config.Configuration; -import org.openecomp.sdc.tosca.parser.config.ConfigurationManager; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest { - - @Test - public void testConfigurationConformanceLevel() { - Configuration config = ConfigurationManager.getInstance().getConfiguration(); - assertNotNull(config); - assertNotNull(config.getConformanceLevel()); - assertNotNull(config.getConformanceLevel().getMaxVersion()); - assertNotNull(config.getConformanceLevel().getMinVersion()); - } - - - @Test - public void testErrorConfigurations() { - ErrorConfiguration errorConfig = ConfigurationManager.getInstance().getErrorConfiguration(); - assertNotNull(errorConfig); - assertNotNull(errorConfig.getErrors()); - } - - @Test - public void testSetErrorConfiguration() { - ConfigurationManager configurationManager = ConfigurationManager.getInstance(); - try { - configurationManager.setErrorConfiguration("error-configuration-test.yaml"); - ErrorConfiguration errorConfig = configurationManager.getErrorConfiguration(); - assertEquals(false, - errorConfig.getErrorInfo("CONFORMANCE_LEVEL_ERROR").getFailOnError()); - assertEquals(true, errorConfig.getErrorInfo("FILE_NOT_FOUND").getFailOnError()); - } - finally { - // Reset the configuration for other tests - configurationManager.setErrorConfiguration("error-configuration.yaml"); - } - } - - @Test - public void testSetJtoscaValidationIssueConfiguration() { - ConfigurationManager configurationManager = ConfigurationManager.getInstance(); - try { - configurationManager.setJtoscaValidationIssueConfiguration( - "jtosca-validation-issue-configuration-test.yaml"); - JtoscaValidationIssueConfiguration issueConfig = configurationManager - .getJtoscaValidationIssueConfiguration(); - assertNotNull(issueConfig); - } - finally { - // Reset the configuration for other tests - configurationManager.setJtoscaValidationIssueConfiguration - ("jtosca-validation-issue-configuration.yaml"); - } - } -} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java deleted file mode 100644 index 8451a58..0000000 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.openecomp.sdc.impl; - -import org.testng.annotations.Test; -import static org.testng.Assert.*; - -import java.io.File; - -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes; - - -/*put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR); - -put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND); -//CSAR contents problems -put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT); -put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT); -put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT); -put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT); -put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT); - - MISSING_META_FILE("JT1001"), -/* INVALID_META_YAML_CONTENT("JT1002"), -/* ENTRY_DEFINITION_NOT_DEFINED("JT1003"), -/* MISSING_ENTRY_DEFINITION_FILE("JT1004"), -/* GENERAL_ERROR("JT1005"), -/* PATH_NOT_VALID("JT1006"), -/* CSAR_TOSCA_VALIDATION_ERROR("JT1007"); - -*/ - -/* - * - * # Errors -errors: - FILE_NOT_FOUND: { - code: TP0001, - message: "Error: CSAR file not found." - } - BAD_FORMAT: { - code: TP0002, - message: "Error: CSAR file bad format. Check the log for details." - } - CONFORMANCE_LEVEL_ERROR: { - code: TP0003, - message: "Error: CSAR version is unsupported. Parser supports versions %s to %s." - } - GENERAL_ERROR: { - code: TP0004, - message: "Error: an unexpected internal error occured." - } - * - */ - -public class ToscaParserErrorHandlingTest extends SdcToscaParserBasicTest { - - - @Test - public void testMissingMetadata(){ - String csarPath = "csars/service-missing-meta-file.csar"; - String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); - File file = new File(fileLocationString); - Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); - testThrowable(captureThrowable, "TP0002"); - } - - - @Test - public void testInvalidYamlContentMeta(){ - String csarPath = "csars/service-invalid-yaml-content-meta.csar"; - String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); - File file = new File(fileLocationString); - Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); - testThrowable(captureThrowable, "TP0002"); - } - - @Test - public void testEntryDefinitionNotDefined(){ - String csarPath = "csars/service-entry-definition-not-defined.csar"; - String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); - File file = new File(fileLocationString); - Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); - testThrowable(captureThrowable, "TP0002"); - } - - @Test - public void testMissingEntryDefinitionFile(){ - String csarPath = "csars/service-missing-entry-definition.csar"; - String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); - File file = new File(fileLocationString); - Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); - testThrowable(captureThrowable, "TP0002"); - } - - //@Test - PA - there are currently no critical erros in JTosca - public void tesValidationError(){ - String csarPath = "csars/service-invalid-input-args.csar"; - String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); - File file = new File(fileLocationString); - Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); - testThrowable(captureThrowable, "TP0002"); - } - - @Test - public void testInValidConformanceLevelError(){ - String csarPath = "csars/service-invalid-conformence-level.csar"; - String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); - File file = new File(fileLocationString); - Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); - testThrowable(captureThrowable, "TP0003"); - } - - @Test - public void testFileNotFound(){ - Throwable captureThrowable = captureThrowable("csars/XXX.csar"); - testThrowable(captureThrowable, "TP0001"); - } - - @Test - public void testInvalidCsarFormat(){ - String csarPath = "csars/csar-invalid-zip.zip"; - String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); - File file = new File(fileLocationString); - Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); - testThrowable(captureThrowable, "TP0002"); - } - - private static void testThrowable(Throwable captureThrowable, String expectedCode) { - assertNotNull(captureThrowable); - assertTrue(captureThrowable instanceof SdcToscaParserException, "Error thrown is of type "+captureThrowable.getClass().getSimpleName()); - assertEquals(((SdcToscaParserException)captureThrowable).getCode(), expectedCode); - } - - public static Throwable captureThrowable(String csarPath) { - Throwable result = null; - try { - factory.getSdcCsarHelper(csarPath); - } catch( Throwable throwable ) { - result = throwable; - } - return result; - } -} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java deleted file mode 100644 index 9f349ae..0000000 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.openecomp.sdc.impl; - -import org.testng.annotations.Test; -import org.openecomp.sdc.tosca.parser.utils.GeneralUtility; - -import static org.testng.Assert.assertTrue; - -public class ToscaParserGeneralUtilTest extends SdcToscaParserBasicTest { - - @Test - public void testVersionCompare() { - assertTrue(GeneralUtility.conformanceLevelCompare("2", "3.0") < 0); - assertTrue(GeneralUtility.conformanceLevelCompare("0.5", "0.5") == 0); - assertTrue(GeneralUtility.conformanceLevelCompare("0.5", "0.6") < 0); - assertTrue(GeneralUtility.conformanceLevelCompare("1.5", "2.6") < 0); - assertTrue(GeneralUtility.conformanceLevelCompare("0.2", "0.1") > 0); - assertTrue(GeneralUtility.conformanceLevelCompare("2", "1.15") > 0); - assertTrue(GeneralUtility.conformanceLevelCompare("2", "2.0.0") == 0); - assertTrue(GeneralUtility.conformanceLevelCompare("2.0", "2.0.0.0") == 0); - assertTrue(GeneralUtility.conformanceLevelCompare("2.", "2.0.0.0") == 0); - assertTrue(GeneralUtility.conformanceLevelCompare("2.0", "2.0.0.2") < 0); - } -} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java deleted file mode 100644 index 8435c12..0000000 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.openecomp.sdc.impl; - -import org.testng.annotations.Test; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.elements.Metadata; - -import java.util.Arrays; -import java.util.List; - -import static org.testng.Assert.*; - -public class ToscaParserGroupTest extends SdcToscaParserBasicTest{ - - //region getVfModulesByVf - @Test - public void testVfModulesFromVf(){ - List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); - assertEquals(2, vfModulesByVf.size()); - for (Group group : vfModulesByVf){ - assertTrue(group.getName().startsWith("fdnt1")); - assertNotNull(group.getMetadata()); - assertNotNull(group.getMetadata().getValue("vfModuleModelCustomizationUUID")); - } - } - - @Test - public void testGetGroupMetadata(){ - List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); - boolean found = false; - for (Group group : vfModulesByVf){ - if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")){ - found = true; - Metadata metadata = group.getMetadata(); - assertNotNull(metadata); - assertEquals("b458f4ef-ede2-403d-9605-d08c9398b6ee", metadata.getValue("vfModuleModelCustomizationUUID")); - } - } - assertTrue(found); - } - - @Test - public void testGetGroupEmptyMetadata(){ - List vfModulesByVf = rainyCsarHelperMultiVfs.getVfModulesByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"); - boolean found = false; - for (Group group : vfModulesByVf){ - if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")){ - found = true; - Metadata metadata = group.getMetadata(); - assertNull(metadata); - } - } - assertTrue(found); - } - - @Test - public void testGetVfModuleNonExisitingVf() { - List vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf("dummy"); - assertNotNull(vfModulesByVf); - assertEquals(0, vfModulesByVf.size()); - } - - @Test - public void testGetVfModuleNullVf() { - List vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf(null); - assertNotNull(vfModulesByVf); - assertEquals(0, vfModulesByVf.size()); - } - //endregion - - //region getGroupPropertyLeafValue - @Test - public void testGroupFlatProperty() throws SdcToscaParserException { - List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); - String volumeGroup = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "volume_group"); - assertEquals("false", volumeGroup); - } - -// @Test -// public void testGroupFlatGetInputProperty() throws SdcToscaParserException { -// List vfModulesByVf = fdntCsarHelperWithInputs.getVfModulesByVf(VF_CUSTOMIZATION_UUID); -// String volumeGroup = fdntCsarHelperWithInputs.getGroupPropertyLeafValue(vfModulesByVf.get(1), "volume_group"); -// assertEquals("false", volumeGroup); -// } - - @Test - public void testGroupPropertyLeafValueByNullProperty() { - List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); - String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), null); - assertNull(groupProperty); - } - - @Test - public void testGroupPropertyLeafValueByDummyProperty() { - List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); - String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "XXX"); - assertNull(groupProperty); - } - - @Test - public void testGroupPropertyLeafValueByNullGroup() { - String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(null, "volume_group"); - assertNull(groupProperty); - } - //endregion - - //region getGroupPropertyAsObject - @Test - public void testGetGroupPropertyAsObject() { - List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); - Object volumeGroup = fdntCsarHelper.getGroupPropertyAsObject(vfModulesByVf.get(0), "volume_group"); - assertEquals(false, volumeGroup); - } - //getGroupPropertyAsObject - -} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java deleted file mode 100644 index 1746042..0000000 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java +++ /dev/null @@ -1,234 +0,0 @@ -package org.openecomp.sdc.impl; - -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.config.ConfigurationManager; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.toscaparser.api.elements.Metadata; -import org.testng.annotations.Test; - -import java.util.List; -import java.util.Map; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - -public class ToscaParserMetadataTest extends SdcToscaParserBasicTest { - - //region getServiceMetadata - @Test - public void testGetServiceMetadata() { - Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata(); - assertNotNull(serviceMetadata); - assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", serviceMetadata.getValue("invariantUUID")); - assertEquals("Service FDNT", serviceMetadata.getValue("name")); - assertEquals("true", String.valueOf(serviceMetadata.getValue("serviceEcompNaming"))); - } - - @Test - public void testServiceMetadata() { - Metadata metadata = rainyCsarHelperSingleVf.getServiceMetadata(); - assertNull(metadata); - } - //endregion - - //region getMetadataPropertyValue - @Test - public void testGetMetadataProperty(){ - Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata(); - String metadataPropertyValue = fdntCsarHelper.getMetadataPropertyValue(serviceMetadata, "invariantUUID"); - assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", metadataPropertyValue); - } - - @Test - public void testGetNullMetadataPropertyValue() { - String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(null, "XXX"); - assertNull(value); - } - - @Test - public void testGetMetadataByNullPropertyValue() { - Metadata metadata = rainyCsarHelperMultiVfs.getServiceMetadata(); - String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(metadata, null); - assertNull(value); - } - - @Test - public void testGetMetadataByEmptyPropertyValue() { - Metadata metadata = rainyCsarHelperMultiVfs.getServiceMetadata(); - String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(metadata, ""); - assertNull(value); - } - //endregion - - @Test - public void GetServiceNodeTemplateMetadataTypeCR() { - NodeTemplate nodeTemplate = csarHelperServiceWithCrs.getServiceNodeTemplateByNodeName("chaya best cr 0"); - Metadata nodeTemplateMetadata = csarHelperServiceWithCrs.getNodeTemplateMetadata(nodeTemplate); - assertNotNull(nodeTemplateMetadata); - assertEquals(nodeTemplateMetadata.getValue("resourceVendorModelNumber"), ""); - assertEquals(nodeTemplateMetadata.getValue("type"), "CR"); - assertEquals(nodeTemplateMetadata.getValue("name"), "chaya best cr"); - assertEquals(nodeTemplateMetadata.getValue("version"), "0.1"); - } - - //region getConformanceLevel - @Test - public void testSunnyGetConformanceLevel() { - String conformanceLevel = fdntCsarHelper.getConformanceLevel(); - assertNotNull(conformanceLevel); - assertEquals("3.0", conformanceLevel); - } - //endregion - - //region getServiceMetadataProperties - @Test - public void testNullServiceMetadataPropertiesMap() { - Map metadata = rainyCsarHelperSingleVf.getServiceMetadataProperties(); - assertNull(metadata); - } - - @Test - public void testServiceMetadataPropertiesMap() { - Map metadata = fdntCsarHelper.getServiceMetadataProperties(); - assertNotNull(metadata); - assertEquals(metadata.size(),9); - 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 - - //QA tests region for US 319197 -port mirroring - - //getNodeTemplateMetadata (All Types) - @Test - public void GetServiceNodeTemplateMetadataTypeVF() { - NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("VF_1_V_port_1 0"); - Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); - assertNotNull(nodeTemplateMetadata); - assertEquals(nodeTemplateMetadata.getValue("resourceVendorRelease"), "12-12-12"); - assertEquals(nodeTemplateMetadata.getValue("type"), "VF"); - } - - @Test - public void GetServiceNodeTemplateMetadataTypeVL() { - NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtVL 0"); - Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); - assertNotNull(nodeTemplateMetadata); - assertEquals(nodeTemplateMetadata.getValue("resourceVendorRelease"), "1.0.0.wd03"); - assertEquals(nodeTemplateMetadata.getValue("type"), "VL"); - } - - @Test - public void GetServiceNodeTemplateMetadataTypeCP() { - NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtCP 0"); - Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); - assertNotNull(nodeTemplateMetadata); - assertEquals(nodeTemplateMetadata.getValue("UUID"), "7a883088-5cab-4bfb-8d55-307d3ffd0758"); - assertEquals(nodeTemplateMetadata.getValue("type"), "CP"); - } - - @Test - public void GetServiceNodeTemplateMetadataTypePNF() { - NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("PNF TEST 0"); - Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); - assertNotNull(nodeTemplateMetadata); - assertEquals(nodeTemplateMetadata.getValue("resourceVendorModelNumber"), ""); - assertEquals(nodeTemplateMetadata.getValue("type"), "PNF"); - } - - //QA end region for US 319197 -port mirroring - - // Added by QA //region getServiceMetadataAllProperties - - @Test - public void testGetAllMetadataProperties() { - Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata(); - assertNotNull(serviceMetadata); - Map allProperties = serviceMetadata.getAllProperties(); - assertNotNull(allProperties); - String invariantUUID = allProperties.get("invariantUUID"); - String UUID = allProperties.get("UUID"); - String name = allProperties.get("name"); - String description = allProperties.get("description"); - String type = allProperties.get("type"); - String category = allProperties.get("category"); - String ecompGeneratedNaming = allProperties.get("ecompGeneratedNaming"); - String namingPolicy = allProperties.get("namingPolicy"); - String serviceEcompNaming = allProperties.get("serviceEcompNaming"); - - assertEquals(invariantUUID, "78c72999-1003-4a35-8534-bbd7d96fcae3"); - assertEquals(UUID, "edd0a9f7-d084-4423-8461-a2eff4cb3eb6"); - assertEquals(name, "Service FDNT"); - assertEquals(description, "Service FDNT"); - assertEquals(type, "Service"); - assertEquals(category, "Network L1-3"); - assertEquals(ecompGeneratedNaming, "true"); - assertEquals(namingPolicy, "test"); - assertEquals(serviceEcompNaming, "true"); - } - //endregion - - @Test - public void testCSARMissingConformanceLevelWithCustomErrorConfig() throws - SdcToscaParserException { - - ConfigurationManager configurationManager = ConfigurationManager.getInstance(); - try { - configurationManager.setErrorConfiguration("error-configuration-test.yaml"); - factory.setConfigurationManager(configurationManager); - ISdcCsarHelper missingCSARMetaCsarCustomConfig = getCsarHelper - ("csars/service-missing-csar-meta-file.csar"); - String conformanceLevel = missingCSARMetaCsarCustomConfig.getConformanceLevel(); - assertNotNull(conformanceLevel); - assertEquals(conformanceLevel, configurationManager.getConfiguration().getConformanceLevel() - .getMaxVersion()); - } - finally { - configurationManager.setErrorConfiguration("error-configuration.yaml"); - factory.setConfigurationManager(configurationManager); - } - - } - - @Test(expectedExceptions = SdcToscaParserException.class) - public void testCSARMissingConformanceLevelWithDefaultErrorConfig() throws - SdcToscaParserException { - ISdcCsarHelper missingCSARMetaCsarDefaultConfig = getCsarHelper("csars/service-missing-csar-meta-file.csar"); - missingCSARMetaCsarDefaultConfig.getConformanceLevel(); - } - -} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java deleted file mode 100644 index 04675b4..0000000 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java +++ /dev/null @@ -1,972 +0,0 @@ -package org.openecomp.sdc.impl; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; -import java.util.*; -import static org.hamcrest.CoreMatchers.is; - -import com.google.common.collect.ImmutableMap; -import org.apache.commons.lang3.tuple.Pair; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -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.Property; -import org.testng.annotations.Test; - -import fj.data.fingertrees.Node; - -public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { - - //region getServiceVfList - @Test - public void testNumberOfVfSunnyFlow() throws SdcToscaParserException { - List serviceVfList = fdntCsarHelper.getServiceVfList(); - assertNotNull(serviceVfList); - assertEquals(2, serviceVfList.size()); - } - - @Test - public void testGetNodeTemplateCustomizationUuid(){ - List serviceVfList = fdntCsarHelper.getServiceVfList(); - boolean found = false; - for (NodeTemplate nt : serviceVfList){ - if (nt.getName().equals("FDNT 1")){ - found = true; - assertEquals(fdntCsarHelper.getNodeTemplateCustomizationUuid(nt), "56179cd8-de4a-4c38-919b-bbc4452d2d73"); - } - } - assertTrue(found); - } - - @Test - public void testSingleVFWithNotMetadata() throws SdcToscaParserException { - //If there is no metadata on VF level - There is no VF's because the type is taken from metadata values. - List serviceVfList = rainyCsarHelperSingleVf.getServiceVfList(); - assertNotNull(serviceVfList); - assertEquals(0, serviceVfList.size()); - } - //endregion - - //region getNodeTemplatePropertyLeafValue - @Test - public void testNodeTemplateFlatProperty() throws SdcToscaParserException { - List serviceVfList = fdntCsarHelper.getServiceVfList(); - assertEquals("2", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "availability_zone_max_count")); - assertEquals("3", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "max_instances")); - assertEquals("some code", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_naming_code")); - } - - @Test - public void testNodeTemplateFlatFunctionProperty() throws SdcToscaParserException { - List serviceVfList = fdntCsarHelperWithInputs.getServiceVfList(); - assertEquals(null, fdntCsarHelperWithInputs.getNodeTemplatePropertyLeafValue(serviceVfList.get(1), "target_network_role")); - } - - @Test - public void testNodeTemplateNestedFunctionProperty() throws SdcToscaParserException { - List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - assertEquals(null, ipAssignCsarHelper.getNodeTemplatePropertyLeafValue(vfcs.get(0), "port_pd01_port_ip_requirements#ip_count_required#count")); - } - - @Test - public void testNodeTemplateNestedProperty() throws SdcToscaParserException { - List serviceVlList = fdntCsarHelper.getServiceVlList(); - NodeTemplate nodeTemplate = serviceVlList.get(0); - //System.out.println("node template " + nodeTemplate.toString()); - assertEquals("24", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#cidr_mask")); - assertEquals("7a6520b-9982354-ee82992c-105720", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_flows#vpn_binding")); - } - - @Test - public void testNodeTemplateNestedPropertyFromInput() throws SdcToscaParserException { - List serviceVfList = fdntCsarHelper.getServiceVfList(); - NodeTemplate nodeTemplate = serviceVfList.get(0); - //System.out.println("node template " + nodeTemplate.toString()); - assertEquals("true", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming#ecomp_generated_naming")); - assertEquals("FDNT_instance_VF_2", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming#naming_policy")); - } - - @Test - public void testNodeTemplateNestedPropertyNotExists() throws SdcToscaParserException { - List serviceVfList = fdntCsarHelper.getServiceVfList(); - String nodeTemplatePropertyLeafValue = fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_role#nf_naming#kuku"); - assertNull(nodeTemplatePropertyLeafValue); - } - - @Test - public void testNodeTemplateFlatPropertyByNotFoundProperty() throws SdcToscaParserException { - List serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList(); - String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "XXXX"); - assertNull(nodeTemplatePropertyLeafValue); - } - - @Test - public void testNodeTemplateFlatPropertyByNullProperty() throws SdcToscaParserException { - List serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList(); - String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), null); - assertNull(nodeTemplatePropertyLeafValue); - } - - @Test - public void testNodeTemplateFlatPropertyByNullNodeTemplate() throws SdcToscaParserException { - String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(null, "availability_zone_max_count"); - assertNull(nodeTemplatePropertyLeafValue); - } - //endregion - - //region getServiceVlList - @Test - public void testServiceVl() { - List vlList = fdntCsarHelper.getServiceVlList(); - assertEquals(1, vlList.size()); - assertEquals("exVL", vlList.get(0).getName()); - } - - @Test - public void testNumberOfVLRainyFlow() throws SdcToscaParserException { - List serviceVlList = rainyCsarHelperMultiVfs.getServiceVlList(); - assertNotNull(serviceVlList); - assertEquals(0, serviceVlList.size()); - } - //endregion - - //region getServiceNodeTemplatesByType - @Test - public void testServiceNodeTemplatesByType() throws SdcToscaParserException { - List serviceVfList = fdntCsarHelper.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Fdnt"); - assertNotNull(serviceVfList); - assertEquals(1, serviceVfList.size()); - } - - @Test - public void testServiceNodeTemplatesByNull() { - List nodeTemplates = rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType(null); - assertNotNull(nodeTemplates); - assertEquals(0, nodeTemplates.size()); - } - - @Test - public void testServiceNodeTemplatesByNotFoundProperty() { - List nodeTemplates = rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType("XXX"); - assertNotNull(nodeTemplates); - assertEquals(0, nodeTemplates.size()); - } - //endregion - - //region getTypeOfNodeTemplate - @Test - public void testGetTypeOfNodeTemplate() { - List serviceVfList = fdntCsarHelper.getServiceVfList(); - String typeOfNodeTemplate = fdntCsarHelper.getTypeOfNodeTemplate(serviceVfList.get(0)); - assertEquals("org.openecomp.resource.vf.Fdnt", typeOfNodeTemplate); - } - - @Test - public void testGetTypeOfNullNodeTemplate() { - String typeOfNodeTemplate = rainyCsarHelperMultiVfs.getTypeOfNodeTemplate(null); - assertNull(typeOfNodeTemplate); - } - //endregion - - //region getAllottedResources - @Test - public void testGetAllottedResources() { - List allottedResources = fdntCsarHelper.getAllottedResources(); - assertEquals(1, allottedResources.size()); - } - - @Test - public void testGetAllottedResourcesZero() { - List allottedResources = rainyCsarHelperMultiVfs.getAllottedResources(); - assertNotNull(allottedResources); - assertEquals(0, allottedResources.size()); - } - //endregion - - //region getVfcListByVf - @Test - public void testGetVfcFromVf() { - List vfcListByVf = fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID); - assertEquals(2, vfcListByVf.size()); - } - - @Test - public void testVfcListByNull() { - List vfcList = rainyCsarHelperMultiVfs.getVfcListByVf(null); - assertNotNull(vfcList); - assertEquals(0, vfcList.size()); - } - - @Test - public void testVfcListByNotFoundProperty() { - List vfcList = rainyCsarHelperMultiVfs.getVfcListByVf("XXX"); - assertNotNull(vfcList); - assertEquals(0, vfcList.size()); - } - //endregion - - //region getCpListByVf - @Test - public void testGetCpFromVf() { - List cpListByVf = fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID); - assertEquals(1, cpListByVf.size()); - NodeTemplate nodeTemplate = cpListByVf.get(0); - assertEquals("DNT_PORT", nodeTemplate.getName()); - } - - @Test - public void testGetCpFromVfByNullId() { - List cpListByVf = rainyCsarHelperMultiVfs.getCpListByVf(null); - assertNotNull(cpListByVf); - assertEquals(0, cpListByVf.size()); - } - - @Test - public void testGetCpFromVfXxx() { - List cpListByVf = rainyCsarHelperMultiVfs.getCpListByVf("XXXXX"); - assertNotNull(cpListByVf); - assertEquals(0, cpListByVf.size()); - } - //endregion - - //region getNodeTemplatePairsByReqName - @Test - public void testGetNodeTemplatePairsByReqName() { - List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding"); - assertNotNull(nodeTemplatePairsByReqName); - assertEquals(1, nodeTemplatePairsByReqName.size()); - Pair pair = nodeTemplatePairsByReqName.get(0); - NodeTemplate cp = pair.getLeft(); - NodeTemplate vfc = pair.getRight(); - assertEquals("DNT_PORT", cp.getName()); - assertEquals("DNT_FW_RHRG", vfc.getName()); - } - - @Test - public void testGetNodeTemplatePairsByReqNameWithNullVF() { - List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( - null, fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding"); - assertNotNull(nodeTemplatePairsByReqName); - assertEquals(0, nodeTemplatePairsByReqName.size()); - } - - @Test - public void testGetNodeTemplatePairsByReqNameWithEmptyVF() { - List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( - new ArrayList<>(), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding"); - assertNotNull(nodeTemplatePairsByReqName); - assertEquals(0, nodeTemplatePairsByReqName.size()); - } - - @Test - public void testGetNodeTemplatePairsByReqNameWithNullCap() { - List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( - fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), null, "binding"); - assertNotNull(nodeTemplatePairsByReqName); - assertEquals(0, nodeTemplatePairsByReqName.size()); - } - - @Test - public void testGetNodeTemplatePairsByReqNameWithEmptyCap() { - List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( - fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), new ArrayList<>(), "binding"); - assertNotNull(nodeTemplatePairsByReqName); - assertEquals(0, nodeTemplatePairsByReqName.size()); - } - - @Test - public void testGetNodeTemplatePairsByReqNameWithNullReq() { - List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( - fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), null); - assertNotNull(nodeTemplatePairsByReqName); - assertEquals(0, nodeTemplatePairsByReqName.size()); - } - - @Test - public void testGetNodeTemplatePairsByReqNameWithDummyReq() { - - List> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( - fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "XXX"); - assertNotNull(nodeTemplatePairsByReqName); - assertEquals(0, nodeTemplatePairsByReqName.size()); - } - //endregion - - //region getMembersOfVfModule - @Test - public void testGetMembersOfVfModule() { - NodeTemplate vf = fdntCsarHelper.getServiceVfList().get(0); - List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); - assertEquals(2, vfModulesByVf.size()); - for (Group group : vfModulesByVf) { - List membersOfVfModule = fdntCsarHelper.getMembersOfVfModule(vf, group); - assertNotNull(membersOfVfModule); - if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")) { - assertEquals(1, membersOfVfModule.size()); - NodeTemplate nodeTemplate = membersOfVfModule.get(0); - assertEquals("DNT_FW_RSG_SI_1", nodeTemplate.getName()); - } else { - assertEquals("fdnt1..Fdnt..mod_vmsi_dnt_fw_parent..module-1", group.getName()); - assertEquals(1, membersOfVfModule.size()); - NodeTemplate nodeTemplate = membersOfVfModule.get(0); - assertEquals("DNT_FW_RHRG", nodeTemplate.getName()); - } - } - } - - @Test - public void testMembersOfVfModuleByNullVf() { - List vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); - List nodeTemplates = fdntCsarHelper.getMembersOfVfModule(null, vfModulesByVf.get(0)); - assertNotNull(nodeTemplates); - assertEquals(0, nodeTemplates.size()); - } - - @Test - public void testMembersOfVfModuleByNullGroup() { - List serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList(); - List nodeTemplates = rainyCsarHelperMultiVfs.getMembersOfVfModule(serviceVfList.get(0), null); - assertNotNull(nodeTemplates); - assertEquals(0, nodeTemplates.size()); - } - //endregion - - //region getCpPropertiesFromVfc - @Test - public void testGetCpPropertiesFromVfc() { - List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - boolean isChecked = false; - - for (NodeTemplate vfc: vfcs) { - - if(vfc.getName().equalsIgnoreCase("abstract_pd_server")) - { - isChecked = true; - Map> cps = ipAssignCsarHelper.getCpPropertiesFromVfcAsObject(vfc); - - assertEquals(2,cps.size()); - Map pd01 = cps.get("port_pd01_port"); - assertEquals(5, pd01.size()); - - Map firstIpRequirements = (Map) ((List)pd01.get("ip_requirements")).get(0); - Map secondIpRequirements = (Map) ((List)pd01.get("ip_requirements")).get(1); - - assertEquals("subnet_role_4", firstIpRequirements.get("subnet_role")); - assertEquals(4, firstIpRequirements.get("ip_version")); - assertEquals(true, ((Map) firstIpRequirements.get("ip_count_required")).get("is_required")); - assertEquals("get_input:node_count", ((Map) firstIpRequirements.get("ip_count_required")).get("count").toString()); - assertEquals(false, ((Map)((Map)pd01.get("mac_requirements")).get("mac_count_required")).get("is_required")); - assertEquals("test_subnetpoolid", pd01.get("subnetpoolid")); - assertEquals("oam", pd01.get("network_role_tag")); - assertEquals(6, secondIpRequirements.get("ip_version")); - } - - } - assertTrue(isChecked); - } - - @Test - public void testGetCpPropertiesFromVfcForNullVFC() { - Map> cps = ipAssignCsarHelper.getCpPropertiesFromVfcAsObject(null); - assertNotNull(cps); - assertEquals(0, cps.size()); - } - //endregion - - //region getNodeTemplatePropertyAsObject - @Test - public void testGetNodeTemplatePropertyAsObject() { - List serviceVfList = fdntCsarHelper.getServiceVfList(); - assertEquals("2", fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "availability_zone_max_count")); - assertEquals(3, fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "max_instances")); - assertEquals("some code", fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "nf_naming_code")); - } - //endregion - - //region getServiceNodeTemplates - @Test - public void testServiceNodeTemplates() throws SdcToscaParserException { - List serviceVfList = fdntCsarHelper.getServiceNodeTemplates(); - assertNotNull(serviceVfList); - assertEquals(3, serviceVfList.size()); - assertEquals(serviceVfList.get(2).getName(), "exVL"); - } - //endregion - - //region filterNodeTemplatePropertiesByValue - @Test - public void testFilterNodeTemplatePropertiesByContains() { - List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - boolean isChecked = false; - for (NodeTemplate vfc: vfcs) { - if(vfc.getName().equalsIgnoreCase("abstract_pd_server")) - { - isChecked = true; - Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfc, FilterType.CONTAINS, "get_input"); - - assertEquals(7, filteredInputs.size()); - assertEquals("get_input:availabilityzone_name", filteredInputs.get("compute_pd_server_availability_zone")); - assertEquals("get_input:[pd_server_names, 0]", filteredInputs.get("compute_pd_server_name")); - assertEquals("get_input:node_count", filteredInputs.get("port_pd01_port_ip_requirements#ip_count_required#count")); - - break; - } - - } - assertTrue(isChecked); - } - - @Test - public void testFilterNodeTemplatePropertiesByDummyContains() { - List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), FilterType.CONTAINS, "dummy"); - assertNotNull(filteredInputs); - assertEquals(0, filteredInputs.size()); - } - - @Test - public void testFilterNodeTemplatePropertiesByEquals() { - List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - boolean isChecked = false; - for (NodeTemplate vfc: vfcs) { - if(vfc.getName().equalsIgnoreCase("abstract_pd_server")) - { - isChecked = true; - Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfc, FilterType.EQUALS, "oam"); - - assertEquals(2, filteredInputs.size()); - assertEquals("oam", filteredInputs.get("port_pd02_port_network_role_tag")); - assertEquals("oam", filteredInputs.get("port_pd01_port_network_role_tag")); - break; - } - - } - assertTrue(isChecked); - } - - @Test - public void testFilterNodeTemplatePropertiesByDummyEquals() { - List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), FilterType.EQUALS, "dummy"); - assertNotNull(filteredInputs); - assertEquals(0, filteredInputs.size()); - } - - @Test - public void testFilterNodeTemplatePropertiesByNullFilterType() { - List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), null, "ddc"); - assertNotNull(filteredInputs); - assertEquals(0, filteredInputs.size()); - } - - @Test - public void testFilterNodeTemplatePropertiesByNullPattern() { - List vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), FilterType.EQUALS, null); - assertNotNull(filteredInputs); - assertEquals(0, filteredInputs.size()); - } - - @Test - public void testFilterNodeTemplatePropertiesByNullVfc() { - Map filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(null, FilterType.EQUALS, "ddc"); - assertNotNull(filteredInputs); - assertEquals(0, filteredInputs.size()); - } - //endregion - - //region getServiceNodeTemplateBySdcType - @Test - public void testServiceNodeTemplateBySdcType() { - List serviceVfList = fdntCsarHelper.getServiceNodeTemplateBySdcType(SdcTypes.VF); - assertNotNull(serviceVfList); - assertEquals(serviceVfList.size(), 2); - assertEquals(serviceVfList.get(0).getName(), "FDNT 1"); - } - - @Test - public void testServiceNodeTemplateBySdcTypeServiceProxy() { - List serviceProxies = portMirroring.getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY); - assertNotNull(serviceProxies); - assertEquals(serviceProxies.size(), 2); - } - - @Test - public void testServiceNodeTemplateByNullSdcType() { - List serviceVfList = fdntCsarHelper.getServiceNodeTemplateBySdcType(null); - assertNotNull(serviceVfList); - assertEquals(serviceVfList.size(), 0); - } - //endregion - - //region getNodeTemplateBySdcType - @Test - public void testNodeTemplateBySdcType() { - List vfList = fdntCsarHelper.getServiceVfList(); - List vfcList = fdntCsarHelper.getNodeTemplateBySdcType(vfList.get(0), SdcTypes.VFC); - assertNotNull(vfcList); - assertEquals(2, vfcList.size()); - assertEquals("DNT_FW_RSG_SI_1", vfcList.get(0).getName()); - } - - @Test - public void testNodeTemplateByNullSdcType() { - List vfList = fdntCsarHelper.getServiceVfList(); - List vfcList = fdntCsarHelper.getNodeTemplateBySdcType(vfList.get(0), null); - assertNotNull(vfcList); - assertEquals(0, vfcList.size()); - } - - @Test - public void testNodeTemplateBySdcTypeNullNT() { - List vfcList = fdntCsarHelper.getNodeTemplateBySdcType(null, SdcTypes.VFC); - assertNotNull(vfcList); - assertEquals(0, vfcList.size()); - } - //endregion - - //region getVnfConfig - @Test - public void testGetVnfConfig() { - NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); - assertNotNull(vnfConfig); - assertEquals("vnfConfiguration", vnfConfig.getMetaData().getValue("name")); - } - - @Test - public void testGetVnfConfigByNonFoundVNF() { - NodeTemplate vnfConfig = ipAssignCsarHelper.getVnfConfig("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - assertNull(vnfConfig); - } - - @Test - public void testGetVnfConfigByDummyUUID() { - NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig("XXX"); - assertNull(vnfConfig); - } - - @Test - public void testGetVnfConfigByNullUUID() { - NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig(null); - assertNull(vnfConfig); - } - - @Test - public void testGetVfcTypWithoutVnf() { - List vfcList = nfodCsarHlper.getVfcListByVf("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); - assertNotNull(vfcList); - assertEquals(2, vfcList.size()); - } - //endregion - - //region nested vfc - @Test - public void testNestedVfcByExistCvfc() { - List vfcList = nestedVfcCsarHlper.getVfcListByVf("71389f8b-8671-4a43-a991-59fb621d3615"); - assertNotNull(vfcList); - assertEquals(vfcList.size(), 2); - assertEquals("VFC1 DUMMY", vfcList.get(0).getName()); - assertEquals("VF_VNF", vfcList.get(1).getName()); - } - - @Test - public void testNestedVfcByNullVf() { - List vfcList = nestedVfcCsarHlper.getVfcListByVf(null); - assertNotNull(vfcList); - assertEquals(0, vfcList.size()); - } - - @Test - public void testNestedVfcByDummyVf() { - List vfcList = nestedVfcCsarHlper.getVfcListByVf("dummy"); - assertNotNull(vfcList); - assertEquals(0, vfcList.size()); - } - //endregion - - //region hasTopology - @Test - public void testHasTopologyByVF() { - List vfList = nestedVfcCsarHlper.getServiceVfList(); - boolean hasTopology = nestedVfcCsarHlper.hasTopology(vfList.get(0)); - assertEquals(true, hasTopology); - } - - @Test - public void testHasTopologyByCVFC() { - List vfcList = nestedVfcCsarHlper.getVfcListByVf("71389f8b-8671-4a43-a991-59fb621d3615"); - boolean hasTopology = nestedVfcCsarHlper.hasTopology(vfcList.get(1)); - assertEquals(true, hasTopology); - } - - @Test - public void testHasTopologyByVL() { - List serviceVlList = fdntCsarHelper.getServiceVlList(); - boolean hasTopology = fdntCsarHelper.hasTopology(serviceVlList.get(0)); - assertEquals(false, hasTopology); - } - - @Test - public void testHasTopologyByNull() { - boolean hasTopology = fdntCsarHelper.hasTopology(null); - assertEquals(false, hasTopology); - } - //endregion - - //region getNodeTemplateChildren - @Test - public void testGetNodeTemplatesListOfNodeTemplateByVF() { - List vfList = fdntCsarHelper.getServiceVfList(); - List children = fdntCsarHelper.getNodeTemplateChildren(vfList.get(0)); - assertNotNull(children); - assertEquals(3, children.size()); - - children.sort(Comparator.comparing(NodeTemplate::getName)); - - assertEquals("DNT_FW_RSG_SI_1", children.get(1).getName()); - assertEquals("VFC", children.get(1).getMetaData().getValue("type")); - assertEquals("DNT_PORT", children.get(2).getName()); - assertEquals("CP", children.get(2).getMetaData().getValue("type")); - } - - @Test - public void testGetNodeTemplatesListOfNodeTemplateByVFC() { - List vfList = nestedVfcCsarHlper.getServiceVfList(); - List vfChildren = nestedVfcCsarHlper.getNodeTemplateChildren(vfList.get(0)); - assertNotNull(vfChildren); - assertEquals(vfChildren.size(), 2); - vfChildren.sort(Comparator.comparing(NodeTemplate::getName)); - assertEquals("VFC1 DUMMY", vfChildren.get(0).getName()); - assertEquals("VF_VNF", vfChildren.get(1).getName()); - assertEquals("CVFC", vfChildren.get(1).getMetaData().getValue("type")); - - - List vfcChildren = nestedVfcCsarHlper.getNodeTemplateChildren(vfChildren.get(1)); - assertNotNull(vfcChildren); - assertEquals(vfcChildren.size(), 3); - vfcChildren.sort(Comparator.comparing(NodeTemplate::getName)); - assertEquals("Test NIC 02_wan_port", vfcChildren.get(0).getName()); - assertEquals("Test NIC_wan_port", vfcChildren.get(1).getName()); - assertEquals("VF", vfcChildren.get(2).getName()); - } - - @Test - public void testGetNodeTemplatesListOfNodeTemplateByNull() { - List children = fdntCsarHelper.getNodeTemplateChildren(null); - assertNotNull(children); - assertEquals(0, children.size()); - } - //endregion - - // added by QA - // Get specific VNF properties - @Test - public void testGetVnfConfigGetProperties() { - NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); - assertNotNull(vnfConfig); - assertEquals("vnfConfiguration", vnfConfig.getMetaData().getValue("name")); - - String manufacturer_reference_number = nfodCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#ATT_part_12345_for_FortiGate-VM00#vendor_info#manufacturer_reference_number"); - String num_cpus = nfodCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#ATT_part_67890_for_FortiGate-VM01#compute_flavor#num_cpus"); - String sp_part_number = nfodCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#ATT_part_67890_for_FortiGate-VM01#sp_part_number"); - - assertEquals("FortiGate-VM00",manufacturer_reference_number); - assertEquals("10",num_cpus); - assertEquals("ATT_part_67890_for_FortiGate-VM01",sp_part_number); - } - - // added by QA - // Check that get vnfconfiguration not return as VFC - @Test - public void testGetVfcTypWithoutVnfCheckNames() { - List vfcList = nfodCsarHlper.getVfcListByVf("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); - assertNotNull(vfcList); - assertEquals(2, vfcList.size()); - for (int i = 0; i < vfcList.size(); i++) { - - String Name= vfcList.get(i).getName(); - - assertEquals(false, Name.equals("vFW_VNF_Configuration")); - - } - } - - @Test - public void testNewGetVnfConfigGetProperties() { - NodeTemplate vnfConfig = nfodNEWCsarHlper.getVnfConfig("a6587663-b27f-4e88-8a86-604604302ce6"); - assertNotNull(vnfConfig); - assertEquals("vnfConfiguration", vnfConfig.getMetaData().getValue("name")); - - //Deployment flavor 1 - String manufacturer_reference_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#123456#vendor_info#manufacturer_reference_number"); - String num_cpus = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#123456#compute_flavor#num_cpus"); - String sp_part_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#123456#sp_part_number"); - - assertEquals("234567",manufacturer_reference_number); - assertEquals("2",num_cpus); - assertEquals("123456",sp_part_number); - - //Deployment flavor 2 - manufacturer_reference_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#FG_partNumbereJqQjUkteF1#vendor_info#manufacturer_reference_number"); - num_cpus = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#FG_partNumbereJqQjUkteF1#compute_flavor#num_cpus"); - sp_part_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#FG_partNumbereJqQjUkteF1#sp_part_number"); - - assertEquals("EP_manufacturerReferenceNumberkbAiqZZNzx1",manufacturer_reference_number); - assertEquals("1",num_cpus); - assertEquals("FG_partNumbereJqQjUkteF1",sp_part_number); - } - - // added by QA - // Check that get vnfconfiguration not return as VFC - @Test - public void testNewGetVfcTypWithoutVnfCheckNames() { - List vfcList = nfodNEWCsarHlper.getVfcListByVf("a6587663-b27f-4e88-8a86-604604302ce6"); - assertNotNull(vfcList); - assertEquals(1, vfcList.size()); - for (int i = 0; i < vfcList.size(); i++) { - - String Name= vfcList.get(i).getName(); - - assertEquals(false, Name.equals("name_6GkVrOjnGp1_VNF_Configuration")); - } - } - - //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() { - //port_pd01_port_ip_requirements is of type list - //This test covers: - // 1) "default" resolving - // 2) complex type resolving - // 3) List access resolving - List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_ip_requirements"); - assertTrue(propertyAsObject instanceof ArrayList); - assertEquals(2, ((ArrayList) propertyAsObject).size()); - //port_pd01_port_ip_requirements: - //- get_input: [ip_requirements, 0] - //- get_input: [ip_requirements, 1] - assertEquals("subnet_role_4", ((Map) ((ArrayList) propertyAsObject).get(0)).get("subnet_role")); - assertEquals("subnet_role_6", ((Map) ((ArrayList) propertyAsObject).get(1)).get("subnet_role")); - } - - @Test - public void testResolveGetInputForPrimitiveTypeString() { - //This test covers "default" resolving of primitive - as Object - List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_network_role_tag"); - assertEquals("oam", propertyAsObject); - } - - @Test - public void testResolveGetInputForPrimitiveTypeInteger() { - //This test covers "default" resolving of primitive - as String - List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - String propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyLeafValue(vfcs.get(0), "port_pd01_port_order"); - assertEquals("1", propertyAsObject); - } - - @Test - public void testResolveGetInputForMap() { - //This test covers "default" resolving of primitive - as Map - List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd02_port_ip_requirements#ip_count_required"); - assertTrue(propertyAsObject instanceof Map); - assertEquals(false, ((Map)propertyAsObject).get("is_required")); - } - - @Test - public void testResolveGetInputForAllHierarchy() { - //This test covers "default" resolving from service level - List vfs = resolveGetInputCsar.getServiceVfList(); - Object vfPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfs.get(0), "vm_count"); - assertEquals(2, vfPropertyAsObject); - //This test covers property assignment resolving on VFI level (service template), from Vf level - List vfcs = resolveGetInputCsar.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.VFC); - Object vfcPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "my_count"); - assertEquals(2, vfcPropertyAsObject); //takes it from upper level (VF) property - } - - @Test - public void testResolveGetInputNoDefValueInnerLevel() { - //This test covers resolving when no "default" value is supplied to the input - should be null - VF/VFCI level - List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - String propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyLeafValue(vfcs.get(0), "index_value"); - assertNull(propertyAsObject); - - } - - @Test - public void testResolveGetInputNoDefValueServiceLevel() { - //This test covers resolving when no "default" value is supplied to the input - should be null - Service/VFI level - List vfs = resolveGetInputCsar.getServiceVfList(); - Object vfPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfs.get(0), "port_order"); - assertNull(vfPropertyAsObject); - - } - //endregion - - // region Added by QA - Continue with testings of resolve get_input - - @Test - public void testResolveGetInputForComplexTypeAndListWithFalseValue() - { - List vfcs = resolveGetInputCsarFalse.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_ip_requirements"); - assertTrue(propertyAsObject instanceof ArrayList); - assertEquals(2, ((ArrayList) propertyAsObject).size()); - assertEquals("get_input:[ip_requirements, 0]", ((ArrayList) propertyAsObject).get(0).toString()); - assertEquals("get_input:[ip_requirements, 1]", ((ArrayList) propertyAsObject).get(1).toString()); - } - - @Test - public void testResolveGetInputForPrimitiveTypeStringWithFalseValue() { - List vfcs = resolveGetInputCsarFalse.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_network_role_tag"); - assertEquals("get_input:role_tag_oam", propertyAsObject.toString()); - } - - @Test - public void testResolveGetInputForPrimitiveTypeListWithFalseValue() { - List vfcs = resolveGetInputCsarFalse.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_name"); - assertEquals("[get_input:[pd_server_names, 0]]", propertyAsObject.toString()); - } - - //@Test // Maybe a bug here.... need to check with Esti - Mait was sent. - public void testResolveGetInputForPrimitiveTypeList() { - List vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_name"); - assertEquals("\"ZRDM1MOGX01MPD001\"", propertyAsObject.toString()); - } - - @Test - public void testResolveGetInputForPrimitiveNullValue() { - List vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - @SuppressWarnings("unchecked") - ListpropertyAsObject = (List) resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_availability_zone"); - assertNull(propertyAsObject.get(0)); - } - @Test - public void testResolveGetInputForPrimitiveIPValue() { - List vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Object propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "vm_image_name"); - assertEquals("107.239.36.5", propertyAsObject.toString()); - } - - //QA region getServiceNodeTemplateByNodeName tests - - @Test - public void getServiceNodeTemplateByNodeNameTypeVF() { - NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("VF_1_V_port_1 0"); - assertNotNull(nodeTemplate); - assertEquals(nodeTemplate.getName(), "VF_1_V_port_1 0"); - assertEquals(nodeTemplate.getMetaData().getValue("type"), "VF"); - } - - @Test - public void getServiceNodeTemplateByNodeNameTypeVL() { - NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtVL 0"); - assertNotNull(nodeTemplate); - assertEquals(nodeTemplate.getName(), "ExtVL 0"); - assertEquals(nodeTemplate.getMetaData().getValue("type"), "VL"); - } - - @Test - public void getServiceNodeTemplateByNodeNameTypeCP() { - NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtCP 0"); - assertNotNull(nodeTemplate); - assertEquals(nodeTemplate.getName(), "ExtCP 0"); - assertEquals(nodeTemplate.getMetaData().getValue("type"), "CP"); - } - - @Test - public void getServiceNodeTemplateByNodeNameTypePNF() { - NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("PNF TEST 0"); - assertNotNull(nodeTemplate); - assertEquals(nodeTemplate.getName(), "PNF TEST 0"); - assertEquals(nodeTemplate.getMetaData().getValue("type"), "PNF"); - } - - //QA region getServiceNodeTemplateBySdcType tests - - @Test - public void getServiceNodeTemplateBySdcType_VF() { - List vfList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Vf1VPort1"); - assertEquals(2, vfList.size()); - assertEquals("VF_1_V_port_1", vfList.get(0).getMetaData().getValue("name")); - } - // endregion Added by QA - Continue with testings of resolve get_input - - - @Test - public void testResolveGetInputArrayStructure() { - List vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); - Object propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_name"); - assertEquals( ((ArrayList)propertyAsObject).get(0).toString(), "\"ZRDM1MOGX01MPD001\""); - propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_ip_requirements"); - assertEquals( ((ArrayList)propertyAsObject).get(1), null); - } - - @Test - public void testServiceNodeTemplateByCRType() { - List serviceCRList = csarHelperServiceWithCrs.getServiceNodeTemplateBySdcType(SdcTypes.CR); - assertNotNull(serviceCRList); - assertEquals(serviceCRList.size(), 2); - assertEquals(serviceCRList.get(0).getName(), "chaya best cr 1"); - assertEquals(serviceCRList.get(0).getType(), "org.openecomp.resource.cr.ChayaBestCr"); - assertEquals(serviceCRList.get(1).getName(), "chaya best cr 0"); - assertEquals(serviceCRList.get(1).getType(), "org.openecomp.resource.cr.ChayaBestCr"); - } - - @Test - public void testGetCPOfCRNodeTemplate() { - NodeTemplate nodeTemplate = csarHelperServiceWithCrs.getServiceNodeTemplateByNodeName("chaya best cr 0"); - List crCpChildren = csarHelperServiceWithCrs.getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CP); - assertEquals(crCpChildren.get(0).getName(), "ContrailPort 0"); - assertEquals(crCpChildren.get(0).getMetaData().getValue("type"), SdcTypes.CP.name()); - } - - @Test - public void testServiceCRInstanceProps() { - List serviceCrList = csarHelperServiceWithCrs.getServiceNodeTemplateBySdcType(SdcTypes.CR); - assertNotNull(serviceCrList); - NodeTemplate crTemplate = serviceCrList.get(0); - assertNotNull(crTemplate); - assertEquals(crTemplate.getPropertyValue("nf_naming").toString(), ImmutableMap.of("ecomp_generated_naming", "true").toString()); - assertEquals(crTemplate.getPropertyValue("contrailport0_virtual_network"), "chaya"); - } - - -} - - diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserReqAndCapTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserReqAndCapTest.java deleted file mode 100644 index 8d800e1..0000000 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserReqAndCapTest.java +++ /dev/null @@ -1,273 +0,0 @@ -package org.openecomp.sdc.impl; - -import org.openecomp.sdc.tosca.parser.impl.SdcTypes; -import org.openecomp.sdc.toscaparser.api.CapabilityAssignments; -import org.openecomp.sdc.toscaparser.api.CapabilityAssignment; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.toscaparser.api.RequirementAssignments; -import org.openecomp.sdc.toscaparser.api.elements.Metadata; -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 - - //QA tests region for US 319197 -port mirroring- - - //get-CapabilitiesOf (All Types) - @Test - public void getServiceNodeTemplateCapabilitiesOfTypeVF() { - List serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF); - CapabilityAssignments capabilitiesOfVF = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVfList.get(0)); - assertEquals(capabilitiesOfVF.getAll().size(),12); - assertNotNull(capabilitiesOfVF.getCapabilityByName("neutronport0.network.incoming.packets.rate")); - } - - @Test - public void getServiceNodeTemplateCapabilitiesOfTypeExVL() { - List serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL"); - CapabilityAssignments capabilitiesOfExtVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceExtVlList.get(0)); - assertEquals(capabilitiesOfExtVL.getAll().size(),2); - assertNotNull(capabilitiesOfExtVL.getCapabilityByName("virtual_linkable").getProperties()); - } - - @Test - public void getServiceNodeTemplateCapabilitiesOfTypeVL() { - List serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network"); - CapabilityAssignments capabilitiesOfVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVlList.get(0)); - assertEquals(capabilitiesOfVL.getAll().size(),2); - assertNotNull(capabilitiesOfVL.getCapabilityByName("link").getProperties()); - } - - @Test - public void getServiceNodeTemplateCapabilitiesOfTypeCP() { - List serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); - CapabilityAssignments capabilitiesOfCP = QAServiceForToscaParserTests.getCapabilitiesOf(serviceCpList.get(0)); - assertEquals(capabilitiesOfCP.getAll().size(),2); - assertNotNull(capabilitiesOfCP.getCapabilityByName("internal_connectionPoint")); - } - - @Test - public void getServiceNodeTemplateCapabilitiesOfTypePNF() { - List servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF); - CapabilityAssignments capabilitiesOfPnf = QAServiceForToscaParserTests.getCapabilitiesOf(servicePnfs.get(0)); - assertEquals(capabilitiesOfPnf.getAll().size(),1); - assertNotNull(capabilitiesOfPnf.getCapabilityByName("feature")); - } - - //get-RequirementsOf (All Types)----------------------------- - - @Test - public void getServiceNodeTemplateRequirementsOfTypeVF() { - List serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF); - RequirementAssignments requirementsOfVF = QAServiceForToscaParserTests.getRequirementsOf(serviceVfList.get(6)); - assertEquals(requirementsOfVF.getAll().size(),3); -// RequirementAssignments requirementsByName = - assertEquals(requirementsOfVF.getRequirementsByName("dependency").getAll().size(),2 ); - //check that API return empty list if requirement property not exist. - assertEquals(requirementsOfVF.getRequirementsByName("blabla").getAll().size(),0); - } - - @Test - public void getServiceNodeTemplateRequirementsOfTypeExVL() { - List serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL"); - RequirementAssignments requirementsOfExtVL = QAServiceForToscaParserTests.getRequirementsOf(serviceExtVlList.get(0)); - assertEquals(requirementsOfExtVL.getAll().size(),1); - } - - @Test - public void getServiceNodeTemplateRequirementsOfTypeVL() { - List serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network"); - RequirementAssignments requirementsOfVL = QAServiceForToscaParserTests.getRequirementsOf(serviceVlList.get(1)); - assertEquals(requirementsOfVL.getAll().size(),2); - assertNotNull(requirementsOfVL.getRequirementsByName("dependency")); - } - - @Test - public void getServiceNodeTemplateRequirementsOfTypeCP() { - List serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); - RequirementAssignments requirementsOfCP = QAServiceForToscaParserTests.getRequirementsOf(serviceCpList.get(0)); - assertEquals(requirementsOfCP.getAll().size(),2); - assertEquals(requirementsOfCP.getRequirementsByName("virtualBinding").getAll().size(),1); - } - - @Test - public void getServiceNodeTemplateRequirementsOfTypePNF() { - List servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF); - RequirementAssignments requirementsOfPnf = QAServiceForToscaParserTests.getRequirementsOf(servicePnfs.get(0)); - assertEquals(requirementsOfPnf.getAll().size(),2); - assertNotNull(requirementsOfPnf.getRequirementsByName("feature")); - } - - //QA end region for US 319197 -port mirroring - - // Added by QA CapabilityAssignments - @Test - public void testGetCapabilitiesByType() { - List vfs = resolveGetInputCsarQA.getServiceVfList(); - CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); - assertNotNull(capabilityAssignments); - CapabilityAssignments capabilitiesByType = capabilityAssignments.getCapabilitiesByType("tosca.capabilities.Scalable"); - int capsQty = capabilitiesByType.getAll().size(); - assertEquals(1, capsQty); - CapabilityAssignment capabilityByName = capabilitiesByType.getCapabilityByName("abstract_pd_server.scalable_pd_server"); - assertNotNull(capabilityByName); - } - - @Test - public void testGetCapabilityByName() { - List vfs = resolveGetInputCsarQA.getServiceVfList(); - CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); - assertNotNull(capabilityAssignments); - CapabilityAssignment capabilityByName = capabilityAssignments.getCapabilityByName("abstract_pd_server.disk.iops_pd_server"); - assertNotNull(capabilityByName); - String capName = capabilityByName.getName(); - assertEquals(capName, "abstract_pd_server.disk.iops_pd_server"); - } - - @Test - public void testGetCapabilitiesGetAll() { - List vfs = resolveGetInputCsarQA.getServiceVfList(); - CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); - assertNotNull(capabilityAssignments); - int capsAssignmentSize = capabilityAssignments.getAll().size(); - assertEquals(65, capsAssignmentSize); - } - - // Added by QA RequirementsAssignments - @Test - public void testGetRequirementsByName() { - List vfs = resolveReqsCapsCsarQA.getServiceVfList(); - List cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); - RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0)); - assertNotNull(requirementAssignments); - assertEquals(2, requirementAssignments.getAll().size()); - assertEquals("DNT_FW_RHRG2", requirementAssignments.getRequirementsByName("binding").getAll().get(1).getNodeTemplateName()); - - } - - @Test - public void testRequirementAssignmentGetNodeGetCapability() { - List vfs = resolveReqsCapsCsarQA.getServiceVfList(); - List cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); - RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0)); - assertNotNull(requirementAssignments); - String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName(); - String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName(); - assertEquals(nodeTemplateName, "DNT_FW_RHRG"); - assertNull(capabilityName); - } - - - @Test - public void testRequirementAssignmentGetCapability() { - List cps = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); - RequirementAssignments requirementAssignments = QAServiceForToscaParserTests.getRequirementsOf(cps.get(0)); - assertNotNull(requirementAssignments); - String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName(); - String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName(); - assertEquals(nodeTemplateName, "ExtVL 0"); - assertEquals(capabilityName,"tosca.capabilities.network.Linkable"); - } - - @Test - public void testGetCapabilityProperties() { - List vfs = fdntCsarHelper.getServiceVfList(); - List cps = fdntCsarHelper.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); - CapabilityAssignments capabilityAssignments = cps.get(0).getCapabilities(); - assertNotNull(capabilityAssignments); - assertEquals(12, capabilityAssignments.getAll().size()); - CapabilityAssignment xxxCapability = capabilityAssignments.getCapabilityByName("xxx"); - //GetInput property - resolved in any case - String getInputProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "DeploymentFlavor"); - assertEquals("{aaa=bbb}", getInputProp); - //Simple property - String simpleProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "distribution"); - assertEquals("rhel", simpleProp); - } - -} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java deleted file mode 100644 index 75f904f..0000000 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.openecomp.sdc.impl; - -import org.testng.annotations.Test; -import org.openecomp.sdc.toscaparser.api.parameters.Input; - -import java.util.List; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - -public class ToscaParserServiceInputTest extends SdcToscaParserBasicTest { - - //region getServiceInputs - @Test - public void testGetServiceInputs(){ - List serviceInputs = fdntCsarHelper.getServiceInputs(); - assertNotNull(serviceInputs); - assertEquals(1, serviceInputs.size()); - } - - @Test - public void testServiceInputs() { - List inputs = rainyCsarHelperSingleVf.getServiceInputs(); - assertNotNull(inputs); - assertEquals(0, inputs.size()); - } - //endregion - - //region getServiceInputLeafValueOfDefault - @Test - public void testGetServiceInputLeafValue(){ - String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default"); - assertEquals("test service naming", serviceInputLeafValue); - } - -// @Test -// public void testGetServiceInputLeafValueWithGetInput(){ -// String serviceInputLeafValue = fdntCsarHelperWithInputs.getServiceInputLeafValueOfDefault("my_input#default"); -// assertEquals(null, serviceInputLeafValue); -// } - - @Test - public void testGetServiceInputLeafValueNotExists(){ - String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default#kuku"); - assertNull(serviceInputLeafValue); - } - - @Test - public void testGetServiceInputLeafValueNull(){ - String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault(null); - assertNull(serviceInputLeafValue); - } - //endregion - - //region getServiceInputLeafValueOfDefaultAsObject - @Test - public void testGetServiceInputLeafValueOfDefaultAsObject() { - Object serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default"); - assertEquals("test service naming", serviceInputLeafValue); - } - - @Test - public void testGetServiceComplexInputLeafValueOfDefault() { - String serviceInputLeafValue = fdntCsarHelperWithInputs.getServiceInputLeafValueOfDefault("complex_input#default#ipv4_subnet_default_assignment#cidr_mask"); - assertEquals(serviceInputLeafValue, "24"); - } - - @Test - public void testGetServiceDummyComplexInputLeafValueOfDefault() { - String serviceInputLeafValue = fdntCsarHelperWithInputs.getServiceInputLeafValueOfDefault("complex_input#default#ipv4_subnet_default_assignment#XXX"); - assertNull(serviceInputLeafValue); - } - - - //endregion -} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java deleted file mode 100644 index 7570ced..0000000 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.openecomp.sdc.impl; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; - -import java.util.*; -import java.util.stream.Collectors; - -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -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; -import org.openecomp.sdc.toscaparser.api.Property; - -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.assertNull; - -public class ToscaParserSubsMappingsTest extends SdcToscaParserBasicTest { - - //region getServiceSubstitutionMappingsTypeName - @Test - public void testGetServiceSubstitutionMappingsTypeName() { - String serviceSubstitutionMappingsTypeName = fdntCsarHelper.getServiceSubstitutionMappingsTypeName(); - assertEquals("org.openecomp.service.ServiceFdnt", serviceSubstitutionMappingsTypeName); - } - - @Test - public void testServiceSubstitutionMappingsTypeName() { - String substitutionMappingsTypeName = rainyCsarHelperMultiVfs.getServiceSubstitutionMappingsTypeName(); - assertNull(substitutionMappingsTypeName); - } - //endregion - - //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)); -// 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)); -// 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 { - List serviceVfList = fdntCsarHelper.getServiceVfList(); - String sName = serviceVfList.get(0).getName(); - assertEquals(sName,"FDNT 1"); - - List ActualReqsValues = new ArrayList<>(Arrays.asList( )); - - List lRequirements = serviceVfList.get(0).getRequirements().getAll(); - - assertEquals(fdntCsarHelper_Data.get("FDNT").get("requirements").size(),lRequirements.size()); // - - // Continue from here after bug is fixed ! ! ! ! - Test the Requirements values - } - -} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserValidationIssueTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserValidationIssueTest.java deleted file mode 100644 index 60119c4..0000000 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserValidationIssueTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.openecomp.sdc.impl; - -import org.apache.commons.io.IOUtils; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.config.ConfigurationManager; -import org.openecomp.sdc.tosca.parser.config.JtoscaValidationIssueConfiguration; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.toscaparser.api.common.JToscaValidationIssue; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.net.URL; -import java.util.List; -import java.util.stream.Collectors; - -import static org.testng.Assert.assertEquals; - -public class ToscaParserValidationIssueTest extends SdcToscaParserBasicTest { - protected static ConfigurationManager configurationManager = ConfigurationManager.getInstance(); - - @BeforeClass - public void loadJtoscaValidationIssueConfiguration() throws IOException { - //load the tests dedicated configuration - configurationManager.setJtoscaValidationIssueConfiguration( "jtosca-validation-issue-configuration-test.yaml"); - factory.setConfigurationManager(configurationManager); - } - - @AfterClass - public void loadJtoscaValidationIssueOriginalConfiguration() throws IOException { - //load the tests dedicated configuration - configurationManager.setJtoscaValidationIssueConfiguration("jtosca-validation-issue-configuration.yaml"); - factory.setConfigurationManager(configurationManager); - - } - - - @Test - public void testNoValidationIssues() throws SdcToscaParserException { - ISdcCsarHelper rainyCsarHelper = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar");//conformance level 3.0 - - //List notAnalyzedReport = factory.getNotAnalyzadExceptions(); - //assertEquals( notAnalyzedReport.size(),0); - List warningsReport = factory.getWarningExceptions(); - assertEquals( warningsReport.size(),0); - List criticalsReport = factory.getCriticalExceptions(); - assertEquals( criticalsReport.size(),0); - } - @Test - public void testGetLowSinceConformanceLevel() throws SdcToscaParserException { - ISdcCsarHelper fdntCsarHelperWithInputs = getCsarHelper("csars/service-NfodService-csar.csar");//conformance level 3.0 - //Service level - - List notAnalyzedReport = factory.getNotAnalyzadExceptions(); - assertEquals( notAnalyzedReport.size(),10); - //JE003 high CL 4.0 - assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE003")).collect(Collectors.toList()).size(), 2); - assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE235")).collect(Collectors.toList()).size(), 7); - assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE236")).collect(Collectors.toList()).size(), 1); - List warningsReport = factory.getWarningExceptions(); - assertEquals( warningsReport.size(),14); - assertEquals( warningsReport.stream().filter(w->w.getCode().equals("JE006")).collect(Collectors.toList()).size(), 13); - //JE004 low CL 2.0 - assertEquals( warningsReport.stream().filter(w->w.getCode().equals("JE004")).collect(Collectors.toList()).size(), 1); - List criticalsReport = factory.getCriticalExceptions(); - assertEquals( criticalsReport.size(),0); - } - - @Test(expectedExceptions = SdcToscaParserException.class) - public void testCriticalIssueThrowsSdcToscaParserException() throws SdcToscaParserException { - getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0 - } - - @Test - public void testMultiSinceConformanceLevelIssues() { - try { - ISdcCsarHelper Nfod2images = getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0 - } catch (SdcToscaParserException e) { - System.out.println("SdcToscaParserException is caught here - this is WAD in this specific test."); - } - List notAnalyzedReport = factory.getNotAnalyzadExceptions(); - assertEquals(3, notAnalyzedReport.size()); - List warningsReport = factory.getWarningExceptions(); - assertEquals( 0, warningsReport.size()); - List criticalsReport = factory.getCriticalExceptions(); - assertEquals( 22, criticalsReport.size()); - //JE006 multy values sinceCsarConformanceLevel - assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE006")).collect - (Collectors.toList()).size(), 18); - assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE003")).collect - (Collectors.toList()).size(), 4); - } - - -} diff --git a/src/test/java/org/openecomp/sdc/impl/myTest.java b/src/test/java/org/openecomp/sdc/impl/myTest.java deleted file mode 100644 index 2f0da7f..0000000 --- a/src/test/java/org/openecomp/sdc/impl/myTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.openecomp.sdc.impl; - -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.testng.annotations.Test; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; - -import java.io.File; -import java.util.List; - -import static org.openecomp.sdc.impl.SdcToscaParserBasicTest.getCsarHelper; - -public class myTest { - - static SdcToscaParserFactory factory; - static ISdcCsarHelper fdntCsarHelper; - - @Test - public void testNoValidationIssues() throws SdcToscaParserException { - - -// factory = SdcToscaParserFactory.getInstance(); -// fdntCsarHelper = getCsarHelper("csars/service-Oren1-csar-4.csar"); -// -// -// List serviceNodeTemplatesByType = fdntCsarHelper.getServiceNodeTemplatesByType("org.openecomp.nodes.ForwardingPath"); -// -// String target_range = fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceNodeTemplatesByType.get(0), "target_range"); - - } - - - protected static ISdcCsarHelper getCsarHelper(String path) throws SdcToscaParserException { - System.out.println("Parsing CSAR "+path+"..."); - String fileStr1 = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile(); - File file1 = new File(fileStr1); - ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath()); - return sdcCsarHelper; - } - -} -- cgit 1.2.3-korg