diff options
Diffstat (limited to 'sdc-tosca-parser/src/test')
17 files changed, 199 insertions, 24 deletions
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/BasicTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java index 0eb58f8..6746df7 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/BasicTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java @@ -11,13 +11,13 @@ import java.util.Map; import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.common.JToscaException; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; -public abstract class BasicTest { +public abstract class SdcToscaParserBasicTest { public static final String VF_CUSTOMIZATION_UUID = "56179cd8-de4a-4c38-919b-bbc4452d2d73"; static SdcToscaParserFactory factory; @@ -97,18 +97,11 @@ public abstract class BasicTest { }; }; - private static ISdcCsarHelper getCsarHelper(String path) throws JToscaException, IOException, SdcToscaParserException { + protected static ISdcCsarHelper getCsarHelper(String path) throws SdcToscaParserException { System.out.println("Parsing CSAR "+path+"..."); - String fileStr1 = BasicTest.class.getClassLoader().getResource(path).getFile(); + String fileStr1 = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile(); File file1 = new File(fileStr1); ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath()); - List<String> exceptionReport = ExceptionCollector.getCriticalsReport(); - if (!exceptionReport.isEmpty()){ - System.out.println("TOSCA Errors found in CSAR - failing the tests..."); - System.out.println(exceptionReport.toString()); - ExceptionCollector.clear(); - //throw new SdcToscaParserException("CSAR didn't pass validation"); - } return sdcCsarHelper; } diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java index 0e6387d..8c96303 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java @@ -1,5 +1,6 @@ package org.openecomp.sdc.impl; +import org.openecomp.sdc.tosca.parser.config.ErrorConfiguration; import org.testng.annotations.Test; import org.openecomp.sdc.tosca.parser.config.Configuration; import org.openecomp.sdc.tosca.parser.config.ConfigurationManager; @@ -8,7 +9,7 @@ import java.io.IOException; import static org.testng.Assert.assertNotNull; -public class ToscaParserConfigurationTest extends BasicTest { +public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest { @Test public void testConfigurationConformanceLevel() throws IOException { @@ -18,4 +19,13 @@ public class ToscaParserConfigurationTest extends BasicTest { assertNotNull(config.getConformanceLevel().getMaxVersion()); assertNotNull(config.getConformanceLevel().getMinVersion()); } + + + @Test + public void testErrorConfigurations() throws IOException { + ErrorConfiguration errorConfig = ConfigurationManager.getInstance().getErrorConfiguration(); + assertNotNull(errorConfig); + assertNotNull(errorConfig.getErrors()); + } + } diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java new file mode 100644 index 0000000..8451a58 --- /dev/null +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java @@ -0,0 +1,143 @@ +package org.openecomp.sdc.impl; + +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +import java.io.File; + +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes; + + +/*put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR); + +put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND); +//CSAR contents problems +put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT); +put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT); +put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT); +put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT); +put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT); + + MISSING_META_FILE("JT1001"), +/* INVALID_META_YAML_CONTENT("JT1002"), +/* ENTRY_DEFINITION_NOT_DEFINED("JT1003"), +/* MISSING_ENTRY_DEFINITION_FILE("JT1004"), +/* GENERAL_ERROR("JT1005"), +/* PATH_NOT_VALID("JT1006"), +/* CSAR_TOSCA_VALIDATION_ERROR("JT1007"); + +*/ + +/* + * + * # Errors +errors: + FILE_NOT_FOUND: { + code: TP0001, + message: "Error: CSAR file not found." + } + BAD_FORMAT: { + code: TP0002, + message: "Error: CSAR file bad format. Check the log for details." + } + CONFORMANCE_LEVEL_ERROR: { + code: TP0003, + message: "Error: CSAR version is unsupported. Parser supports versions %s to %s." + } + GENERAL_ERROR: { + code: TP0004, + message: "Error: an unexpected internal error occured." + } + * + */ + +public class ToscaParserErrorHandlingTest extends SdcToscaParserBasicTest { + + + @Test + public void testMissingMetadata(){ + String csarPath = "csars/service-missing-meta-file.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + + @Test + public void testInvalidYamlContentMeta(){ + String csarPath = "csars/service-invalid-yaml-content-meta.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testEntryDefinitionNotDefined(){ + String csarPath = "csars/service-entry-definition-not-defined.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testMissingEntryDefinitionFile(){ + String csarPath = "csars/service-missing-entry-definition.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + //@Test - PA - there are currently no critical erros in JTosca + public void tesValidationError(){ + String csarPath = "csars/service-invalid-input-args.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testInValidConformanceLevelError(){ + String csarPath = "csars/service-invalid-conformence-level.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0003"); + } + + @Test + public void testFileNotFound(){ + Throwable captureThrowable = captureThrowable("csars/XXX.csar"); + testThrowable(captureThrowable, "TP0001"); + } + + @Test + public void testInvalidCsarFormat(){ + String csarPath = "csars/csar-invalid-zip.zip"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + private static void testThrowable(Throwable captureThrowable, String expectedCode) { + assertNotNull(captureThrowable); + assertTrue(captureThrowable instanceof SdcToscaParserException, "Error thrown is of type "+captureThrowable.getClass().getSimpleName()); + assertEquals(((SdcToscaParserException)captureThrowable).getCode(), expectedCode); + } + + public static Throwable captureThrowable(String csarPath) { + Throwable result = null; + try { + factory.getSdcCsarHelper(csarPath); + } catch( Throwable throwable ) { + result = throwable; + } + return result; + } +} diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java index b903867..9f349ae 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java @@ -5,7 +5,7 @@ import org.openecomp.sdc.tosca.parser.utils.GeneralUtility; import static org.testng.Assert.assertTrue; -public class ToscaParserGeneralUtilTest extends BasicTest { +public class ToscaParserGeneralUtilTest extends SdcToscaParserBasicTest { @Test public void testVersionCompare() { diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java index 58e967a..01c888f 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java @@ -10,7 +10,7 @@ import java.util.List; import static org.testng.Assert.*; -public class ToscaParserGroupTest extends BasicTest{ +public class ToscaParserGroupTest extends SdcToscaParserBasicTest{ //region getVfModulesByVf @Test diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java index 802d5b8..4fbc9c3 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java @@ -7,7 +7,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; -public class ToscaParserMetadataTest extends BasicTest { +public class ToscaParserMetadataTest extends SdcToscaParserBasicTest { //region getServiceMetadata @Test diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java index c9215a2..dd895c3 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java @@ -14,7 +14,7 @@ import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.openecomp.sdc.toscaparser.api.Group; import org.openecomp.sdc.toscaparser.api.NodeTemplate; -public class ToscaParserNodeTemplateTest extends BasicTest { +public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { //region getServiceVfList @Test @@ -311,13 +311,22 @@ public class ToscaParserNodeTemplateTest extends BasicTest { List<NodeTemplate> vfcs = complexCps.getVfcListByVf(VF_CUSTOMIZATION_UUID); Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(vfcs.get(0)); - assertEquals("1", cps.get("port_fe1_sigtran").get("ip_requirements#ip_count_required#count")); - assertEquals("true", cps.get("port_fe1_sigtran").get("ip_requirements#dhcp_enabled")); - assertEquals("4", cps.get("port_fe1_sigtran").get("ip_requirements#ip_version")); + assertEquals(5, cps.size()); - assertEquals("2", cps.get("port_fe_cluster").get("ip_requirements#ip_count_required#count")); - assertEquals("true", cps.get("port_fe_cluster").get("ip_requirements#dhcp_enabled")); - assertEquals("4", cps.get("port_fe_cluster").get("ip_requirements#ip_version")); + assertEquals(1, cps.get("port_fe1_sigtran").get("ip_requirements#ip_count_required#count")); + assertEquals(true, cps.get("port_fe1_sigtran").get("ip_requirements#dhcp_enabled")); + assertEquals(4, cps.get("port_fe1_sigtran").get("ip_requirements#ip_version")); + + assertEquals(2, cps.get("port_fe_cluster").get("ip_requirements#ip_count_required#count")); + assertEquals(true, cps.get("port_fe_cluster").get("ip_requirements#dhcp_enabled")); + assertEquals(4, cps.get("port_fe_cluster").get("ip_requirements#ip_version")); + } + + @Test + public void testGetCpPropertiesFromVfcForNullVFC() { + Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(null); + assertNotNull(cps); + assertEquals(0, cps.size()); } //endregion diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java index 0599dcc..0b172f5 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java @@ -9,7 +9,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; -public class ToscaParserServiceInputTest extends BasicTest { +public class ToscaParserServiceInputTest extends SdcToscaParserBasicTest { //region getServiceInputs @Test diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java index c61f465..6461a92 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java @@ -20,7 +20,7 @@ import org.openecomp.sdc.toscaparser.api.Property; //import static org.junit.Assert.assertEquals; //import static org.junit.Assert.assertNull; -public class ToscaParserSubsMappingsTest extends BasicTest { +public class ToscaParserSubsMappingsTest extends SdcToscaParserBasicTest { //region getServiceSubstitutionMappingsTypeName @Test diff --git a/sdc-tosca-parser/src/test/resources/config/error-configuration.yaml b/sdc-tosca-parser/src/test/resources/config/error-configuration.yaml new file mode 100644 index 0000000..3febd33 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/config/error-configuration.yaml @@ -0,0 +1,18 @@ +# 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." + }
\ No newline at end of file diff --git a/sdc-tosca-parser/src/test/resources/csars/csar-invalid-zip.zip b/sdc-tosca-parser/src/test/resources/csars/csar-invalid-zip.zip new file mode 100644 index 0000000..04de055 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/csar-invalid-zip.zip @@ -0,0 +1,2 @@ +SDC-TOSCA-Meta-File-Version: 1.0 +SDC-TOSCA-Definitions-Version: 2.0 diff --git a/sdc-tosca-parser/src/test/resources/csars/service-entry-definition-not-defined.csar b/sdc-tosca-parser/src/test/resources/csars/service-entry-definition-not-defined.csar Binary files differnew file mode 100644 index 0000000..47e65b6 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-entry-definition-not-defined.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-invalid-conformence-level.csar b/sdc-tosca-parser/src/test/resources/csars/service-invalid-conformence-level.csar Binary files differnew file mode 100644 index 0000000..12621f0 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-invalid-conformence-level.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-invalid-input-args.csar b/sdc-tosca-parser/src/test/resources/csars/service-invalid-input-args.csar Binary files differnew file mode 100644 index 0000000..22f9970 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-invalid-input-args.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-invalid-yaml-content-meta.csar b/sdc-tosca-parser/src/test/resources/csars/service-invalid-yaml-content-meta.csar Binary files differnew file mode 100644 index 0000000..f77af6f --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-invalid-yaml-content-meta.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-missing-entry-definition.csar b/sdc-tosca-parser/src/test/resources/csars/service-missing-entry-definition.csar Binary files differnew file mode 100644 index 0000000..8fd1962 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-missing-entry-definition.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-missing-meta-file.csar b/sdc-tosca-parser/src/test/resources/csars/service-missing-meta-file.csar Binary files differnew file mode 100644 index 0000000..79348db --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-missing-meta-file.csar |