diff options
Diffstat (limited to 'src/test/java/org/onap')
12 files changed, 2313 insertions, 0 deletions
diff --git a/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java b/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java new file mode 100644 index 0000000..39f5190 --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java @@ -0,0 +1,149 @@ +package org.onap.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.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.onap.sdc.toscaparser.api.common.JToscaException; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; + +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 fdntCsarHelperWithInputs; + static ISdcCsarHelper nfodCsarHlper; + static ISdcCsarHelper ipAssignCsarHelper; + static ISdcCsarHelper nestedVfcCsarHlper; + static ISdcCsarHelper nfodNEWCsarHlper; + static ISdcCsarHelper QAServiceForToscaParserTests; + static ISdcCsarHelper resolveGetInputCsar; + static ISdcCsarHelper resolveGetInputCsarFalse; + static ISdcCsarHelper resolveGetInputCsarQA; + static ISdcCsarHelper resolveReqsCapsCsarQA; + static ISdcCsarHelper portMirroring; + static ISdcCsarHelper csarHelperServiceWithCrs; + + + static Map<String, HashMap<String, List<String>>> fdntCsarHelper_Data; + + @BeforeSuite + public static void init() throws SdcToscaParserException, JToscaException, IOException { + + factory = SdcToscaParserFactory.getInstance(); + 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"); + QAServiceForToscaParserTests = getCsarHelper("csars/service-ServiceForToscaParserTests-csar.csar"); + resolveReqsCapsCsarQA = getCsarHelper("csars/service-sunny-flow2.csar"); + portMirroring = getCsarHelper("csars/service-PortMirroring.csar"); + csarHelperServiceWithCrs = getCsarHelper("csars/service-CrTestService-csar.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; + } + + 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() + " ###########"); + } + + @AfterMethod + public void tearDown(Method method){ + System.out.println("#### Ended test " + method.getName() + " ###########"); + } +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserConfigurationTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserConfigurationTest.java new file mode 100644 index 0000000..6c0455b --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserConfigurationTest.java @@ -0,0 +1,63 @@ +package org.onap.sdc.impl; + +import org.onap.sdc.tosca.parser.config.ErrorConfiguration; +import org.onap.sdc.tosca.parser.config.JtoscaValidationIssueConfiguration; +import org.testng.annotations.Test; +import org.onap.sdc.tosca.parser.config.Configuration; +import org.onap.sdc.tosca.parser.config.ConfigurationManager; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest { + + @Test + public void testConfigurationConformanceLevel() { + Configuration config = ConfigurationManager.getInstance().getConfiguration(); + assertNotNull(config); + assertNotNull(config.getConformanceLevel()); + assertNotNull(config.getConformanceLevel().getMaxVersion()); + assertNotNull(config.getConformanceLevel().getMinVersion()); + } + + + @Test + public void testErrorConfigurations() { + ErrorConfiguration errorConfig = ConfigurationManager.getInstance().getErrorConfiguration(); + assertNotNull(errorConfig); + assertNotNull(errorConfig.getErrors()); + } + + @Test + public void testSetErrorConfiguration() { + ConfigurationManager configurationManager = ConfigurationManager.getInstance(); + try { + configurationManager.setErrorConfiguration("error-configuration-test.yaml"); + ErrorConfiguration errorConfig = configurationManager.getErrorConfiguration(); + assertEquals(false, + errorConfig.getErrorInfo("CONFORMANCE_LEVEL_ERROR").getFailOnError()); + assertEquals(true, errorConfig.getErrorInfo("FILE_NOT_FOUND").getFailOnError()); + } + finally { + // Reset the configuration for other tests + configurationManager.setErrorConfiguration("error-configuration.yaml"); + } + } + + @Test + public void testSetJtoscaValidationIssueConfiguration() { + ConfigurationManager configurationManager = ConfigurationManager.getInstance(); + try { + configurationManager.setJtoscaValidationIssueConfiguration( + "jtosca-validation-issue-configuration-test.yaml"); + JtoscaValidationIssueConfiguration issueConfig = configurationManager + .getJtoscaValidationIssueConfiguration(); + assertNotNull(issueConfig); + } + finally { + // Reset the configuration for other tests + configurationManager.setJtoscaValidationIssueConfiguration + ("jtosca-validation-issue-configuration.yaml"); + } + } +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserErrorHandlingTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserErrorHandlingTest.java new file mode 100644 index 0000000..d022a1a --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserErrorHandlingTest.java @@ -0,0 +1,143 @@ +package org.onap.sdc.impl; + +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +import java.io.File; + +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.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/onap/sdc/impl/ToscaParserGeneralUtilTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserGeneralUtilTest.java new file mode 100644 index 0000000..d4ad73d --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserGeneralUtilTest.java @@ -0,0 +1,23 @@ +package org.onap.sdc.impl; + +import org.testng.annotations.Test; +import org.onap.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/onap/sdc/impl/ToscaParserGroupTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserGroupTest.java new file mode 100644 index 0000000..540236c --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserGroupTest.java @@ -0,0 +1,115 @@ +package org.onap.sdc.impl; + +import org.testng.annotations.Test; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.toscaparser.api.Group; +import org.onap.sdc.toscaparser.api.elements.Metadata; + +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("vfModuleModelCustomizationUUID")); + } + } + + @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/onap/sdc/impl/ToscaParserMetadataTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserMetadataTest.java new file mode 100644 index 0000000..8487dec --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserMetadataTest.java @@ -0,0 +1,235 @@ +package org.onap.sdc.impl; + +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.config.ConfigurationManager; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.testng.annotations.Test; + +import java.util.List; +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 + + @Test + public void GetServiceNodeTemplateMetadataTypeCR() { + NodeTemplate nodeTemplate = csarHelperServiceWithCrs.getServiceNodeTemplateByNodeName("chaya best cr 0"); + Metadata nodeTemplateMetadata = csarHelperServiceWithCrs.getNodeTemplateMetadata(nodeTemplate); + assertNotNull(nodeTemplateMetadata); + assertEquals(nodeTemplateMetadata.getValue("resourceVendorModelNumber"), ""); + assertEquals(nodeTemplateMetadata.getValue("type"), "CR"); + assertEquals(nodeTemplateMetadata.getValue("name"), "chaya best cr"); + assertEquals(nodeTemplateMetadata.getValue("version"), "0.1"); + } + + //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 + + //region getServiceMetadataAllProperties + @Test + public void testNullServiceMetadataAllPropertiesMap() { + Map<String, String> metadata = rainyCsarHelperSingleVf.getServiceMetadataAllProperties(); + assertNull(metadata); + } + + @Test + public void testServiceMetadataAllPropertiesMap() { + Map<String, String> metadata = fdntCsarHelper.getServiceMetadataAllProperties(); + assertNotNull(metadata); + assertEquals(metadata.size(),9); + assertEquals(metadata.get("namingPolicy"),"test"); + } + //endregion + + //region getNodeTemplateMetadata + @Test + public void testGetNodeTemplateMetadata() { + List<NodeTemplate> vfs = fdntCsarHelper.getServiceVfList(); + Metadata metadata = fdntCsarHelper.getNodeTemplateMetadata(vfs.get(0)); + assertNotNull(metadata); + assertEquals("VF", metadata.getValue("type")); + assertEquals("1.0", metadata.getValue("version")); + } + + @Test + public void testGetNodeTemplateMetadataByNull() { + Metadata metadata = fdntCsarHelper.getNodeTemplateMetadata(null); + assertNull(metadata); + } + //endregion + + //QA tests region for US 319197 -port mirroring + + //getNodeTemplateMetadata (All Types) + @Test + public void GetServiceNodeTemplateMetadataTypeVF() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("VF_1_V_port_1 0"); + Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); + assertNotNull(nodeTemplateMetadata); + assertEquals(nodeTemplateMetadata.getValue("resourceVendorRelease"), "12-12-12"); + assertEquals(nodeTemplateMetadata.getValue("type"), "VF"); + } + + @Test + public void GetServiceNodeTemplateMetadataTypeVL() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtVL 0"); + Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); + assertNotNull(nodeTemplateMetadata); + assertEquals(nodeTemplateMetadata.getValue("resourceVendorRelease"), "1.0.0.wd03"); + assertEquals(nodeTemplateMetadata.getValue("type"), "VL"); + } + + @Test + public void GetServiceNodeTemplateMetadataTypeCP() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtCP 0"); + Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); + assertNotNull(nodeTemplateMetadata); + assertEquals(nodeTemplateMetadata.getValue("UUID"), "7a883088-5cab-4bfb-8d55-307d3ffd0758"); + assertEquals(nodeTemplateMetadata.getValue("type"), "CP"); + } + + @Test + public void GetServiceNodeTemplateMetadataTypePNF() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("PNF TEST 0"); + Metadata nodeTemplateMetadata = QAServiceForToscaParserTests.getNodeTemplateMetadata(nodeTemplate); + assertNotNull(nodeTemplateMetadata); + assertEquals(nodeTemplateMetadata.getValue("resourceVendorModelNumber"), ""); + assertEquals(nodeTemplateMetadata.getValue("type"), "PNF"); + } + + //QA end region for US 319197 -port mirroring + + // Added by QA //region getServiceMetadataAllProperties + + @Test + public void testGetAllMetadataProperties() { + Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata(); + assertNotNull(serviceMetadata); + Map<String, String> allProperties = serviceMetadata.getAllProperties(); + assertNotNull(allProperties); + String invariantUUID = allProperties.get("invariantUUID"); + String UUID = allProperties.get("UUID"); + String name = allProperties.get("name"); + String description = allProperties.get("description"); + String type = allProperties.get("type"); + String category = allProperties.get("category"); + String ecompGeneratedNaming = allProperties.get("ecompGeneratedNaming"); + String namingPolicy = allProperties.get("namingPolicy"); + String serviceEcompNaming = allProperties.get("serviceEcompNaming"); + + assertEquals(invariantUUID, "78c72999-1003-4a35-8534-bbd7d96fcae3"); + assertEquals(UUID, "edd0a9f7-d084-4423-8461-a2eff4cb3eb6"); + assertEquals(name, "Service FDNT"); + assertEquals(description, "Service FDNT"); + assertEquals(type, "Service"); + assertEquals(category, "Network L1-3"); + assertEquals(ecompGeneratedNaming, "true"); + assertEquals(namingPolicy, "test"); + assertEquals(serviceEcompNaming, "true"); + } + //endregion + + @Test + public void testCSARMissingConformanceLevelWithCustomErrorConfig() throws + SdcToscaParserException { + + ConfigurationManager configurationManager = ConfigurationManager.getInstance(); + try { + configurationManager.setErrorConfiguration("error-configuration-test.yaml"); + factory.setConfigurationManager(configurationManager); + ISdcCsarHelper missingCSARMetaCsarCustomConfig = getCsarHelper + ("csars/service-missing-csar-meta-file.csar"); + String conformanceLevel = missingCSARMetaCsarCustomConfig.getConformanceLevel(); + assertNotNull(conformanceLevel); + assertEquals(conformanceLevel, configurationManager.getConfiguration().getConformanceLevel() + .getMaxVersion()); + } + finally { + configurationManager.setErrorConfiguration("error-configuration.yaml"); + factory.setConfigurationManager(configurationManager); + } + + } + + @Test(expectedExceptions = SdcToscaParserException.class) + public void testCSARMissingConformanceLevelWithDefaultErrorConfig() throws + SdcToscaParserException { + ISdcCsarHelper missingCSARMetaCsarDefaultConfig = getCsarHelper("csars/service-missing-csar-meta-file.csar"); + missingCSARMetaCsarDefaultConfig.getConformanceLevel(); + } + +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java new file mode 100644 index 0000000..0692ebe --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java @@ -0,0 +1,972 @@ +package org.onap.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.*; +import static org.hamcrest.CoreMatchers.is; + +import com.google.common.collect.ImmutableMap; +import org.apache.commons.lang3.tuple.Pair; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.FilterType; +import org.onap.sdc.tosca.parser.impl.SdcTypes; +import org.onap.sdc.toscaparser.api.Group; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Property; +import org.testng.annotations.Test; + +import fj.data.fingertrees.Node; + +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 testNodeTemplateNestedFunctionProperty() throws SdcToscaParserException { + List<NodeTemplate> vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + assertEquals(null, ipAssignCsarHelper.getNodeTemplatePropertyLeafValue(vfcs.get(0), "port_pd01_port_ip_requirements#ip_count_required#count")); + } + + @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 = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + boolean isChecked = false; + + for (NodeTemplate vfc: vfcs) { + + if(vfc.getName().equalsIgnoreCase("abstract_pd_server")) + { + isChecked = true; + Map<String, Map<String, Object>> cps = ipAssignCsarHelper.getCpPropertiesFromVfcAsObject(vfc); + + assertEquals(2,cps.size()); + Map<String, Object> pd01 = cps.get("port_pd01_port"); + assertEquals(5, pd01.size()); + + Map<String, Object> firstIpRequirements = (Map<String, Object>) ((List<Object>)pd01.get("ip_requirements")).get(0); + Map<String, Object> secondIpRequirements = (Map<String, Object>) ((List<Object>)pd01.get("ip_requirements")).get(1); + + assertEquals("subnet_role_4", firstIpRequirements.get("subnet_role")); + assertEquals(4, firstIpRequirements.get("ip_version")); + assertEquals(true, ((Map<String, Object>) firstIpRequirements.get("ip_count_required")).get("is_required")); + assertEquals("get_input:node_count", ((Map<String, Object>) firstIpRequirements.get("ip_count_required")).get("count").toString()); + assertEquals(false, ((Map<String, Object>)((Map<String, Object>)pd01.get("mac_requirements")).get("mac_count_required")).get("is_required")); + assertEquals("test_subnetpoolid", pd01.get("subnetpoolid")); + assertEquals("oam", pd01.get("network_role_tag")); + assertEquals(6, secondIpRequirements.get("ip_version")); + } + + } + assertTrue(isChecked); + } + + @Test + public void testGetCpPropertiesFromVfcForNullVFC() { + Map<String, Map<String, Object>> cps = ipAssignCsarHelper.getCpPropertiesFromVfcAsObject(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 + + //region filterNodeTemplatePropertiesByValue + @Test + public void testFilterNodeTemplatePropertiesByContains() { + List<NodeTemplate> vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + boolean isChecked = false; + for (NodeTemplate vfc: vfcs) { + if(vfc.getName().equalsIgnoreCase("abstract_pd_server")) + { + isChecked = true; + Map<String, String> filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfc, FilterType.CONTAINS, "get_input"); + + assertEquals(7, filteredInputs.size()); + assertEquals("get_input:availabilityzone_name", filteredInputs.get("compute_pd_server_availability_zone")); + assertEquals("get_input:[pd_server_names, 0]", filteredInputs.get("compute_pd_server_name")); + assertEquals("get_input:node_count", filteredInputs.get("port_pd01_port_ip_requirements#ip_count_required#count")); + + break; + } + + } + assertTrue(isChecked); + } + + @Test + public void testFilterNodeTemplatePropertiesByDummyContains() { + List<NodeTemplate> vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Map<String, String> filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), FilterType.CONTAINS, "dummy"); + assertNotNull(filteredInputs); + assertEquals(0, filteredInputs.size()); + } + + @Test + public void testFilterNodeTemplatePropertiesByEquals() { + List<NodeTemplate> vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + boolean isChecked = false; + for (NodeTemplate vfc: vfcs) { + if(vfc.getName().equalsIgnoreCase("abstract_pd_server")) + { + isChecked = true; + Map<String, String> filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfc, FilterType.EQUALS, "oam"); + + assertEquals(2, filteredInputs.size()); + assertEquals("oam", filteredInputs.get("port_pd02_port_network_role_tag")); + assertEquals("oam", filteredInputs.get("port_pd01_port_network_role_tag")); + break; + } + + } + assertTrue(isChecked); + } + + @Test + public void testFilterNodeTemplatePropertiesByDummyEquals() { + List<NodeTemplate> vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Map<String, String> filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), FilterType.EQUALS, "dummy"); + assertNotNull(filteredInputs); + assertEquals(0, filteredInputs.size()); + } + + @Test + public void testFilterNodeTemplatePropertiesByNullFilterType() { + List<NodeTemplate> vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Map<String, String> filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), null, "ddc"); + assertNotNull(filteredInputs); + assertEquals(0, filteredInputs.size()); + } + + @Test + public void testFilterNodeTemplatePropertiesByNullPattern() { + List<NodeTemplate> vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Map<String, String> filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(vfcs.get(0), FilterType.EQUALS, null); + assertNotNull(filteredInputs); + assertEquals(0, filteredInputs.size()); + } + + @Test + public void testFilterNodeTemplatePropertiesByNullVfc() { + Map<String, String> filteredInputs = ipAssignCsarHelper.filterNodeTemplatePropertiesByValue(null, FilterType.EQUALS, "ddc"); + assertNotNull(filteredInputs); + assertEquals(0, filteredInputs.size()); + } + //endregion + + //region getServiceNodeTemplateBySdcType + @Test + public void testServiceNodeTemplateBySdcType() { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceNodeTemplateBySdcType(SdcTypes.VF); + assertNotNull(serviceVfList); + assertEquals(serviceVfList.size(), 2); + assertEquals(serviceVfList.get(0).getName(), "FDNT 1"); + } + + @Test + public void testServiceNodeTemplateBySdcTypeServiceProxy() { + List<NodeTemplate> serviceProxies = portMirroring.getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY); + assertNotNull(serviceProxies); + assertEquals(serviceProxies.size(), 2); + } + + @Test + public void testServiceNodeTemplateByNullSdcType() { + List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceNodeTemplateBySdcType(null); + assertNotNull(serviceVfList); + assertEquals(serviceVfList.size(), 0); + } + //endregion + + //region getNodeTemplateBySdcType + @Test + public void testNodeTemplateBySdcType() { + List<NodeTemplate> vfList = fdntCsarHelper.getServiceVfList(); + List<NodeTemplate> vfcList = fdntCsarHelper.getNodeTemplateBySdcType(vfList.get(0), SdcTypes.VFC); + assertNotNull(vfcList); + assertEquals(2, vfcList.size()); + assertEquals("DNT_FW_RSG_SI_1", vfcList.get(0).getName()); + } + + @Test + public void testNodeTemplateByNullSdcType() { + List<NodeTemplate> vfList = fdntCsarHelper.getServiceVfList(); + List<NodeTemplate> vfcList = fdntCsarHelper.getNodeTemplateBySdcType(vfList.get(0), null); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + + @Test + public void testNodeTemplateBySdcTypeNullNT() { + List<NodeTemplate> vfcList = fdntCsarHelper.getNodeTemplateBySdcType(null, SdcTypes.VFC); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + //endregion + + //region getVnfConfig + @Test + public void testGetVnfConfig() { + NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); + assertNotNull(vnfConfig); + assertEquals("vnfConfiguration", vnfConfig.getMetaData().getValue("name")); + } + + @Test + public void testGetVnfConfigByNonFoundVNF() { + NodeTemplate vnfConfig = ipAssignCsarHelper.getVnfConfig("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + assertNull(vnfConfig); + } + + @Test + public void testGetVnfConfigByDummyUUID() { + NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig("XXX"); + assertNull(vnfConfig); + } + + @Test + public void testGetVnfConfigByNullUUID() { + NodeTemplate vnfConfig = nfodCsarHlper.getVnfConfig(null); + assertNull(vnfConfig); + } + + @Test + public void testGetVfcTypWithoutVnf() { + List<NodeTemplate> vfcList = nfodCsarHlper.getVfcListByVf("9bb2ef82-f8f6-4391-bc71-db063f15bf57"); + assertNotNull(vfcList); + assertEquals(2, vfcList.size()); + } + //endregion + + //region nested vfc + @Test + public void testNestedVfcByExistCvfc() { + List<NodeTemplate> vfcList = nestedVfcCsarHlper.getVfcListByVf("71389f8b-8671-4a43-a991-59fb621d3615"); + assertNotNull(vfcList); + assertEquals(vfcList.size(), 2); + assertEquals("VFC1 DUMMY", vfcList.get(0).getName()); + assertEquals("VF_VNF", vfcList.get(1).getName()); + } + + @Test + public void testNestedVfcByNullVf() { + List<NodeTemplate> vfcList = nestedVfcCsarHlper.getVfcListByVf(null); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + + @Test + public void testNestedVfcByDummyVf() { + List<NodeTemplate> vfcList = nestedVfcCsarHlper.getVfcListByVf("dummy"); + assertNotNull(vfcList); + assertEquals(0, vfcList.size()); + } + //endregion + + //region hasTopology + @Test + public void testHasTopologyByVF() { + List<NodeTemplate> vfList = nestedVfcCsarHlper.getServiceVfList(); + boolean hasTopology = nestedVfcCsarHlper.hasTopology(vfList.get(0)); + assertEquals(true, hasTopology); + } + + @Test + public void testHasTopologyByCVFC() { + List<NodeTemplate> vfcList = nestedVfcCsarHlper.getVfcListByVf("71389f8b-8671-4a43-a991-59fb621d3615"); + boolean hasTopology = nestedVfcCsarHlper.hasTopology(vfcList.get(1)); + assertEquals(true, hasTopology); + } + + @Test + public void testHasTopologyByVL() { + List<NodeTemplate> serviceVlList = fdntCsarHelper.getServiceVlList(); + boolean hasTopology = fdntCsarHelper.hasTopology(serviceVlList.get(0)); + assertEquals(false, hasTopology); + } + + @Test + public void testHasTopologyByNull() { + boolean hasTopology = fdntCsarHelper.hasTopology(null); + assertEquals(false, hasTopology); + } + //endregion + + //region getNodeTemplateChildren + @Test + public void testGetNodeTemplatesListOfNodeTemplateByVF() { + List<NodeTemplate> vfList = fdntCsarHelper.getServiceVfList(); + List<NodeTemplate> children = fdntCsarHelper.getNodeTemplateChildren(vfList.get(0)); + assertNotNull(children); + assertEquals(3, children.size()); + + children.sort(Comparator.comparing(NodeTemplate::getName)); + + assertEquals("DNT_FW_RSG_SI_1", children.get(1).getName()); + assertEquals("VFC", children.get(1).getMetaData().getValue("type")); + assertEquals("DNT_PORT", children.get(2).getName()); + assertEquals("CP", children.get(2).getMetaData().getValue("type")); + } + + @Test + public void testGetNodeTemplatesListOfNodeTemplateByVFC() { + List<NodeTemplate> vfList = nestedVfcCsarHlper.getServiceVfList(); + List<NodeTemplate> vfChildren = nestedVfcCsarHlper.getNodeTemplateChildren(vfList.get(0)); + assertNotNull(vfChildren); + assertEquals(vfChildren.size(), 2); + vfChildren.sort(Comparator.comparing(NodeTemplate::getName)); + assertEquals("VFC1 DUMMY", vfChildren.get(0).getName()); + assertEquals("VF_VNF", vfChildren.get(1).getName()); + assertEquals("CVFC", vfChildren.get(1).getMetaData().getValue("type")); + + + List<NodeTemplate> vfcChildren = nestedVfcCsarHlper.getNodeTemplateChildren(vfChildren.get(1)); + assertNotNull(vfcChildren); + assertEquals(vfcChildren.size(), 3); + vfcChildren.sort(Comparator.comparing(NodeTemplate::getName)); + assertEquals("Test NIC 02_wan_port", vfcChildren.get(0).getName()); + assertEquals("Test NIC_wan_port", vfcChildren.get(1).getName()); + assertEquals("VF", vfcChildren.get(2).getName()); + } + + @Test + public void testGetNodeTemplatesListOfNodeTemplateByNull() { + List<NodeTemplate> children = fdntCsarHelper.getNodeTemplateChildren(null); + assertNotNull(children); + assertEquals(0, children.size()); + } + //endregion + + // added by QA + // Get specific VNF properties + @Test + public void testGetVnfConfigGetProperties() { + 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 + @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); + + //Deployment flavor 2 + 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 + @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 getServiceNodeTemplateByNodeName + @Test + public void testGetServiceNodeTemplateByRealNodeName() { + NodeTemplate nodeTemplate = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); + assertNotNull(nodeTemplate); + assertEquals(nodeTemplate.getName(), "FDNT 1"); + assertEquals(nodeTemplate.getMetaData().getValue("type"), "VF"); + } + + @Test + public void testGetServiceNodeTemplateByNullNodeName() { + NodeTemplate nodeTemplate = fdntCsarHelper.getServiceNodeTemplateByNodeName(null); + assertNull(nodeTemplate); + } + + @Test + public void testGetServiceNodeTemplateByDummyNodeName() { + NodeTemplate nodeTemplate = fdntCsarHelper.getServiceNodeTemplateByNodeName("dummy"); + assertNull(nodeTemplate); + } + + + + //endregion + //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()); + } + + //QA region getServiceNodeTemplateByNodeName tests + + @Test + public void getServiceNodeTemplateByNodeNameTypeVF() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("VF_1_V_port_1 0"); + assertNotNull(nodeTemplate); + assertEquals(nodeTemplate.getName(), "VF_1_V_port_1 0"); + assertEquals(nodeTemplate.getMetaData().getValue("type"), "VF"); + } + + @Test + public void getServiceNodeTemplateByNodeNameTypeVL() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtVL 0"); + assertNotNull(nodeTemplate); + assertEquals(nodeTemplate.getName(), "ExtVL 0"); + assertEquals(nodeTemplate.getMetaData().getValue("type"), "VL"); + } + + @Test + public void getServiceNodeTemplateByNodeNameTypeCP() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("ExtCP 0"); + assertNotNull(nodeTemplate); + assertEquals(nodeTemplate.getName(), "ExtCP 0"); + assertEquals(nodeTemplate.getMetaData().getValue("type"), "CP"); + } + + @Test + public void getServiceNodeTemplateByNodeNameTypePNF() { + NodeTemplate nodeTemplate = QAServiceForToscaParserTests.getServiceNodeTemplateByNodeName("PNF TEST 0"); + assertNotNull(nodeTemplate); + assertEquals(nodeTemplate.getName(), "PNF TEST 0"); + assertEquals(nodeTemplate.getMetaData().getValue("type"), "PNF"); + } + + //QA region getServiceNodeTemplateBySdcType tests + + @Test + public void getServiceNodeTemplateBySdcType_VF() { + List<NodeTemplate> vfList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Vf1VPort1"); + assertEquals(2, vfList.size()); + assertEquals("VF_1_V_port_1", vfList.get(0).getMetaData().getValue("name")); + } + // endregion Added by QA - Continue with testings of resolve get_input + + + @Test + public void testResolveGetInputArrayStructure() { + List<NodeTemplate> vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); + Object propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "compute_pd_server_name"); + assertEquals( ((ArrayList)propertyAsObject).get(0).toString(), "\"ZRDM1MOGX01MPD001\""); + propertyAsObject = resolveGetInputCsarQA.getNodeTemplatePropertyAsObject(vfcs.get(0), "port_pd01_port_ip_requirements"); + assertEquals( ((ArrayList)propertyAsObject).get(1), null); + } + + @Test + public void testServiceNodeTemplateByCRType() { + List<NodeTemplate> serviceCRList = csarHelperServiceWithCrs.getServiceNodeTemplateBySdcType(SdcTypes.CR); + assertNotNull(serviceCRList); + assertEquals(serviceCRList.size(), 2); + assertEquals(serviceCRList.get(0).getName(), "chaya best cr 1"); + assertEquals(serviceCRList.get(0).getType(), "org.openecomp.resource.cr.ChayaBestCr"); + assertEquals(serviceCRList.get(1).getName(), "chaya best cr 0"); + assertEquals(serviceCRList.get(1).getType(), "org.openecomp.resource.cr.ChayaBestCr"); + } + + @Test + public void testGetCPOfCRNodeTemplate() { + NodeTemplate nodeTemplate = csarHelperServiceWithCrs.getServiceNodeTemplateByNodeName("chaya best cr 0"); + List<NodeTemplate> crCpChildren = csarHelperServiceWithCrs.getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CP); + assertEquals(crCpChildren.get(0).getName(), "ContrailPort 0"); + assertEquals(crCpChildren.get(0).getMetaData().getValue("type"), SdcTypes.CP.name()); + } + + @Test + public void testServiceCRInstanceProps() { + List<NodeTemplate> serviceCrList = csarHelperServiceWithCrs.getServiceNodeTemplateBySdcType(SdcTypes.CR); + assertNotNull(serviceCrList); + NodeTemplate crTemplate = serviceCrList.get(0); + assertNotNull(crTemplate); + assertEquals(crTemplate.getPropertyValue("nf_naming").toString(), ImmutableMap.of("ecomp_generated_naming", "true").toString()); + assertEquals(crTemplate.getPropertyValue("contrailport0_virtual_network"), "chaya"); + } + + +} + + diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java new file mode 100644 index 0000000..75f8962 --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserReqAndCapTest.java @@ -0,0 +1,273 @@ +package org.onap.sdc.impl; + +import org.onap.sdc.tosca.parser.impl.SdcTypes; +import org.onap.sdc.toscaparser.api.CapabilityAssignments; +import org.onap.sdc.toscaparser.api.CapabilityAssignment; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.RequirementAssignments; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.testng.annotations.Test; + +import java.util.List; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +public class ToscaParserReqAndCapTest extends SdcToscaParserBasicTest { + + //region getCapabilitiesOf + @Test + public void testGetCapabilitiesOfNodeTemplate() { + List<NodeTemplate> vfs = fdntCsarHelper.getServiceVfList(); + CapabilityAssignments capabilityAssignments = fdntCsarHelper.getCapabilitiesOf(vfs.get(0)); + assertNotNull(capabilityAssignments); + assertEquals(13, capabilityAssignments.getAll().size()); + assertNotNull(capabilityAssignments.getCapabilityByName("DNT_FW_RHRG.binding_DNT_FW_INT_DNS_TRUSTED_RVMI")); + assertEquals(6, capabilityAssignments.getCapabilitiesByType("tosca.capabilities.network.Bindable").getAll().size()); + } + + @Test + public void testGetCapabilitiesOfNull() { + CapabilityAssignments capabilityAssignments = fdntCsarHelper.getCapabilitiesOf(null); + assertNull(capabilityAssignments); + } + //endregion + + //region getRequirementsOf + @Test + public void testGetRequirementsOfNodeTemplate() { + List<NodeTemplate> vfs = fdntCsarHelper.getServiceVfList(); + List<NodeTemplate> cps = fdntCsarHelper.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); + RequirementAssignments requirementAssignments = fdntCsarHelper.getRequirementsOf(cps.get(0)); + assertNotNull(requirementAssignments); + assertEquals(1, requirementAssignments.getAll().size()); + assertEquals("DNT_FW_RHRG", requirementAssignments.getRequirementsByName("binding").getAll().get(0).getNodeTemplateName()); + } + + @Test + public void testGetRequirementsOfNull() { + RequirementAssignments requirementAssignments = fdntCsarHelper.getRequirementsOf(null); + assertNull(requirementAssignments); + } + //endregion + + //region getCapabilityPropertyLeafValue + @Test + public void testGetCapabilityPropertyLeafValue() { + NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); + CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER"); + assertNotNull(capabilityAssignment); + String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "max_instances#type"); + assertEquals("integer", propValue); + } + + @Test + public void testGetCapabilityHierarchyPropertyLeafValue() { + NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); + CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.endpoint_DNT_FW_SERVER"); + assertNotNull(capabilityAssignment); + String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "ports#entry_schema#type"); + assertEquals("PortSpec", propValue); + } + + @Test + public void testGetCapabilityDummyPropertyLeafValue() { + NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); + CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER"); + assertNotNull(capabilityAssignment); + String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "dummy"); + assertNull(propValue); + } + + @Test + public void testGetCapabilityNullPropertyLeafValue() { + NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); + CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER"); + assertNotNull(capabilityAssignment); + String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, null); + assertNull(propValue); + } + + @Test + public void testGetNullCapabilityPropertyLeafValue() { + String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(null, "max_instances#type"); + assertNull(propValue); + } + //endregion + + //QA tests region for US 319197 -port mirroring- + + //get-CapabilitiesOf (All Types) + @Test + public void getServiceNodeTemplateCapabilitiesOfTypeVF() { + List<NodeTemplate> serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF); + CapabilityAssignments capabilitiesOfVF = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVfList.get(0)); + assertEquals(capabilitiesOfVF.getAll().size(),12); + assertNotNull(capabilitiesOfVF.getCapabilityByName("neutronport0.network.incoming.packets.rate")); + } + + @Test + public void getServiceNodeTemplateCapabilitiesOfTypeExVL() { + List<NodeTemplate> serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL"); + CapabilityAssignments capabilitiesOfExtVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceExtVlList.get(0)); + assertEquals(capabilitiesOfExtVL.getAll().size(),2); + assertNotNull(capabilitiesOfExtVL.getCapabilityByName("virtual_linkable").getProperties()); + } + + @Test + public void getServiceNodeTemplateCapabilitiesOfTypeVL() { + List<NodeTemplate> serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network"); + CapabilityAssignments capabilitiesOfVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVlList.get(0)); + assertEquals(capabilitiesOfVL.getAll().size(),2); + assertNotNull(capabilitiesOfVL.getCapabilityByName("link").getProperties()); + } + + @Test + public void getServiceNodeTemplateCapabilitiesOfTypeCP() { + List<NodeTemplate> serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); + CapabilityAssignments capabilitiesOfCP = QAServiceForToscaParserTests.getCapabilitiesOf(serviceCpList.get(0)); + assertEquals(capabilitiesOfCP.getAll().size(),2); + assertNotNull(capabilitiesOfCP.getCapabilityByName("internal_connectionPoint")); + } + + @Test + public void getServiceNodeTemplateCapabilitiesOfTypePNF() { + List<NodeTemplate> servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF); + CapabilityAssignments capabilitiesOfPnf = QAServiceForToscaParserTests.getCapabilitiesOf(servicePnfs.get(0)); + assertEquals(capabilitiesOfPnf.getAll().size(),1); + assertNotNull(capabilitiesOfPnf.getCapabilityByName("feature")); + } + + //get-RequirementsOf (All Types)----------------------------- + + @Test + public void getServiceNodeTemplateRequirementsOfTypeVF() { + List<NodeTemplate> serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF); + RequirementAssignments requirementsOfVF = QAServiceForToscaParserTests.getRequirementsOf(serviceVfList.get(6)); + assertEquals(requirementsOfVF.getAll().size(),3); +// RequirementAssignments requirementsByName = + assertEquals(requirementsOfVF.getRequirementsByName("dependency").getAll().size(),2 ); + //check that API return empty list if requirement property not exist. + assertEquals(requirementsOfVF.getRequirementsByName("blabla").getAll().size(),0); + } + + @Test + public void getServiceNodeTemplateRequirementsOfTypeExVL() { + List<NodeTemplate> serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL"); + RequirementAssignments requirementsOfExtVL = QAServiceForToscaParserTests.getRequirementsOf(serviceExtVlList.get(0)); + assertEquals(requirementsOfExtVL.getAll().size(),1); + } + + @Test + public void getServiceNodeTemplateRequirementsOfTypeVL() { + List<NodeTemplate> serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network"); + RequirementAssignments requirementsOfVL = QAServiceForToscaParserTests.getRequirementsOf(serviceVlList.get(1)); + assertEquals(requirementsOfVL.getAll().size(),2); + assertNotNull(requirementsOfVL.getRequirementsByName("dependency")); + } + + @Test + public void getServiceNodeTemplateRequirementsOfTypeCP() { + List<NodeTemplate> serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); + RequirementAssignments requirementsOfCP = QAServiceForToscaParserTests.getRequirementsOf(serviceCpList.get(0)); + assertEquals(requirementsOfCP.getAll().size(),2); + assertEquals(requirementsOfCP.getRequirementsByName("virtualBinding").getAll().size(),1); + } + + @Test + public void getServiceNodeTemplateRequirementsOfTypePNF() { + List<NodeTemplate> servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF); + RequirementAssignments requirementsOfPnf = QAServiceForToscaParserTests.getRequirementsOf(servicePnfs.get(0)); + assertEquals(requirementsOfPnf.getAll().size(),2); + assertNotNull(requirementsOfPnf.getRequirementsByName("feature")); + } + + //QA end region for US 319197 -port mirroring + + // Added by QA CapabilityAssignments + @Test + public void testGetCapabilitiesByType() { + List<NodeTemplate> vfs = resolveGetInputCsarQA.getServiceVfList(); + CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); + assertNotNull(capabilityAssignments); + CapabilityAssignments capabilitiesByType = capabilityAssignments.getCapabilitiesByType("tosca.capabilities.Scalable"); + int capsQty = capabilitiesByType.getAll().size(); + assertEquals(1, capsQty); + CapabilityAssignment capabilityByName = capabilitiesByType.getCapabilityByName("abstract_pd_server.scalable_pd_server"); + assertNotNull(capabilityByName); + } + + @Test + public void testGetCapabilityByName() { + List<NodeTemplate> vfs = resolveGetInputCsarQA.getServiceVfList(); + CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); + assertNotNull(capabilityAssignments); + CapabilityAssignment capabilityByName = capabilityAssignments.getCapabilityByName("abstract_pd_server.disk.iops_pd_server"); + assertNotNull(capabilityByName); + String capName = capabilityByName.getName(); + assertEquals(capName, "abstract_pd_server.disk.iops_pd_server"); + } + + @Test + public void testGetCapabilitiesGetAll() { + List<NodeTemplate> vfs = resolveGetInputCsarQA.getServiceVfList(); + CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); + assertNotNull(capabilityAssignments); + int capsAssignmentSize = capabilityAssignments.getAll().size(); + assertEquals(65, capsAssignmentSize); + } + + // Added by QA RequirementsAssignments + @Test + public void testGetRequirementsByName() { + List<NodeTemplate> vfs = resolveReqsCapsCsarQA.getServiceVfList(); + List<NodeTemplate> cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); + RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0)); + assertNotNull(requirementAssignments); + assertEquals(2, requirementAssignments.getAll().size()); + assertEquals("DNT_FW_RHRG2", requirementAssignments.getRequirementsByName("binding").getAll().get(1).getNodeTemplateName()); + + } + + @Test + public void testRequirementAssignmentGetNodeGetCapability() { + List<NodeTemplate> vfs = resolveReqsCapsCsarQA.getServiceVfList(); + List<NodeTemplate> cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); + RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0)); + assertNotNull(requirementAssignments); + String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName(); + String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName(); + assertEquals(nodeTemplateName, "DNT_FW_RHRG"); + assertNull(capabilityName); + } + + + @Test + public void testRequirementAssignmentGetCapability() { + List<NodeTemplate> cps = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); + RequirementAssignments requirementAssignments = QAServiceForToscaParserTests.getRequirementsOf(cps.get(0)); + assertNotNull(requirementAssignments); + String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName(); + String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName(); + assertEquals(nodeTemplateName, "ExtVL 0"); + assertEquals(capabilityName,"tosca.capabilities.network.Linkable"); + } + + @Test + public void testGetCapabilityProperties() { + List<NodeTemplate> vfs = fdntCsarHelper.getServiceVfList(); + List<NodeTemplate> cps = fdntCsarHelper.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); + CapabilityAssignments capabilityAssignments = cps.get(0).getCapabilities(); + assertNotNull(capabilityAssignments); + assertEquals(12, capabilityAssignments.getAll().size()); + CapabilityAssignment xxxCapability = capabilityAssignments.getCapabilityByName("xxx"); + //GetInput property - resolved in any case + String getInputProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "DeploymentFlavor"); + assertEquals("{aaa=bbb}", getInputProp); + //Simple property + String simpleProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "distribution"); + assertEquals("rhel", simpleProp); + } + +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserServiceInputTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserServiceInputTest.java new file mode 100644 index 0000000..b11487f --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserServiceInputTest.java @@ -0,0 +1,77 @@ +package org.onap.sdc.impl; + +import org.testng.annotations.Test; +import org.onap.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); + } + + @Test + public void testGetServiceComplexInputLeafValueOfDefault() { + String serviceInputLeafValue = fdntCsarHelperWithInputs.getServiceInputLeafValueOfDefault("complex_input#default#ipv4_subnet_default_assignment#cidr_mask"); + assertEquals(serviceInputLeafValue, "24"); + } + + @Test + public void testGetServiceDummyComplexInputLeafValueOfDefault() { + String serviceInputLeafValue = fdntCsarHelperWithInputs.getServiceInputLeafValueOfDefault("complex_input#default#ipv4_subnet_default_assignment#XXX"); + assertNull(serviceInputLeafValue); + } + + + //endregion +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserSubsMappingsTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserSubsMappingsTest.java new file mode 100644 index 0000000..cbd8e8a --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserSubsMappingsTest.java @@ -0,0 +1,129 @@ +package org.onap.sdc.impl; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.util.*; + +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.toscaparser.api.CapabilityAssignment; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.RequirementAssignment; +import org.onap.sdc.toscaparser.api.elements.CapabilityTypeDef; +//import org.testng.ReporterConfig.Property; +import org.testng.annotations.Test; +import org.onap.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)); +// Map<String, CapabilityAssignment> lCapabilitys = serviceVfList.get(0).getCapabilities().getAll(); +// List<String> CPkeys = new ArrayList<>(lCapabilitys.keySet()); +// List<String> CapabilitiesNames = new ArrayList<String>(CPkeys.size()); +// +// for (int i = 0; i < CPkeys.size(); i++) { +// +// CapabilityAssignment 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)); +// Map<String, CapabilityAssignment> lCapabilitys = serviceVfList.get(0).getCapabilities().getAll(); +// +// 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++) { +// +// CapabilityAssignment 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( )); + + List<RequirementAssignment> lRequirements = serviceVfList.get(0).getRequirements().getAll(); + + assertEquals(fdntCsarHelper_Data.get("FDNT").get("requirements").size(),lRequirements.size()); // + + // Continue from here after bug is fixed ! ! ! ! - Test the Requirements values + } + +} diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserValidationIssueTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserValidationIssueTest.java new file mode 100644 index 0000000..0fc42f7 --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/ToscaParserValidationIssueTest.java @@ -0,0 +1,93 @@ +package org.onap.sdc.impl; + +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.config.ConfigurationManager; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; + +import static org.testng.Assert.assertEquals; + +public class ToscaParserValidationIssueTest extends SdcToscaParserBasicTest { + protected static ConfigurationManager configurationManager = ConfigurationManager.getInstance(); + + @BeforeClass + public void loadJtoscaValidationIssueConfiguration() throws IOException { + //load the tests dedicated configuration + configurationManager.setJtoscaValidationIssueConfiguration( "jtosca-validation-issue-configuration-test.yaml"); + factory.setConfigurationManager(configurationManager); + } + + @AfterClass + public void loadJtoscaValidationIssueOriginalConfiguration() throws IOException { + //load the tests dedicated configuration + configurationManager.setJtoscaValidationIssueConfiguration("jtosca-validation-issue-configuration.yaml"); + factory.setConfigurationManager(configurationManager); + + } + + + @Test + public void testNoValidationIssues() throws SdcToscaParserException { + ISdcCsarHelper rainyCsarHelper = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar");//conformance level 3.0 + + //List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions(); + //assertEquals( notAnalyzedReport.size(),0); + List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions(); + assertEquals( warningsReport.size(),0); + List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions(); + assertEquals( criticalsReport.size(),0); + } + @Test + public void testGetLowSinceConformanceLevel() throws SdcToscaParserException { + ISdcCsarHelper fdntCsarHelperWithInputs = getCsarHelper("csars/service-NfodService-csar.csar");//conformance level 3.0 + //Service level + + List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions(); + assertEquals( notAnalyzedReport.size(),10); + //JE003 high CL 4.0 + assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE003")).collect(Collectors.toList()).size(), 2); + assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE235")).collect(Collectors.toList()).size(), 7); + assertEquals( notAnalyzedReport.stream().filter(n->n.getCode().equals("JE236")).collect(Collectors.toList()).size(), 1); + List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions(); + assertEquals( warningsReport.size(),14); + assertEquals( warningsReport.stream().filter(w->w.getCode().equals("JE006")).collect(Collectors.toList()).size(), 13); + //JE004 low CL 2.0 + assertEquals( warningsReport.stream().filter(w->w.getCode().equals("JE004")).collect(Collectors.toList()).size(), 1); + List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions(); + assertEquals( criticalsReport.size(),0); + } + + @Test(expectedExceptions = SdcToscaParserException.class) + public void testCriticalIssueThrowsSdcToscaParserException() throws SdcToscaParserException { + getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0 + } + + @Test + public void testMultiSinceConformanceLevelIssues() { + try { + ISdcCsarHelper Nfod2images = getCsarHelper("csars/service-Nfod2images-csar.csar");//conformance level 4.0 + } catch (SdcToscaParserException e) { + System.out.println("SdcToscaParserException is caught here - this is WAD in this specific test."); + } + List<JToscaValidationIssue> notAnalyzedReport = factory.getNotAnalyzadExceptions(); + assertEquals(3, notAnalyzedReport.size()); + List<JToscaValidationIssue> warningsReport = factory.getWarningExceptions(); + assertEquals( 0, warningsReport.size()); + List<JToscaValidationIssue> criticalsReport = factory.getCriticalExceptions(); + assertEquals( 22, criticalsReport.size()); + //JE006 multy values sinceCsarConformanceLevel + assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE006")).collect + (Collectors.toList()).size(), 18); + assertEquals( criticalsReport.stream().filter(c->c.getCode().equals("JE003")).collect + (Collectors.toList()).size(), 4); + } + + +} diff --git a/src/test/java/org/onap/sdc/impl/myTest.java b/src/test/java/org/onap/sdc/impl/myTest.java new file mode 100644 index 0000000..4833f6f --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/myTest.java @@ -0,0 +1,41 @@ +package org.onap.sdc.impl; + +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.testng.annotations.Test; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; + +import java.io.File; + +import static org.onap.sdc.impl.SdcToscaParserBasicTest.getCsarHelper; + +public class myTest { + + static SdcToscaParserFactory factory; + static ISdcCsarHelper fdntCsarHelper; + + @Test + public void testNoValidationIssues() throws SdcToscaParserException { + + +// factory = SdcToscaParserFactory.getInstance(); +// fdntCsarHelper = getCsarHelper("csars/service-Oren1-csar-4.csar"); +// +// +// List<NodeTemplate> serviceNodeTemplatesByType = fdntCsarHelper.getServiceNodeTemplatesByType("org.openecomp.nodes.ForwardingPath"); +// +// String target_range = fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceNodeTemplatesByType.get(0), "target_range"); + + } + + + 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; + } + +} |