diff options
author | Pavel Aharoni <pa0916@att.com> | 2017-06-08 12:26:00 +0300 |
---|---|---|
committer | Pavel Aharoni <pa0916@att.com> | 2017-06-08 12:26:00 +0300 |
commit | 6b61b88108c5d35efb61cd1006d0a3b9db9d35bf (patch) | |
tree | 85c77d3d6e944f58ba6a9b3a5e9ac3778658d5a2 /src/test/java | |
parent | 9b5e11ba43f82c87623e05671a96a4ce0aedfde7 (diff) |
[SDC-30] SDC-TOSCA initial commit
Change-Id: I1048701a6f4a2e14cb37ecc6205b07ffce8af38f
Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'src/test/java')
9 files changed, 1109 insertions, 0 deletions
diff --git a/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java b/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java new file mode 100644 index 0000000..7ea231c --- /dev/null +++ b/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java @@ -0,0 +1,120 @@ +package org.openecomp.sdc.impl; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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; + +public abstract class SdcToscaParserBasicTest { + + public static final String VF_CUSTOMIZATION_UUID = "56179cd8-de4a-4c38-919b-bbc4452d2d73"; + static SdcToscaParserFactory factory; + static ISdcCsarHelper rainyCsarHelperSingleVf; + static ISdcCsarHelper rainyCsarHelperMultiVfs; + static ISdcCsarHelper fdntCsarHelper; + static ISdcCsarHelper complexCps; + static ISdcCsarHelper fdntCsarHelperWithInputs; + static Map<String, HashMap<String, List<String>>> fdntCsarHelper_Data; + + @BeforeClass + public static void init() throws SdcToscaParserException, JToscaException, IOException { + + factory = SdcToscaParserFactory.getInstance(); + fdntCsarHelper = getCsarHelper("csars/service-ServiceFdnt-with-allotted.csar"); + rainyCsarHelperMultiVfs = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar"); + rainyCsarHelperSingleVf = getCsarHelper("csars/service-ServiceFdnt-csar.csar"); + complexCps = getCsarHelper("csars/service-Renanatst2-csar.csar"); + fdntCsarHelperWithInputs = getCsarHelper("csars/service-ServiceFdnt-with-get-input.csar"); + + fdntCsarHelper_Data = new HashMap<String, HashMap<String, List<String>>>(){ + { + HashMap<String, List<String>> FDNT ; + + FDNT = new HashMap<String, List<String>>(); + FDNT.put("VF Name", Arrays.asList("FDNT 1")); + FDNT.put("capabilities", Arrays.asList( + "dnt_fw_rhrg.binding_DNT_FW_INT_DNS_TRUSTED_RVMI", + "dnt_fw_rhrg.host_DNT_FW_SERVER", + "dnt_fw_rhrg.binding_DNT_FW_CORE_DIRECT_RVMI", + "dnt_fw_rhrg.scalable_DNT_FW_SERVER", + "dnt_fw_rhrg.endpoint_DNT_FW_SERVER", + "dnt_fw_rhrg.binding_DNT_FW_INTERNET_DNS_DIRECT_RVMI", + "dnt_fw_rhrg.os_DNT_FW_SERVER", + "dnt_fw_rhrg.feature", + "dnt_fw_rhrg.binding_DNT_FW_OAM_PROTECTED_RVMI", + "dnt_fw_rhrg.binding_DNT_FW_SERVER", + "dnt_fw_rhrg.binding_DNT_FW_NIMBUS_HSL_RVMI", + "dnt_fw_rsg_si_1.feature")); + FDNT.put("requirements", Arrays.asList( + "DNT_FW_RSG_SI_1.dependency", + "DNT_FW_RHRG.dependency", + "DNT_FW_RHRG.link_DNT_FW_INTERNET_DNS_DIRECT_RVMI", + "DNT_FW_RHRG.link_DNT_FW_CORE_DIRECT_RVMI", + "DNT_FW_RHRG.link_DNT_FW_OAM_PROTECTED_RVMI", + "DNT_FW_RHRG.link_DNT_FW_INT_DNS_TRUSTED_RVMI", + "DNT_FW_RHRG.link_DNT_FW_NIMBUS_HSL_RVMI", + "DNT_FW_RSG_SI_1.port", + "DNT_FW_RHRG.local_storage_DNT_FW_SERVER")); + FDNT.put("capabilitiesTypes", Arrays.asList( + "tosca.capabilities.network.Bindable", + "tosca.capabilities.OperatingSystem", + "tosca.capabilities.network.Bindable", + "tosca.capabilities.Scalable", + "tosca.capabilities.Endpoint.Admin", + "tosca.capabilities.network.Bindable", + "tosca.capabilities.network.Bindable", + "tosca.capabilities.network.Bindable", + "tosca.capabilities.Node", + "tosca.capabilities.Container", + "tosca.nodes.SoftwareComponent", + "tosca.capabilities.network.Bindable")); + FDNT.put("capabilityProperties", Arrays.asList( + "dnt_fw_rhrg.binding_DNT_FW_INT_DNS_TRUSTED_RVMI:none", + "dnt_fw_rhrg.host_DNT_FW_SERVER:num_cpus,integer,false;", + "dnt_fw_rhrg.binding_DNT_FW_CORE_DIRECT_RVMI", + "dnt_fw_rhrg.scalable_DNT_FW_SERVER", + "dnt_fw_rhrg.endpoint_DNT_FW_SERVER", + "dnt_fw_rhrg.binding_DNT_FW_INTERNET_DNS_DIRECT_RVMI", + "dnt_fw_rhrg.os_DNT_FW_SERVER", + "dnt_fw_rhrg.feature", + "dnt_fw_rhrg.binding_DNT_FW_OAM_PROTECTED_RVMI", + "dnt_fw_rhrg.binding_DNT_FW_SERVER", + "dnt_fw_rhrg.binding_DNT_FW_NIMBUS_HSL_RVMI", + "dnt_fw_rsg_si_1.feature")); + + + put("FDNT", FDNT); + } + }; + }; + + protected static ISdcCsarHelper getCsarHelper(String path) 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()); + return sdcCsarHelper; + } + + @BeforeMethod + public void setupTest(Method method) { + System.out.println("#### Starting Test " + method.getName() + " ###########"); + } + + @AfterMethod + public void tearDown(Method method){ + System.out.println("#### Ended test " + method.getName() + " ###########"); + } +} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java new file mode 100644 index 0000000..8c96303 --- /dev/null +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java @@ -0,0 +1,31 @@ +package org.openecomp.sdc.impl; + +import org.openecomp.sdc.tosca.parser.config.ErrorConfiguration; +import org.testng.annotations.Test; +import org.openecomp.sdc.tosca.parser.config.Configuration; +import org.openecomp.sdc.tosca.parser.config.ConfigurationManager; + +import java.io.IOException; + +import static org.testng.Assert.assertNotNull; + +public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest { + + @Test + public void testConfigurationConformanceLevel() throws IOException { + Configuration config = ConfigurationManager.getInstance().getConfiguration(); + assertNotNull(config); + assertNotNull(config.getConformanceLevel()); + assertNotNull(config.getConformanceLevel().getMaxVersion()); + assertNotNull(config.getConformanceLevel().getMinVersion()); + } + + + @Test + public void testErrorConfigurations() throws IOException { + ErrorConfiguration errorConfig = ConfigurationManager.getInstance().getErrorConfiguration(); + assertNotNull(errorConfig); + assertNotNull(errorConfig.getErrors()); + } + +} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java new file mode 100644 index 0000000..8451a58 --- /dev/null +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java @@ -0,0 +1,143 @@ +package org.openecomp.sdc.impl; + +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +import java.io.File; + +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes; + + +/*put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR); + +put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND); +//CSAR contents problems +put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT); +put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT); +put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT); +put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT); +put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT); + + MISSING_META_FILE("JT1001"), +/* INVALID_META_YAML_CONTENT("JT1002"), +/* ENTRY_DEFINITION_NOT_DEFINED("JT1003"), +/* MISSING_ENTRY_DEFINITION_FILE("JT1004"), +/* GENERAL_ERROR("JT1005"), +/* PATH_NOT_VALID("JT1006"), +/* CSAR_TOSCA_VALIDATION_ERROR("JT1007"); + +*/ + +/* + * + * # Errors +errors: + FILE_NOT_FOUND: { + code: TP0001, + message: "Error: CSAR file not found." + } + BAD_FORMAT: { + code: TP0002, + message: "Error: CSAR file bad format. Check the log for details." + } + CONFORMANCE_LEVEL_ERROR: { + code: TP0003, + message: "Error: CSAR version is unsupported. Parser supports versions %s to %s." + } + GENERAL_ERROR: { + code: TP0004, + message: "Error: an unexpected internal error occured." + } + * + */ + +public class ToscaParserErrorHandlingTest extends SdcToscaParserBasicTest { + + + @Test + public void testMissingMetadata(){ + String csarPath = "csars/service-missing-meta-file.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + + @Test + public void testInvalidYamlContentMeta(){ + String csarPath = "csars/service-invalid-yaml-content-meta.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testEntryDefinitionNotDefined(){ + String csarPath = "csars/service-entry-definition-not-defined.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testMissingEntryDefinitionFile(){ + String csarPath = "csars/service-missing-entry-definition.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + //@Test - PA - there are currently no critical erros in JTosca + public void tesValidationError(){ + String csarPath = "csars/service-invalid-input-args.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testInValidConformanceLevelError(){ + String csarPath = "csars/service-invalid-conformence-level.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0003"); + } + + @Test + public void testFileNotFound(){ + Throwable captureThrowable = captureThrowable("csars/XXX.csar"); + testThrowable(captureThrowable, "TP0001"); + } + + @Test + public void testInvalidCsarFormat(){ + String csarPath = "csars/csar-invalid-zip.zip"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + private static void testThrowable(Throwable captureThrowable, String expectedCode) { + assertNotNull(captureThrowable); + assertTrue(captureThrowable instanceof SdcToscaParserException, "Error thrown is of type "+captureThrowable.getClass().getSimpleName()); + assertEquals(((SdcToscaParserException)captureThrowable).getCode(), expectedCode); + } + + public static Throwable captureThrowable(String csarPath) { + Throwable result = null; + try { + factory.getSdcCsarHelper(csarPath); + } catch( Throwable throwable ) { + result = throwable; + } + return result; + } +} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java new file mode 100644 index 0000000..9f349ae --- /dev/null +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java @@ -0,0 +1,23 @@ +package org.openecomp.sdc.impl; + +import org.testng.annotations.Test; +import org.openecomp.sdc.tosca.parser.utils.GeneralUtility; + +import static org.testng.Assert.assertTrue; + +public class ToscaParserGeneralUtilTest extends SdcToscaParserBasicTest { + + @Test + public void testVersionCompare() { + assertTrue(GeneralUtility.conformanceLevelCompare("2", "3.0") < 0); + assertTrue(GeneralUtility.conformanceLevelCompare("0.5", "0.5") == 0); + assertTrue(GeneralUtility.conformanceLevelCompare("0.5", "0.6") < 0); + assertTrue(GeneralUtility.conformanceLevelCompare("1.5", "2.6") < 0); + assertTrue(GeneralUtility.conformanceLevelCompare("0.2", "0.1") > 0); + assertTrue(GeneralUtility.conformanceLevelCompare("2", "1.15") > 0); + assertTrue(GeneralUtility.conformanceLevelCompare("2", "2.0.0") == 0); + assertTrue(GeneralUtility.conformanceLevelCompare("2.0", "2.0.0.0") == 0); + assertTrue(GeneralUtility.conformanceLevelCompare("2.", "2.0.0.0") == 0); + assertTrue(GeneralUtility.conformanceLevelCompare("2.0", "2.0.0.2") < 0); + } +} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java new file mode 100644 index 0000000..d7321d1 --- /dev/null +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java @@ -0,0 +1,116 @@ +package org.openecomp.sdc.impl; + +import org.testng.annotations.Test; +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.sdc.toscaparser.api.Group; +import org.openecomp.sdc.toscaparser.api.elements.Metadata; + +import java.util.Arrays; +import java.util.List; + +import static org.testng.Assert.*; + +public class ToscaParserGroupTest extends SdcToscaParserBasicTest{ + + //region getVfModulesByVf + @Test + public void testVfModulesFromVf(){ + List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + assertEquals(2, vfModulesByVf.size()); + for (Group group : vfModulesByVf){ + assertTrue(group.getName().startsWith("fdnt1")); + assertNotNull(group.getMetadata()); + assertNotNull(group.getMetadata().getValue("vfModuleCustomizationUUID")); + } + } + + @Test + public void testGetGroupMetadata(){ + List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + boolean found = false; + for (Group group : vfModulesByVf){ + if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")){ + found = true; + Metadata metadata = group.getMetadata(); + assertNotNull(metadata); + assertEquals("b458f4ef-ede2-403d-9605-d08c9398b6ee", metadata.getValue("vfModuleModelCustomizationUUID")); + } + } + assertTrue(found); + } + + @Test + public void testGetGroupEmptyMetadata(){ + List<Group> vfModulesByVf = rainyCsarHelperMultiVfs.getVfModulesByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72"); + boolean found = false; + for (Group group : vfModulesByVf){ + if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")){ + found = true; + Metadata metadata = group.getMetadata(); + assertNull(metadata); + } + } + assertTrue(found); + } + + @Test + public void testGetVfModuleNonExisitingVf() { + List<Group> vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf("dummy"); + assertNotNull(vfModulesByVf); + assertEquals(0, vfModulesByVf.size()); + } + + @Test + public void testGetVfModuleNullVf() { + List<Group> vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf(null); + assertNotNull(vfModulesByVf); + assertEquals(0, vfModulesByVf.size()); + } + //endregion + + //region getGroupPropertyLeafValue + @Test + public void testGroupFlatProperty() throws SdcToscaParserException { + List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + String volumeGroup = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "volume_group"); + assertEquals("false", volumeGroup); + } + +// @Test +// public void testGroupFlatGetInputProperty() throws SdcToscaParserException { +// List<Group> vfModulesByVf = fdntCsarHelperWithInputs.getVfModulesByVf(VF_CUSTOMIZATION_UUID); +// String volumeGroup = fdntCsarHelperWithInputs.getGroupPropertyLeafValue(vfModulesByVf.get(1), "volume_group"); +// assertEquals("false", volumeGroup); +// } + + @Test + public void testGroupPropertyLeafValueByNullProperty() { + List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), null); + assertNull(groupProperty); + } + + @Test + public void testGroupPropertyLeafValueByDummyProperty() { + List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "XXX"); + assertNull(groupProperty); + } + + @Test + public void testGroupPropertyLeafValueByNullGroup() { + String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(null, "volume_group"); + assertNull(groupProperty); + } + //endregion + + //region getGroupPropertyAsObject + @Test + public void testGetGroupPropertyAsObject() { + List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + Object volumeGroup = fdntCsarHelper.getGroupPropertyAsObject(vfModulesByVf.get(0), "volume_group"); + assertEquals(false, volumeGroup); + } + //getGroupPropertyAsObject + +} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java new file mode 100644 index 0000000..cd80f3a --- /dev/null +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java @@ -0,0 +1,84 @@ +package org.openecomp.sdc.impl; + +import org.testng.annotations.Test; +import org.openecomp.sdc.toscaparser.api.elements.Metadata; + +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +public class ToscaParserMetadataTest extends SdcToscaParserBasicTest { + + //region getServiceMetadata + @Test + public void testGetServiceMetadata() { + Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata(); + assertNotNull(serviceMetadata); + assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", serviceMetadata.getValue("invariantUUID")); + assertEquals("Service FDNT", serviceMetadata.getValue("name")); + assertEquals("true", String.valueOf(serviceMetadata.getValue("serviceEcompNaming"))); + } + + @Test + public void testServiceMetadata() { + Metadata metadata = rainyCsarHelperSingleVf.getServiceMetadata(); + assertNull(metadata); + } + //endregion + + //region getMetadataPropertyValue + @Test + public void testGetMetadataProperty(){ + Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata(); + String metadataPropertyValue = fdntCsarHelper.getMetadataPropertyValue(serviceMetadata, "invariantUUID"); + assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", metadataPropertyValue); + } + + @Test + public void testGetNullMetadataPropertyValue() { + String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(null, "XXX"); + assertNull(value); + } + + @Test + public void testGetMetadataByNullPropertyValue() { + Metadata metadata = rainyCsarHelperMultiVfs.getServiceMetadata(); + String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(metadata, null); + assertNull(value); + } + + @Test + public void testGetMetadataByEmptyPropertyValue() { + Metadata metadata = rainyCsarHelperMultiVfs.getServiceMetadata(); + String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(metadata, ""); + assertNull(value); + } + //endregion + + //region getConformanceLevel + @Test + public void testSunnyGetConformanceLevel() { + String conformanceLevel = fdntCsarHelper.getConformanceLevel(); + assertNotNull(conformanceLevel); + assertEquals("3.0", conformanceLevel); + } + //endregion + + //region getServiceMetadataProperties + @Test + public void testNullServiceMetadataPropertiesMap() { + Map<String, Object> metadata = rainyCsarHelperSingleVf.getServiceMetadataProperties(); + assertNull(metadata); + } + + @Test + public void testServiceMetadataPropertiesMap() { + Map<String, Object> metadata = fdntCsarHelper.getServiceMetadataProperties(); + assertNotNull(metadata); + assertEquals(metadata.size(),9); + assertEquals(metadata.get("namingPolicy"),"test"); + } + //endregion +} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java new file mode 100644 index 0000000..42a6bd4 --- /dev/null +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java @@ -0,0 +1,397 @@ +package org.openecomp.sdc.impl; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.Pair; +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.sdc.toscaparser.api.Group; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.testng.annotations.Test; + +public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { + + //region getServiceVfList + @Test + public void testNumberOfVfSunnyFlow() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList(); + assertNotNull(serviceVfList); + assertEquals(2, serviceVfList.size()); + } + + @Test + public void testGetNodeTemplateCustomizationUuid(){ + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList(); + boolean found = false; + for (NodeTemplate nt : serviceVfList){ + if (nt.getName().equals("FDNT 1")){ + found = true; + assertEquals(fdntCsarHelper.getNodeTemplateCustomizationUuid(nt), "56179cd8-de4a-4c38-919b-bbc4452d2d73"); + } + } + assertTrue(found); + } + + @Test + public void testSingleVFWithNotMetadata() throws SdcToscaParserException { + //If there is no metadata on VF level - There is no VF's because the type is taken from metadata values. + List<NodeTemplate> serviceVfList = rainyCsarHelperSingleVf.getServiceVfList(); + assertNotNull(serviceVfList); + assertEquals(0, serviceVfList.size()); + } + //endregion + + //region getNodeTemplatePropertyLeafValue + @Test + public void testNodeTemplateFlatProperty() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList(); + assertEquals("2", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "availability_zone_max_count")); + assertEquals("3", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "max_instances")); + assertEquals("some code", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_naming_code")); + } + + @Test + public void testNodeTemplateFlatFunctionProperty() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = fdntCsarHelperWithInputs.getServiceVfList(); + assertEquals(null, fdntCsarHelperWithInputs.getNodeTemplatePropertyLeafValue(serviceVfList.get(1), "target_network_role")); + } + + @Test + public void testNodeTemplateNestedProperty() throws SdcToscaParserException { + List<NodeTemplate> serviceVlList = fdntCsarHelper.getServiceVlList(); + NodeTemplate nodeTemplate = serviceVlList.get(0); + //System.out.println("node template " + nodeTemplate.toString()); + assertEquals("24", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#cidr_mask")); + assertEquals("7a6520b-9982354-ee82992c-105720", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_flows#vpn_binding")); + } + + @Test + public void testNodeTemplateNestedPropertyFromInput() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList(); + NodeTemplate nodeTemplate = serviceVfList.get(0); + //System.out.println("node template " + nodeTemplate.toString()); + assertEquals("true", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming#ecomp_generated_naming")); + assertEquals("FDNT_instance_VF_2", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming#naming_policy")); + } + + @Test + public void testNodeTemplateNestedPropertyNotExists() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList(); + String nodeTemplatePropertyLeafValue = fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_role#nf_naming#kuku"); + assertNull(nodeTemplatePropertyLeafValue); + } + + @Test + public void testNodeTemplateFlatPropertyByNotFoundProperty() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList(); + String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "XXXX"); + assertNull(nodeTemplatePropertyLeafValue); + } + + @Test + public void testNodeTemplateFlatPropertyByNullProperty() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList(); + String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), null); + assertNull(nodeTemplatePropertyLeafValue); + } + + @Test + public void testNodeTemplateFlatPropertyByNullNodeTemplate() throws SdcToscaParserException { + String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(null, "availability_zone_max_count"); + assertNull(nodeTemplatePropertyLeafValue); + } + //endregion + + //region getServiceVlList + @Test + public void testServiceVl() { + List<NodeTemplate> vlList = fdntCsarHelper.getServiceVlList(); + assertEquals(1, vlList.size()); + assertEquals("exVL", vlList.get(0).getName()); + } + + @Test + public void testNumberOfVLRainyFlow() throws SdcToscaParserException { + List<NodeTemplate> serviceVlList = rainyCsarHelperMultiVfs.getServiceVlList(); + assertNotNull(serviceVlList); + assertEquals(0, serviceVlList.size()); + } + //endregion + + //region getServiceNodeTemplatesByType + @Test + public void testServiceNodeTemplatesByType() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Fdnt"); + assertNotNull(serviceVfList); + assertEquals(1, serviceVfList.size()); + } + + @Test + public void testServiceNodeTemplatesByNull() { + List<NodeTemplate> nodeTemplates = rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType(null); + assertNotNull(nodeTemplates); + assertEquals(0, nodeTemplates.size()); + } + + @Test + public void testServiceNodeTemplatesByNotFoundProperty() { + List<NodeTemplate> nodeTemplates = rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType("XXX"); + assertNotNull(nodeTemplates); + assertEquals(0, nodeTemplates.size()); + } + //endregion + + //region getTypeOfNodeTemplate + @Test + public void testGetTypeOfNodeTemplate() { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList(); + String typeOfNodeTemplate = fdntCsarHelper.getTypeOfNodeTemplate(serviceVfList.get(0)); + assertEquals("org.openecomp.resource.vf.Fdnt", typeOfNodeTemplate); + } + + @Test + public void testGetTypeOfNullNodeTemplate() { + String typeOfNodeTemplate = rainyCsarHelperMultiVfs.getTypeOfNodeTemplate(null); + assertNull(typeOfNodeTemplate); + } + //endregion + + //region getAllottedResources + @Test + public void testGetAllottedResources() { + List<NodeTemplate> allottedResources = fdntCsarHelper.getAllottedResources(); + assertEquals(1, allottedResources.size()); + } + + @Test + public void testGetAllottedResourcesZero() { + List<NodeTemplate> allottedResources = rainyCsarHelperMultiVfs.getAllottedResources(); + assertNotNull(allottedResources); + assertEquals(0, allottedResources.size()); + } + //endregion + + //region getVfcListByVf + @Test + public void testGetVfcFromVf() { + List<NodeTemplate> vfcListByVf = fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID); + assertEquals(2, vfcListByVf.size()); + } + + @Test + public void testVfcListByNull() { + List<NodeTemplate> vfcList = rainyCsarHelperMultiVfs.getVfcListByVf(null); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + + @Test + public void testVfcListByNotFoundProperty() { + List<NodeTemplate> vfcList = rainyCsarHelperMultiVfs.getVfcListByVf("XXX"); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + //endregion + + //region getCpListByVf + @Test + public void testGetCpFromVf() { + List<NodeTemplate> cpListByVf = fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID); + assertEquals(1, cpListByVf.size()); + NodeTemplate nodeTemplate = cpListByVf.get(0); + assertEquals("DNT_PORT", nodeTemplate.getName()); + } + + @Test + public void testGetCpFromVfByNullId() { + List<NodeTemplate> cpListByVf = rainyCsarHelperMultiVfs.getCpListByVf(null); + assertNotNull(cpListByVf); + assertEquals(0, cpListByVf.size()); + } + + @Test + public void testGetCpFromVfXxx() { + List<NodeTemplate> cpListByVf = rainyCsarHelperMultiVfs.getCpListByVf("XXXXX"); + assertNotNull(cpListByVf); + assertEquals(0, cpListByVf.size()); + } + //endregion + + //region getNodeTemplatePairsByReqName + @Test + public void testGetNodeTemplatePairsByReqName() { + List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(1, nodeTemplatePairsByReqName.size()); + Pair<NodeTemplate, NodeTemplate> pair = nodeTemplatePairsByReqName.get(0); + NodeTemplate cp = pair.getLeft(); + NodeTemplate vfc = pair.getRight(); + assertEquals("DNT_PORT", cp.getName()); + assertEquals("DNT_FW_RHRG", vfc.getName()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithNullVF() { + List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + null, fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithEmptyVF() { + List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + new ArrayList<>(), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithNullCap() { + List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), null, "binding"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithEmptyCap() { + List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), new ArrayList<>(), "binding"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithNullReq() { + List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), null); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + + @Test + public void testGetNodeTemplatePairsByReqNameWithDummyReq() { + + List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName( + fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "XXX"); + assertNotNull(nodeTemplatePairsByReqName); + assertEquals(0, nodeTemplatePairsByReqName.size()); + } + //endregion + + //region getMembersOfVfModule + @Test + public void testGetMembersOfVfModule() { + NodeTemplate vf = fdntCsarHelper.getServiceVfList().get(0); + List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + assertEquals(2, vfModulesByVf.size()); + for (Group group : vfModulesByVf) { + List<NodeTemplate> membersOfVfModule = fdntCsarHelper.getMembersOfVfModule(vf, group); + assertNotNull(membersOfVfModule); + if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")) { + assertEquals(1, membersOfVfModule.size()); + NodeTemplate nodeTemplate = membersOfVfModule.get(0); + assertEquals("DNT_FW_RSG_SI_1", nodeTemplate.getName()); + } else { + assertEquals("fdnt1..Fdnt..mod_vmsi_dnt_fw_parent..module-1", group.getName()); + assertEquals(1, membersOfVfModule.size()); + NodeTemplate nodeTemplate = membersOfVfModule.get(0); + assertEquals("DNT_FW_RHRG", nodeTemplate.getName()); + } + } + } + + @Test + public void testMembersOfVfModuleByNullVf() { + List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID); + List<NodeTemplate> nodeTemplates = fdntCsarHelper.getMembersOfVfModule(null, vfModulesByVf.get(0)); + assertNotNull(nodeTemplates); + assertEquals(0, nodeTemplates.size()); + } + + @Test + public void testMembersOfVfModuleByNullGroup() { + List<NodeTemplate> serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList(); + List<NodeTemplate> nodeTemplates = rainyCsarHelperMultiVfs.getMembersOfVfModule(serviceVfList.get(0), null); + assertNotNull(nodeTemplates); + assertEquals(0, nodeTemplates.size()); + } + //endregion + + //region getCpPropertiesFromVfc + @Test + public void testGetCpPropertiesFromVfc() { + List<NodeTemplate> vfcs = complexCps.getVfcListByVf("f999e2ca-72c0-42d3-9b11-13f2122fb8ef"); + boolean isChecked = false; + boolean isChecked1 = false; + for (int i = 0; i < vfcs.size(); i++) { + + if(vfcs.get(i).getName().equalsIgnoreCase("abstract_ddc")) + { + isChecked = true; + Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(vfcs.get(i)); + + assertEquals(3,cps.size()); + + assertEquals(new Integer(1), cps.get("ddc_int_imbl__port").get("ip_requirements#ip_count_required#count")); + assertEquals(new Boolean(true), cps.get("ddc_int_imbl__port").get("ip_requirements#dhcp_enabled")); + assertEquals(new Integer(6), cps.get("ddc_int_imbl__port").get("ip_requirements#ip_version")); + assertEquals(null, cps.get("ddc_int_imbl__port").get("subnetpoolid")); + + //assertEquals("\"int_imsp\"", cps.get("mon_ist_imsp__port").get("network_role_tag")); + + } + + if(vfcs.get(i).getName().equalsIgnoreCase("abstract_mda")) + { + isChecked1 = true; + Map<String, Map<String, Object>> cps1 = complexCps.getCpPropertiesFromVfc(vfcs.get(i)); + + assertEquals(new Integer(4), cps1.get("mda_int_imsp__port").get("ip_requirements#ip_version")); + assertEquals(null, cps1.get("mda_int_imsp__port").get("ip_requirements#ip_count_required#count")); + + } + + } + assertTrue(isChecked); + assertTrue(isChecked1); + } + + + @Test + public void testGetCpPropertiesFromVfcForNullVFC() { + Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(null); + assertNotNull(cps); + assertEquals(0, cps.size()); + } + //endregion + + //region getNodeTemplatePropertyAsObject + @Test + public void testGetNodeTemplatePropertyAsObject() { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList(); + assertEquals("2", fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "availability_zone_max_count")); + assertEquals(3, fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "max_instances")); + assertEquals("some code", fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "nf_naming_code")); + } + //endregion + + //region getServiceNodeTemplates + @Test + public void testServiceNodeTemplates() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceNodeTemplates(); + assertNotNull(serviceVfList); + assertEquals(3, serviceVfList.size()); + assertEquals(serviceVfList.get(2).getName(), "exVL"); + } + //endregion + +} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java new file mode 100644 index 0000000..ea5c2ef --- /dev/null +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java @@ -0,0 +1,63 @@ +package org.openecomp.sdc.impl; + +import org.testng.annotations.Test; +import org.openecomp.sdc.toscaparser.api.parameters.Input; + +import java.util.List; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +public class ToscaParserServiceInputTest extends SdcToscaParserBasicTest { + + //region getServiceInputs + @Test + public void testGetServiceInputs(){ + List<Input> serviceInputs = fdntCsarHelper.getServiceInputs(); + assertNotNull(serviceInputs); + assertEquals(1, serviceInputs.size()); + } + + @Test + public void testServiceInputs() { + List<Input> inputs = rainyCsarHelperSingleVf.getServiceInputs(); + assertNotNull(inputs); + assertEquals(0, inputs.size()); + } + //endregion + + //region getServiceInputLeafValueOfDefault + @Test + public void testGetServiceInputLeafValue(){ + String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default"); + assertEquals("test service naming", serviceInputLeafValue); + } + +// @Test +// public void testGetServiceInputLeafValueWithGetInput(){ +// String serviceInputLeafValue = fdntCsarHelperWithInputs.getServiceInputLeafValueOfDefault("my_input#default"); +// assertEquals(null, serviceInputLeafValue); +// } + + @Test + public void testGetServiceInputLeafValueNotExists(){ + String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default#kuku"); + assertNull(serviceInputLeafValue); + } + + @Test + public void testGetServiceInputLeafValueNull(){ + String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault(null); + assertNull(serviceInputLeafValue); + } + //endregion + + //region getServiceInputLeafValueOfDefaultAsObject + @Test + public void testGetServiceInputLeafValueOfDefaultAsObject() { + Object serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default"); + assertEquals("test service naming", serviceInputLeafValue); + } + //endregion +} diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java new file mode 100644 index 0000000..6461a92 --- /dev/null +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java @@ -0,0 +1,132 @@ +package org.openecomp.sdc.impl; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.stream.Collectors; + +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.sdc.toscaparser.api.Capability; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.elements.CapabilityTypeDef; +//import org.testng.ReporterConfig.Property; +import org.testng.annotations.Test; +import org.openecomp.sdc.toscaparser.api.Property; + +//import static org.junit.Assert.assertEquals; +//import static org.junit.Assert.assertNull; + +public class ToscaParserSubsMappingsTest extends SdcToscaParserBasicTest { + + //region getServiceSubstitutionMappingsTypeName + @Test + public void testGetServiceSubstitutionMappingsTypeName() { + String serviceSubstitutionMappingsTypeName = fdntCsarHelper.getServiceSubstitutionMappingsTypeName(); + assertEquals("org.openecomp.service.ServiceFdnt", serviceSubstitutionMappingsTypeName); + } + + @Test + public void testServiceSubstitutionMappingsTypeName() { + String substitutionMappingsTypeName = rainyCsarHelperMultiVfs.getServiceSubstitutionMappingsTypeName(); + assertNull(substitutionMappingsTypeName); + } + //endregion + + //Added by QA - Check for Capabilities in VF level (Capabilities QTY and Names). + //@Test // - BUG 283369 + public void testCapabilitiesofVFNames_QTY() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList(); + String sName = serviceVfList.get(0).getName(); + assertEquals(sName,fdntCsarHelper_Data.get("FDNT").get("VF Name").get(0)); + LinkedHashMap<String, Capability> lCapabilitys = serviceVfList.get(0).getCapabilities(); + List<String> CPkeys = new ArrayList<>(lCapabilitys.keySet()); + List<String> CapabilitiesNames = new ArrayList<String>(CPkeys.size()); + + for (int i = 0; i < CPkeys.size(); i++) { + + Capability cCp = lCapabilitys.get(CPkeys.get(i)); + + CapabilitiesNames.add(cCp.getName()); + + assertEquals(CPkeys.get(i).toLowerCase(), CapabilitiesNames.get(i).toLowerCase());// Compare keys to values, Should it be checked as Case sensitive???? + + //System.out.println(String.format("Value of key: %s , Value of capability: %s", keys.get(i).toLowerCase(), Capabilities.get(i).toLowerCase())); + //System.out.println(String.format("Value of key: %s , Value of capability: %s", ActualValues.get(i).toLowerCase(), Capabilities.get(i).toLowerCase())); + //System.out.println(String.format("*******%d*******",i)); + } + + for (int i = 0; i < CPkeys.size(); i++) { + assertEquals(true, CapabilitiesNames.stream().map(String::toLowerCase).collect(Collectors.toList()).contains(fdntCsarHelper_Data.get("FDNT").get("capabilities").get(i).toLowerCase())); // Compare capabilities predefined list to actual one. + } + + assertEquals(fdntCsarHelper_Data.get("FDNT").get("capabilities").size(), CapabilitiesNames.size()); // Compare capabilities qty expected vs actual + } + + //Added by QA - Check for Capabilities in VF level (Capabilities Types and Properties). + //@Test + public void testCapabilitiesofVFTypes_Properties() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList(); + String sName = serviceVfList.get(0).getName(); + assertEquals(sName,fdntCsarHelper_Data.get("FDNT").get("VF Name").get(0)); + LinkedHashMap<String, Capability> lCapabilitys = serviceVfList.get(0).getCapabilities(); + + List<String> CPkeys = new ArrayList<>(lCapabilitys.keySet()); + List<String> CPPropkeys = new ArrayList<>(lCapabilitys.keySet()); + List<String> CapabilitiesTypes = new ArrayList<String>(CPkeys.size()); + + //int iKeysSize = keys.size(); //for debug + + for (int i = 0; i < CPkeys.size(); i++) { + + Capability cCp = lCapabilitys.get(CPkeys.get(i)); + CapabilityTypeDef CpDef = cCp.getDefinition(); + CapabilitiesTypes.add(CpDef.getType()); + + //LinkedHashMap<String,Object> lProperties = cCp.getDefinition().getProperties(); + LinkedHashMap<String, Property> lPropertiesR = cCp.getProperties(); + + List<String> CP_Propkeys = new ArrayList<>(lPropertiesR.keySet()); + + for (int j = 0; j < CP_Propkeys.size(); j++) { + + Property p = lPropertiesR.get(CP_Propkeys.get(j)); + + if(p != null){ + String sPType = p.getType(); + Boolean bPRequired = p.isRequired(); + + System.out.println(sPType + " " + bPRequired); + + } + + } + + } + + for (int i = 0; i < CPkeys.size(); i++) { + + } + + assertEquals(fdntCsarHelper_Data.get("FDNT").get("capabilitiesTypes").size(), CapabilitiesTypes.size()); // Compare capabilities qty expected vs actual + } + + //@Test // - BUG 283387 + public void testRequirmentsofVF() throws SdcToscaParserException { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList(); + String sName = serviceVfList.get(0).getName(); + assertEquals(sName,"FDNT 1"); + + List<String> ActualReqsValues = new ArrayList<>(Arrays.asList( )); + + ArrayList<Object> lRequirements = serviceVfList.get(0).getRequirements(); + + assertEquals(fdntCsarHelper_Data.get("FDNT").get("requirements").size(),lRequirements.size()); // + + // Continue from here after bug is fixed ! ! ! ! - Test the Requirements values + } + +} |