aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java19
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/Group.java12
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java16
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/Policy.java14
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/Property.java212
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/RelationshipTemplate.java12
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/TopologyTemplate.java41
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/elements/constraints/Schema.java10
-rw-r--r--src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java33
-rw-r--r--src/test/java/org/onap/sdc/toscaparser/api/elements/CalculatePropertyByPathTest.java147
-rw-r--r--src/test/resources/csars/service-NetworkCloudVnfServiceMock-csar.csarbin0 -> 60223 bytes
11 files changed, 472 insertions, 44 deletions
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java b/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java
index 637329e..2178be3 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java
@@ -5,6 +5,7 @@ import org.onap.sdc.toscaparser.api.elements.*;
import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder;
+import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -51,16 +52,27 @@ public abstract class EntityTemplate {
private ArrayList<RequirementAssignment> _requirements;
private ArrayList<CapabilityAssignment> _capabilities;
+ @Nullable
+ private NodeTemplate _parentNodeTemplate;
+
// dummy constructor for subclasses that don't want super
public EntityTemplate() {
return;
}
+ public EntityTemplate(String _name,
+ LinkedHashMap<String,Object> _template,
+ String _entityName,
+ LinkedHashMap<String,Object> _customDef) {
+ this(_name, _template, _entityName, _customDef, null);
+ }
+
@SuppressWarnings("unchecked")
public EntityTemplate(String _name,
LinkedHashMap<String,Object> _template,
String _entityName,
- LinkedHashMap<String,Object> _customDef) {
+ LinkedHashMap<String,Object> _customDef,
+ NodeTemplate parentNodeTemplate) {
name = _name;
entityTpl = _template;
customDef = _customDef;
@@ -111,8 +123,13 @@ public abstract class EntityTemplate {
_interfaces = null;
_requirements = null;
_capabilities = null;
+ _parentNodeTemplate = parentNodeTemplate;
}
+ public NodeTemplate getParentNodeTemplate() {
+ return _parentNodeTemplate;
+ }
+
public String getType() {
if(typeDefinition != null) {
String clType = typeDefinition.getClass().getSimpleName();
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/Group.java b/src/main/java/org/onap/sdc/toscaparser/api/Group.java
index de031e6..15ddfb1 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/Group.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/Group.java
@@ -25,12 +25,18 @@ public class Group extends EntityTemplate {
ArrayList<NodeTemplate> memberNodes;
LinkedHashMap<String,Object> customDef;
Metadata metaData;
-
+
+
+ public Group(String _name, LinkedHashMap<String, Object> _templates,
+ ArrayList<NodeTemplate> _memberNodes,
+ LinkedHashMap<String, Object> _customDef){
+ this(_name, _templates, _memberNodes, _customDef, null);
+ }
public Group(String _name, LinkedHashMap<String, Object> _templates,
ArrayList<NodeTemplate> _memberNodes,
- LinkedHashMap<String, Object> _customDef) {
- super(_name, _templates, "group_type", _customDef);
+ LinkedHashMap<String, Object> _customDef, NodeTemplate parentNodeTemplate) {
+ super(_name, _templates, "group_type", _customDef, parentNodeTemplate);
name = _name;
tpl = _templates;
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java b/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java
index 270e908..eaa650b 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java
@@ -29,15 +29,25 @@ public class NodeTemplate extends EntityTemplate {
private static final String METADATA = "metadata";
+ public NodeTemplate(String name,
+ LinkedHashMap<String,Object> ntnodeTemplates,
+ LinkedHashMap<String,Object> ntcustomDef,
+ ArrayList<RelationshipTemplate> ntavailableRelTpls,
+ LinkedHashMap<String,Object> ntavailableRelTypes) {
+ this( name, ntnodeTemplates, ntcustomDef, ntavailableRelTpls,
+ ntavailableRelTypes, null);
+ }
@SuppressWarnings("unchecked")
public NodeTemplate(String name,
LinkedHashMap<String,Object> ntnodeTemplates,
LinkedHashMap<String,Object> ntcustomDef,
ArrayList<RelationshipTemplate> ntavailableRelTpls,
- LinkedHashMap<String,Object> ntavailableRelTypes) {
+ LinkedHashMap<String,Object> ntavailableRelTypes,
+ NodeTemplate parentNodeTemplate) {
- super(name, (LinkedHashMap<String,Object>)ntnodeTemplates.get(name), "node_type", ntcustomDef);
+ super(name, (LinkedHashMap<String,Object>)ntnodeTemplates.get(name),
+ "node_type", ntcustomDef, parentNodeTemplate);
templates = ntnodeTemplates;
_validateFields((LinkedHashMap<String,Object>)templates.get(name));
@@ -209,7 +219,7 @@ public class NodeTemplate extends EntityTemplate {
LinkedHashMap<String,Object> req = new LinkedHashMap<>();
req.put("relationship", CopyUtils.copyLhmOrAl(requirement.getRelationship()));
req.put("type",rtype);
- RelationshipTemplate tpl = new RelationshipTemplate(req, rtype, customDef, this, source);
+ RelationshipTemplate tpl = new RelationshipTemplate(req, rtype, customDef, this, source, getParentNodeTemplate());
relationshipTpl.add(tpl);
}
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/Policy.java b/src/main/java/org/onap/sdc/toscaparser/api/Policy.java
index 9eaacfc..5945532 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/Policy.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/Policy.java
@@ -28,14 +28,22 @@ public class Policy extends EntityTemplate {
String targetsType;
ArrayList<Object> triggers;
LinkedHashMap<String,Object> properties;
-
+
public Policy(String _name,
LinkedHashMap<String,Object> _policy,
-// ArrayList<NodeTemplate> targetObjects,
ArrayList<Object> targetObjects,
String _targetsType,
LinkedHashMap<String,Object> _customDef) {
- super(_name,_policy,"policy_type",_customDef);
+ this(_name, _policy, targetObjects, _targetsType, _customDef, null);
+ }
+
+ public Policy(String _name,
+ LinkedHashMap<String,Object> _policy,
+// ArrayList<NodeTemplate> targetObjects,
+ ArrayList<Object> targetObjects,
+ String _targetsType,
+ LinkedHashMap<String,Object> _customDef, NodeTemplate parentNodeTemplate) {
+ super(_name,_policy,"policy_type",_customDef, parentNodeTemplate);
if(_policy.get(METADATA) != null) {
LinkedHashMap<String,Object> metadataMap = (LinkedHashMap<String,Object>)_policy.get(METADATA);
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/Property.java b/src/main/java/org/onap/sdc/toscaparser/api/Property.java
index 6d05af0..0ef9dd1 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/Property.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/Property.java
@@ -1,29 +1,38 @@
package org.onap.sdc.toscaparser.api;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.onap.sdc.toscaparser.api.elements.PropertyDef;
-import org.onap.sdc.toscaparser.api.elements.StatefulEntityType;
+import com.google.common.collect.Lists;
import org.onap.sdc.toscaparser.api.elements.constraints.Constraint;
import org.onap.sdc.toscaparser.api.elements.constraints.Schema;
import org.onap.sdc.toscaparser.api.functions.Function;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
public class Property {
// TOSCA built-in Property type
+ private static final Logger logger = LoggerFactory.getLogger(Property.class.getName());
private static final String TYPE = "type";
private static final String REQUIRED = "required";
private static final String DESCRIPTION = "description";
private static final String DEFAULT = "default";
private static final String CONSTRAINTS = "constraints";
-
+ private static String ENTRY_SCHEMA = "entry_schema";
+ private static String DATA_TYPE = "datatypes";
+
private static final String[] PROPERTY_KEYS = {
TYPE, REQUIRED, DESCRIPTION, DEFAULT, CONSTRAINTS};
private static final String ENTRYTYPE = "type";
private static final String ENTRYPROPERTIES = "properties";
+ private static final String PATH_DELIMITER = "#";
private static final String[] ENTRY_SCHEMA_KEYS = {
ENTRYTYPE, ENTRYPROPERTIES};
@@ -117,6 +126,195 @@ public class Property {
", customDef=" + customDef +
'}';
}
+
+ /**
+ * Retrieves property value as list of strings if<br>
+ * - the value is simple<br>
+ * - the value is list of simple values<br>
+ * - the provided path refers to a simple property inside a data type<br>
+ * @param propertyPath valid name of property for search.<br>
+ * If a name refers to a simple field inside a datatype, the property name should be defined with # delimiter.<br>
+ *
+ * @return List of property values. If not found, empty list will be returned.<br>
+ * If property value is a list either of simple fields or of simple fields inside a datatype, all values from the list should be returned
+ */
+ public List<String> getLeafPropertyValue(String propertyPath) {
+ List<String> propertyValueList = Collections.emptyList();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("getLeafPropertyValue=> A new request: propertyPath: {}, value: {}", propertyPath, getValue());
+ }
+ if (propertyPath == null || getValue() == null ||
+ //if entry_schema disappears, it is datatype,
+ // otherwise it is map of simple types - should be ignored
+ isValueMapOfSimpleTypes()) {
+ logger.error("It is a wrong request - ignoring! propertyPath: {}, value: {}", propertyPath, getValue());
+ return propertyValueList;
+ }
+ String[] path = propertyPath.split(PATH_DELIMITER);
+
+ if (Schema.isRequestedTypeSimple(getPropertyTypeByPath(path))) {
+ //the internal property type in the path is either simple or list of simple types
+ if (isValueInsideDataType()) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("The requested is an internal simple property inside of a data type");
+ }
+ //requested value is an internal simple property inside of a data type
+ propertyValueList = getSimplePropertyValueForComplexType(path);
+ }
+ else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("The requested property has simple type or list of simple types");
+ }
+ //the requested property is simple type or list of simple types
+ propertyValueList = getSimplePropertyValueForSimpleType();
+ }
+ }
+ return propertyValueList;
+ }
+
+ private boolean isValueMapOfSimpleTypes() {
+ if (getValue() instanceof Map && getEntrySchema() != null) {
+ logger.warn("This property value is a map of simple types");
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isValueInsideDataType() {
+ //value is either a list of values for data type
+ //or data type
+ return (Schema.LIST.equals(getType()) && isDataTypeInEntrySchema())
+ || (getEntrySchema() == null && getType().contains(DATA_TYPE));
+ }
+
+ private Object getSimpleValueFromComplexObject(Object current, String[] path) {
+ if (current == null) {
+ return null;
+ }
+ int index = 0;
+
+ if (path.length > index) {
+ for (int i = index; i < path.length; i++) {
+ if (current instanceof Map) {
+ current = ((Map<String, Object>) current).get(path[i]);
+ } else if (current instanceof List) {
+ current = ((List) current).get(0);
+ i--;
+ }
+ else {
+ return null;
+ }
+ }
+ }
+ if (current != null) {
+ return current;
+ }
+ return null;
+ }
+
+ private List<String> getSimplePropertyValueForSimpleType() {
+ if (getValue() instanceof List || getValue() instanceof Map) {
+ return getSimplePropertyValueForComplexType(null);
+ }
+ return Lists.newArrayList(String.valueOf(value));
+ }
+
+ private List<String> getSimplePropertyValueForComplexType(String[] path) {
+ if (getValue() instanceof List ) {
+ return ((List<Object>) getValue()).stream()
+ .map(v -> {
+ if (path != null) {
+ return getSimpleValueFromComplexObject(v, path);
+ } else {
+ return v;
+ }
+ })
+ //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());
+ }
+ //it is data type
+ List<String> valueList = Lists.newArrayList();
+ String valueString = String.valueOf(getSimpleValueFromComplexObject(getValue(), path));
+ if (Objects.nonNull(valueString)) {
+ valueList.add(valueString);
+ }
+ return valueList;
+ }
+
+ private String getPropertyTypeByPath(String[] path) {
+ String propertyType = calculatePropertyType();
+
+ if (path.length > 0 && !path[0].isEmpty()) {
+ return getInternalPropertyType(propertyType, path, 0);
+ }
+ return propertyType;
+ }
+
+ private String calculatePropertyType() {
+ String propertyType = getType();
+ if (Schema.LIST.equals(propertyType)) {
+ //if it is list, return entry schema type
+ return (String)getEntrySchema().get(ENTRYTYPE);
+ }
+ return propertyType;
+ }
+
+ private String calculatePropertyType(LinkedHashMap<String, Object> property) {
+ String type = (String) property.get(TYPE);
+ if (Schema.LIST.equals(type)) {
+ //it might be a data type
+ return getEntrySchemaType(property);
+ }
+ return type;
+ }
+
+ private String getInternalPropertyType(String dataTypeName, String[] path, int index) {
+ if (path.length > index) {
+ LinkedHashMap<String, Object> complexProperty = (LinkedHashMap<String, Object>)customDef.get(dataTypeName);
+ if (complexProperty != null) {
+ LinkedHashMap<String, Object> dataTypeProperties = (LinkedHashMap<String, Object>) complexProperty.get(ENTRYPROPERTIES);
+ return getPropertyTypeFromCustomDefDeeply(path, index, dataTypeProperties);
+ }
+ }
+ //stop searching - seems as wrong flow: the path is finished but the value is not found yet
+ return null;
+ }
+
+ private String getEntrySchemaType(LinkedHashMap<String, Object> property) {
+ LinkedHashMap<String, Object> entrySchema = (LinkedHashMap<String, Object>)property.get(ENTRY_SCHEMA);
+ if (entrySchema != null) {
+ return (String) entrySchema.get(TYPE);
+ }
+ return null;
+ }
+
+ private String getPropertyTypeFromCustomDefDeeply(String[] path, int index, LinkedHashMap<String, Object> properties) {
+ if (properties != null) {
+ LinkedHashMap<String, Object> foundProperty = (LinkedHashMap<String, Object>) (properties).get(path[index]);
+ if (foundProperty != null) {
+ String propertyType = calculatePropertyType(foundProperty);
+ if (propertyType == null || index == path.length - 1){
+ return propertyType;
+ }
+ return getInternalPropertyType(propertyType, path, index + 1);
+ }
+ }
+ return null;
+ }
+
+ private boolean isDataTypeInEntrySchema() {
+ String entrySchemaType = (String)getEntrySchema().get(ENTRYTYPE);
+ return entrySchemaType != null && entrySchemaType.contains(DATA_TYPE);
+ }
+
+
}
/*python
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/RelationshipTemplate.java b/src/main/java/org/onap/sdc/toscaparser/api/RelationshipTemplate.java
index a94caed..79bf83b 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/RelationshipTemplate.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/RelationshipTemplate.java
@@ -24,13 +24,21 @@ public class RelationshipTemplate extends EntityTemplate {
private NodeTemplate target;
private NodeTemplate source;
private ArrayList<Property> _properties;
-
+
public RelationshipTemplate(LinkedHashMap<String,Object> rtrelationshipTemplate,
String rtname,
LinkedHashMap<String,Object> rtcustomDef,
NodeTemplate rttarget,
NodeTemplate rtsource) {
- super(rtname,rtrelationshipTemplate,"relationship_type",rtcustomDef);
+ this(rtrelationshipTemplate, rtname, rtcustomDef, rttarget, rtsource, null);
+ }
+
+ public RelationshipTemplate(LinkedHashMap<String,Object> rtrelationshipTemplate,
+ String rtname,
+ LinkedHashMap<String,Object> rtcustomDef,
+ NodeTemplate rttarget,
+ NodeTemplate rtsource, NodeTemplate parentNodeTemplate) {
+ super(rtname,rtrelationshipTemplate,"relationship_type",rtcustomDef, parentNodeTemplate);
name = rtname;
target = rttarget;
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/TopologyTemplate.java b/src/main/java/org/onap/sdc/toscaparser/api/TopologyTemplate.java
index 4c9a53d..0b1dfcd 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/TopologyTemplate.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/TopologyTemplate.java
@@ -71,6 +71,7 @@ public class TopologyTemplate {
description = _tplDescription();
inputs = _inputs();
relationshipTemplates =_relationshipTemplates();
+ //todo: pass subMappedNodeTemplate to ET constractor
nodeTemplates = _nodeTemplates();
outputs = _outputs();
if(nodeTemplates != null) {
@@ -128,7 +129,8 @@ public class TopologyTemplate {
tpls,
customDefs,
relationshipTemplates,
- relTypes);
+ relTypes,
+ subMappedNodeTemplate);
if(tpl.getTypeDefinition() != null) {
boolean b = NodeType.TOSCA_DEF.get(tpl.getType()) != null;
if(b || (tpl.getCustomDef() != null && !tpl.getCustomDef().isEmpty())) {
@@ -148,7 +150,7 @@ public class TopologyTemplate {
if(tpls != null) {
for(String name: tpls.keySet()) {
RelationshipTemplate tpl = new RelationshipTemplate(
- (LinkedHashMap<String,Object>)tpls.get(name),name,customDefs,null,null);
+ (LinkedHashMap<String,Object>)tpls.get(name),name,customDefs,null,null, subMappedNodeTemplate);
alRelationshipTemplates.add(tpl);
}
@@ -216,7 +218,8 @@ public class TopologyTemplate {
policyTpl,
targetObjects,
targetsType,
- customDefs);
+ customDefs,
+ subMappedNodeTemplate);
alPolicies.add(policyObj);
}
return alPolicies;
@@ -244,7 +247,7 @@ public class TopologyTemplate {
Group group = new Group(groupName,
groupTpl,
memberNodes,
- customDefs);
+ customDefs, subMappedNodeTemplate);
groups.add(group);
}
return groups;
@@ -314,9 +317,7 @@ public class TopologyTemplate {
if(tpl.get(INPUTS) != null) {
return (LinkedHashMap<String,Object>)tpl.get(INPUTS);
}
- else {
- return new LinkedHashMap<String,Object>();
- }
+ return new LinkedHashMap<String,Object>();
}
@SuppressWarnings("unchecked")
@@ -329,19 +330,15 @@ public class TopologyTemplate {
if(tpl.get(RELATIONSHIP_TEMPLATES) != null) {
return (LinkedHashMap<String,Object>)tpl.get(RELATIONSHIP_TEMPLATES);
}
- else {
- return new LinkedHashMap<String,Object>();
- }
+ return new LinkedHashMap<String,Object>();
}
@SuppressWarnings("unchecked")
private LinkedHashMap<String,Object> _tplOutputs() {
- if(tpl.get(OUTPUTS) != null) {
- return (LinkedHashMap<String,Object>)tpl.get(OUTPUTS);
- }
- else {
- return new LinkedHashMap<String,Object>();
- }
+ if(tpl.get(OUTPUTS) != null) {
+ return (LinkedHashMap<String,Object>)tpl.get(OUTPUTS);
+ }
+ return new LinkedHashMap<String,Object>();
}
@SuppressWarnings("unchecked")
@@ -349,9 +346,7 @@ public class TopologyTemplate {
if(tpl.get(SUBSTITUTION_MAPPINGS) != null) {
return (LinkedHashMap<String,Object>)tpl.get(SUBSTITUTION_MAPPINGS);
}
- else {
- return new LinkedHashMap<String,Object>();
- }
+ return new LinkedHashMap<String,Object>();
}
@SuppressWarnings("unchecked")
@@ -359,9 +354,7 @@ public class TopologyTemplate {
if(tpl.get(GROUPS) != null) {
return (LinkedHashMap<String,Object>)tpl.get(GROUPS);
}
- else {
- return new LinkedHashMap<String,Object>();
- }
+ return new LinkedHashMap<String,Object>();
}
@SuppressWarnings("unchecked")
@@ -369,9 +362,7 @@ public class TopologyTemplate {
if(tpl.get(POLICIES) != null) {
return (LinkedHashMap<String,Object>)tpl.get(POLICIES);
}
- else {
- return new LinkedHashMap<>();
- }
+ return new LinkedHashMap<>();
}
private void _validateField() {
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/elements/constraints/Schema.java b/src/main/java/org/onap/sdc/toscaparser/api/elements/constraints/Schema.java
index 73a63ef..c0ed6bc 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/elements/constraints/Schema.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/elements/constraints/Schema.java
@@ -4,6 +4,7 @@ import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue;
import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -42,6 +43,11 @@ public class Schema {
INTEGER, STRING, BOOLEAN, FLOAT, RANGE,NUMBER, TIMESTAMP, LIST, MAP,
SCALAR_UNIT_SIZE, SCALAR_UNIT_FREQUENCY, SCALAR_UNIT_TIME,
VERSION, PORTDEF, PORTSPEC, JSON};
+
+ public static final String SIMPLE_PROPERTY_TYPES[] = {
+ INTEGER, STRING, BOOLEAN, FLOAT, RANGE,NUMBER, TIMESTAMP,
+ SCALAR_UNIT_SIZE, SCALAR_UNIT_FREQUENCY, SCALAR_UNIT_TIME,
+ VERSION};
@SuppressWarnings("unused")
private static final String SCALAR_UNIT_SIZE_DEFAULT = "B";
@@ -107,6 +113,10 @@ public class Schema {
return (String)schema.getOrDefault(STATUS,"");
}
+ public static boolean isRequestedTypeSimple(String type) {
+ return Arrays.stream(SIMPLE_PROPERTY_TYPES).anyMatch(t->t.equals(type));
+ }
+
@SuppressWarnings("unchecked")
public ArrayList<Constraint> getConstraints() {
if(constraintsList.size() == 0) {
diff --git a/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java b/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java
index 8e587a9..c660153 100644
--- a/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java
+++ b/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java
@@ -13,6 +13,7 @@ import java.util.Optional;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -112,6 +113,38 @@ public class JToscaImportTest {
}
@Test
+ public void testGetParentNodeTemplateTest() throws JToscaException {
+
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-AdiodVmxVpeBvService-csar.csar").getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ NodeTemplate nodeTemplate = toscaTemplate.getNodeTemplates().get(0);
+ //parent of this VF is service (null)
+ assertNull(nodeTemplate.getParentNodeTemplate());
+ List<NodeTemplate> children = nodeTemplate.getSubMappingToscaTemplate().getNodeTemplates();
+ assertFalse(children.isEmpty());
+ NodeTemplate cVFC = children.get(4);
+ //parent is the VF above
+ assertEquals("2017-488_ADIOD-vPE 0", cVFC.getParentNodeTemplate().getName());
+ List<NodeTemplate> children1 = cVFC.getSubMappingToscaTemplate().getNodeTemplates();
+ assertFalse(children1.isEmpty());
+ //parent is the CVFC above
+ assertEquals(cVFC, children1.get(0).getParentNodeTemplate());
+
+/*
+
+ TopologyTemplate tt = nodeTemplate.getOriginComponentTemplate();
+ List<Group> groups = tt.getGroups();
+ List<Policy> policies = tt.getPolicies();
+
+ TopologyTemplate tt1 = cVFC.getOriginComponentTemplate();
+ groups = tt.getGroups();
+ policies = tt.getPolicies();
+*/
+
+ }
+
+ @Test
public void testNullValueHasNoNullPointerException() throws JToscaException {
String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-JennyVtsbcKarunaSvc-csar.csar").getFile();
diff --git a/src/test/java/org/onap/sdc/toscaparser/api/elements/CalculatePropertyByPathTest.java b/src/test/java/org/onap/sdc/toscaparser/api/elements/CalculatePropertyByPathTest.java
new file mode 100644
index 0000000..59c8445
--- /dev/null
+++ b/src/test/java/org/onap/sdc/toscaparser/api/elements/CalculatePropertyByPathTest.java
@@ -0,0 +1,147 @@
+package org.onap.sdc.toscaparser.api.elements;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.sdc.toscaparser.api.JToscaImportTest;
+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.common.JToscaException;
+
+import java.io.File;
+import java.net.URL;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class CalculatePropertyByPathTest {
+ private static ToscaTemplate toscaTemplate;
+
+ @BeforeClass
+ public static void setUpClass() throws JToscaException {
+ URL scarUrl = JToscaImportTest.class.getClassLoader().getResource("csars/service-NetworkCloudVnfServiceMock-csar.csar");
+ if (scarUrl != null) {
+ File file = new File(scarUrl.getFile());
+ toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ }
+
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsNotEmpty() throws JToscaException {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
+
+ Property property = cp.getProperties().get("related_networks");
+ List<String> propertyValueList = property.getLeafPropertyValue("related_network_role");
+ assertEquals(3, propertyValueList.size());
+ assertTrue(propertyValueList.contains("cor_direct_2"));
+ assertTrue(propertyValueList.contains("sgi_direct_2"));
+ assertTrue(propertyValueList.contains("int_imbl_2"));
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasDataTypeAndPathIsEmpty() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(1); //testVM_testVM_SRIOVNonTrunk0_port
+
+ Property property = cp.getProperties().get("exCP_naming");
+ List<String> propertyValueList = property.getLeafPropertyValue("");
+ assertTrue(propertyValueList.isEmpty());
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasSimpleTypeAndValueAsGetInputIsNotResolvedCorrectlyAndPathIsEmpty() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(1); //testVM_testVM_SRIOVNonTrunk0_port
+
+ Property property = cp.getProperties().get("network");
+ List<String> propertyValueList = property.getLeafPropertyValue("");
+ assertTrue(propertyValueList.isEmpty());
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasSimpleTypeAndPathIsEmpty() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(1); //testVM_testVM_SRIOVNonTrunk0_port
+
+ Property property = cp.getProperties().get("subinterface_indicator");
+ List<String> propertyValueList = property.getLeafPropertyValue("");
+ assertEquals(1, propertyValueList.size());
+ assertEquals("false", propertyValueList.get(0));
+ }
+
+
+ @Test
+ public void testGetPropertyWhenPropertyHasDataTypeAndPathIsNotEmpty() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(2); //testVM_testVM_OVS_port
+
+ Property property = cp.getProperties().get("ip_requirements");
+ List<String> propertyValueList = property.getLeafPropertyValue("ip_version");
+ assertEquals(1, propertyValueList.size());
+ assertEquals("4", propertyValueList.get(0));
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsNull() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(2); //testVM_testVM_OVS_port
+
+ Property property = cp.getProperties().get("ip_requirements");
+ assertTrue(property.getLeafPropertyValue(null).isEmpty());
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsComplex() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
+
+ Property property = cp.getProperties().get("ip_requirements");
+ List<String> propertyValueList = property.getLeafPropertyValue("ip_count_required#is_required");
+ assertEquals(1, propertyValueList.size());
+ assertEquals("false", propertyValueList.get(0));
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasListOfDataTypesAndPathIsWrong() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
+
+ Property property = cp.getProperties().get("ip_requirements");
+ List<String> propertyValueList = property.getLeafPropertyValue("ip_count_required#is_required_1");
+ assertEquals(0, propertyValueList.size());
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasDataTypeWithoutSchemaAndComplexPath() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
+
+ Property property = cp.getProperties().get("mac_requirements");
+ List<String> propertyValueList = property.getLeafPropertyValue("mac_count_required#is_required");
+ assertEquals(1, propertyValueList.size());
+ assertEquals("false", propertyValueList.get(0));
+ }
+
+ @Test
+ public void testGetPropertyWhenPropertyHasDataTypeWithoutSchemaAndSimplePath() {
+ NodeTemplate cp = toscaTemplate.getNodeTemplates().get(0) //Network Cloud VNF MOCK 0
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0) //abstract_testVM
+ .getSubMappingToscaTemplate().getNodeTemplates().get(0); //testVM_testVM_SRIOVtrunk1_port
+
+ Property property = cp.getProperties().get("mac_requirements");
+ List<String> propertyValueList = property.getLeafPropertyValue("mac_count_required");
+ assertEquals(0, propertyValueList.size());
+ }
+}
diff --git a/src/test/resources/csars/service-NetworkCloudVnfServiceMock-csar.csar b/src/test/resources/csars/service-NetworkCloudVnfServiceMock-csar.csar
new file mode 100644
index 0000000..aabf83c
--- /dev/null
+++ b/src/test/resources/csars/service-NetworkCloudVnfServiceMock-csar.csar
Binary files differ