summaryrefslogtreecommitdiffstats
path: root/sdc-tosca-parser
diff options
context:
space:
mode:
authorPavel Aharoni <pa0916@att.com>2017-04-03 10:06:16 +0300
committerPavel Aharoni <pa0916@att.com>2017-04-03 10:06:32 +0300
commit1df0b72a316dcc7f913061706db165d78d2c3a03 (patch)
treeba549dc1e15b963ee39cc55d577317c08367e53e /sdc-tosca-parser
parentb51f888ee16f8bf92c7d9a0331eaa05e3bb938d2 (diff)
[SDC-8] trying to merge changes of tests and csars
Change-Id: Iac4d5bd1ea312b76cba52a172d5ac80757173409 Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'sdc-tosca-parser')
-rw-r--r--sdc-tosca-parser/pom.xml2
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java61
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java96
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csarbin0 -> 39949 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csarbin0 -> 39943 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csarbin0 -> 39948 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csarbin0 -> 39938 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar.csarbin0 -> 39979 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csarbin0 -> 74074 bytes
9 files changed, 135 insertions, 24 deletions
diff --git a/sdc-tosca-parser/pom.xml b/sdc-tosca-parser/pom.xml
index d4ffda8..cd6e49e 100644
--- a/sdc-tosca-parser/pom.xml
+++ b/sdc-tosca-parser/pom.xml
@@ -71,7 +71,7 @@
<dependency>
<groupId>org.openecomp.sdc.sdc-distribution-client</groupId>
<artifactId>jython-tosca-parser</artifactId>
- <version>0.4.0-SNAPSHOT</version>
+ <version>0.4.1-SNAPSHOT</version>
</dependency>
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
index 51afe7e..d5caa5d 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
@@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.stream.Collector;
+import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
@@ -32,27 +34,34 @@ import org.openecomp.sdc.toscaparser.api.NodeTemplate;
import org.openecomp.sdc.toscaparser.api.Property;
import org.openecomp.sdc.toscaparser.api.TopologyTemplate;
import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
+import org.yaml.snakeyaml.Yaml;
public class SdcCsarHelperImpl implements ISdcCsarHelper {
private ToscaTemplate toscaTemplate;
-
+ private static Yaml defaultYaml = new Yaml();
+
+
public SdcCsarHelperImpl(ToscaTemplate toscaTemplate) {
this.toscaTemplate = toscaTemplate;
}
@Override
+ //Sunny flow - covered with UT, flat and nested
public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) {
String[] split = leafValuePath.split("#");
List<Property> properties = nodeTemplate.getProperties();
Optional<Property> findFirst = properties.stream().filter(x -> x.getName().equals(split[0])).findFirst();
if (findFirst.isPresent()){
- Object current = findFirst.get().getValue();
- /*for (int i = 1; i < split.length; i++) {
- //if (i )
- }*/
- //TODO add nested props
- return (String)current;
+ Property property = findFirst.get();
+ Object current = property.getValue();
+ if (split.length > 1){
+ current = defaultYaml.load((String)current);
+ for (int i = 1; i < split.length; i++) {
+ current = ((Map<String, Object>)current).get(split[i]);
+ }
+ }
+ return String.valueOf(current);
}
return null;
}
@@ -64,11 +73,13 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
}
@Override
+ //Sunny flow - covered with UT
public List<NodeTemplate> getServiceVfList() {
return getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF);
}
-
+
@Override
+ //Sunny flow - covered with UT
public List<NodeTemplate> getServiceNodeTemplatesByType(String nodeType) {
List<NodeTemplate> res = new ArrayList<>();
List<NodeTemplate> nodeTemplates = toscaTemplate.getNodeTemplates();
@@ -113,11 +124,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return res;
}
- /*@Override
- public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName) {
- return (String)metadata.get(metadataPropertyName);
- }*/
-
@Override
public String getServiceInputLeafValue(String inputLeafValuePath) {
//toscaTemplate.getTopologyTemplate().getNodeTemplates().get(0).getProperties().get(0).
@@ -131,7 +137,9 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
@Override
public Map<String, String> getServiceMetadata() {
- return toscaTemplate.getTopologyTemplate().getMetadata();
+ TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
+ System.out.println(topologyTemplate.toString());
+ return topologyTemplate.getMetadata();
}
//Get property from group
@@ -139,10 +147,10 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
public String getGroupPropertyLeafValue(Group group, String propertyName) {
return null;//getLeafPropertyValue(group, propertyName);
}
-
+
private List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate nodeTemplate, String sdcType){
//Need metadata to fetch by type
-
+
/*List<NodeTemplate> nodeTemplates = nodeTemplate.getNestedNodeTemplates();
List<NodeTemplate> res = new ArrayList<>();
for (NodeTemplate nodeTemplateEntry : nodeTemplates){
@@ -152,16 +160,16 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
}*/
return null;
}
-
+
private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, String sdcType){
//Need metadata to fetch by type
-
+
List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
List<NodeTemplate> res = new ArrayList<>();
for (NodeTemplate nodeTemplateEntry : nodeTemplates){
//TODO switch back to type condition
if (nodeTemplateEntry.getTypeDefinition().getType().contains("."+sdcType.toLowerCase()+".")){
- //if (sdcType.equals(nodeTemplateEntry.getMetadata().get(SdcPropertyNames.PROPERTY_NAME_TYPE))){
+ //if (sdcType.equals(nodeTemplateEntry.getMetadata().get(SdcPropertyNames.PROPERTY_NAME_TYPE))){
res.add(nodeTemplateEntry);
}
}
@@ -189,16 +197,23 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
}
@Override
+ //TODO constant strings
public List<NodeTemplate> getAllottedResources() {
- //TODO - Need metadata
- return new ArrayList<>();
+ List<NodeTemplate> nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates();
+ return nodeTemplates.stream().filter(x -> x.getMetadata() != null && x.getMetadata().get("category").equals("allotted_resources")).collect(Collectors.toList());
}
@Override
+ //Sunny flow - covered with UT
public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate) {
//Can be done
return nodeTemplate.getTypeDefinition().getType();
}
-
-
+
+ /*//Not part of API, for inner/test use
+ public NodeTemplate getNodeTemplateByName(TopologyTemplate topologyTemplate, String topologyName){
+ List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
+ Optional<NodeTemplate> findFirst = nodeTemplates.stream().filter(x -> x.getName().equals(topologyName)).findFirst();
+ return findFirst.isPresent() ? findFirst.get() : null;
+ }*/
}
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java
new file mode 100644
index 0000000..aac552c
--- /dev/null
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java
@@ -0,0 +1,96 @@
+package org.openecomp.sdc.impl;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.AfterClass;
+import static org.junit.Assert.*;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
+import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+
+public class ToscaParserStubsTest {
+
+ private static ISdcCsarHelper csarHelper;
+ private static SdcToscaParserFactory factory;
+
+
+ @BeforeClass
+ public static void init() throws SdcToscaParserException{
+ factory = SdcToscaParserFactory.getInstance();
+ //csarHelper = factory.getSdcCsarHelper("C:\\Users\\pa0916\\Desktop\\Work\\ASDC\\CSARs\\service-ServiceFdnt-csar-allotted-resources-4.csar");
+ String fileStr = ToscaParserStubsTest.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-allotted-resources-4.csar").getFile();
+ File file = new File(fileStr);
+ csarHelper = factory.getSdcCsarHelper(file.getAbsolutePath());
+ }
+
+
+ @Test
+ //TODO add rainy flows
+ public void testNumberOfVfSunnyFlow() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
+ assertNotNull(serviceVfList);
+ assertEquals(1, serviceVfList.size());
+ }
+
+ @Test
+ //TODO add rainy flows
+ public void testNodeTemplateFlatProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = csarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "availability_zone_max_count");
+ assertEquals("2", nodeTemplatePropertyLeafValue);
+ }
+
+ @Test
+ //TODO add rainy flows
+ public void testNodeTemplateNestedProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = csarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_role#nf_naming#instance_name");
+ assertEquals("FDNT_instance_VF", nodeTemplatePropertyLeafValue);
+ }
+
+ @Test
+ //TODO add rainy flows
+ public void testServiceNodeTemplatesByType() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = csarHelper.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Fdnt");
+ assertNotNull(serviceVfList);
+ assertEquals(1, serviceVfList.size());
+ }
+
+ @Test
+ //TODO add rainy flows
+ public void testGetTypeOfNodeTemplate() {
+ List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
+ String typeOfNodeTemplate = csarHelper.getTypeOfNodeTemplate(serviceVfList.get(0));
+ assertEquals("org.openecomp.resource.vf.Fdnt", typeOfNodeTemplate);
+ }
+
+
+ //@Test
+ //TODO add rainy flows
+ public void testGetServiceMetadata() {
+ //FAILS!! Metadata is null
+ Map<String, String> serviceMetadata = csarHelper.getServiceMetadata();
+ assertNotNull(serviceMetadata);
+ assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", serviceMetadata.get("invariantUUID"));
+ assertEquals("Service FDNT", serviceMetadata.get("name"));
+ assertEquals("true", serviceMetadata.get("serviceEcompNaming"));
+ }
+
+ @Test
+ //TODO add rainy flows
+ public void testGetAllottedResources() {
+ List<NodeTemplate> allottedResources = csarHelper.getAllottedResources();
+ assertEquals(1, allottedResources.size());
+ }
+
+
+ @AfterClass
+ public static void close(){
+ factory.close();
+ }
+ }
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csar
new file mode 100644
index 0000000..7b4cff2
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csar
new file mode 100644
index 0000000..7286663
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csar
new file mode 100644
index 0000000..ceac90a
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csar
new file mode 100644
index 0000000..3cda214
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar.csar
new file mode 100644
index 0000000..6179316
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csar b/sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csar
new file mode 100644
index 0000000..416707c
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csar
Binary files differ