aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorManzon, Inna (im453s) <im453s@intl.att.com>2018-09-12 18:58:05 +0300
committerMichael Lando <ml636r@att.com>2018-09-27 12:14:56 +0000
commita8b7b97e8f4aa088a7e39e06946c425ddd1ba2b4 (patch)
tree8c9ba44de4e337f67602c3b54776494e2eb047ee /src
parentc244e1a7ede9c936b81b48b9e6e00dff64461e1d (diff)
Tosca Parser - getPropertyValue and tests
Change-Id: I1baa920033f410f90b2b742c007d917eb6e151ff Issue-ID: SDC-1757 Signed-off-by: Manzon, Inna (im453s) <im453s@intl.att.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java51
-rw-r--r--src/main/java/org/onap/sdc/tosca/parser/enums/FilterType.java (renamed from src/main/java/org/onap/sdc/tosca/parser/impl/FilterType.java)2
-rw-r--r--src/main/java/org/onap/sdc/tosca/parser/enums/JToscaValidationIssueType.java (renamed from src/main/java/org/onap/sdc/tosca/parser/impl/JToscaValidationIssueType.java)2
-rw-r--r--src/main/java/org/onap/sdc/tosca/parser/enums/PropertySchemaType.java69
-rw-r--r--src/main/java/org/onap/sdc/tosca/parser/enums/SdcTypes.java (renamed from src/main/java/org/onap/sdc/tosca/parser/impl/SdcTypes.java)4
-rw-r--r--src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java199
-rw-r--r--src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java1
-rw-r--r--src/main/java/org/onap/sdc/tosca/parser/impl/SdcToscaParserFactory.java1
-rw-r--r--src/main/java/org/onap/sdc/tosca/parser/utils/PropertyUtils.java172
-rw-r--r--src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java122
-rw-r--r--src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java3
-rw-r--r--src/test/java/org/onap/sdc/tosca/parser/impl/ToscaParserNodeTemplateMockTest.java197
12 files changed, 712 insertions, 111 deletions
diff --git a/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java b/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java
index cc47db9..8ce4b1b 100644
--- a/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java
+++ b/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java
@@ -24,8 +24,8 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
-import org.onap.sdc.tosca.parser.impl.SdcTypes;
-import org.onap.sdc.tosca.parser.impl.FilterType;
+import org.onap.sdc.tosca.parser.enums.SdcTypes;
+import org.onap.sdc.tosca.parser.enums.FilterType;
import org.onap.sdc.toscaparser.api.*;
import org.onap.sdc.toscaparser.api.elements.InterfacesDef;
import org.onap.sdc.toscaparser.api.elements.Metadata;
@@ -108,7 +108,7 @@ public interface ISdcCsarHelper {
* @param pathToPropertyLeafValue - the full path of the required property.
* @return the leaf value as Object, or null if there's no such property. It's up to the caller to cast it to a proper type.
*/
- public Object getNodeTemplatePropertyAsObject(NodeTemplate nodeTemplate, String pathToPropertyLeafValue);
+ public Object getNodeTemplatePropertyValueAsObject(NodeTemplate nodeTemplate, String pathToPropertyLeafValue);
/**
* Get any property leaf value for a group definition by full path separated by #.
@@ -479,14 +479,14 @@ public interface ISdcCsarHelper {
* @param policyTypeName the name of the policy type
* @return the list of the policies
*/
- public List<Policy> getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName);
+ List<Policy> getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName);
/**
* Get all the node templates of the topology template, which are the targets of the policy specified by name
* @param policyName the name of the policy
* @return the list of the node templates
*/
- public List<NodeTemplate> getPolicyTargetsFromTopologyTemplate(String policyName);
+ List<NodeTemplate> getPolicyTargetsFromTopologyTemplate(String policyName);
/**
* Get all the node templates of the origin component (nested topology template) of node template, which are the targets of the policy specified by name
@@ -494,21 +494,21 @@ public interface ISdcCsarHelper {
* @param policyName the name of the policy
* @return the list of the node templates
*/
- public List<NodeTemplate> getPolicyTargetsFromOrigin(NodeTemplate nodeTemplate, String policyName);
+ List<NodeTemplate> getPolicyTargetsFromOrigin(NodeTemplate nodeTemplate, String policyName);
/**
* Get the node template of the topology template specified by name
* @param nodeTemplateName the name of the node template
* @return the node template
*/
- public NodeTemplate getNodeTemplateByName(String nodeTemplateName);
+ NodeTemplate getNodeTemplateByName(String nodeTemplateName);
/**
* Get all the policies, which contain the specified node template as a target
* @param targetNode the node template
* @return the list of the policies
*/
- public List<Policy> getPoliciesOfTarget(NodeTemplate targetNode);
+ List<Policy> getPoliciesOfTarget(NodeTemplate targetNode);
/**
* Get all the policies of the specified type, which contain the specified node template as a target
@@ -516,27 +516,27 @@ public interface ISdcCsarHelper {
* @param policyTypeName the name of the policy type
* @return the list of the policies
*/
- public List<Policy> getPoliciesOfTargetByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName);
+ List<Policy> getPoliciesOfTargetByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName);
/**
* Get all the groups of the origin component (nested topology template) of the node template
* @param nodeTemplate the node template
* @return the list of the groups
*/
- public ArrayList<Group> getGroupsOfOriginOfNodeTemplate(NodeTemplate nodeTemplate);
+ ArrayList<Group> getGroupsOfOriginOfNodeTemplate(NodeTemplate nodeTemplate);
/**
* Get all groups of this of the main topology template (either VF or service) by specified tosca group type
* @param groupType the group type
* @return the list of the groups
*/
- public ArrayList<Group> getGroupsOfTopologyTemplateByToscaGroupType(String groupType);
+ ArrayList<Group> getGroupsOfTopologyTemplateByToscaGroupType(String groupType);
/**
* Get all groups of this of the main topology template (either VF or service)
* @return the list of the groups
*/
- public ArrayList<Group> getGroupsOfTopologyTemplate();
+ ArrayList<Group> getGroupsOfTopologyTemplate();
/**
* Get all groups of this of the origin component (nested topology template) of the node template by specified tosca group type
@@ -544,14 +544,14 @@ public interface ISdcCsarHelper {
* @param groupType the group type
* @return the list of the groups
*/
- public ArrayList<Group> getGroupsOfOriginOfNodeTemplateByToscaGroupType(NodeTemplate nodeTemplate, String groupType);
+ ArrayList<Group> getGroupsOfOriginOfNodeTemplateByToscaGroupType(NodeTemplate nodeTemplate, String groupType);
/**
* Get members of the group belongs to the main topology template (either VF or service) by group name
* @param groupName the name of the group
* @return the list of the node templates
*/
- public List<NodeTemplate> getGroupMembersFromTopologyTemplate(String groupName);
+ List<NodeTemplate> getGroupMembersFromTopologyTemplate(String groupName);
/**
* Get members of the group belongs to the origin component (nested topology template) of the node template by group name
@@ -559,20 +559,20 @@ public interface ISdcCsarHelper {
* @param groupName the name of the group
* @return the list of the node templates
*/
- public List<NodeTemplate> getGroupMembersOfOriginOfNodeTemplate(NodeTemplate nodeTemplate, String groupName);
+ List<NodeTemplate> getGroupMembersOfOriginOfNodeTemplate(NodeTemplate nodeTemplate, String groupName);
/**
* Get inputs of the topology template including existing annotations
* @return the list of the inputs
*/
- public List<Input> getInputsWithAnnotations();
+ List<Input> getInputsWithAnnotations();
/**
* Get all interface details for given node template.<br>
* @return Map that contains the list of all interfaces and their definitions.
* If none found, an empty map will be returned.
*/
- public Map<String, List<InterfacesDef>> getInterfacesOf(NodeTemplate nt);
+ Map<String, List<InterfacesDef>> getInterfacesOf(NodeTemplate nt);
/**
* Get all interface names for given node template.<br>
@@ -586,20 +586,31 @@ public interface ISdcCsarHelper {
* @return List that contains the definitions of given interface name.
* If none found, an empty list will be returned.
*/
- public List<InterfacesDef> getInterfaceDetails(NodeTemplate nt, String interfaceName);
+ List<InterfacesDef> getInterfaceDetails(NodeTemplate nt, String interfaceName);
/**
* Get all operation names for given node template and interface name.<br>
* @return List that contains the name of all operations for a given node template and interface name.
* If none found, an empty list will be returned.
*/
- public List<String> getAllInterfaceOperations(NodeTemplate nt, String interfaceName);
+ List<String> getAllInterfaceOperations(NodeTemplate nt, String interfaceName);
/**
* Get interface details for a given node template, interface name and operation name.<br>
* @return InterfaceDef representing the operation details.
* If none found, null will be returned.
*/
- public InterfacesDef getInterfaceOperationDetails(NodeTemplate nt, String interfaceName, String operationName);
+ InterfacesDef getInterfaceOperationDetails(NodeTemplate nt, String interfaceName, String operationName);
+ /**
+ * Get property value for a property of given node template.<br>
+ * @param propertyNamePath valid name of property for search.<br>
+ * To find value in the datatype with datatype entry schema, the property name should be defined with # delimiter
+ * @param nodeTemplatePath path to the model node template that property value will be searched.<br>
+ * Path is based on the collection of the node templates names delimited by #.
+ * @return List of property values. If none found, empty list will be returned.
+ */
+ List<String> getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath(String propertyNamePath, String nodeTemplatePath);
+
+ boolean isNodeTypeSupported(NodeTemplate nodeTemplate);
} \ No newline at end of file
diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/FilterType.java b/src/main/java/org/onap/sdc/tosca/parser/enums/FilterType.java
index 09c3c5c..c4ce838 100644
--- a/src/main/java/org/onap/sdc/tosca/parser/impl/FilterType.java
+++ b/src/main/java/org/onap/sdc/tosca/parser/enums/FilterType.java
@@ -1,4 +1,4 @@
-package org.onap.sdc.tosca.parser.impl;
+package org.onap.sdc.tosca.parser.enums;
public enum FilterType {
diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/JToscaValidationIssueType.java b/src/main/java/org/onap/sdc/tosca/parser/enums/JToscaValidationIssueType.java
index fb13867..539ba00 100644
--- a/src/main/java/org/onap/sdc/tosca/parser/impl/JToscaValidationIssueType.java
+++ b/src/main/java/org/onap/sdc/tosca/parser/enums/JToscaValidationIssueType.java
@@ -1,4 +1,4 @@
-package org.onap.sdc.tosca.parser.impl;
+package org.onap.sdc.tosca.parser.enums;
public enum JToscaValidationIssueType {
CRITICAL,
diff --git a/src/main/java/org/onap/sdc/tosca/parser/enums/PropertySchemaType.java b/src/main/java/org/onap/sdc/tosca/parser/enums/PropertySchemaType.java
new file mode 100644
index 0000000..48fc28f
--- /dev/null
+++ b/src/main/java/org/onap/sdc/tosca/parser/enums/PropertySchemaType.java
@@ -0,0 +1,69 @@
+package org.onap.sdc.tosca.parser.enums;
+
+
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+
+import static org.onap.sdc.tosca.parser.enums.PropertySchemaType.PropertySchemaComplexity.Complex;
+import static org.onap.sdc.tosca.parser.enums.PropertySchemaType.PropertySchemaComplexity.DataType;
+import static org.onap.sdc.tosca.parser.enums.PropertySchemaType.PropertySchemaComplexity.Simple;
+
+public enum PropertySchemaType {
+
+ STRING(Simple, "string"),
+ INTEGER(Simple, "integer"),
+ BOOLEAN(Simple, "boolean"),
+ FLOAT(Simple, "float"),
+ NUMBER(Simple, "number"),
+ TIMESTAMP(Simple, "timestamp"),
+ RANGE(Simple, "range"),
+ VERSION(Simple, "version"),
+ SCALAR_UNIT_SIZE(Simple, "scalar-unit.size"),
+ SCALAR_UNIT_TIME(Simple, "scalar-unit.time"),
+ SCALAR_UNIT_FREQUENCY(Simple, "scalar-unit.frequency"),
+ LIST(Complex, "list"),
+ MAP(Complex, "map"),
+ DATATYPE(DataType, "datatypes");
+
+ private PropertySchemaComplexity complexity;
+ private String schemaType;
+
+ PropertySchemaType(PropertySchemaComplexity complexity, String schemaType) {
+ this.complexity = complexity;
+ this.schemaType = schemaType;
+ }
+
+ public PropertySchemaComplexity getSchemaTypeComplexity() {
+ return complexity;
+ }
+
+ public String getSchemaTypeName() {
+ return schemaType;
+ }
+
+ public enum PropertySchemaComplexity {
+ Simple, Complex, DataType
+ }
+
+ public static PropertySchemaType getEnumByValue(String type){
+ if (type == null) {
+ throwNoSuchElementException(null);
+ }
+
+ if (type.contains(DATATYPE.getSchemaTypeName())) {
+ return DATATYPE;
+ }
+ PropertySchemaType propertySchemaType = Arrays.stream(PropertySchemaType.values())
+ .filter(v->v.getSchemaTypeName().equals(type))
+ .findFirst().orElse(null);
+ if (propertySchemaType == null) {
+ throwNoSuchElementException(type);
+ }
+ return propertySchemaType;
+ }
+
+ private static void throwNoSuchElementException(String type) {
+ throw new NoSuchElementException(String.format("Value %s is not defined in %s", type, PropertySchemaType.class.getName()));
+ }
+
+}
diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcTypes.java b/src/main/java/org/onap/sdc/tosca/parser/enums/SdcTypes.java
index 9daf0ef..99bdd81 100644
--- a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcTypes.java
+++ b/src/main/java/org/onap/sdc/tosca/parser/enums/SdcTypes.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.sdc.tosca.parser.impl;
+package org.onap.sdc.tosca.parser.enums;
import java.util.Arrays;
import java.util.List;
@@ -32,7 +32,7 @@ public enum SdcTypes {
private static List<String> complexTypes = Arrays.asList(VF, PNF, CR, SERVICE, CVFC).stream().map(SdcTypes::getValue).collect(Collectors.toList());
- private SdcTypes(String value) {
+ SdcTypes(String value) {
this.value = value;
}
diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
index f82272b..ee9ac06 100644
--- a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
+++ b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
@@ -21,7 +21,10 @@
package org.onap.sdc.tosca.parser.impl;
import static java.util.stream.Collectors.toList;
+
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -35,7 +38,11 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.tosca.parser.config.ConfigurationManager;
+import org.onap.sdc.tosca.parser.enums.FilterType;
+import org.onap.sdc.tosca.parser.enums.PropertySchemaType;
+import org.onap.sdc.tosca.parser.enums.SdcTypes;
import org.onap.sdc.tosca.parser.utils.GeneralUtility;
+import org.onap.sdc.tosca.parser.utils.PropertyUtils;
import org.onap.sdc.tosca.parser.utils.SdcToscaUtility;
import org.onap.sdc.toscaparser.api.CapabilityAssignment;
import org.onap.sdc.toscaparser.api.CapabilityAssignments;
@@ -199,33 +206,23 @@ 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;
- }
- String[] split = getSplittedPath(leafValuePath);
- LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
- Object property = processProperties(split, properties);
- return property == null || property instanceof Function ? null : String.valueOf(property);
+ Object value = getNodeTemplatePropertyValueAsObject(nodeTemplate, leafValuePath);
+ return value == null || value instanceof Function ? null : String.valueOf(value);
}
@Override
- public Object getNodeTemplatePropertyAsObject(NodeTemplate nodeTemplate, String leafValuePath) {
+ public Object getNodeTemplatePropertyValueAsObject(NodeTemplate nodeTemplate, String leafValuePath) {
if (nodeTemplate == null) {
- log.error("getNodeTemplatePropertyAsObject - nodeTemplate is null");
+ log.error("getNodeTemplatePropertyValueAsObject - nodeTemplate is null");
return null;
}
if (GeneralUtility.isEmptyString(leafValuePath)) {
- log.error("getNodeTemplatePropertyAsObject - leafValuePath is null or empty");
+ log.error("getNodeTemplatePropertyValueAsObject - leafValuePath is null or empty");
return null;
}
String[] split = getSplittedPath(leafValuePath);
LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
- return processProperties(split, properties);
+ return PropertyUtils.processProperties(split, properties);
}
public Map<String, Map<String, Object>> getCpPropertiesFromVfcAsObject(NodeTemplate vfc) {
@@ -436,7 +433,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
if (findFirst.isPresent()) {
Input input = findFirst.get();
Object current = input.getDefault();
- Object property = iterateProcessPath(2, current, split);
+ Object property = PropertyUtils.iterateProcessPath(2, current, split);
return property == null || property instanceof Function? null : String.valueOf(property);
}
}
@@ -463,42 +460,15 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
if (findFirst.isPresent()) {
Input input = findFirst.get();
Object current = input.getDefault();
- return iterateProcessPath(2, current, split);
+ return PropertyUtils.iterateProcessPath(2, current, split);
}
}
log.error("getServiceInputLeafValueOfDefaultAsObject - value not found");
return null;
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private Object iterateProcessPath(Integer index, Object current, String[] split) {
- if (current == null) {
- log.error("iterateProcessPath - this input has no default");
- return null;
- }
- if (split.length > index) {
- for (int i = index; i < split.length; i++) {
- if (current instanceof Map) {
- current = ((Map<String, Object>) current).get(split[i]);
- } else if (current instanceof List) {
- current = ((List) current).get(0);
- i--;
- }
- else {
- log.error("iterateProcessPath - found an unexpected leaf where expected to find a complex type");
- return null;
- }
- }
- }
- if (current != null) {
- return current;
- }
- log.error("iterateProcessPath - Path not Found");
- return null;
- }
-
- private String[] getSplittedPath(String inputLeafValuePath) {
- return inputLeafValuePath.split(PATH_DELIMITER);
+ private String[] getSplittedPath(String leafValuePath) {
+ return leafValuePath.split(PATH_DELIMITER);
}
@@ -564,7 +534,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
String[] split = getSplittedPath(leafValuePath);
LinkedHashMap<String, Property> properties = group.getProperties();
- Object property = processProperties(split, properties);
+ Object property = PropertyUtils.processProperties(split, properties);
return property == null || property instanceof Function? null : String.valueOf(property);
}
@@ -582,7 +552,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
String[] split = getSplittedPath(leafValuePath);
LinkedHashMap<String, Property> properties = group.getProperties();
- return processProperties(split, properties);
+ return PropertyUtils.processProperties(split, properties);
}
@Override
@@ -757,6 +727,13 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
public List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType) {
return getNodeTemplateBySdcType(parentNodeTemplate, sdcType, false);
}
+
+ public boolean isNodeTypeSupported(NodeTemplate nodeTemplate) {
+ SdcTypes[] supportedTypes = SdcTypes.values();
+ return Arrays.stream(supportedTypes)
+ .anyMatch(v->nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)
+ .equals(v.getValue()));
+ }
private List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType, boolean isVNF) {
@@ -941,7 +918,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
String[] split = getSplittedPath(pathToPropertyLeafValue);
LinkedHashMap<String, Property> properties = capability.getProperties();
- Object property = processProperties(split, properties);
+ Object property = PropertyUtils.processProperties(split, properties);
return property == null || property instanceof Function ? null : String.valueOf(property);
}
@@ -1073,18 +1050,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
}
}
- private Object processProperties(String[] split, LinkedHashMap<String, Property> properties) {
- Optional<Entry<String, Property>> findFirst = properties.entrySet().stream().filter(x -> x.getKey().equals(split[0])).findFirst();
- if (findFirst.isPresent()) {
- Property property = findFirst.get().getValue();
- Object current = property.getValue();
- return iterateProcessPath(1, current, split);
- }
- String propName = (split != null && split.length > 0 ? split[0] : null);
- log.error("processProperties - property {} not found", propName);
- return null;
- }
-
@Override
public Map<String, List<InterfacesDef>> getInterfacesOf(NodeTemplate nt){
if (nt == null) {
@@ -1122,7 +1087,115 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return null;
}
- @Override
+ @Override
+ public List<String> getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath(String propertyNamePath, String nodeTemplatePath) {
+ log.info("A new request is received: property path is [{}], node template path is [{}]",
+ propertyNamePath, nodeTemplatePath);
+
+ List<String> propertyValuesList;
+
+ if (StringUtils.isEmpty(nodeTemplatePath) || StringUtils.isEmpty(propertyNamePath)) {
+ log.error("One of parameters is empty or null: property path is [{}], node template path is [{}]",
+ propertyNamePath, nodeTemplatePath);
+ propertyValuesList = Collections.emptyList();
+ }
+ else {
+ String[] nodeTemplates = getSplittedPath(nodeTemplatePath);
+ propertyValuesList = getPropertyFromInternalNodeTemplate(getNodeTemplateByName(nodeTemplates[0]), 1, nodeTemplates, propertyNamePath);
+ log.info("Found property value {} by path [{}] for node template [{}]",
+ propertyValuesList, propertyNamePath, nodeTemplatePath);
+ }
+ return propertyValuesList;
+ }
+
+ private List<String> getPropertyFromInternalNodeTemplate(NodeTemplate parent, int index,
+ String[] nodeTemplatePath, String propertyPath) {
+ List<String> propertyValuesList;
+ if (parent == null) {
+ log.error("Node template {} is not found, the request will be rejected", nodeTemplatePath[index]);
+ propertyValuesList = Collections.emptyList();
+ }
+ else if (nodeTemplatePath.length <= index) {
+ log.debug("Stop NODE TEMPLATE searching");
+ propertyValuesList = getSimpleOrListPropertyValue(parent, propertyPath);
+ }
+ else {
+ log.debug("Node template {} is found with name {}", nodeTemplatePath[index], parent.getName());
+ NodeTemplate childNT = getChildNodeTemplateByName(parent, nodeTemplatePath[index]);
+
+ if (childNT == null || !isNodeTypeSupported(childNT)) {
+ log.error("Unsupported or not found node template named {}, the request will be rejected",
+ nodeTemplatePath[index]);
+ propertyValuesList = Collections.emptyList();
+ }
+ else {
+ propertyValuesList = getPropertyFromInternalNodeTemplate(childNT, index + 1, nodeTemplatePath,
+ propertyPath);
+ }
+ }
+ return propertyValuesList;
+ }
+
+
+
+ private List<String> getSimpleOrListPropertyValue(NodeTemplate nodeTemplate, String propertyPath) {
+ List<String> propertyValueList;
+ String[] path = getSplittedPath(propertyPath);
+ Property property = getNodeTemplatePropertyObjectByName(nodeTemplate, path[0]);
+
+ if (PropertyUtils.isPropertyTypeSimpleOrListOfSimpleTypes(nodeTemplate, path, property)) {
+ //the requested property type is either simple or list of simple types
+ PropertySchemaType propertyType = PropertySchemaType.getEnumByValue(property.getType());
+ if (propertyType == PropertySchemaType.LIST &&
+ PropertyUtils.isDataPropertyType((String)property.getEntrySchema()
+ .get(SdcPropertyNames.PROPERTY_NAME_TYPE))) {
+ //cover the case when a type of property "path[0]' is list of data types
+ // and the requested property is an internal simple property of this data type
+ propertyValueList = calculatePropertyValue(getNodeTemplatePropertyValueAsObject(nodeTemplate, path[0]), path, nodeTemplate.getName());
+ }
+ else {
+ //the requested property is simple type or list of simple types
+ propertyValueList = calculatePropertyValue(getNodeTemplatePropertyValueAsObject(nodeTemplate, propertyPath), null, nodeTemplate.getName());
+ }
+ }
+ else {
+ log.error("The type of property {} on node {} is neither simple nor list of simple objects, the request will be rejected",
+ propertyPath, nodeTemplate.getName());
+ propertyValueList = Collections.emptyList();
+ }
+ return propertyValueList;
+ }
+
+ private List<String> calculatePropertyValue(Object valueAsObject, String path[], String nodeName) {
+ if (valueAsObject == null || valueAsObject instanceof Map) {
+ log.error("The property {} either is not found on node template [{}], or it is data type, or it is not resolved get_input", path, nodeName);
+ return Collections.emptyList();
+ }
+ if (path != null) {
+ return PropertyUtils.findSimplePropertyValueInListOfDataTypes((List<Object>)valueAsObject, path);
+ }
+ return PropertyUtils.buildSimplePropertValueOrList(valueAsObject);
+ }
+
+
+
+
+ private Property getNodeTemplatePropertyObjectByName(NodeTemplate nodeTemplate, String propertyName) {
+ return nodeTemplate.getPropertiesObjects()
+ .stream()
+ .filter(p->p.getName().equals(propertyName))
+ .findFirst()
+ .orElse(null);
+ }
+
+ private NodeTemplate getChildNodeTemplateByName(NodeTemplate parent, String nodeTemplateName) {
+ return getNodeTemplateChildren(parent)
+ .stream()
+ .filter(nt->nt.getName().equals(nodeTemplateName))
+ .findFirst().orElse(null);
+ }
+
+ @Override
public List<Input> getInputsWithAnnotations() {
return toscaTemplate.getInputs(true);
}
diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java
index 6f7e568..f791520 100644
--- a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java
+++ b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java
@@ -117,4 +117,5 @@ public class SdcPropertyNames {
public static String PROPERTY_NAME_TARGETS = "targets";
public static String PROPERTY_NAME_MEMBERS = "members";
public static String PROPERTY_NAME_CAPABILITIES = "capabilities";
+ public static String PROPERTY_NAME_ENTRY_SCHEMA = "entry_schema";
}
diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcToscaParserFactory.java b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcToscaParserFactory.java
index 3293a58..12fa0e8 100644
--- a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcToscaParserFactory.java
+++ b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcToscaParserFactory.java
@@ -8,6 +8,7 @@ import org.onap.sdc.tosca.parser.config.ConfigurationManager;
import org.onap.sdc.tosca.parser.config.ErrorInfo;
import org.onap.sdc.tosca.parser.config.JToscaValidationIssueInfo;
import org.onap.sdc.tosca.parser.config.SdcToscaParserErrors;
+import org.onap.sdc.tosca.parser.enums.JToscaValidationIssueType;
import org.onap.sdc.tosca.parser.utils.GeneralUtility;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
diff --git a/src/main/java/org/onap/sdc/tosca/parser/utils/PropertyUtils.java b/src/main/java/org/onap/sdc/tosca/parser/utils/PropertyUtils.java
new file mode 100644
index 0000000..cefb426
--- /dev/null
+++ b/src/main/java/org/onap/sdc/tosca/parser/utils/PropertyUtils.java
@@ -0,0 +1,172 @@
+package org.onap.sdc.tosca.parser.utils;
+
+import com.google.common.collect.Lists;
+import org.onap.sdc.tosca.parser.enums.PropertySchemaType;
+import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.Property;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.onap.sdc.tosca.parser.enums.PropertySchemaType.PropertySchemaComplexity.Simple;
+
+public class PropertyUtils {
+
+ private static Logger log = LoggerFactory.getLogger(PropertyUtils.class.getName());
+
+ private PropertyUtils() {}
+
+ private static String calculatePropertyType(LinkedHashMap<String, Object> property) {
+ String type = (String) property.get(SdcPropertyNames.PROPERTY_NAME_TYPE);
+ if (PropertySchemaType.LIST.getSchemaTypeName().equals(type)) {
+ //it might be a data type
+ return getEntrySchemaType(property);
+ }
+ return type;
+ }
+
+ private static String getEntrySchemaType(LinkedHashMap<String, Object> property) {
+ LinkedHashMap<String, Object> entrySchema = (LinkedHashMap<String, Object>)property.get(SdcPropertyNames.PROPERTY_NAME_ENTRY_SCHEMA);
+ if (entrySchema != null) {
+ return (String) entrySchema.get(SdcPropertyNames.PROPERTY_NAME_TYPE);
+ }
+ return null;
+ }
+
+ private static String calculatePropertyType(Property property) {
+ if (PropertySchemaType.LIST.getSchemaTypeName().equals(property.getType())) {
+ //if it is list, return entry schema type
+ return (String)property.getEntrySchema().get(SdcPropertyNames.PROPERTY_NAME_TYPE);
+ }
+ return property.getType();
+ }
+
+ public static boolean isListOfSimpleTypes(String type) {
+ PropertySchemaType entrySchemaType = PropertySchemaType.getEnumByValue(type);
+ return entrySchemaType.getSchemaTypeComplexity() == PropertySchemaType.PropertySchemaComplexity.Simple;
+ }
+
+ public static boolean isDataPropertyType(String type) {
+ PropertySchemaType entrySchemaType = PropertySchemaType.getEnumByValue(type);
+ return entrySchemaType == PropertySchemaType.DATATYPE;
+ }
+
+ public static Object processProperties(String[] split, LinkedHashMap<String, Property> properties) {
+ Optional<Map.Entry<String, Property>> findFirst = properties.entrySet().stream().filter(x -> x.getKey().equals(split[0])).findFirst();
+ if (findFirst.isPresent()) {
+ Property property = findFirst.get().getValue();
+ Object current = property.getValue();
+ return iterateProcessPath(1, current, split);
+ }
+ String propName = (split != null && split.length > 0 ? split[0] : null);
+ log.error("processProperties - property {} is not found", propName);
+ return null;
+ }
+
+ public static List<String> findSimplePropertyValueInListOfDataTypes(List<Object> valueAsObjectList, String[] path) {
+ return valueAsObjectList.stream()
+ .map(v->iterateProcessPath(1, v, path))
+ .filter(Objects::nonNull)
+ .map(String::valueOf)
+ .collect(Collectors.toList());
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static Object iterateProcessPath(Integer index, Object current, String[] split) {
+ if (current == null) {
+ log.error("iterateProcessPath - this input has no default");
+ return null;
+ }
+ if (split.length > index) {
+ for (int i = index; i < split.length; i++) {
+ if (current instanceof Map) {
+ current = ((Map<String, Object>) current).get(split[i]);
+ } else if (current instanceof List) {
+ current = ((List) current).get(0);
+ i--;
+ }
+ else {
+ log.error("iterateProcessPath - found an unexpected leaf where expected to find a complex type");
+ return null;
+ }
+ }
+ }
+ if (current != null) {
+ return current;
+ }
+ log.error("iterateProcessPath - Path not Found");
+ return null;
+ }
+
+ public static boolean isPropertyTypeSimpleOrListOfSimpleTypes(NodeTemplate nodeTemplate, String[] path, Property property) {
+ PropertySchemaType internalPropertyType = PropertyUtils.getPropertyTypeByPath(nodeTemplate, path, property);
+ return internalPropertyType.getSchemaTypeComplexity() == Simple;
+ }
+
+ private static PropertySchemaType getPropertyTypeByPath(NodeTemplate nodeTemplate, String[] path, Property property) {
+ String propertyType = calculatePropertyType(property);
+ String propertyTypeByPath = propertyType;
+
+ if (path.length > 1) {
+ propertyTypeByPath = getInternalPropertyType(nodeTemplate, propertyType, path, 1);
+ }
+ return PropertySchemaType.getEnumByValue(propertyTypeByPath);
+ }
+
+ public static List<String> buildSimplePropertValueOrList(Object value) {
+ if (value instanceof List) {
+ return ((ArrayList<Object>) value)
+ .stream()
+ //it might be null when get_input can't be resolved
+ // e.g.:
+ // - get_input has two parameters: 1. list and 2. index in this list
+ //and list has no value
+ // - neither value no default is defined for get_input
+ .filter(Objects::nonNull)
+ .map(String::valueOf)
+ .collect(Collectors.toList());
+ }
+ return Lists.newArrayList(String.valueOf(value));
+ }
+
+ private static String getInternalPropertyType(NodeTemplate nodeTemplate, String dataTypeName, String[] path, int index) {
+ if (path.length > index) {
+ LinkedHashMap<String, Object> complexProperty = (LinkedHashMap<String, Object>) nodeTemplate.getCustomDef().get(dataTypeName);
+ if (complexProperty != null) {
+ LinkedHashMap<String, Object> properties = (LinkedHashMap<String, Object>) complexProperty.get(SdcPropertyNames.PROPERTY_NAME_PROPERTIES);
+ return getPropertyTypeFromCustomDef(nodeTemplate, path, index, properties);
+ }
+ }
+ //stop searching - seems as wrong flow: the path is finished but the value is not found yet
+ log.error("The property path {} is incorrect, the request will be rejected", path);
+ return null;
+ }
+
+ private static String getPropertyTypeFromCustomDef(NodeTemplate nodeTemplate, String[] path, int index, LinkedHashMap<String, Object> properties) {
+ final String methodName = "getPropertyTypeFromCustomDef";
+ if (properties != null) {
+ LinkedHashMap<String, Object> foundProperty = (LinkedHashMap<String, Object>) (properties).get(path[index]);
+ if (foundProperty != null) {
+ String propertyType = calculatePropertyType(foundProperty);
+ log.info("{} - type {} is data type", methodName, propertyType);
+ if ((index == path.length - 1)){
+ log.info("{} - the last element {} in the property path is found", methodName, path[index]);
+ return propertyType;
+ }
+ return getInternalPropertyType(nodeTemplate, propertyType, path, index + 1);
+ }
+ log.error("{} - the property [{}] is not found", methodName, path[index]);
+ }
+ return null;
+ }
+
+
+}
diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java
index 7b268c6..89cdb7a 100644
--- a/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java
+++ b/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java
@@ -11,8 +11,8 @@ import java.util.stream.Collectors;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
-import org.onap.sdc.tosca.parser.impl.FilterType;
-import org.onap.sdc.tosca.parser.impl.SdcTypes;
+import org.onap.sdc.tosca.parser.enums.FilterType;
+import org.onap.sdc.tosca.parser.enums.SdcTypes;
import org.onap.sdc.toscaparser.api.CapabilityAssignment;
import org.onap.sdc.toscaparser.api.CapabilityAssignments;
import org.onap.sdc.toscaparser.api.Group;
@@ -382,13 +382,13 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
}
//endregion
- //region getNodeTemplatePropertyAsObject
+ //region getNodeTemplatePropertyValueAsObject
@Test
public void testGetNodeTemplatePropertyAsObject() {
List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
- assertEquals("2", fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "availability_zone_max_count"));
- assertEquals(3, fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "max_instances"));
- assertEquals("some code", fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "nf_naming_code"));
+ assertEquals("2", fdntCsarHelper.getNodeTemplatePropertyValueAsObject(serviceVfList.get(0), "availability_zone_max_count"));
+ assertEquals(3, fdntCsarHelper.getNodeTemplatePropertyValueAsObject(serviceVfList.get(0), "max_instances"));
+ assertEquals("some code", fdntCsarHelper.getNodeTemplatePropertyValueAsObject(serviceVfList.get(0), "nf_naming_code"));
}
//endregion
@@ -775,7 +775,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
// 2) complex type resolving
// 3) List access resolving
List<NodeTemplate> vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b");
- Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_ip_requirements");
+ Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "port_pd01_port_ip_requirements");
assertTrue(propertyAsObject instanceof ArrayList);
assertEquals(2, ((ArrayList) propertyAsObject).size());
//port_pd01_port_ip_requirements:
@@ -810,7 +810,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
public void testResolveGetInputForPrimitiveTypeString() {
//This test covers "default" resolving of primitive - as Object
List<NodeTemplate> vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b");
- Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_network_role_tag");
+ Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "port_pd01_port_network_role_tag");
assertEquals("oam", propertyAsObject);
}
@@ -827,7 +827,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
public void testResolveGetInputForMap() {
//This test covers "default" resolving of primitive - as Map
List<NodeTemplate> vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b");
- Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd02_port_ip_requirements#ip_count_required");
+ Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "port_pd02_port_ip_requirements#ip_count_required");
assertTrue(propertyAsObject instanceof Map);
assertEquals(false, ((Map)propertyAsObject).get("is_required"));
}
@@ -836,11 +836,11 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
public void testResolveGetInputForAllHierarchy() {
//This test covers "default" resolving from service level
List<NodeTemplate> vfs = resolveGetInputCsar.getServiceVfList();
- Object vfPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfs.get(0), "vm_count");
+ Object vfPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyValueAsObject(vfs.get(0), "vm_count");
assertEquals(2, vfPropertyAsObject);
//This test covers property assignment resolving on VFI level (service template), from Vf level
List<NodeTemplate> vfcs = resolveGetInputCsar.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.VFC);
- Object vfcPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "my_count");
+ Object vfcPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "my_count");
assertEquals(2, vfcPropertyAsObject); //takes it from upper level (VF) property
}
@@ -857,7 +857,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
public void testResolveGetInputNoDefValueServiceLevel() {
//This test covers resolving when no "default" value is supplied to the input - should be null - Service/VFI level
List<NodeTemplate> vfs = resolveGetInputCsar.getServiceVfList();
- Object vfPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfs.get(0), "port_order");
+ Object vfPropertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyValueAsObject(vfs.get(0), "port_order");
assertNull(vfPropertyAsObject);
}
@@ -870,7 +870,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
public void testResolveGetInputForComplexTypeAndListWithFalseValue()
{
List<NodeTemplate> vfcs = resolveGetInputCsarFalse.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b");
- Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_ip_requirements");
+ Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "port_pd01_port_ip_requirements");
assertTrue(propertyAsObject instanceof ArrayList);
assertEquals(2, ((ArrayList) propertyAsObject).size());
assertEquals("get_input:[ip_requirements, 0]", ((ArrayList) propertyAsObject).get(0).toString());
@@ -880,21 +880,21 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
@Test
public void testResolveGetInputForPrimitiveTypeStringWithFalseValue() {
List<NodeTemplate> vfcs = resolveGetInputCsarFalse.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b");
- Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_network_role_tag");
+ Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "port_pd01_port_network_role_tag");
assertEquals("get_input:role_tag_oam", propertyAsObject.toString());
}
@Test
public void testResolveGetInputForPrimitiveTypeListWithFalseValue() {
List<NodeTemplate> vfcs = resolveGetInputCsarFalse.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b");
- Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_name");
+ Object propertyAsObject = resolveGetInputCsarFalse.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "compute_pd_server_name");
assertEquals("[get_input:[pd_server_names, 0]]", propertyAsObject.toString());
}
//@Test // Maybe a bug here.... need to check with Esti - Mait was sent.
public void testResolveGetInputForPrimitiveTypeList() {
List<NodeTemplate> vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b");
- Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_name");
+ Object propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "compute_pd_server_name");
assertEquals("\"ZRDM1MOGX01MPD001\"", propertyAsObject.toString());
}
@@ -902,13 +902,13 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
public void testResolveGetInputForPrimitiveNullValue() {
List<NodeTemplate> vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b");
@SuppressWarnings("unchecked")
- List<String>propertyAsObject = (List<String>) resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_availability_zone");
+ List<String>propertyAsObject = (List<String>) resolveGetInputCsarQA.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "compute_pd_server_availability_zone");
assertNull(propertyAsObject.get(0));
}
@Test
public void testResolveGetInputForPrimitiveIPValue() {
List<NodeTemplate> vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b");
- Object propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "vm_image_name");
+ Object propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "vm_image_name");
assertEquals("107.239.36.5", propertyAsObject.toString());
}
@@ -961,10 +961,10 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
@Test
public void testResolveGetInputArrayStructure() {
List<NodeTemplate> vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b");
- Object propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_name");
+ Object propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "compute_pd_server_name");
assertEquals( ((ArrayList)propertyAsObject).get(0).toString(), "\"ZRDM1MOGX01MPD001\"");
- propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_ip_requirements");
- assertEquals( ((ArrayList)propertyAsObject).get(1), null);
+ propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyValueAsObject(vfcs.get(0), "port_pd01_port_ip_requirements");
+ assertEquals(2, ((ArrayList)propertyAsObject).size());
}
@Test
@@ -1185,7 +1185,85 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
assertNotNull(inputs);
validateInputsAnnotations(inputs);
}
-
+
+ @Test
+ public void getPropertyValueByNamePathAndNodeTypePathWhenPropertyValueIncludesGetInputAndPropertyHasDataType() {
+ List<String> propertyValues = csarHelperServiceGroupsInputs.getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath("exCP_naming",
+ "vDBE 0#abstract_vdbe_1#vdbe_vdbe_untr_port");
+ assertEquals(0, propertyValues.size());
+ }
+
+ @Test
+ public void getPropertyValueByNamePathAndNodeTypePathWhenPropertyPathIsComplex() {
+ List<String> propertyValues = csarHelperServiceGroupsInputs.getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath("exCP_naming#ecomp_generated_naming",
+ "vDBE 0#abstract_vdbe_1#vdbe_vdbe_untr_port");
+ assertEquals(1, propertyValues.size());
+ assertEquals("true", propertyValues.get(0));
+ }
+
+ @Test
+ public void getPropertyValueByNamePathAndNodeTypePathWhenNoValueFoundForGetInputProperty() {
+ List<String> propertyValues = csarHelperServiceGroupsInputs.getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath("virtual_machine_interface_allowed_address_pairs#allowed_address_pair#address_mode",
+ "vDBE 0#abstract_vdbe_1#vdbe_vdbe_untr_port_nested2#vdbe_0_subint_oam_vmi_0");
+ assertEquals(0, propertyValues.size());
+ }
+
+ @Test
+ public void getPropertyValueByNamePathAndNodeTemplatePathSuccess() {
+ List<String> propertyValues = csarHelperServiceGroupsInputs.getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath("is_default",
+ "vDBE 0#abstract_vdbe_1#vdbe_vdbe_untr_port_nested2#vdbe_0_subint_oam_vmi_0");
+ assertEquals(1, propertyValues.size());
+ assertEquals("false", propertyValues.get(0));
+ }
+
+ @Test
+ public void getPropertyValueByNamePathAndEmptyNodeTypePath() {
+ List<String> propertyValues = csarHelperServiceGroupsInputs.getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath(null, "");
+ assertEquals(0, propertyValues.size());
+ }
+
+ @Test
+ public void getPropertyValueByNamePathAndNullNodeTypePath() {
+ List<String> propertyValues = csarHelperServiceGroupsInputs.getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath(null, null);
+ assertTrue(propertyValues.isEmpty());
+ }
+
+ @Test
+ public void getPropertyValueByNamePathAndNodeTypePathForListOfGetInputs() {
+ List<String> propertyValues = resolveGetInputCsar.getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath("port_pd01_port_ip_requirements#subnet_role",
+ "ipAssign4 0#abstract_pd_server");
+ assertEquals(2, propertyValues.size());
+ assertTrue(propertyValues.get(0).equals("subnet_role_4") || propertyValues.get(0).equals("subnet_role_6"));
+ assertTrue(propertyValues.get(1).equals("subnet_role_4") || propertyValues.get(1).equals("subnet_role_6"));
+ }
+
+ @Test
+ public void getPropertyValueByNamePathAndNodeTypePathForNetworkCloud() {
+ List<String> propertyValues = csarHelperServiceNetworkCloud.getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath("related_networks#related_network_role",
+ "Network Cloud VNF MOCK 0#abstract_testVM#testVM_testVM_SRIOVtrunk1_port");
+ assertEquals(3, propertyValues.size());
+ assertTrue(propertyValues.contains("cor_direct_2"));
+ assertTrue(propertyValues.contains("sgi_direct_2"));
+ assertTrue(propertyValues.contains("int_imbl_2"));
+ }
+
+ @Test
+ public void getPropertyValueByNamePathAndSingleNodeTypeNameForNetworkCloud() {
+ List<String> propertyValues = csarHelperServiceNetworkCloud.getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath("nf_naming#ecomp_generated_naming",
+ "Network Cloud VNF MOCK 0");
+ assertEquals(1, propertyValues.size());
+ assertEquals("true", propertyValues.get(0));
+ }
+
+ @Test
+ //todo test for port_order on resolveGetInputCsar
+ public void getPropertyValueByNamePathAndNodeTypePathWithGetInputNotSet() {
+ List<String> propertyValues = csarHelperServiceNetworkCloud.getPropertyLeafValueByPropertyNamePathAndNodeTemplatePath(
+ "name", "Network Cloud VNF MOCK 0#abstract_testVM#testVM");
+ assertTrue(propertyValues.isEmpty());
+ }
+
+
@SuppressWarnings("unchecked")
private void validateInputsProperties(NodeTemplate vdbe0, Group group) {
assertNotNull(group.getPropertiesObjects());
diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java
index 75f8962..b4e773b 100644
--- a/src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java
+++ b/src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java
@@ -1,11 +1,10 @@
package org.onap.sdc.impl;
-import org.onap.sdc.tosca.parser.impl.SdcTypes;
+import org.onap.sdc.tosca.parser.enums.SdcTypes;
import org.onap.sdc.toscaparser.api.CapabilityAssignments;
import org.onap.sdc.toscaparser.api.CapabilityAssignment;
import org.onap.sdc.toscaparser.api.NodeTemplate;
import org.onap.sdc.toscaparser.api.RequirementAssignments;
-import org.onap.sdc.toscaparser.api.elements.Metadata;
import org.testng.annotations.Test;
import java.util.List;
diff --git a/src/test/java/org/onap/sdc/tosca/parser/impl/ToscaParserNodeTemplateMockTest.java b/src/test/java/org/onap/sdc/tosca/parser/impl/ToscaParserNodeTemplateMockTest.java
new file mode 100644
index 0000000..ae9f5b3
--- /dev/null
+++ b/src/test/java/org/onap/sdc/tosca/parser/impl/ToscaParserNodeTemplateMockTest.java
@@ -0,0 +1,197 @@
+package org.onap.sdc.tosca.parser.impl;
+
+import org.apache.commons.lang3.StringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.enums.PropertySchemaType;
+import org.onap.sdc.tosca.parser.utils.PropertyUtils;
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.Property;
+import org.onap.sdc.toscaparser.api.ToscaTemplate;
+import org.onap.sdc.toscaparser.api.elements.Metadata;
+
+import java.util.LinkedHashMap;
+import java.util.NoSuchElementException;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertFalse;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ToscaParserNodeTemplateMockTest {
+ @Mock
+ private NodeTemplate nodeTemplate;
+
+ @Mock
+ private Metadata metadata;
+
+ @Mock
+ private ToscaTemplate toscaTemplate;
+
+ @Mock
+ private Property property;
+
+ private static final String dataTypeA = String.format(".%s.aaa", PropertySchemaType.DATATYPE.getSchemaTypeName());
+ private static final String dataTypeB = String.format(".%s.bbb", PropertySchemaType.DATATYPE.getSchemaTypeName());
+ private static final String dataTypeD = String.format(".%s.ddd", PropertySchemaType.DATATYPE.getSchemaTypeName());
+ private static final String dataTypeR = String.format(".%s.rrr", PropertySchemaType.DATATYPE.getSchemaTypeName());
+
+ @Before
+ public void setUp() {
+ when(property.getType()).thenReturn(dataTypeA);
+ }
+
+
+ @Test
+ public void verifyCorrectPropertyPath() {
+ String[] path = String.format("%s#%s#%s#%s", "x", "y", "z", "q").split("#");
+ LinkedHashMap<String, Object> bProp = fillDataTypeEntry(dataTypeA, "y", dataTypeB);
+ LinkedHashMap<String, Object> cProp = fillDataTypeEntry(dataTypeB, "z", dataTypeD);
+ LinkedHashMap<String, Object> dProp = fillDataTypeEntry(dataTypeD, "q", PropertySchemaType.STRING.getSchemaTypeName());
+
+ when(nodeTemplate.getCustomDef())
+ .thenReturn(bProp)
+ .thenReturn(cProp)
+ .thenReturn(dProp);
+
+ assertTrue(PropertyUtils.isPropertyTypeSimpleOrListOfSimpleTypes(nodeTemplate, path, property));
+ }
+
+ @Test
+ public void verifyPropertyPathWithMapOfStringsType() {
+ String[] path = String.format("%s#%s#%s#%s", "x", "y", "z", "q").split("#");
+ LinkedHashMap<String, Object> bProp = fillDataTypeEntry(dataTypeA, "y", dataTypeB);
+ LinkedHashMap<String, Object> cProp = fillDataTypeEntry(dataTypeB, "z", PropertySchemaType.MAP.getSchemaTypeName());
+ LinkedHashMap<String, Object> dProp = fillDataTypeEntry(PropertySchemaType.MAP.getSchemaTypeName(), "q", PropertySchemaType.STRING.getSchemaTypeName());
+
+ when(nodeTemplate.getCustomDef())
+ .thenReturn(bProp)
+ .thenReturn(cProp)
+ .thenReturn(dProp);
+
+ assertTrue(PropertyUtils.isPropertyTypeSimpleOrListOfSimpleTypes(nodeTemplate, path, property));
+ }
+
+ @Test
+ public void verifyPropertyPathWithMapType() {
+ String[] path = String.format("%s#%s#%s", "x", "y", "z").split("#");
+ LinkedHashMap<String, Object> bProp = fillDataTypeEntry(dataTypeA, "y", dataTypeB);
+ LinkedHashMap<String, Object> cProp = fillDataTypeEntry(dataTypeB, "z", PropertySchemaType.MAP.getSchemaTypeName());
+
+ when(nodeTemplate.getCustomDef())
+ .thenReturn(bProp)
+ .thenReturn(cProp);
+
+ assertFalse(PropertyUtils.isPropertyTypeSimpleOrListOfSimpleTypes(nodeTemplate, path, property));
+ }
+
+
+ @Test
+ public void verifyPropertyPathWithListOfDataTypeShouldBeRejected() {
+ String[] path = String.format("%s#%s#%s#%s", "x", "y", "z", "m").split("#");
+ LinkedHashMap<String, Object> bProp = fillDataTypeEntry(dataTypeA, "y", dataTypeB);
+ LinkedHashMap<String, Object> cProp = fillDataTypeEntry(dataTypeB, "z", dataTypeD);
+ LinkedHashMap<String, Object> dProp = fillDataTypeEntry(dataTypeD, "m", PropertySchemaType.LIST.getSchemaTypeName(), dataTypeR);
+
+ when(nodeTemplate.getCustomDef())
+ .thenReturn(bProp)
+ .thenReturn(cProp)
+ .thenReturn(dProp);
+
+ assertFalse(PropertyUtils.isPropertyTypeSimpleOrListOfSimpleTypes(nodeTemplate, path, property));
+ }
+
+ @Test
+ public void verifyPropertyPathWithListOfIntegersAsType() {
+ String[] path = String.format("%s#%s#%s#%s", "x", "y", "z", "m").split("#");
+ LinkedHashMap<String, Object> bProp = fillDataTypeEntry(dataTypeA, "y", dataTypeB);
+ LinkedHashMap<String, Object> cProp = fillDataTypeEntry(dataTypeB, "z", dataTypeD);
+ LinkedHashMap<String, Object> dProp = fillDataTypeEntry(dataTypeD, "m", PropertySchemaType.LIST.getSchemaTypeName(), PropertySchemaType.INTEGER.getSchemaTypeName());
+
+ when(nodeTemplate.getCustomDef())
+ .thenReturn(bProp)
+ .thenReturn(cProp)
+ .thenReturn(dProp);
+
+ assertTrue(PropertyUtils.isPropertyTypeSimpleOrListOfSimpleTypes(nodeTemplate, path, property));
+ }
+
+ @Test
+ public void propertyPathIsRejectedAsShorterThanExpected() {
+ String[] path = String.format("%s#%s", "x", "y").split("#");
+ LinkedHashMap<String, Object> bProp = fillDataTypeEntry(dataTypeA, "y", dataTypeB);
+ LinkedHashMap<String, Object> dProp = fillDataTypeEntry(dataTypeB, "z", PropertySchemaType.STRING.getSchemaTypeName());
+
+ when(nodeTemplate.getCustomDef())
+ .thenReturn(bProp)
+ .thenReturn(dProp);
+
+ assertFalse(PropertyUtils.isPropertyTypeSimpleOrListOfSimpleTypes(nodeTemplate, path, property));
+ }
+
+ @Test(expected = NoSuchElementException.class)
+ public void propertyPathIsRejectedAsLongerThanExpected() {
+ String[] path = String.format("%s#%s#%s#%s", "x", "y", "z", "q").split("#");
+ LinkedHashMap<String, Object> bProp = fillDataTypeEntry(dataTypeA, "y", dataTypeB);
+ LinkedHashMap<String, Object> dProp = fillDataTypeEntry(dataTypeB, "z", PropertySchemaType.STRING.getSchemaTypeName());
+
+ when(nodeTemplate.getCustomDef())
+ .thenReturn(bProp)
+ .thenReturn(dProp);
+
+ PropertyUtils.isPropertyTypeSimpleOrListOfSimpleTypes(nodeTemplate, path, property);
+ }
+
+ @Test(expected = NoSuchElementException.class)
+ public void propertyPathIsRejectedAsPropertyIsNotFound() {
+ String[] path = String.format("%s#%s", "x", "y").split("#");
+ LinkedHashMap<String, Object> bProp = fillDataTypeEntry(dataTypeA, "t", dataTypeB);
+ when(nodeTemplate.getCustomDef())
+ .thenReturn(bProp);
+
+ assertFalse(PropertyUtils.isPropertyTypeSimpleOrListOfSimpleTypes(nodeTemplate, path, property));
+ }
+
+ @Test
+ public void verifyNodeTypeIsNotSupported() {
+ when(nodeTemplate.getMetaData()).thenReturn(metadata);
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn("VFC-TEST");
+
+ ISdcCsarHelper sdcCsarHelper = new SdcCsarHelperImpl(toscaTemplate);
+ assertFalse(sdcCsarHelper.isNodeTypeSupported(nodeTemplate));
+ }
+
+
+ private LinkedHashMap<String, Object> fillDataTypeEntry(String dataTypeName, String propertyName, String type) {
+ return fillDataTypeEntry(dataTypeName, propertyName, type, "");
+ }
+
+ private LinkedHashMap<String, Object> fillDataTypeEntry(String dataTypeName, String propertyName, String type, String entrySchemaType) {
+ LinkedHashMap<String, Object> dataTypes = new LinkedHashMap<>();
+ LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
+ LinkedHashMap<String, Object> property = new LinkedHashMap<>();
+ LinkedHashMap<String, Object> dataType = new LinkedHashMap<>();
+ property.put(SdcPropertyNames.PROPERTY_NAME_TYPE, type);
+ property.put(SdcPropertyNames.PROPERTY_NAME_NAME, propertyName);
+
+ PropertySchemaType propertySchemaType = PropertySchemaType.getEnumByValue(type);
+
+ if (!StringUtils.isEmpty(entrySchemaType) &&
+ (propertySchemaType.getSchemaTypeComplexity() == PropertySchemaType.PropertySchemaComplexity.Complex)) {
+ LinkedHashMap<String, Object> entry_schema = new LinkedHashMap<>();
+ entry_schema.put(SdcPropertyNames.PROPERTY_NAME_TYPE, entrySchemaType);
+ property.put(SdcPropertyNames.PROPERTY_NAME_ENTRY_SCHEMA, entry_schema);
+ }
+ properties.put(propertyName, property);
+ dataType.put(SdcPropertyNames.PROPERTY_NAME_PROPERTIES, properties);
+ dataTypes.put(dataTypeName, dataType);
+ return dataTypes;
+ }
+
+
+
+}