aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManzon, Inna (im453s) <im453s@intl.att.com>2019-01-21 16:21:36 +0200
committerManzon, Inna (im453s) <im453s@intl.att.com>2019-01-21 16:22:44 +0200
commit8b7eb2c7c60a8a8be540e810967bff8542c45cd1 (patch)
tree0d023a3838ede3e43808d94394a0fb2778b90f57
parentf500065cc4edf1e51657d701c487cad90930c86e (diff)
SDC Tosca Parser getEntity API
Change-Id: I237ea812e7ff4e12900776de79cfb6b154464974 Issue-ID: SDC-1967 Signed-off-by: Manzon, Inna (im453s) <im453s@intl.att.com>
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/Policy.java24
-rw-r--r--src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java26
2 files changed, 38 insertions, 12 deletions
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 5945532..563ea25 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/Policy.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/Policy.java
@@ -13,17 +13,17 @@ import org.onap.sdc.toscaparser.api.utils.ValidateUtils;
public class Policy extends EntityTemplate {
- private static final String TYPE = "type";
- private static final String METADATA = "metadata";
- private static final String DESCRIPTION = "description";
- private static final String PROPERTIES = "properties";
- private static final String TARGETS = "targets";
+ static final String TYPE = "type";
+ static final String METADATA = "metadata";
+ static final String DESCRIPTION = "description";
+ static final String PROPERTIES = "properties";
+ static final String TARGETS = "targets";
private static final String TRIGGERS = "triggers";
private static final String SECTIONS[] = {
TYPE, METADATA, DESCRIPTION, PROPERTIES, TARGETS, TRIGGERS};
-// LinkedHashMap<String,Object> metaData;
- Metadata metaData;
+ Metadata metaDataObject;
+ LinkedHashMap<String,Object> metaData = null;
ArrayList<Object> targetsList; // *** a list of NodeTemplate OR a list of Group ***
String targetsType;
ArrayList<Object> triggers;
@@ -46,9 +46,9 @@ public class Policy extends EntityTemplate {
super(_name,_policy,"policy_type",_customDef, parentNodeTemplate);
if(_policy.get(METADATA) != null) {
- LinkedHashMap<String,Object> metadataMap = (LinkedHashMap<String,Object>)_policy.get(METADATA);
- ValidateUtils.validateMap(metadataMap);
- metaData = new Metadata(metadataMap);
+ metaData = (LinkedHashMap<String,Object>)_policy.get(METADATA);
+ ValidateUtils.validateMap(metaData);
+ metaDataObject = new Metadata(metaData);
}
targetsList = targetObjects;
@@ -78,11 +78,11 @@ public class Policy extends EntityTemplate {
}
public Metadata getMetaDataObj() {
- return metaData;
+ return metaDataObject;
}
public LinkedHashMap<String, Object> getMetaData() {
- return (LinkedHashMap)metaData.getAllProperties();
+ return metaData;
}
// public ArrayList<NodeTemplate> getTargetsList() {
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 c660153..ff03aed 100644
--- a/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java
+++ b/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java
@@ -154,6 +154,31 @@ public class JToscaImportTest {
assertNotNull(inputs);
}
+ @Test
+ public void testGetPolicyMetadata() throws JToscaException {
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-NetworkCloudVnfServiceMock-csar.csar").getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ ArrayList<Policy> policies = toscaTemplate.getPolicies();
+ assertNotNull(policies);
+ assertEquals(1, policies.size());
+ assertEquals("org.openecomp.policies.External", policies.get(0).getType());
+ assertEquals("adf03496-bf87-43cf-b20a-450e47cb44bd", policies.get(0).getMetaData().getOrDefault("UUID", "").toString());
+ assertTrue(policies.get(0).getMetaData().getOrDefault("UUID_test", "").toString().isEmpty());
+ }
+
+ @Test
+ public void testGetPolicyMetadataObj() throws JToscaException {
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-NetworkCloudVnfServiceMock-csar.csar").getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ ArrayList<Policy> policies = toscaTemplate.getPolicies();
+ assertNotNull(policies);
+ assertEquals(1, policies.size());
+ assertEquals("adf03496-bf87-43cf-b20a-450e47cb44bd", policies.get(0).getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString());
+ assertTrue(policies.get(0).getMetaDataObj().getAllProperties().getOrDefault("name_test", "").toString().isEmpty());
+ }
+
private void validateInputsAnnotations(List<Input> inputs) {
List<Input> inputsWithAnnotations = inputs.stream().filter(i -> i.getAnnotations() != null)
.collect(Collectors.toList());
@@ -174,4 +199,5 @@ public class JToscaImportTest {
assertEquals(source_type.get().getValue(), "HEAT");
}
+
}