summaryrefslogtreecommitdiffstats
path: root/sdc-tosca-parser/src
diff options
context:
space:
mode:
Diffstat (limited to 'sdc-tosca-parser/src')
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java8
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java204
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java54
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/BasicTest.java22
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java99
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java58
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java298
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java50
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java503
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java24
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserTestSuite.java64
11 files changed, 725 insertions, 659 deletions
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 88e22a0..8d04d97 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
@@ -22,10 +22,10 @@ package org.openecomp.sdc.tosca.parser.api;
import java.util.List;
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;
+import org.openecomp.sdc.toscaparser.Group;
+import org.openecomp.sdc.toscaparser.NodeTemplate;
+import org.openecomp.sdc.toscaparser.elements.Metadata;
+import org.openecomp.sdc.toscaparser.parameters.Input;
public interface ISdcCsarHelper {
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 9ee3132..f24dce7 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
@@ -21,8 +21,10 @@
package org.openecomp.sdc.tosca.parser.impl;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -31,21 +33,21 @@ 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.tosca.parser.utils.SdcToscaUtility;
-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.Property;
-import org.openecomp.sdc.toscaparser.api.SubstitutionMappings;
-import org.openecomp.sdc.toscaparser.api.TopologyTemplate;
-import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
-import org.openecomp.sdc.toscaparser.api.elements.NodeType;
-import org.openecomp.sdc.toscaparser.api.parameters.Input;
+import org.openecomp.sdc.toscaparser.Group;
+import org.openecomp.sdc.toscaparser.NodeTemplate;
+import org.openecomp.sdc.toscaparser.Property;
+import org.openecomp.sdc.toscaparser.SubstitutionMappings;
+import org.openecomp.sdc.toscaparser.TopologyTemplate;
+import org.openecomp.sdc.toscaparser.ToscaTemplate;
+import org.openecomp.sdc.toscaparser.elements.Metadata;
+import org.openecomp.sdc.toscaparser.elements.NodeType;
+import org.openecomp.sdc.toscaparser.parameters.Input;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.yaml.snakeyaml.Yaml;
public class SdcCsarHelperImpl implements ISdcCsarHelper {
+ private static final String PATH_DELIMITER = "#";
private ToscaTemplate toscaTemplate;
private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName());
@@ -64,18 +66,17 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
log.error("getNodeTemplatePropertyLeafValue - leafValuePath is null or empty");
return null;
}
- log.trace("getNodeTemplatePropertyLeafValue - nodeTemplate is : {}, leafValuePath is {} ", nodeTemplate, leafValuePath);
- String[] split = leafValuePath.split("#");
- List<Property> properties = nodeTemplate.getProperties();
- log.trace("getNodeTemplatePropertyLeafValue - properties of nodeTemplate are : {}", properties);
+ log.debug("getNodeTemplatePropertyLeafValue - nodeTemplate is : {}, leafValuePath is {} ", nodeTemplate, leafValuePath);
+ String[] split = getSplittedPath(leafValuePath);
+ LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
+ log.debug("getNodeTemplatePropertyLeafValue - properties of nodeTemplate are : {}", properties);
return processProperties(split, properties);
}
-
@Override
//Sunny flow - covered with UT
public List<NodeTemplate> getServiceVlList() {
List<NodeTemplate> serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VL);
- log.trace("getServiceVlList - the VL list is {}", serviceVlList);
+ log.debug("getServiceVlList - the VL list is {}", serviceVlList);
return serviceVlList;
}
@@ -83,7 +84,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
//Sunny flow - covered with UT
public List<NodeTemplate> getServiceVfList() {
List<NodeTemplate> serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF);
- log.trace("getServiceVfList - the VF list is {}", serviceVfList);
+ log.debug("getServiceVfList - the VF list is {}", serviceVfList);
return serviceVfList;
}
@@ -99,7 +100,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return null;
}
String metadataPropertyValue = metadata.getValue(metadataPropertyName);
- log.trace("getMetadataPropertyValue - metadata is {} metadataPropertyName is {} the value is : {}", metadata, metadataPropertyName , metadataPropertyValue);
+ log.debug("getMetadataPropertyValue - metadata is {} metadataPropertyName is {} the value is : {}", metadata, metadataPropertyName , metadataPropertyValue);
return metadataPropertyValue;
}
@@ -120,7 +121,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
}
}
- log.trace("getServiceNodeTemplatesByType - NodeTemplate list value is: {}", res);
+ log.debug("getServiceNodeTemplatesByType - For Node Type : {} - NodeTemplate list value is: {}", nodeType, res);
return res;
}
@@ -134,7 +135,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
List<NodeTemplate> serviceVfList = getServiceVfList();
NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
- log.trace("getVfcListByVf - serviceVfList value: {}, vfInstance value: {}", serviceVfList, vfInstance);
+ log.debug("getVfcListByVf - serviceVfList value: {}, vfInstance value: {}", serviceVfList, vfInstance);
return getNodeTemplateBySdcType(vfInstance, Types.TYPE_VFC);
}
@@ -142,29 +143,29 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
//Sunny flow - covered with UT
public List<Group> getVfModulesByVf(String vfCustomizationUuid) {
List<NodeTemplate> serviceVfList = getServiceVfList();
- log.trace("getVfModulesByVf - VF list is {}", serviceVfList);
+ log.debug("getVfModulesByVf - VF list is {}", serviceVfList);
NodeTemplate nodeTemplateByCustomizationUuid = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid);
- log.trace("getVfModulesByVf - getNodeTemplateByCustomizationUuid is {}, customizationUuid {}", nodeTemplateByCustomizationUuid, vfCustomizationUuid);
+ log.debug("getVfModulesByVf - getNodeTemplateByCustomizationUuid is {}, customizationUuid {}", nodeTemplateByCustomizationUuid, vfCustomizationUuid);
if (nodeTemplateByCustomizationUuid != null){
/*SubstitutionMappings substitutionMappings = nodeTemplateByCustomizationUuid.getSubstitutionMappings();
if (substitutionMappings != null){
List<Group> groups = substitutionMappings.getGroups();
if (groups != null){
List<Group> collect = groups.stream().filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType())).collect(Collectors.toList());
- log.trace("getVfModulesByVf - VfModules are {}", collect);
+ log.debug("getVfModulesByVf - VfModules are {}", collect);
return collect;
}
}*/
String name = nodeTemplateByCustomizationUuid.getName();
String normaliseComponentInstanceName = SdcToscaUtility.normaliseComponentInstanceName(name);
List<Group> serviceLevelGroups = toscaTemplate.getTopologyTemplate().getGroups();
- log.trace("getVfModulesByVf - VF node template name {}, normalized name {}. Searching groups on service level starting with VF normalized name...", name, normaliseComponentInstanceName);
+ 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<Group> collect = serviceLevelGroups
.stream()
.filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType()) && x.getName().startsWith(normaliseComponentInstanceName))
.collect(Collectors.toList());
- log.trace("getVfModulesByVf - VfModules are {}", collect);
+ log.debug("getVfModulesByVf - VfModules are {}", collect);
return collect;
}
}
@@ -179,62 +180,71 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return null;
}
- String[] split = inputLeafValuePath.split("#");
+ String[] split = getSplittedPath(inputLeafValuePath);
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);
+ log.debug("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());
+ log.debug("getServiceInputLeafValue - find first item is {}", findFirst.get());
Input input = findFirst.get();
Object current = input.getDefault();
- if (current == null){
- log.error("getServiceInputLeafValue - this input has no default");
+ return iterateProcessPath(2, current, split);
+ }
+ }
+ log.error("getServiceInputLeafValue - value not found");
+ return null;
+ }
+
+ private String 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<String, Object>)current).get(split[i]);
+ } else {
+ log.error("iterateProcessPath - found an unexpected leaf where expected to find a complex type");
return null;
}
- if (split.length > 2){
- current = new Yaml().load(current.toString());
- 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");
+ if (current != null) {
+ log.debug("iterateProcessPath - the input default leaf value is {}", String.valueOf(current));
+ return String.valueOf(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.trace("getServiceSubstitutionMappingsTypeName - No Substitution Mappings defined");
+ log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings defined");
return null;
}
- log.trace("getServiceSubstitutionMappingsTypeName - SubstitutionMappings value: {}", substitutionMappings);
+ log.debug("getServiceSubstitutionMappingsTypeName - SubstitutionMappings value: {}", substitutionMappings);
NodeType nodeType = substitutionMappings.getNodeDefinition();
if (nodeType == null) {
- log.trace("getServiceSubstitutionMappingsTypeName - No Substitution Mappings node defined");
+ log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings node defined");
return null;
}
- log.trace("getServiceSubstitutionMappingsTypeName - nodeType value: {}", nodeType);
+ log.debug("getServiceSubstitutionMappingsTypeName - nodeType value: {}", nodeType);
return nodeType.getType();
}
@@ -242,7 +252,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
@Override
//Sunny flow - covered with UT
public Metadata getServiceMetadata() {
- return toscaTemplate.getMetadata();
+ return toscaTemplate.getMetaData();
}
@Override
@@ -264,8 +274,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return null;
}
- String[] split = leafValuePath.split("#");
- List<Property> properties = group.getProperties();
+ String[] split = getSplittedPath(leafValuePath);
+ LinkedHashMap<String,Property> properties = group.getProperties();
return processProperties(split, properties);
}
@@ -291,7 +301,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
}
cpList = getNodeTemplateBySdcType(vfInstance, Types.TYPE_CP);
if(cpList == null || cpList.size()==0)
- log.trace("getCpListByVf cps not exist for vfCustomizationId {}",vfCustomizationId);
+ log.debug("getCpListByVf cps not exist for vfCustomizationId {}",vfCustomizationId);
return cpList;
}
@@ -309,7 +319,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
}
- SubstitutionMappings substitutionMappings = vf.getSubstitutionMappings();
+ SubstitutionMappings substitutionMappings = vf.getSubMappingToscaTemplate();
if (substitutionMappings != null){
List<Group> groups = substitutionMappings.getGroups();
if (groups != null){
@@ -317,12 +327,12 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
.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()){
- log.trace("getMembersOfVfModule - Found VF level group with vfModuleModelInvariantUUID {}", serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID));
+ log.debug("getMembersOfVfModule - Found VF level group with vfModuleModelInvariantUUID {}", serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID));
List<String> members = findFirst.get().getMembers();
- log.trace("getMembersOfVfModule - members section is {}", members);
+ log.debug("getMembersOfVfModule - members section is {}", members);
if (members != null){
List<NodeTemplate> collect = substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(Collectors.toList());
- log.trace("getMembersOfVfModule - Node templates are {}", collect);
+ log.debug("getMembersOfVfModule - Node templates are {}", collect);
return collect;
}
}
@@ -344,19 +354,17 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
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()));
- }
+ List<Object> requirements = reqNodeTemplate.getRequirements();
+ for (Object reqEntry : requirements) {
+ LinkedHashMap<String, Object> reqEntryHash = (LinkedHashMap<String, Object>) reqEntry;
+ Map<String, Object> reqEntryMap = (Map<String, Object>) reqEntryHash.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()));
}
}
}
@@ -376,12 +384,12 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
log.error("getAllottedResources nodeTemplates not exist");
}
nodeTemplates = nodeTemplates.stream().filter(
- x -> x.getMetadata() != null && x.getMetadata().getValue("category").equals("Allotted Resources"))
+ x -> x.getMetaData() != null && x.getMetaData().getValue("category").equals("Allotted Resources"))
.collect(Collectors.toList());
if (nodeTemplates.isEmpty()) {
- log.trace("getAllottedResources - allotted resources not exist");
+ log.debug("getAllottedResources - allotted resources not exist");
} else {
- log.trace("getAllottedResources - the allotted resources list is {}", nodeTemplates);
+ log.debug("getAllottedResources - the allotted resources list is {}", nodeTemplates);
}
return nodeTemplates;
@@ -410,16 +418,16 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return new ArrayList<>();
}
- SubstitutionMappings substitutionMappings = nodeTemplate.getSubstitutionMappings();
+ SubstitutionMappings substitutionMappings = nodeTemplate.getSubMappingToscaTemplate();
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());
+ 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");
+ log.debug("getNodeTemplateBySdcType - SubstitutionMappings' node Templates not exist");
} else
- log.trace("getNodeTemplateBySdcType - SubstitutionMappings not exist");
+ log.debug("getNodeTemplateBySdcType - SubstitutionMappings not exist");
return new ArrayList<>();
}
@@ -438,47 +446,29 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
List<NodeTemplate> nodeTemplates = topologyTemplate.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());
+ 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");
+ log.debug("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){
- log.trace("getNodeTemplateByCustomizationUuid - nodeTemplates {}, customizationId {}", nodeTemplates, customizationId);
- Optional<NodeTemplate> findFirst = nodeTemplates.stream().filter(x -> (x.getMetadata() != null && customizationId.equals(x.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)))).findFirst();
+ log.debug("getNodeTemplateByCustomizationUuid - nodeTemplates {}, customizationId {}", nodeTemplates, customizationId);
+ Optional<NodeTemplate> findFirst = nodeTemplates.stream().filter(x -> (x.getMetaData() != null && customizationId.equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)))).findFirst();
return findFirst.isPresent() ? findFirst.get() : 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();
+ private String processProperties(String[] split, LinkedHashMap<String, Property> properties) {
+ log.debug("processProperties - the leafValuePath is {} , the properties are {}", split.toString(), properties.toString());
+ Optional<Entry<String, Property>> findFirst = properties.entrySet().stream().filter(x -> x.getKey().equals(split[0])).findFirst();
if (findFirst.isPresent()){
- log.trace("processProperties - find first item is {}", findFirst.get());
- Property property = findFirst.get();
+ log.debug("processProperties - find first item is {}", findFirst.get());
+ Property property = findFirst.get().getValue();
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(current.toString());
- 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);
- }
+ return iterateProcessPath(1, current, split);
}
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 243d238..f8ac3cc 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
@@ -5,15 +5,13 @@ 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;
+import org.openecomp.sdc.toscaparser.NodeTemplate;
+import org.openecomp.sdc.toscaparser.ToscaTemplate;
+import org.openecomp.sdc.toscaparser.common.JToscaException;
-public class SdcToscaParserFactory implements AutoCloseable{
+public class SdcToscaParserFactory{
private static SdcToscaParserFactory instance;
- private static ToscaParserFactory toscaParserFactory;
private SdcToscaParserFactory(){}
@@ -26,7 +24,6 @@ public class SdcToscaParserFactory implements AutoCloseable{
synchronized (SdcToscaParserFactory.class) {
if (instance == null) {
instance = new SdcToscaParserFactory();
- toscaParserFactory = new ToscaParserFactory();
}
}
}
@@ -38,48 +35,15 @@ public class SdcToscaParserFactory implements AutoCloseable{
* @param csarPath - the path to CSAR file.
* @return ISdcCsarHelper object.
* @throws SdcToscaParserException - in case the path or CSAR are invalid.
+ * @throws JToscaException
*/
- public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws SdcToscaParserException{
+ public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws SdcToscaParserException, JToscaException, IOException{
//TODO add logic to check if legal file and csar
synchronized (SdcToscaParserFactory.class) {
- if (toscaParserFactory == null){
- throw new SdcToscaParserException("The factory is closed. It was probably closed too soon.");
- }
- try {
- 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());
- }
+ ToscaTemplate tosca = new ToscaTemplate(csarPath, null, true, null);
+ SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(tosca);
+ return sdcCsarHelperImpl;
}
}
- /**
- * Close the SdcToscaParserFactory.
- */
- public void close() {
- if (toscaParserFactory != null){
- synchronized (SdcToscaParserFactory.class) {
- if (toscaParserFactory != null) {
- try {
- toscaParserFactory.close();
- toscaParserFactory = null;
- } catch (IOException e) {
- //TODO add logging
- }
- }
- }
- }
- }
-
- 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/test/java/org/openecomp/sdc/impl/BasicTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/BasicTest.java
new file mode 100644
index 0000000..450e6b1
--- /dev/null
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/BasicTest.java
@@ -0,0 +1,22 @@
+package org.openecomp.sdc.impl;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+
+public class BasicTest {
+
+ @Rule
+ public TestName testName = new TestName();
+
+ @Before
+ public void setup(){
+ System.out.println("#### Starting Test " + testName.getMethodName() + " ###########");
+ }
+
+ @After
+ public void tearDown(){
+ System.out.println("#### Ended test " + testName.getMethodName() + " ###########");
+ }
+}
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java
new file mode 100644
index 0000000..e92502c
--- /dev/null
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java
@@ -0,0 +1,99 @@
+package org.openecomp.sdc.impl;
+
+import org.junit.Test;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.toscaparser.Group;
+import org.openecomp.sdc.toscaparser.elements.Metadata;
+
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+public class ToscaParserGroupTest extends BasicTest{
+
+ //region getVfModulesByVf
+ @Test
+ public void testVfModulesFromVf(){
+ List<Group> vfModulesByVf = ToscaParserTestSuite.fdntCsarHelper.getVfModulesByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID);
+ assertEquals(2, vfModulesByVf.size());
+ for (Group group : vfModulesByVf){
+ assertTrue(group.getName().startsWith("fdnt1"));
+ assertNotNull(group.getMetadata());
+ assertNotNull(group.getMetadata().getValue("vfModuleCustomizationUUID"));
+ }
+ }
+
+ @Test
+ public void testGetGroupMetadata(){
+ List<Group> vfModulesByVf = ToscaParserTestSuite.fdntCsarHelper.getVfModulesByVf(ToscaParserTestSuite.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<Group> vfModulesByVf = ToscaParserTestSuite.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<Group> vfModulesByVf = ToscaParserTestSuite.rainyCsarHelperSingleVf.getVfModulesByVf("dummy");
+ assertNotNull(vfModulesByVf);
+ assertEquals(0, vfModulesByVf.size());
+ }
+
+ @Test
+ public void testGetVfModuleNullVf() {
+ List<Group> vfModulesByVf = ToscaParserTestSuite.rainyCsarHelperSingleVf.getVfModulesByVf(null);
+ assertNotNull(vfModulesByVf);
+ assertEquals(0, vfModulesByVf.size());
+ }
+ //endregion
+
+ //region getGroupPropertyLeafValue
+ @Test
+ public void testGroupFlatProperty() throws SdcToscaParserException {
+ List<Group> vfModulesByVf = ToscaParserTestSuite.fdntCsarHelper.getVfModulesByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID);
+ String volumeGroup = ToscaParserTestSuite.fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "volume_group");
+ assertEquals("false", volumeGroup);
+ }
+
+ @Test
+ public void testGroupPropertyLeafValueByNullProperty() {
+ List<Group> vfModulesByVf = ToscaParserTestSuite.fdntCsarHelper.getVfModulesByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID);
+ String groupProperty = ToscaParserTestSuite.fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), null);
+ assertNull(groupProperty);
+ }
+
+ @Test
+ public void testGroupPropertyLeafValueByDummyProperty() {
+ List<Group> vfModulesByVf = ToscaParserTestSuite.fdntCsarHelper.getVfModulesByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID);
+ String groupProperty = ToscaParserTestSuite.fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "XXX");
+ assertNull(groupProperty);
+ }
+
+ @Test
+ public void testGroupPropertyLeafValueByNullGroup() {
+ String groupProperty = ToscaParserTestSuite.fdntCsarHelper.getGroupPropertyLeafValue(null, "volume_group");
+ assertNull(groupProperty);
+ }
+ //endregion
+
+}
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java
new file mode 100644
index 0000000..6744536
--- /dev/null
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java
@@ -0,0 +1,58 @@
+package org.openecomp.sdc.impl;
+
+import org.junit.Test;
+import org.openecomp.sdc.toscaparser.elements.Metadata;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class ToscaParserMetadataTest extends BasicTest {
+
+ //region getServiceMetadata
+ @Test
+ public void testGetServiceMetadata() {
+ Metadata serviceMetadata = ToscaParserTestSuite.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 = ToscaParserTestSuite.rainyCsarHelperSingleVf.getServiceMetadata();
+ assertNull(metadata);
+ }
+ //endregion
+
+ //region getMetadataPropertyValue
+ @Test
+ public void testGetMetadataProperty(){
+ Metadata serviceMetadata = ToscaParserTestSuite.fdntCsarHelper.getServiceMetadata();
+ String metadataPropertyValue = ToscaParserTestSuite.fdntCsarHelper.getMetadataPropertyValue(serviceMetadata, "invariantUUID");
+ assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", metadataPropertyValue);
+ }
+
+ @Test
+ public void testGetNullMetadataPropertyValue() {
+ String value = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getMetadataPropertyValue(null, "XXX");
+ assertNull(value);
+ }
+
+ @Test
+ public void testGetMetadataByNullPropertyValue() {
+ Metadata metadata = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getServiceMetadata();
+ String value = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getMetadataPropertyValue(metadata, null);
+ assertNull(value);
+ }
+
+ @Test
+ public void testGetMetadataByEmptyPropertyValue() {
+ Metadata metadata = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getServiceMetadata();
+ String value = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getMetadataPropertyValue(metadata, "");
+ assertNull(value);
+ }
+ //endregion
+
+}
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
new file mode 100644
index 0000000..3ca3ca4
--- /dev/null
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
@@ -0,0 +1,298 @@
+package org.openecomp.sdc.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Test;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.toscaparser.Group;
+import org.openecomp.sdc.toscaparser.NodeTemplate;
+
+public class ToscaParserNodeTemplateTest extends BasicTest {
+
+ //region getServiceVfList
+ @Test
+ public void testNumberOfVfSunnyFlow() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = ToscaParserTestSuite.fdntCsarHelper.getServiceVfList();
+ assertNotNull(serviceVfList);
+ assertEquals(1, serviceVfList.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 = ToscaParserTestSuite.rainyCsarHelperSingleVf.getServiceVfList();
+ assertNotNull(serviceVfList);
+ assertEquals(0, serviceVfList.size());
+ }
+ //endregion
+
+ //region getNodeTemplatePropertyLeafValue
+ @Test
+ public void testNodeTemplateFlatProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = ToscaParserTestSuite.fdntCsarHelper.getServiceVfList();
+ assertEquals("2", ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "availability_zone_max_count"));
+ assertEquals("3", ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "max_instances"));
+ assertEquals("some code", ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_naming_code"));
+ }
+
+ @Test
+ public void testNodeTemplateNestedProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVlList = ToscaParserTestSuite.fdntCsarHelper.getServiceVlList();
+ NodeTemplate nodeTemplate = serviceVlList.get(0);
+ System.out.println("node template " + nodeTemplate.toString());
+ assertEquals("24", ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#cidr_mask"));
+ assertEquals("7a6520b-9982354-ee82992c-105720", ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_flows#vpn_binding"));
+ }
+
+ @Test
+ public void testNodeTemplateNestedPropertyNotExists() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = ToscaParserTestSuite.fdntCsarHelper.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_role#nf_naming#kuku");
+ assertNull(nodeTemplatePropertyLeafValue);
+ }
+
+ @Test
+ public void testNodeTemplateFlatPropertyByNotFoundProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "XXXX");
+ assertNull(nodeTemplatePropertyLeafValue);
+ }
+
+ @Test
+ public void testNodeTemplateFlatPropertyByNullProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), null);
+ assertNull(nodeTemplatePropertyLeafValue);
+ }
+
+ @Test
+ public void testNodeTemplateFlatPropertyByNullNodeTemplate() throws SdcToscaParserException {
+ String nodeTemplatePropertyLeafValue = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(null, "availability_zone_max_count");
+ assertNull(nodeTemplatePropertyLeafValue);
+ }
+ //endregion
+
+ //region getServiceVlList
+ @Test
+ public void testServiceVl() {
+ List<NodeTemplate> vlList = ToscaParserTestSuite.fdntCsarHelper.getServiceVlList();
+ assertEquals(1, vlList.size());
+ assertEquals("exVL", vlList.get(0).getName());
+ }
+
+ @Test
+ public void testNumberOfVLRainyFlow() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVlList = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getServiceVlList();
+ assertNotNull(serviceVlList);
+ assertEquals(0, serviceVlList.size());
+ }
+ //endregion
+
+ //region getServiceNodeTemplatesByType
+ @Test
+ public void testServiceNodeTemplatesByType() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = ToscaParserTestSuite.fdntCsarHelper.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Fdnt");
+ assertNotNull(serviceVfList);
+ assertEquals(1, serviceVfList.size());
+ }
+
+ @Test
+ public void testServiceNodeTemplatesByNull() {
+ List<NodeTemplate> nodeTemplates = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType(null);
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+
+ @Test
+ public void testServiceNodeTemplatesByNotFoundProperty() {
+ List<NodeTemplate> nodeTemplates = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType("XXX");
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+ //endregion
+
+ //region getTypeOfNodeTemplate
+ @Test
+ public void testGetTypeOfNodeTemplate() {
+ List<NodeTemplate> serviceVfList = ToscaParserTestSuite.fdntCsarHelper.getServiceVfList();
+ String typeOfNodeTemplate = ToscaParserTestSuite.fdntCsarHelper.getTypeOfNodeTemplate(serviceVfList.get(0));
+ assertEquals("org.openecomp.resource.vf.Fdnt", typeOfNodeTemplate);
+ }
+
+ @Test
+ public void testGetTypeOfNullNodeTemplate() {
+ String typeOfNodeTemplate = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getTypeOfNodeTemplate(null);
+ assertNull(typeOfNodeTemplate);
+ }
+ //endregion
+
+ //region getAllottedResources
+ @Test
+ public void testGetAllottedResources() {
+ List<NodeTemplate> allottedResources = ToscaParserTestSuite.fdntCsarHelper.getAllottedResources();
+ assertEquals(0, allottedResources.size());
+ }
+
+ @Test
+ public void testGetAllottedResourcesZero() {
+ List<NodeTemplate> allottedResources = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getAllottedResources();
+ assertNotNull(allottedResources);
+ assertEquals(0, allottedResources.size());
+ }
+ //endregion
+
+ //region getVfcListByVf
+ @Test
+ public void testGetVfcFromVf() {
+ List<NodeTemplate> vfcListByVf = ToscaParserTestSuite.fdntCsarHelper.getVfcListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID);
+ assertEquals(2, vfcListByVf.size());
+ }
+
+ @Test
+ public void testVfcListByNull() {
+ List<NodeTemplate> vfcList = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getVfcListByVf(null);
+ assertNotNull(vfcList);
+ assertEquals(0, vfcList.size());
+ }
+
+ @Test
+ public void testVfcListByNotFoundProperty() {
+ List<NodeTemplate> vfcList = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getVfcListByVf("XXX");
+ assertNotNull(vfcList);
+ assertEquals(0, vfcList.size());
+ }
+ //endregion
+
+ //region getCpListByVf
+ @Test
+ public void testGetCpFromVf() {
+ List<NodeTemplate> cpListByVf = ToscaParserTestSuite.fdntCsarHelper.getCpListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID);
+ assertEquals(1, cpListByVf.size());
+ NodeTemplate nodeTemplate = cpListByVf.get(0);
+ assertEquals("DNT_PORT", nodeTemplate.getName());
+ }
+
+ @Test
+ public void testGetCpFromVfByNullId() {
+ List<NodeTemplate> cpListByVf = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getCpListByVf(null);
+ assertNotNull(cpListByVf);
+ assertEquals(0, cpListByVf.size());
+ }
+
+ @Test
+ public void testGetCpFromVfXxx() {
+ List<NodeTemplate> cpListByVf = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getCpListByVf("XXXXX");
+ assertNotNull(cpListByVf);
+ assertEquals(0, cpListByVf.size());
+ }
+ //endregion
+
+ //region getNodeTemplatePairsByReqName
+ @Test
+ public void testGetNodeTemplatePairsByReqName() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePairsByReqName(ToscaParserTestSuite.fdntCsarHelper.getCpListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID), ToscaParserTestSuite.fdntCsarHelper.getVfcListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID), "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 testGetNodeTemplatePairsByReqNameWithNullVF() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePairsByReqName(
+ null, ToscaParserTestSuite.fdntCsarHelper.getVfcListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID), "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithEmptyVF() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePairsByReqName(
+ new ArrayList<>(), ToscaParserTestSuite.fdntCsarHelper.getVfcListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID), "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithNullCap() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePairsByReqName(
+ ToscaParserTestSuite.fdntCsarHelper.getCpListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID), null, "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithEmptyCap() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePairsByReqName(
+ ToscaParserTestSuite.fdntCsarHelper.getCpListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID), new ArrayList<>(), "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithNullReq() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePairsByReqName(
+ ToscaParserTestSuite.fdntCsarHelper.getCpListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID), ToscaParserTestSuite.fdntCsarHelper.getVfcListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID), null);
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithDummyReq() {
+
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePairsByReqName(
+ ToscaParserTestSuite.fdntCsarHelper.getCpListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID), ToscaParserTestSuite.fdntCsarHelper.getVfcListByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID), "XXX");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+ //endregion
+
+ //region getMembersOfVfModule
+ @Test
+ public void testGetMembersOfVfModule() {
+ NodeTemplate vf = ToscaParserTestSuite.fdntCsarHelper.getServiceVfList().get(0);
+ List<Group> vfModulesByVf = ToscaParserTestSuite.fdntCsarHelper.getVfModulesByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID);
+ assertEquals(2, vfModulesByVf.size());
+ for (Group group : vfModulesByVf) {
+ List<NodeTemplate> membersOfVfModule = ToscaParserTestSuite.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<Group> vfModulesByVf = ToscaParserTestSuite.fdntCsarHelper.getVfModulesByVf(ToscaParserTestSuite.VF_CUSTOMIZATION_UUID);
+ List<NodeTemplate> nodeTemplates = ToscaParserTestSuite.fdntCsarHelper.getMembersOfVfModule(null, vfModulesByVf.get(0));
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+
+ @Test
+ public void testMembersOfVfModuleByNullGroup() {
+ List<NodeTemplate> serviceVfList = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getServiceVfList();
+ List<NodeTemplate> nodeTemplates = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getMembersOfVfModule(serviceVfList.get(0), null);
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+ //endregion
+
+}
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java
new file mode 100644
index 0000000..30aff6a
--- /dev/null
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java
@@ -0,0 +1,50 @@
+package org.openecomp.sdc.impl;
+
+import org.junit.Test;
+import org.openecomp.sdc.toscaparser.parameters.Input;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class ToscaParserServiceInputTest extends BasicTest {
+
+ //region getServiceInputs
+ @Test
+ public void testGetServiceInputs(){
+ List<Input> serviceInputs = ToscaParserTestSuite.fdntCsarHelper.getServiceInputs();
+ assertNotNull(serviceInputs);
+ assertEquals(1, serviceInputs.size());
+ }
+
+ @Test
+ public void testServiceInputs() {
+ List<Input> inputs = ToscaParserTestSuite.rainyCsarHelperSingleVf.getServiceInputs();
+ assertNotNull(inputs);
+ assertEquals(0, inputs.size());
+ }
+ //endregion
+
+ //region getServiceInputLeafValueOfDefault
+ @Test
+ public void testGetServiceInputLeafValue(){
+ String serviceInputLeafValue = ToscaParserTestSuite.fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default");
+ assertEquals("test service naming", serviceInputLeafValue);
+ }
+
+ @Test
+ public void testGetServiceInputLeafValueNotExists(){
+ String serviceInputLeafValue = ToscaParserTestSuite.fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default#kuku");
+ assertNull(serviceInputLeafValue);
+ }
+
+ @Test
+ public void testGetServiceInputLeafValueNull(){
+ String serviceInputLeafValue = ToscaParserTestSuite.fdntCsarHelper.getServiceInputLeafValueOfDefault(null);
+ assertNull(serviceInputLeafValue);
+ }
+ //endregion
+
+}
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
deleted file mode 100644
index e3cdb6f..0000000
--- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java
+++ /dev/null
@@ -1,503 +0,0 @@
-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 org.apache.commons.lang3.tuple.Pair;
-import org.junit.AfterClass;
-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 final String VF_CUSTOMIZATION_UUID = "56179cd8-de4a-4c38-919b-bbc4452d2d73";
- static SdcToscaParserFactory factory;
- static ISdcCsarHelper rainyCsarHelperSingleVf;
- static ISdcCsarHelper rainyCsarHelperMultiVfs;
- static ISdcCsarHelper rainyCsarHelperNoVf;
- static ISdcCsarHelper fdntCsarHelper;
-
- @BeforeClass
- public static void init() throws SdcToscaParserException{
- long startTime = System.currentTimeMillis();
- factory = SdcToscaParserFactory.getInstance();
- long estimatedTime = System.currentTimeMillis() - startTime;
- System.out.println("Time to init factory "+estimatedTime);
- String fileStr2 = ToscaParserStubsTest.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-0904-2.csar").getFile();
- File file2 = new File(fileStr2);
- startTime = System.currentTimeMillis();
- fdntCsarHelper = 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);
- 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(fileStr4);
- rainyCsarHelperNoVf = factory.getSdcCsarHelper(file4.getAbsolutePath());*/
- }
-
- @Test
- public void testNumberOfVfSunnyFlow() throws SdcToscaParserException {
- List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
- assertNotNull(serviceVfList);
- assertEquals(1, serviceVfList.size());
- }
-
- @Test
- public void testNodeTemplateFlatProperty() throws SdcToscaParserException {
- List<NodeTemplate> 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 testGroupFlatProperty() throws SdcToscaParserException {
- List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
- String volumeGroup = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "volume_group");
- assertEquals("false", volumeGroup);
- }
-
- @Test
- public void testServiceVl(){
- List<NodeTemplate> vlList = fdntCsarHelper.getServiceVlList();
- assertEquals(1, vlList.size());
- assertEquals("exVL", vlList.get(0).getName());
- }
-
- @Test
- public void testNodeTemplateNestedProperty() throws SdcToscaParserException {
- List<NodeTemplate> 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 testServiceNodeTemplatesByType() throws SdcToscaParserException {
- List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Fdnt");
- assertNotNull(serviceVfList);
- assertEquals(1, serviceVfList.size());
- }
-
- @Test
- public void testGetTypeOfNodeTemplate() {
- List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
- String typeOfNodeTemplate = fdntCsarHelper.getTypeOfNodeTemplate(serviceVfList.get(0));
- assertEquals("org.openecomp.resource.vf.Fdnt", typeOfNodeTemplate);
- }
-
- @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 testGetAllottedResources() {
- List<NodeTemplate> allottedResources = fdntCsarHelper.getAllottedResources();
- assertEquals(0, allottedResources.size());
- }
-
- @Test
- public void testGetServiceSubstitutionMappingsTypeName() {
- String serviceSubstitutionMappingsTypeName = fdntCsarHelper.getServiceSubstitutionMappingsTypeName();
- assertEquals("org.openecomp.service.ServiceFdnt", serviceSubstitutionMappingsTypeName);
- }
-
- @Test
- public void testGetVfcFromVf(){
- List<NodeTemplate> vfcListByVf = fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID);
- assertEquals(2, vfcListByVf.size());
- }
-
- @Test
- public void testGetCpFromVf(){
- List<NodeTemplate> cpListByVf = fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID);
- assertEquals(1, cpListByVf.size());
- NodeTemplate nodeTemplate = cpListByVf.get(0);
- assertEquals("DNT_PORT", nodeTemplate.getName());
- }
-
- @Test
- public void testVfModulesFromVf(){
- List<Group> 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("vfModuleCustomizationUUID"));
- }
- }
-
- @Test
- public void testGetNodeTemplatePairsByReqName(){
- List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "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 = fdntCsarHelper.getServiceVfList().get(0);
- List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
- assertEquals(2, vfModulesByVf.size());
- for (Group group : vfModulesByVf){
- List<NodeTemplate> 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 testGetServiceInputs(){
- List<Input> serviceInputs = fdntCsarHelper.getServiceInputs();
- assertNotNull(serviceInputs);
- assertEquals(1, serviceInputs.size());
- }
-
- @Test
- public void testGetMetadataProperty(){
- Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata();
- String metadataPropertyValue = fdntCsarHelper.getMetadataPropertyValue(serviceMetadata, "invariantUUID");
- assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", metadataPropertyValue);
- }
-
- @Test
- public void testGetGroupMetadata(){
- List<Group> 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 testGetServiceInputLeafValue(){
- String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default");
- assertEquals("test service naming", serviceInputLeafValue);
- }
-
-
- /***************** RAINY TESTS ***************************/
-
-
- @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);
- }
-
- @Test
- public void testNodeTemplateNestedPropertyNotExists() throws SdcToscaParserException {
- List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
- String nodeTemplatePropertyLeafValue = fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_role#nf_naming#kuku");
- assertNull(nodeTemplatePropertyLeafValue);
- }
-
- @Test
- public void testGetGroupEmptyMetadata(){
- List<Group> 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 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 = fdntCsarHelper.getGroupPropertyLeafValue(null, "volume_group");
- assertNull(groupProperty);
- }
-
- @Test
- public void testGroupPropertyLeafValueByNullProperty() {
- List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
- String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), null);
- assertNull(groupProperty);
- }
-
- @Test
- public void testGroupPropertyLeafValueByDummyProperty() {
- List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
- String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "XXX");
- assertNull(groupProperty);
- }
-
- @Test
- public void testMembersOfVfModuleByNullVf() {
- List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
- List<NodeTemplate> nodeTemplates = fdntCsarHelper.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 = fdntCsarHelper.getNodeTemplatePairsByReqName(
- null, fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding");
- assertNotNull(nodeTemplatePairsByReqName);
- assertEquals(0, nodeTemplatePairsByReqName.size());
- }
-
- @Test
- public void testGetNodeTemplatePairsByReqNameWithEmptyVF(){
- List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(
- new ArrayList<>(), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding");
- assertNotNull(nodeTemplatePairsByReqName);
- assertEquals(0, nodeTemplatePairsByReqName.size());
- }
-
- @Test
- public void testGetNodeTemplatePairsByReqNameWithNullCap(){
- List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(
- fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), null, "binding");
- assertNotNull(nodeTemplatePairsByReqName);
- assertEquals(0, nodeTemplatePairsByReqName.size());
- }
-
- @Test
- public void testGetNodeTemplatePairsByReqNameWithEmptyCap(){
- List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(
- fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), new ArrayList<>(), "binding");
- assertNotNull(nodeTemplatePairsByReqName);
- assertEquals(0, nodeTemplatePairsByReqName.size());
- }
-
- @Test
- public void testGetNodeTemplatePairsByReqNameWithNullReq(){
- List<Pair<NodeTemplate, NodeTemplate>> 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<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(
- fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "XXX");
- assertNotNull(nodeTemplatePairsByReqName);
- assertEquals(0, nodeTemplatePairsByReqName.size());
- }
-
- @Test
- public void testServiceInputs() {
- List<Input> inputs = rainyCsarHelperSingleVf.getServiceInputs();
- assertNotNull(inputs);
- assertEquals(0, inputs.size());
- }
-
- //TODO restore the test - the CSAR without VF is failing Tosca parser
- /*@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/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java
new file mode 100644
index 0000000..fc0aff5
--- /dev/null
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java
@@ -0,0 +1,24 @@
+package org.openecomp.sdc.impl;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class ToscaParserSubsMappingsTest extends BasicTest {
+
+ //region getServiceSubstitutionMappingsTypeName
+ @Test
+ public void testGetServiceSubstitutionMappingsTypeName() {
+ String serviceSubstitutionMappingsTypeName = ToscaParserTestSuite.fdntCsarHelper.getServiceSubstitutionMappingsTypeName();
+ assertEquals("org.openecomp.service.ServiceFdnt", serviceSubstitutionMappingsTypeName);
+ }
+
+ @Test
+ public void testServiceSubstitutionMappingsTypeName() {
+ String substitutionMappingsTypeName = ToscaParserTestSuite.rainyCsarHelperMultiVfs.getServiceSubstitutionMappingsTypeName();
+ assertNull(substitutionMappingsTypeName);
+ }
+ //endregion
+
+}
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserTestSuite.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserTestSuite.java
new file mode 100644
index 0000000..3437b8d
--- /dev/null
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserTestSuite.java
@@ -0,0 +1,64 @@
+package org.openecomp.sdc.impl;
+
+import org.junit.*;
+import org.junit.runners.Suite;
+import org.junit.runner.RunWith;
+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.common.JToscaException;
+
+import java.io.File;
+import java.io.IOException;
+
+@RunWith( Suite.class )
+@Suite.SuiteClasses( {
+ ToscaParserNodeTemplateTest.class,
+ ToscaParserSubsMappingsTest.class,
+ ToscaParserGroupTest.class,
+ ToscaParserMetadataTest.class,
+ ToscaParserServiceInputTest.class,
+} )
+public class ToscaParserTestSuite {
+
+ public static final String VF_CUSTOMIZATION_UUID = "56179cd8-de4a-4c38-919b-bbc4452d2d73";
+ static SdcToscaParserFactory factory;
+ static ISdcCsarHelper rainyCsarHelperSingleVf;
+ static ISdcCsarHelper rainyCsarHelperMultiVfs;
+ static ISdcCsarHelper fdntCsarHelper;
+
+ @BeforeClass
+ public static void init() throws SdcToscaParserException, JToscaException, IOException {
+
+ factory = SdcToscaParserFactory.getInstance();
+ long startTime = System.currentTimeMillis();
+ long estimatedTime = System.currentTimeMillis() - startTime;
+ System.out.println("Time to init factory " + estimatedTime);
+
+ String fileStr1 = ToscaParserTestSuite.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-0904-2.csar").getFile();
+ File file1 = new File(fileStr1);
+ startTime = System.currentTimeMillis();
+
+ fdntCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath());
+
+ estimatedTime = System.currentTimeMillis() - startTime;
+ System.out.println("init CSAR Execution time: " + estimatedTime);
+
+ String fileStr2 = ToscaParserTestSuite.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-rainy.csar").getFile();
+ File file2 = new File(fileStr2);
+ rainyCsarHelperMultiVfs = factory.getSdcCsarHelper(file2.getAbsolutePath());
+
+ String fileStr3 = ToscaParserTestSuite.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar.csar").getFile();
+ File file3 = new File(fileStr3);
+ rainyCsarHelperSingleVf = factory.getSdcCsarHelper(file3.getAbsolutePath());
+ };
+
+ @AfterClass
+ public static void after(){
+ long startTime = System.currentTimeMillis();
+ long estimatedTime = System.currentTimeMillis() - startTime;
+ System.out.println("close Execution time: "+estimatedTime);
+ };
+
+
+}