diff options
author | Pavel Aharoni <pa0916@att.com> | 2017-08-21 17:42:38 +0300 |
---|---|---|
committer | Pavel Aharoni <pa0916@att.com> | 2017-08-21 17:42:38 +0300 |
commit | 20e20e9cd5d471d505ffcec2b5498f57a1793bc7 (patch) | |
tree | bd6a7d3b40178d44e729f1d1163eedd729740cd7 | |
parent | 2c7efd20eb813e6217e70600df61281085e600f0 (diff) |
[SDC-242] sdc-tosca resolve get_input
Change-Id: I8617ca99e0699d24e6749f84d216e1bf4cbc3e43
Signed-off-by: Pavel Aharoni <pa0916@att.com>
-rw-r--r-- | pom.xml | 4 | ||||
-rw-r--r-- | src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java | 18 | ||||
-rw-r--r-- | src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java | 38 | ||||
-rw-r--r-- | src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java | 162 | ||||
-rw-r--r-- | src/test/resources/csars/service-resolve-get-input-csar.csar | bin | 0 -> 50501 bytes | |||
-rw-r--r-- | src/test/resources/csars/service-resolve-get-input-csar_QA.csar | bin | 0 -> 50447 bytes |
6 files changed, 185 insertions, 37 deletions
@@ -7,7 +7,7 @@ <artifactId>sdc-tosca</artifactId>
<name>SDC Tosca Parser</name>
<description>SDC Tosca Parser JAR file for use by consumers</description>
- <version>1.1.32-SNAPSHOT</version>
+ <version>1.1.34-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
@@ -97,7 +97,7 @@ <dependency>
<groupId>org.openecomp.sdc.jtosca</groupId>
<artifactId>jtosca</artifactId>
- <version>1.1.1-SNAPSHOT</version>
+ <version>1.1.3-SNAPSHOT</version>
</dependency>
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java index 2ddde1f..868b84f 100644 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java +++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java @@ -44,10 +44,26 @@ public class SdcToscaParserFactory { * @throws SdcToscaParserException - in case the path or CSAR are invalid.
*/
public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws SdcToscaParserException {
+ return init(csarPath, true);
+ }
+
+ /**
+ * Get an ISdcCsarHelper object for this CSAR file.
+ *
+ * @param csarPath - the absolute path to CSAR file.
+ * @param resolveGetInput - resolve get_input properties
+ * @return ISdcCsarHelper object.
+ * @throws SdcToscaParserException - in case the path or CSAR are invalid.
+ */
+ public ISdcCsarHelper getSdcCsarHelper(String csarPath, boolean resolveGetInput) throws SdcToscaParserException {
+ return init(csarPath, resolveGetInput);
+ }
+
+ private ISdcCsarHelper init(String csarPath, boolean resolveGetInput) throws SdcToscaParserException {
synchronized (SdcToscaParserFactory.class) {
ToscaTemplate tosca = null;
try {
- tosca = new ToscaTemplate(csarPath, null, true, null);
+ tosca = new ToscaTemplate(csarPath, null, true, null, resolveGetInput);
} catch (JToscaException e) {
throwSdcToscaParserException(e);
}
diff --git a/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java b/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java index 2789a93..4c1f84e 100644 --- a/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java +++ b/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java @@ -12,7 +12,6 @@ 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.common.JToscaException; -import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; @@ -28,8 +27,10 @@ public abstract class SdcToscaParserBasicTest { static ISdcCsarHelper nfodCsarHlper; static ISdcCsarHelper ipAssignCsarHelper; static ISdcCsarHelper nestedVfcCsarHlper; - static ISdcCsarHelper nfodNEWCsarHlper; - + static ISdcCsarHelper nfodNEWCsarHlper; + static ISdcCsarHelper resolveGetInputCsar; + static ISdcCsarHelper resolveGetInputCsarFalse; + static ISdcCsarHelper resolveGetInputCsarQA; static Map<String, HashMap<String, List<String>>> fdntCsarHelper_Data; @@ -37,15 +38,18 @@ public abstract class SdcToscaParserBasicTest { public static void init() throws SdcToscaParserException, JToscaException, IOException { factory = SdcToscaParserFactory.getInstance(); - fdntCsarHelper = getCsarHelper("csars/service-sunny-flow.csar"); - rainyCsarHelperMultiVfs = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar"); - rainyCsarHelperSingleVf = getCsarHelper("csars/service-ServiceFdnt-csar.csar"); - fdntCsarHelperWithInputs = getCsarHelper("csars/service-ServiceFdnt-with-get-input.csar"); - nfodCsarHlper = getCsarHelper("csars/service-NfodService-csar.csar"); - ipAssignCsarHelper = getCsarHelper("csars/service-Ipassignservice-csar.csar"); - nestedVfcCsarHlper = getCsarHelper("csars/service-nested-vfc-csar.csar"); - nfodNEWCsarHlper = getCsarHelper("csars/service-Nfod2images-csar.csar"); - + fdntCsarHelper = getCsarHelper("csars/service-sunny-flow.csar", false); + rainyCsarHelperMultiVfs = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar", false); + rainyCsarHelperSingleVf = getCsarHelper("csars/service-ServiceFdnt-csar.csar", false); + fdntCsarHelperWithInputs = getCsarHelper("csars/service-ServiceFdnt-with-get-input.csar", false); + nfodCsarHlper = getCsarHelper("csars/service-NfodService-csar.csar", false); + ipAssignCsarHelper = getCsarHelper("csars/service-Ipassignservice-csar.csar", false); + nestedVfcCsarHlper = getCsarHelper("csars/service-nested-vfc-csar.csar", false); + nfodNEWCsarHlper = getCsarHelper("csars/service-Nfod2images-csar.csar", false); + resolveGetInputCsar = getCsarHelper("csars/service-resolve-get-input-csar.csar"); + resolveGetInputCsarFalse = getCsarHelper("csars/service-resolve-get-input-csar.csar",false); + resolveGetInputCsarQA = getCsarHelper("csars/service-resolve-get-input-csar_QA.csar"); + fdntCsarHelper_Data = new HashMap<String, HashMap<String, List<String>>>(){ { HashMap<String, List<String>> FDNT ; @@ -115,7 +119,15 @@ public abstract class SdcToscaParserBasicTest { ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath()); return sdcCsarHelper; } - + + protected static ISdcCsarHelper getCsarHelper(String path, boolean resolveGetInput) throws SdcToscaParserException { + System.out.println("Parsing CSAR "+path+"..."); + String fileStr1 = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile(); + File file1 = new File(fileStr1); + ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath(), resolveGetInput); + return sdcCsarHelper; + } + @BeforeMethod public void setupTest(Method method) { System.out.println("#### Starting Test " + method.getName() + " ###########"); diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java index e71e75c..80bf1b9 100644 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java @@ -6,12 +6,7 @@ import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import org.apache.commons.lang3.tuple.Pair; import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; @@ -660,7 +655,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { assertEquals(0, children.size()); } //endregion - + // added by QA // Get specific VNF properties @Test @@ -668,43 +663,43 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); assertNotNull(vnfConfig); assertEquals("vnfConfiguration", vnfConfig.getMetaData().getValue("name")); - + String manufacturer_reference_number = nfodCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#ATT_part_12345_for_FortiGate-VM00#vendor_info#manufacturer_reference_number"); String num_cpus = nfodCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#ATT_part_67890_for_FortiGate-VM01#compute_flavor#num_cpus"); String sp_part_number = nfodCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#ATT_part_67890_for_FortiGate-VM01#sp_part_number"); - + assertEquals("FortiGate-VM00",manufacturer_reference_number); assertEquals("10",num_cpus); assertEquals("ATT_part_67890_for_FortiGate-VM01",sp_part_number); } // added by QA - // Check that get vnfconfiguration not return as VFC + // Check that get vnfconfiguration not return as VFC @Test public void testGetVfcTypWithoutVnfCheckNames() { List<NodeTemplate> vfcList = nfodCsarHlper.getVfcListByVf("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); assertNotNull(vfcList); assertEquals(2, vfcList.size()); for (int i = 0; i < vfcList.size(); i++) { - + String Name= vfcList.get(i).getName(); - + assertEquals(false, Name.equals("vFW_VNF_Configuration")); - + } } - + @Test public void testNewGetVnfConfigGetProperties() { NodeTemplate vnfConfig = nfodNEWCsarHlper.getVnfConfig("a6587663-b27f-4e88-8a86-604604302ce6"); assertNotNull(vnfConfig); assertEquals("vnfConfiguration", vnfConfig.getMetaData().getValue("name")); - + //Deployment flavor 1 String manufacturer_reference_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#123456#vendor_info#manufacturer_reference_number"); String num_cpus = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#123456#compute_flavor#num_cpus"); String sp_part_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#123456#sp_part_number"); - + assertEquals("234567",manufacturer_reference_number); assertEquals("2",num_cpus); assertEquals("123456",sp_part_number); @@ -713,25 +708,150 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { manufacturer_reference_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#FG_partNumbereJqQjUkteF1#vendor_info#manufacturer_reference_number"); num_cpus = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#FG_partNumbereJqQjUkteF1#compute_flavor#num_cpus"); sp_part_number = nfodNEWCsarHlper.getNodeTemplatePropertyLeafValue(vnfConfig, "allowed_flavors#FG_partNumbereJqQjUkteF1#sp_part_number"); - + assertEquals("EP_manufacturerReferenceNumberkbAiqZZNzx1",manufacturer_reference_number); assertEquals("1",num_cpus); assertEquals("FG_partNumbereJqQjUkteF1",sp_part_number); } // added by QA - // Check that get vnfconfiguration not return as VFC + // Check that get vnfconfiguration not return as VFC @Test public void testNewGetVfcTypWithoutVnfCheckNames() { List<NodeTemplate> vfcList = nfodNEWCsarHlper.getVfcListByVf("a6587663-b27f-4e88-8a86-604604302ce6"); assertNotNull(vfcList); assertEquals(1, vfcList.size()); for (int i = 0; i < vfcList.size(); i++) { - + String Name= vfcList.get(i).getName(); - + assertEquals(false, Name.equals("name_6GkVrOjnGp1_VNF_Configuration")); } } - + + //region resolve get_input + @Test + public void testResolveGetInputForComplexTypeAndList() { + //port_pd01_port_ip_requirements is of type list<org.openecomp.datatypes.network.IpRequirements> + //This test covers: + // 1) "default" resolving + // 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"); + assertTrue(propertyAsObject instanceof ArrayList); + assertEquals(2, ((ArrayList) propertyAsObject).size()); + //port_pd01_port_ip_requirements: + //- get_input: [ip_requirements, 0] + //- get_input: [ip_requirements, 1] + assertEquals("subnet_role_4", ((Map) ((ArrayList) propertyAsObject).get(0)).get("subnet_role")); + assertEquals("subnet_role_6", ((Map) ((ArrayList) propertyAsObject).get(1)).get("subnet_role")); + } + + @Test + 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"); + assertEquals("oam", propertyAsObject); + } + + @Test + public void testResolveGetInputForPrimitiveTypeInteger() { + //This test covers "default" resolving of primitive - as String + List<NodeTemplate> vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + String propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyLeafValue(vfcs.get(0), "port_pd01_port_order"); + assertEquals("1", propertyAsObject); + } + + @Test + 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"); + assertTrue(propertyAsObject instanceof Map); + assertEquals(false, ((Map)propertyAsObject).get("is_required")); + } + + @Test + 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"); + 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"); + assertEquals(2, vfcPropertyAsObject); //takes it from upper level (VF) property + } + + @Test + public void testResolveGetInputNoDefValueInnerLevel() { + //This test covers resolving when no "default" value is supplied to the input - should be null - VF/VFCI level + List<NodeTemplate> vfcs = resolveGetInputCsar.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + String propertyAsObject = resolveGetInputCsar.getNodeTemplatePropertyLeafValue(vfcs.get(0), "index_value"); + assertNull(propertyAsObject); + + } + + @Test + 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"); + assertNull(vfPropertyAsObject); + + } + //endregion + + // region Added by QA - Continue with testings of resolve get_input + + @Test + 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"); + assertTrue(propertyAsObject instanceof ArrayList); + assertEquals(2, ((ArrayList) propertyAsObject).size()); + assertEquals("get_input:[ip_requirements, 0]", ((ArrayList) propertyAsObject).get(0).toString()); + assertEquals("get_input:[ip_requirements, 1]", ((ArrayList) propertyAsObject).get(1).toString()); + } + + @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"); + 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"); + 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"); + assertEquals("\"ZRDM1MOGX01MPD001\"", propertyAsObject.toString()); + } + + @Test + 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"); + 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"); + assertEquals("107.239.36.5", propertyAsObject.toString()); + } + + // endregion Added by QA - Continue with testings of resolve get_input + } diff --git a/src/test/resources/csars/service-resolve-get-input-csar.csar b/src/test/resources/csars/service-resolve-get-input-csar.csar Binary files differnew file mode 100644 index 0000000..fe433f6 --- /dev/null +++ b/src/test/resources/csars/service-resolve-get-input-csar.csar diff --git a/src/test/resources/csars/service-resolve-get-input-csar_QA.csar b/src/test/resources/csars/service-resolve-get-input-csar_QA.csar Binary files differnew file mode 100644 index 0000000..c35c890 --- /dev/null +++ b/src/test/resources/csars/service-resolve-get-input-csar_QA.csar |