diff options
Diffstat (limited to 'sdc-tosca-parser')
16 files changed, 808 insertions, 150 deletions
diff --git a/sdc-tosca-parser/pom.xml b/sdc-tosca-parser/pom.xml index cd6e49e..3bc6a80 100644 --- a/sdc-tosca-parser/pom.xml +++ b/sdc-tosca-parser/pom.xml @@ -6,7 +6,7 @@ <parent>
<groupId>org.openecomp.sdc.sdc-distribution-client</groupId>
<artifactId>sdc-main-distribution-client</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.1.6-SNAPSHOT</version>
</parent>
<artifactId>sdc-tosca-parser</artifactId>
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java index 26995c4..88e22a0 100644 --- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java +++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java @@ -20,11 +20,12 @@ 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.toscaparser.api.Group; +import org.openecomp.sdc.toscaparser.api.Metadata; import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.parameters.Input; public interface ISdcCsarHelper { @@ -120,17 +121,18 @@ public interface ISdcCsarHelper { * @param metadata - metadata object. * @param metadataPropertyName - the name of the metadata property. * @return metadata property value - *//* - //public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName); - */ + */ + public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName); + /** * Get input leaf value for the CSAR service, by full path separated by #.<br> * 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 getServiceInputLeafValue(String inputLeafValuePath); + public String getServiceInputLeafValueOfDefault(String inputLeafValuePath); /** * Get the type name of the CSAR service's substitution mappings element.<br> @@ -151,7 +153,7 @@ public interface ISdcCsarHelper { * Get the CSAR service metadata * @return - the service metadata object. */ - public Map<String, String> getServiceMetadata(); + public Metadata getServiceMetadata(); /** * Get all VFC node templates from a specified VF. @@ -178,13 +180,14 @@ public interface ISdcCsarHelper { members: [vIPR_ATM_Ha_Two, vIPR_ATM_Ha_One, vIPR_ATM_OAM_SG, vIPR_ATM_HA_TWO_SG, vIPR_ATM_HA_ONE_SG]<br><br> calling<br> - getMembersOfGroup(group)<br> - will return List of the following Strings: "vIPR_ATM_Ha_Two, vIPR_ATM_Ha_One, vIPR_ATM_OAM_SG, vIPR_ATM_HA_TWO_SG, vIPR_ATM_HA_ONE_SG"<br> - * @param group - group to return the members. - * @return names of all group members. + getMembersOfVfModule(NoteTemplate vfNodeTemplate, Group group)<br> + 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"<br> + * @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<String> getMembersOfGroup(Group group); + public List<NodeTemplate> getMembersOfVfModule(NodeTemplate vf, Group vfModule); /** @@ -238,4 +241,10 @@ public interface ISdcCsarHelper { */ public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate); + /** + * Get the CSAR service inputs list. + * @return - the service inputs list. + */ + public List<Input> getServiceInputs(); + } diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java index d5caa5d..612bc04 100644 --- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java +++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java @@ -20,27 +20,27 @@ package org.openecomp.sdc.tosca.parser.impl; +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.utils.GeneralUtility; +import org.openecomp.sdc.toscaparser.api.*; +import org.openecomp.sdc.toscaparser.api.elements.NodeType; +import org.openecomp.sdc.toscaparser.api.parameters.Input; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; + import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.stream.Collector; import java.util.stream.Collectors; -import org.apache.commons.lang3.tuple.Pair; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.toscaparser.api.Property; -import org.openecomp.sdc.toscaparser.api.TopologyTemplate; -import org.openecomp.sdc.toscaparser.api.ToscaTemplate; -import org.yaml.snakeyaml.Yaml; - public class SdcCsarHelperImpl implements ISdcCsarHelper { private ToscaTemplate toscaTemplate; - private static Yaml defaultYaml = new Yaml(); - + private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName()); public SdcCsarHelperImpl(ToscaTemplate toscaTemplate) { this.toscaTemplate = toscaTemplate; @@ -49,38 +49,62 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { @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; + } + log.trace("getNodeTemplatePropertyLeafValue - nodeTemplate is : {}, leafValuePath is {} ", nodeTemplate.toString(), leafValuePath); String[] split = leafValuePath.split("#"); List<Property> properties = nodeTemplate.getProperties(); - Optional<Property> findFirst = properties.stream().filter(x -> x.getName().equals(split[0])).findFirst(); - if (findFirst.isPresent()){ - Property property = findFirst.get(); - Object current = property.getValue(); - if (split.length > 1){ - current = defaultYaml.load((String)current); - for (int i = 1; i < split.length; i++) { - current = ((Map<String, Object>)current).get(split[i]); - } - } - return String.valueOf(current); - } - return null; + log.trace("getNodeTemplatePropertyLeafValue - properties of nodeTemplate are : {}", properties.toString()); + return processProperties(split, properties); } @Override + //Sunny flow - covered with UT public List<NodeTemplate> getServiceVlList() { - return getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VL); - + List<NodeTemplate> serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VL); + log.trace("getServiceVlList - the VL list is {}", serviceVlList); + return serviceVlList; } @Override //Sunny flow - covered with UT public List<NodeTemplate> getServiceVfList() { - return getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF); + List<NodeTemplate> serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF); + log.trace("getServiceVfList - the VF list is {}", serviceVfList); + 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); + log.trace("getMetadataPropertyValue - metadata is {} metadataPropertyName is {} the value is : {}", metadata.toString(), metadataPropertyName , metadataPropertyValue); + return metadataPropertyValue; } + @Override //Sunny flow - covered with UT public List<NodeTemplate> getServiceNodeTemplatesByType(String nodeType) { + if (GeneralUtility.isEmptyString(nodeType)) { + log.error("getServiceNodeTemplatesByType - nodeType - is null or empty"); + return new ArrayList<>(); + } + List<NodeTemplate> res = new ArrayList<>(); List<NodeTemplate> nodeTemplates = toscaTemplate.getNodeTemplates(); for (NodeTemplate nodeTemplate : nodeTemplates){ @@ -88,132 +112,336 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { res.add(nodeTemplate); } } + + log.trace("getServiceNodeTemplatesByType - NodeTemplate list value is: {}", res); return res; } @Override + //Sunny flow - covered with UT public List<NodeTemplate> getVfcListByVf(String vfCustomizationId) { + if (GeneralUtility.isEmptyString(vfCustomizationId)) { + log.error("getVfcListByVf - vfCustomizationId - is null or empty"); + return new ArrayList<>(); + } + List<NodeTemplate> serviceVfList = getServiceVfList(); NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId); + log.trace("getVfcListByVf - serviceVfList value: {}, vfInstance value: {}", serviceVfList, vfInstance); return getNodeTemplateBySdcType(vfInstance, Types.TYPE_VFC); } - //Assumed to be unique property for the list - private NodeTemplate getNodeTemplateByCustomizationUuid(List<NodeTemplate> nodeTemplates, String customizationId){ - for (NodeTemplate nodeTemplate : nodeTemplates){ - if (customizationId.equals(nodeTemplate.getMetadata().get(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))){ - return nodeTemplate; - } - } - return null; - } - @Override + //Sunny flow - covered with UT public List<Group> getVfModulesByVf(String vfCustomizationUuid) { List<NodeTemplate> serviceVfList = getServiceVfList(); - List<Group> res = new ArrayList<>(); NodeTemplate nodeTemplateByCustomizationUuid = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid); - //Asked Yaniv about getGroups from NodeTemplate - /* - List<Group> groups = nodeTemplateByCustomizationUuid.; - for (Group group : groups){ - if (Types.TYPE_VFMODULE.equals(group.getType())){ - res.add(group); + if (nodeTemplateByCustomizationUuid != null){ + SubstitutionMappings substitutionMappings = nodeTemplateByCustomizationUuid.getSubstitutionMappings(); + if (substitutionMappings != null){ + List<Group> groups = substitutionMappings.getGroups(); + if (groups != null){ + return groups.stream().filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType())).collect(Collectors.toList()); + } } - }*/ - return res; + } + return new ArrayList<>(); } @Override - public String getServiceInputLeafValue(String inputLeafValuePath) { - //toscaTemplate.getTopologyTemplate().getNodeTemplates().get(0).getProperties().get(0). - return null;//getLeafPropertyValue(toscaTemplate, inputLeafValuePath); + //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 = inputLeafValuePath.split("#"); + if (split.length < 2 || !split[1].equals("default")){ + log.error("getServiceInputLeafValue - inputLeafValuePath should be of format <input name>#default[optionally #<rest of path>] "); + return null; + } + + List<Input> inputs = toscaTemplate.getInputs(); + log.trace("getServiceInputLeafValue - the leafValuePath is {} , the inputs are {}", inputLeafValuePath, inputs); + if (inputs != null){ + Optional<Input> findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst(); + if (findFirst.isPresent()){ + log.trace("getServiceInputLeafValue - find first item is {}", findFirst.get().toString()); + Input input = findFirst.get(); + Object current = input.getDefault(); + if (current == null){ + log.error("getServiceInputLeafValue - this input has no default"); + return null; + } + if (split.length > 2){ + current = new Yaml().load((String)current); + for (int i = 2; i < split.length; i++) { + if (current instanceof Map){ + current = ((Map<String, Object>)current).get(split[i]); + } else { + log.error("getServiceInputLeafValue - found an unexpected leaf where expected to find a complex type"); + return null; + } + } + } + if (current != null){ + log.trace("getServiceInputLeafValue - the input default leaf value is {}", String.valueOf(current)); + return String.valueOf(current); + } + } + } + log.error("getServiceInputLeafValue - value not found"); + return null; } + @Override + //Sunny flow - covered with UT public String getServiceSubstitutionMappingsTypeName() { - return toscaTemplate.getTopologyTemplate().getSubstitutionMappings().getNodeDefinition().getType(); - } + SubstitutionMappings substitutionMappings = toscaTemplate.getTopologyTemplate().getSubstitutionMappings(); + if (substitutionMappings == null) { + log.trace("getServiceSubstitutionMappingsTypeName - No Substitution Mappings defined"); + return null; + } + log.trace("getServiceSubstitutionMappingsTypeName - SubstitutionMappings value: {}", substitutionMappings); - @Override - public Map<String, String> getServiceMetadata() { - TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate(); - System.out.println(topologyTemplate.toString()); - return topologyTemplate.getMetadata(); + NodeType nodeType = substitutionMappings.getNodeDefinition(); + if (nodeType == null) { + log.trace("getServiceSubstitutionMappingsTypeName - No Substitution Mappings node defined"); + return null; + } + log.trace("getServiceSubstitutionMappingsTypeName - nodeType value: {}", nodeType); + + return nodeType.getType(); } - //Get property from group @Override - public String getGroupPropertyLeafValue(Group group, String propertyName) { - return null;//getLeafPropertyValue(group, propertyName); + //Sunny flow - covered with UT + public Metadata getServiceMetadata() { + return toscaTemplate.getMetadata(); } - private List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate nodeTemplate, String sdcType){ - //Need metadata to fetch by type - - /*List<NodeTemplate> nodeTemplates = nodeTemplate.getNestedNodeTemplates(); - List<NodeTemplate> res = new ArrayList<>(); - for (NodeTemplate nodeTemplateEntry : nodeTemplates){ - if (nodeTemplateEntry.getMetadata().getMetadataPropertyValue(SdcPropertyNames.PROPERTY_NAME_TYPE).equals(sdcType)){ - res.add(nodeTemplateEntry); - } - }*/ - return null; + @Override + //Sunny flow - covered with UT + public List<Input> getServiceInputs() { + return toscaTemplate.getInputs(); } - private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, String sdcType){ - //Need metadata to fetch by type + @Override + //Sunny flow - covered with UT + public String getGroupPropertyLeafValue(Group group, String leafValuePath) { + if (group == null) { + log.error("getGroupPropertyLeafValue - group is null"); + return null; + } - List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates(); - List<NodeTemplate> res = new ArrayList<>(); - for (NodeTemplate nodeTemplateEntry : nodeTemplates){ - //TODO switch back to type condition - if (nodeTemplateEntry.getTypeDefinition().getType().contains("."+sdcType.toLowerCase()+".")){ - //if (sdcType.equals(nodeTemplateEntry.getMetadata().get(SdcPropertyNames.PROPERTY_NAME_TYPE))){ - res.add(nodeTemplateEntry); - } + if (GeneralUtility.isEmptyString(leafValuePath)) { + log.error("getGroupPropertyLeafValue - leafValuePath is null or empty"); + return null; } - return res; + + String[] split = leafValuePath.split("#"); + List<Property> properties = group.getProperties(); + return processProperties(split, properties); } @Override + //Sunny flow - covered with UT public List<NodeTemplate> getCpListByVf(String vfCustomizationId) { + List<NodeTemplate> cpList = new ArrayList<>(); + if (GeneralUtility.isEmptyString(vfCustomizationId)){ + log.error("getCpListByVf vfCustomizationId string is empty"); + return cpList; + } + List<NodeTemplate> serviceVfList = getServiceVfList(); + if (serviceVfList == null || serviceVfList.size() == 0){ + log.error("getCpListByVf Vfs not exist for vfCustomizationId {}",vfCustomizationId); + return cpList; + } NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId); - return getNodeTemplateBySdcType(vfInstance, Types.TYPE_CP); + log.debug("getCpListByVf vf list is {}", vfInstance); + if (vfInstance == null) { + log.debug("getCpListByVf vf list is null"); + return cpList; + } + cpList = getNodeTemplateBySdcType(vfInstance, Types.TYPE_CP); + if(cpList == null || cpList.size()==0) + log.trace("getCpListByVf cps not exist for vfCustomizationId {}",vfCustomizationId); + return cpList; } @Override - public List<String> getMembersOfGroup(Group group) { - //Can be done - return null;//toscaTemplate.getTopologyTemplate().getSubstitutionMappings().getNodeTemplates().get(0).get + //Sunny flow - covered with UT + public List<NodeTemplate> getMembersOfVfModule(NodeTemplate vf, Group vfModule) { + if (vf == null) { + log.error("getMembersOfVfModule - vf is null"); + return new ArrayList<>(); + } + + if (vfModule == null) { + log.error("getMembersOfVfModule - vfModule is null"); + return new ArrayList<>(); + } + + List<String> members = vfModule.getMembers(); + if (members != null){ + SubstitutionMappings substitutionMappings = vf.getSubstitutionMappings(); + if (substitutionMappings != null){ + return substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(Collectors.toList()); + } + } + return new ArrayList<>(); } @Override + //Sunny flow - covered with UT public List<Pair<NodeTemplate, NodeTemplate>> getNodeTemplatePairsByReqName( List<NodeTemplate> listOfReqNodeTemplates, List<NodeTemplate> listOfCapNodeTemplates, String reqName) { - //TODO - Can be done - return new ArrayList<>(); + if (listOfReqNodeTemplates == null || listOfCapNodeTemplates == null || reqName == null){ + //TODO error message + return new ArrayList<>(); + } + + List<Pair<NodeTemplate, NodeTemplate>> pairsList = new ArrayList<>(); + + if (listOfReqNodeTemplates != null){ + for (NodeTemplate reqNodeTemplate : listOfReqNodeTemplates) { + List<Map<String, Map<String, Object>>> requirements = reqNodeTemplate.getRequirements(); + if (requirements != null){ + for (Map<String, Map<String, Object>> reqEntry : requirements){ + Map<String, Object> reqEntryMap = reqEntry.get(reqName); + + if (reqEntryMap != null){ + Object node = reqEntryMap.get("node"); + if (node != null){ + String nodeString = (String)node; + Optional<NodeTemplate> findFirst = listOfCapNodeTemplates.stream().filter(x -> x.getName().equals(nodeString)).findFirst(); + if (findFirst.isPresent()){ + pairsList.add(new ImmutablePair<NodeTemplate, NodeTemplate>(reqNodeTemplate, findFirst.get())); + } + } + } + } + } + } + } + return pairsList; } @Override + //Sunny flow - covered with UT //TODO constant strings public List<NodeTemplate> getAllottedResources() { - List<NodeTemplate> nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates(); - return nodeTemplates.stream().filter(x -> x.getMetadata() != null && x.getMetadata().get("category").equals("allotted_resources")).collect(Collectors.toList()); + List<NodeTemplate> nodeTemplates = null; + nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates(); + if(nodeTemplates==null || nodeTemplates.size()==0 ){ + log.error("getAllottedResources nodeTemplates not exist"); + } + nodeTemplates = nodeTemplates.stream().filter(x -> x.getMetadata() != null && x.getMetadata().getValue("category").equals("Allotted Resources")).collect(Collectors.toList()); + if(nodeTemplates==null || nodeTemplates.size()==0 ){ + log.trace("getAllottedResources - allotted resources not exist"); + }else + log.trace("getAllottedResources - the allotted resources list is {}", nodeTemplates); + return nodeTemplates; } - @Override //Sunny flow - covered with UT public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate) { - //Can be done + if(nodeTemplate == null){ + + log.error("getTypeOfNodeTemplate nodeTemplate is null"); + return null; + } + log.debug("getTypeOfNodeTemplate node template type is {}",nodeTemplate.getTypeDefinition().getType()); return nodeTemplate.getTypeDefinition().getType(); } - /*//Not part of API, for inner/test use - public NodeTemplate getNodeTemplateByName(TopologyTemplate topologyTemplate, String topologyName){ + /************************************* helper functions ***********************************/ + private List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate nodeTemplate, String sdcType){ + if (nodeTemplate == null) { + log.error("getNodeTemplateBySdcType - nodeTemplate is null or empty"); + return new ArrayList<>(); + } + + if (GeneralUtility.isEmptyString(sdcType)) { + log.error("getNodeTemplateBySdcType - sdcType is null or empty"); + return new ArrayList<>(); + } + + SubstitutionMappings substitutionMappings = nodeTemplate.getSubstitutionMappings(); + + if (substitutionMappings != null) { + List<NodeTemplate> nodeTemplates = substitutionMappings.getNodeTemplates(); + if (nodeTemplates != null && nodeTemplates.size() > 0) + return nodeTemplates.stream().filter(x -> (x.getMetadata() != null && sdcType.equals(x.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList()); + else + log.trace("getNodeTemplateBySdcType - SubstitutionMappings' node Templates not exist"); + } else + log.trace("getNodeTemplateBySdcType - SubstitutionMappings not exist"); + + return new ArrayList<>(); + } + + private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, String sdcType){ + if (GeneralUtility.isEmptyString(sdcType)) { + log.error("getNodeTemplateBySdcType - sdcType is null or empty"); + return new ArrayList<>(); + } + + if (topologyTemplate == null) { + log.error("getNodeTemplateBySdcType - topologyTemplate is null"); + return new ArrayList<>(); + } + List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates(); - Optional<NodeTemplate> findFirst = nodeTemplates.stream().filter(x -> x.getName().equals(topologyName)).findFirst(); - return findFirst.isPresent() ? findFirst.get() : null; - }*/ + + if (nodeTemplates != null && nodeTemplates.size() > 0) + return nodeTemplates.stream().filter(x -> (x.getMetadata() != null && sdcType.equals(x.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList()); + + log.trace("getNodeTemplateBySdcType - topologyTemplate's nodeTemplates not exist"); + return new ArrayList<>(); + } + + //Assumed to be unique property for the list + private NodeTemplate getNodeTemplateByCustomizationUuid(List<NodeTemplate> nodeTemplates, String customizationId){ + for (NodeTemplate nodeTemplate : nodeTemplates){ + if (customizationId.equals(nodeTemplate.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))){ + return nodeTemplate; + } + } + return null; + } + + private String processProperties(String[] split, List<Property> properties) { + log.trace("processProperties - the leafValuePath is {} , the properties are {}", split.toString(), properties.toString()); + Optional<Property> findFirst = properties.stream().filter(x -> x.getName().equals(split[0])).findFirst(); + if (findFirst.isPresent()){ + log.trace("processProperties - find first item is {}", findFirst.get().toString()); + Property property = findFirst.get(); + Object current = property.getValue(); + if (current == null){ + log.error("processProperties - this property has no value"); + return null; + } + if (split.length > 1){ + current = new Yaml().load((String)current); + for (int i = 1; i < split.length; i++) { + if (current instanceof Map){ + current = ((Map<String, Object>)current).get(split[i]); + } else { + log.error("processProperties - found an unexpected leaf where expected to find a complex type"); + return null; + } + } + } + if (current != null){ + log.trace("processProperties - the property value is {}", String.valueOf(current)); + return String.valueOf(current); + } + } + log.error("processProperties - Dont find property"); + return null; + } } diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java index 6be293e..243d238 100644 --- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java +++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java @@ -1,10 +1,14 @@ package org.openecomp.sdc.tosca.parser.impl;
import java.io.IOException;
+import java.util.List;
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.toscaparser.ToscaParser;
import org.openecomp.sdc.toscaparser.ToscaParserFactory;
+import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
public class SdcToscaParserFactory implements AutoCloseable{
@@ -42,7 +46,10 @@ public class SdcToscaParserFactory implements AutoCloseable{ throw new SdcToscaParserException("The factory is closed. It was probably closed too soon.");
}
try {
- return new SdcCsarHelperImpl(toscaParserFactory.create().parse(csarPath));
+ ToscaParser create = toscaParserFactory.create();
+ ToscaTemplate parse = create.parse(csarPath);
+ SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(parse);
+ return sdcCsarHelperImpl;
} catch (IOException e) {
throw new SdcToscaParserException("Exception when creating the parser: "+e.getMessage());
}
@@ -66,4 +73,13 @@ public class SdcToscaParserFactory implements AutoCloseable{ }
}
}
+
+ public static void main(String[] args) throws SdcToscaParserException {
+ try (SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance()){ //Autoclosable
+ ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper("C:\\Users\\pa0916\\Desktop\\Work\\ASDC\\CSARs\\csar_hello_world.zip");
+ //Can run methods on the helper
+ List<NodeTemplate> allottedResources = sdcCsarHelper.getAllottedResources();
+ //..............
+ }
+ }
}
\ No newline at end of file diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java new file mode 100644 index 0000000..e4d92f5 --- /dev/null +++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java @@ -0,0 +1,8 @@ +package org.openecomp.sdc.tosca.parser.utils; + +public class GeneralUtility { + + public static boolean isEmptyString(String str){ + return str == null || str.trim().isEmpty(); + } +} diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java index aac552c..6a23cc4 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java @@ -1,96 +1,493 @@ package org.openecomp.sdc.impl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
+import org.apache.commons.lang3.tuple.Pair;
import org.junit.AfterClass;
-import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.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 org.openecomp.sdc.toscaparser.api.Group;
+import org.openecomp.sdc.toscaparser.api.Metadata;
import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import org.openecomp.sdc.toscaparser.api.parameters.Input;
public class ToscaParserStubsTest {
- private static ISdcCsarHelper csarHelper;
- private static SdcToscaParserFactory factory;
-
+ static SdcToscaParserFactory factory;
+ static ISdcCsarHelper rainyCsarHelperSingleVf;
+ static ISdcCsarHelper rainyCsarHelperMultiVfs;
+ static ISdcCsarHelper rainyCsarHelperNoVf;
+ static ISdcCsarHelper sunnyCsarHelperMultipleVf;
@BeforeClass
public static void init() throws SdcToscaParserException{
+ long startTime = System.currentTimeMillis();
factory = SdcToscaParserFactory.getInstance();
- //csarHelper = factory.getSdcCsarHelper("C:\\Users\\pa0916\\Desktop\\Work\\ASDC\\CSARs\\service-ServiceFdnt-csar-allotted-resources-4.csar");
- String fileStr = ToscaParserStubsTest.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-allotted-resources-4.csar").getFile();
+ long estimatedTime = System.currentTimeMillis() - startTime;
+ System.out.println("Time to init factory "+estimatedTime);
+ String fileStr2 = ToscaParserStubsTest.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-group-meta-10.csar").getFile();
+ File file2 = new File(fileStr2);
+ startTime = System.currentTimeMillis();
+ sunnyCsarHelperMultipleVf = factory.getSdcCsarHelper(file2.getAbsolutePath());
+ estimatedTime = System.currentTimeMillis() - startTime;
+ System.out.println("init CSAR Execution time: "+estimatedTime);
+ String fileStr = ToscaParserStubsTest.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-rainy.csar").getFile();
File file = new File(fileStr);
- csarHelper = factory.getSdcCsarHelper(file.getAbsolutePath());
+ rainyCsarHelperMultiVfs = factory.getSdcCsarHelper(file.getAbsolutePath());
+ String fileStr3 = ToscaParserStubsTest.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar.csar").getFile();
+ File file3 = new File(fileStr3);
+ rainyCsarHelperSingleVf = factory.getSdcCsarHelper(file3.getAbsolutePath());
+ String fileStr4 = ToscaParserStubsTest.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-no-vf.csar").getFile();
+ File file4 = new File(fileStr3);
+ rainyCsarHelperNoVf = factory.getSdcCsarHelper(file3.getAbsolutePath());
}
-
-
+
@Test
- //TODO add rainy flows
public void testNumberOfVfSunnyFlow() throws SdcToscaParserException {
- List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
+ List<NodeTemplate> serviceVfList = sunnyCsarHelperMultipleVf.getServiceVfList();
assertNotNull(serviceVfList);
- assertEquals(1, serviceVfList.size());
+ assertEquals(2, serviceVfList.size());
}
@Test
- //TODO add rainy flows
public void testNodeTemplateFlatProperty() throws SdcToscaParserException {
- List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
- String nodeTemplatePropertyLeafValue = csarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "availability_zone_max_count");
+ List<NodeTemplate> serviceVfList = sunnyCsarHelperMultipleVf.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = sunnyCsarHelperMultipleVf.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "availability_zone_max_count");
assertEquals("2", nodeTemplatePropertyLeafValue);
}
+
+ @Test
+ public void testGroupFlatProperty() throws SdcToscaParserException {
+ List<Group> vfModulesByVf = sunnyCsarHelperMultipleVf.getVfModulesByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72");
+ String volumeGroup = sunnyCsarHelperMultipleVf.getGroupPropertyLeafValue(vfModulesByVf.get(0), "volume_group");
+ assertEquals("false", volumeGroup);
+ }
@Test
- //TODO add rainy flows
public void testNodeTemplateNestedProperty() throws SdcToscaParserException {
- List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
- String nodeTemplatePropertyLeafValue = csarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_role#nf_naming#instance_name");
- assertEquals("FDNT_instance_VF", nodeTemplatePropertyLeafValue);
+ List<NodeTemplate> serviceVfList = sunnyCsarHelperMultipleVf.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = sunnyCsarHelperMultipleVf.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_role#nf_naming#ecomp_generated_naming");
+ assertEquals("false", nodeTemplatePropertyLeafValue);
}
@Test
- //TODO add rainy flows
public void testServiceNodeTemplatesByType() throws SdcToscaParserException {
- List<NodeTemplate> serviceVfList = csarHelper.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Fdnt");
+ List<NodeTemplate> serviceVfList = sunnyCsarHelperMultipleVf.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Fdnt");
assertNotNull(serviceVfList);
- assertEquals(1, serviceVfList.size());
+ assertEquals(2, serviceVfList.size());
}
@Test
- //TODO add rainy flows
public void testGetTypeOfNodeTemplate() {
- List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
- String typeOfNodeTemplate = csarHelper.getTypeOfNodeTemplate(serviceVfList.get(0));
+ List<NodeTemplate> serviceVfList = sunnyCsarHelperMultipleVf.getServiceVfList();
+ String typeOfNodeTemplate = sunnyCsarHelperMultipleVf.getTypeOfNodeTemplate(serviceVfList.get(0));
assertEquals("org.openecomp.resource.vf.Fdnt", typeOfNodeTemplate);
}
-
- //@Test
- //TODO add rainy flows
+ @Test
public void testGetServiceMetadata() {
- //FAILS!! Metadata is null
- Map<String, String> serviceMetadata = csarHelper.getServiceMetadata();
+ Metadata serviceMetadata = sunnyCsarHelperMultipleVf.getServiceMetadata();
assertNotNull(serviceMetadata);
- assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", serviceMetadata.get("invariantUUID"));
- assertEquals("Service FDNT", serviceMetadata.get("name"));
- assertEquals("true", serviceMetadata.get("serviceEcompNaming"));
+ assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", serviceMetadata.getValue("invariantUUID"));
+ assertEquals("Service FDNT", serviceMetadata.getValue("name"));
+ assertEquals("true", String.valueOf(serviceMetadata.getValue("serviceEcompNaming")));
}
@Test
- //TODO add rainy flows
public void testGetAllottedResources() {
- List<NodeTemplate> allottedResources = csarHelper.getAllottedResources();
- assertEquals(1, allottedResources.size());
+ List<NodeTemplate> allottedResources = sunnyCsarHelperMultipleVf.getAllottedResources();
+ assertEquals(2, allottedResources.size());
+ }
+
+ @Test
+ public void testGetServiceSubstitutionMappingsTypeName() {
+ String serviceSubstitutionMappingsTypeName = sunnyCsarHelperMultipleVf.getServiceSubstitutionMappingsTypeName();
+ assertEquals("org.openecomp.service.ServiceFdnt", serviceSubstitutionMappingsTypeName);
+ }
+
+ @Test
+ public void testGetVfcFromVf(){
+ List<NodeTemplate> vfcListByVf = sunnyCsarHelperMultipleVf.getVfcListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72");
+ assertEquals(2, vfcListByVf.size());
+ }
+
+ @Test
+ public void testGetCpFromVf(){
+ List<NodeTemplate> cpListByVf = sunnyCsarHelperMultipleVf.getCpListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72");
+ assertEquals(1, cpListByVf.size());
+ NodeTemplate nodeTemplate = cpListByVf.get(0);
+ assertEquals("DNT_PORT", nodeTemplate.getName());
+ }
+
+ @Test
+ public void testServiceVl(){
+ List<NodeTemplate> vlList = sunnyCsarHelperMultipleVf.getServiceVlList();
+ assertEquals(1, vlList.size());
+ }
+
+ @Test
+ public void testVfModulesFromVf(){
+ List<Group> vfModulesByVf = sunnyCsarHelperMultipleVf.getVfModulesByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72");
+ assertEquals(2, vfModulesByVf.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqName(){
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = sunnyCsarHelperMultipleVf.getNodeTemplatePairsByReqName(sunnyCsarHelperMultipleVf.getCpListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"), sunnyCsarHelperMultipleVf.getVfcListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"), "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(1, nodeTemplatePairsByReqName.size());
+ Pair<NodeTemplate, NodeTemplate> 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 testGetMembersOfVfModule(){
+ NodeTemplate vf = sunnyCsarHelperMultipleVf.getServiceVfList().get(0);
+ List<Group> vfModulesByVf = sunnyCsarHelperMultipleVf.getVfModulesByVf(vf.getMetadata().getValue("customizationUUID"));
+ assertEquals(2, vfModulesByVf.size());
+ for (Group group : vfModulesByVf){
+ List<NodeTemplate> membersOfVfModule = sunnyCsarHelperMultipleVf.getMembersOfVfModule(vf, group);
+ assertNotNull(membersOfVfModule);
+ if (group.getName().equals("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("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 testGetServiceInputs(){
+ List<Input> serviceInputs = sunnyCsarHelperMultipleVf.getServiceInputs();
+ assertNotNull(serviceInputs);
+ assertEquals(1, serviceInputs.size());
+ }
+
+ @Test
+ public void testGetMetadataProperty(){
+ Metadata serviceMetadata = sunnyCsarHelperMultipleVf.getServiceMetadata();
+ String metadataPropertyValue = sunnyCsarHelperMultipleVf.getMetadataPropertyValue(serviceMetadata, "invariantUUID");
+ assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", metadataPropertyValue);
+ }
+
+ @Test
+ public void testGetGroupMetadata(){
+ NodeTemplate vf = sunnyCsarHelperMultipleVf.getServiceVfList().get(0);
+ List<Group> vfModulesByVf = sunnyCsarHelperMultipleVf.getVfModulesByVf(vf.getMetadata().getValue("customizationUUID"));
+ boolean found = false;
+ for (Group group : vfModulesByVf){
+ if (group.getName().equals("Fdnt..base_stsi_dnt_frwl..module-0")){
+ found = true;
+ Metadata metadata = group.getMetadata();
+ assertNotNull(metadata);
+ assertEquals("1", metadata.getValue("vfModuleModelVersion"));
+ }
+ }
+ assertTrue(found);
+ }
+
+
+ @Test
+ public void testGetServiceInputLeafValue(){
+ String serviceInputLeafValue = sunnyCsarHelperMultipleVf.getServiceInputLeafValueOfDefault("service_naming#default");
+ assertEquals("test service naming", serviceInputLeafValue);
+ }
+
+
+ /***************** RAINY TESTS ***************************/
+
+
+ @Test
+ public void testGetServiceInputLeafValueNotExists(){
+ String serviceInputLeafValue = sunnyCsarHelperMultipleVf.getServiceInputLeafValueOfDefault("service_naming#default#kuku");
+ assertNull(serviceInputLeafValue);
+ }
+
+ @Test
+ public void testGetServiceInputLeafValueNull(){
+ String serviceInputLeafValue = sunnyCsarHelperMultipleVf.getServiceInputLeafValueOfDefault(null);
+ assertNull(serviceInputLeafValue);
}
+ @Test
+ public void testNodeTemplateNestedPropertyNotExists() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = sunnyCsarHelperMultipleVf.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = sunnyCsarHelperMultipleVf.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_role#nf_naming#kuku");
+ assertNull(nodeTemplatePropertyLeafValue);
+ }
- @AfterClass
- public static void close(){
- factory.close();
+ @Test
+ public void testGetGroupEmptyMetadata(){
+ NodeTemplate vf = sunnyCsarHelperMultipleVf.getServiceVfList().get(0);
+ List<Group> vfModulesByVf = sunnyCsarHelperMultipleVf.getVfModulesByVf(vf.getMetadata().getValue("customizationUUID"));
+ boolean found = false;
+ for (Group group : vfModulesByVf){
+ if (group.getName().equals("Fdnt..mod_vmsi_dnt_fw_parent..module-1")){
+ found = true;
+ Metadata metadata = group.getMetadata();
+ assertNull(metadata);
+ }
}
+ assertTrue(found);
+ }
+
+ @Test
+ public void testNodeTemplateFlatPropertyByNotFoundProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "XXXX");
+ assertNull(nodeTemplatePropertyLeafValue);
+ }
+
+ @Test
+ public void testNodeTemplateFlatPropertyByNullProperty() throws SdcToscaParserException {
+ List<NodeTemplate> 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);
+ }
+
+ @Test
+ public void testNumberOfVLRainyFlow() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVlList = rainyCsarHelperMultiVfs.getServiceVlList();
+ assertNotNull(serviceVlList);
+ assertEquals(0, serviceVlList.size());
+ }
+
+ @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<NodeTemplate> serviceVfList = rainyCsarHelperSingleVf.getServiceVfList();
+ assertNotNull(serviceVfList);
+ assertEquals(0, serviceVfList.size());
+ }
+
+ @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);
+ }
+
+ @Test
+ public void testGetCpFromVfByNullId() {
+ List<NodeTemplate> cpListByVf = rainyCsarHelperMultiVfs.getCpListByVf(null);
+ assertNotNull(cpListByVf);
+ assertEquals(0, cpListByVf.size());
+ }
+
+ @Test
+ public void testGetAllottedResourcesZero() {
+ List<NodeTemplate> allottedResources = rainyCsarHelperMultiVfs.getAllottedResources();
+ assertNotNull(allottedResources);
+ assertEquals(0, allottedResources.size());
+ }
+
+ @Test
+ public void testGetTypeOfNullNodeTemplate() {
+ String typeOfNodeTemplate = rainyCsarHelperMultiVfs.getTypeOfNodeTemplate(null);
+ assertNull(typeOfNodeTemplate);
+ }
+
+ @Test
+ public void testGetCpFromVfXxx() {
+ List<NodeTemplate> cpListByVf = rainyCsarHelperMultiVfs.getCpListByVf("XXXXX");
+ assertNotNull(cpListByVf);
+ assertEquals(0, cpListByVf.size());
+ }
+
+ @Test
+ public void testServiceNodeTemplatesByNull() {
+ List<NodeTemplate> nodeTemplates = rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType(null);
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+
+ @Test
+ public void testServiceNodeTemplatesByNotFoundProperty() {
+ List<NodeTemplate> nodeTemplates = rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType("XXX");
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+
+ @Test
+ public void testVfcListByNull() {
+ List<NodeTemplate> vfcList = rainyCsarHelperMultiVfs.getVfcListByVf(null);
+ assertNotNull(vfcList);
+ assertEquals(0, vfcList.size());
+ }
+
+ @Test
+ public void testVfcListByNotFoundProperty() {
+ List<NodeTemplate> vfcList = rainyCsarHelperMultiVfs.getVfcListByVf("XXX");
+ assertNotNull(vfcList);
+ assertEquals(0, vfcList.size());
+ }
+
+ @Test
+ public void testServiceSubstitutionMappingsTypeName() {
+ String substitutionMappingsTypeName = rainyCsarHelperMultiVfs.getServiceSubstitutionMappingsTypeName();
+ assertNull(substitutionMappingsTypeName);
+ }
+
+ @Test
+ public void testServiceMetadata() {
+ Metadata metadata = rainyCsarHelperSingleVf.getServiceMetadata();
+ assertNull(metadata);
+ }
+
+ @Test
+ public void testGetVfModuleNonExisitingVf() {
+ List<Group> vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf("dummy");
+ assertNotNull(vfModulesByVf);
+ assertEquals(0, vfModulesByVf.size());
+ }
+
+ @Test
+ public void testGetVfModuleNullVf() {
+ List<Group> vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf(null);
+ assertNotNull(vfModulesByVf);
+ assertEquals(0, vfModulesByVf.size());
+ }
+
+ @Test
+ public void testGroupPropertyLeafValueByNullGroup() {
+ String groupProperty = sunnyCsarHelperMultipleVf.getGroupPropertyLeafValue(null, "volume_group");
+ assertNull(groupProperty);
+ }
+
+ @Test
+ public void testGroupPropertyLeafValueByNullProperty() {
+ List<Group> vfModulesByVf = sunnyCsarHelperMultipleVf.getVfModulesByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72");
+ String groupProperty = sunnyCsarHelperMultipleVf.getGroupPropertyLeafValue(vfModulesByVf.get(0), null);
+ assertNull(groupProperty);
+ }
+
+ @Test
+ public void testGroupPropertyLeafValueByDummyProperty() {
+ List<Group> vfModulesByVf = sunnyCsarHelperMultipleVf.getVfModulesByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72");
+ String groupProperty = sunnyCsarHelperMultipleVf.getGroupPropertyLeafValue(vfModulesByVf.get(0), "XXX");
+ assertNull(groupProperty);
+ }
+
+ @Test
+ public void testMembersOfVfModuleByNullVf() {
+ List<Group> vfModulesByVf = sunnyCsarHelperMultipleVf.getVfModulesByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72");
+ List<NodeTemplate> nodeTemplates = sunnyCsarHelperMultipleVf.getMembersOfVfModule(null, vfModulesByVf.get(0));
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+
+ @Test
+ public void testMembersOfVfModuleByNullGroup() {
+ List<NodeTemplate> serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList();
+ List<NodeTemplate> nodeTemplates = rainyCsarHelperMultiVfs.getMembersOfVfModule(serviceVfList.get(0), null);
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithNullVF(){
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = sunnyCsarHelperMultipleVf.getNodeTemplatePairsByReqName(
+ null, sunnyCsarHelperMultipleVf.getVfcListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"), "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithEmptyVF(){
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = sunnyCsarHelperMultipleVf.getNodeTemplatePairsByReqName(
+ new ArrayList<>(), sunnyCsarHelperMultipleVf.getVfcListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"), "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithNullCap(){
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = sunnyCsarHelperMultipleVf.getNodeTemplatePairsByReqName(
+ sunnyCsarHelperMultipleVf.getCpListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"), null, "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithEmptyCap(){
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = sunnyCsarHelperMultipleVf.getNodeTemplatePairsByReqName(
+ sunnyCsarHelperMultipleVf.getCpListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"), new ArrayList<>(), "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithNullReq(){
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = sunnyCsarHelperMultipleVf.getNodeTemplatePairsByReqName(
+ sunnyCsarHelperMultipleVf.getCpListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"), sunnyCsarHelperMultipleVf.getVfcListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"), null);
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithDummyReq(){
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = sunnyCsarHelperMultipleVf.getNodeTemplatePairsByReqName(
+ sunnyCsarHelperMultipleVf.getCpListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"), sunnyCsarHelperMultipleVf.getVfcListByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"), "XXX");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testServiceInputs() {
+ List<Input> inputs = rainyCsarHelperSingleVf.getServiceInputs();
+ assertNotNull(inputs);
+ assertEquals(0, inputs.size());
+ }
+
+ @Test
+ public void testServiceWithoutVF() {
+ List<NodeTemplate> vfList = rainyCsarHelperNoVf.getServiceVfList();
+ assertNotNull(vfList);
+ assertEquals(0, vfList.size());
+ }
+
+ @AfterClass
+ public static void close(){
+ long startTime = System.currentTimeMillis();
+ factory.close();
+ long estimatedTime = System.currentTimeMillis() - startTime;
+ System.out.println("close Execution time: "+estimatedTime);
}
+}
diff --git a/sdc-tosca-parser/src/test/resources/csars/csar_hello_world.zip b/sdc-tosca-parser/src/test/resources/csars/csar_hello_world.zip Binary files differnew file mode 100644 index 0000000..43ffbbc --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/csar_hello_world.zip diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-cp-vfc-req-cap-8.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-cp-vfc-req-cap-8.csar Binary files differnew file mode 100644 index 0000000..be254a0 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-cp-vfc-req-cap-8.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-flat-input-9-1.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-flat-input-9-1.csar Binary files differnew file mode 100644 index 0000000..4ae4c6f --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-flat-input-9-1.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-group-meta-10.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-group-meta-10.csar Binary files differnew file mode 100644 index 0000000..dc21ce9 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-group-meta-10.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-inputs-9.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-inputs-9.csar Binary files differnew file mode 100644 index 0000000..c1c2855 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-inputs-9.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-no-vf.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-no-vf.csar Binary files differnew file mode 100644 index 0000000..c35baf5 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-no-vf.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-rainy.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-rainy.csar Binary files differnew file mode 100644 index 0000000..412935f --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-rainy.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-service-vl-7.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-service-vl-7.csar Binary files differnew file mode 100644 index 0000000..db3af99 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-service-vl-7.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-two-vfs-5.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-two-vfs-5.csar Binary files differnew file mode 100644 index 0000000..565929a --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-two-vfs-5.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-test-csar.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-test-csar.csar Binary files differnew file mode 100644 index 0000000..5a364cd --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-test-csar.csar |