diff options
author | Manzon, Inna (im453s) <im453s@intl.att.com> | 2018-11-29 17:26:34 +0200 |
---|---|---|
committer | Manzon, Inna (im453s) <im453s@intl.att.com> | 2019-01-03 15:20:38 +0200 |
commit | 9220c7ac558a42f65c2df48337dfc8f03d6b129c (patch) | |
tree | 3e04a020302f48373c845b0d45285b05094aa898 /src/test/java | |
parent | 92208f69ec00a3f9d28a917d6f6a43ef150863dd (diff) |
Retrieve leaf property value by path
Change-Id: I556f6bfaa3d7c96f9d1f26ae0fcba199d23800c7
Issue-ID: SDC-1982
Signed-off-by: Manzon, Inna (im453s) <im453s@intl.att.com>
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java | 33 | ||||
-rw-r--r-- | src/test/java/org/onap/sdc/toscaparser/api/elements/CalculatePropertyByPathTest.java | 147 |
2 files changed, 180 insertions, 0 deletions
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()); + } +} |