diff options
author | 2020-02-05 12:13:57 +0000 | |
---|---|---|
committer | 2020-06-15 08:06:51 +0000 | |
commit | 0b3c65c18977212bc74b1f01cefe5ebecc2586f3 (patch) | |
tree | dd81f6c5fafb4932868f505db0eddaa9af688b1a /openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl | |
parent | e3e2db1d777b89e8292b88f677bcc7d81e6bf2c0 (diff) |
Onboard TOSCA data_types defined in package
Onboard TOSCA data_types defined in a CSAR package
that does not exists in the SDC default data_types
library. Those data_types were being lost.
All data_types declared in the package will be
included in the "GlobalSubstitutionServiceTemplate".
This includes the data_types declared in the main
topology template and in its imported definition
files.
Defines a maven profile to compile the catalog-be
in the main SDC pom.
Change-Id: I39445b0f42e924dc1015945b7e605e804c1d505b
Issue-ID: SDC-2763
Signed-off-by: André Schmid <andre.schmid@est.tech>
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl')
2 files changed, 87 insertions, 71 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaConvertorDefinitionsTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaConvertorDefinitionsTest.java index b978b7db99..8167cce3aa 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaConvertorDefinitionsTest.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaConvertorDefinitionsTest.java @@ -64,7 +64,7 @@ public class ToscaConvertorDefinitionsTest { assertTrue(((Map) serviceTemplate.getImports().get(0)).containsKey(HEAT_INDEX)); assertTrue(((Map) serviceTemplate.getImports().get(0)).containsKey(ONAP_INDEX)); - assertEquals(DEFININTION_VERSION, serviceTemplate.getTosca_definitions_version()); + assertEquals(DEFINITION_VERSION, serviceTemplate.getTosca_definitions_version()); assertNotNull(serviceTemplate.getNode_types()); diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaDefinitionImportHandlerTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaDefinitionImportHandlerTest.java index fe0d5a8620..6f0901cfdb 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaDefinitionImportHandlerTest.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaDefinitionImportHandlerTest.java @@ -21,6 +21,8 @@ package org.openecomp.core.impl; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceBytesOrFail; @@ -32,9 +34,10 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; +import java.util.stream.Collectors; import org.junit.Before; import org.junit.Test; +import org.openecomp.core.converter.ServiceTemplateReaderService; import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; @@ -54,7 +57,10 @@ public class ToscaDefinitionImportHandlerTest { */ @Test public void testGivenDescriptorFiles_whenMainDescriptorImportsAreHandled_allDescriptorsAreProcessedWithoutError() { - final List<String> filesToHandleList = Arrays.asList("Definitions/Main.yaml", "Definitions/descriptorBasicImport.yaml", + final String mainDefinitionFilePath = "Definitions/Main.yaml"; + descriptorFileMap + .put(mainDefinitionFilePath, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(mainDefinitionFilePath))); + final List<String> filesToHandleList = Arrays.asList("Definitions/descriptorBasicImport.yaml", "Definitions/descriptorWithRelativePaths.yaml", "Artifacts/descriptorWithAbsolutePaths.yaml", "Artifacts/descriptorCyclicReference.yaml"); @@ -64,12 +70,14 @@ public class ToscaDefinitionImportHandlerTest { final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler( descriptorFileMap, - "Definitions/Main.yaml"); - final Set<String> actualHandledFiles = toscaDefinitionImportHandler.getHandledDefinitionFilesList(); + mainDefinitionFilePath); + final Map<String, ServiceTemplateReaderService> actualHandledFiles = + toscaDefinitionImportHandler.getHandledImportDefinitionFileMap(); - assertThat("The handled files should be the same", actualHandledFiles, hasSize(filesToHandleList.size())); + assertThat("The handled files should be the same", + actualHandledFiles.keySet(), hasSize(filesToHandleList.size())); assertThat("The handled files should be the same" - , actualHandledFiles, containsInAnyOrder(filesToHandleList.toArray(new String[0])) + , actualHandledFiles.keySet(), containsInAnyOrder(filesToHandleList.toArray(new String[0])) ); final List<ErrorMessage> validationErrorList = toscaDefinitionImportHandler.getErrors(); @@ -83,19 +91,20 @@ public class ToscaDefinitionImportHandlerTest { public void testGivenEmptyPackage_whenMainDescriptorIsHandled_aMissingFileErrorIsReported() { final List<String> filesToHandleList = Collections.emptyList(); - final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler( - descriptorFileMap, - "Definitions/Main.yaml"); - final Set<String> actualHandledFiles = toscaDefinitionImportHandler.getHandledDefinitionFilesList(); + final ToscaDefinitionImportHandler toscaDefinitionImportHandler = + new ToscaDefinitionImportHandler(descriptorFileMap, "Definitions/Main.yaml"); + final Map<String, ServiceTemplateReaderService> actualHandledFiles = + toscaDefinitionImportHandler.getHandledImportDefinitionFileMap(); - assertThat("The handled files should be the same", actualHandledFiles, hasSize(filesToHandleList.size())); + assertThat("The handled files should be the same", + actualHandledFiles.keySet(), hasSize(filesToHandleList.size())); assertThat("The handled files should be the same" - , actualHandledFiles, containsInAnyOrder(filesToHandleList.toArray(new String[0])) + , actualHandledFiles.keySet(), containsInAnyOrder(filesToHandleList.toArray(new String[0])) ); final List<ErrorMessage> expectedErrorList = new ArrayList<>(); expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, - Messages.MISSING_IMPORT_FILE.formatMessage("Definitions/Main.yaml"))); + Messages.MISSING_MAIN_DEFINITION_FILE.formatMessage("Definitions/Main.yaml"))); final List<ErrorMessage> validationErrorList = toscaDefinitionImportHandler.getErrors(); assertThat("The errors should be the same", validationErrorList, hasSize(expectedErrorList.size())); @@ -109,25 +118,30 @@ public class ToscaDefinitionImportHandlerTest { */ @Test public void testGivenOneMissingDescriptorFile_whenMainDescriptorImportsAreHandled_aMissingFileErrorIsReported() { - final List<String> filesToHandleList = Arrays.asList("Definitions/Main.yaml", - "Definitions/descriptorBasicImport.yaml", "Definitions/descriptorWithRelativePaths.yaml", - "Artifacts/descriptorWithAbsolutePaths.yaml"); + descriptorFileMap + .put("Definitions/Main.yaml", + getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve("Definitions/Main.yaml"))); + + final List<String> filesToHandleList = Arrays.asList("Definitions/descriptorBasicImport.yaml", + "Definitions/descriptorWithRelativePaths.yaml", "Artifacts/descriptorWithAbsolutePaths.yaml"); filesToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file))) ); final List<ErrorMessage> expectedErrorList = new ArrayList<>(); expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, - String.format(Messages.MISSING_IMPORT_FILE.getErrorMessage(), "Artifacts/descriptorCyclicReference.yaml"))); + Messages.MISSING_IMPORT_FILE.formatMessage("Artifacts/descriptorCyclicReference.yaml"))); final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler( descriptorFileMap, "Definitions/Main.yaml"); - final Set<String> actualHandledFiles = toscaDefinitionImportHandler.getHandledDefinitionFilesList(); + final Map<String, ServiceTemplateReaderService> actualHandledFiles = + toscaDefinitionImportHandler.getHandledImportDefinitionFileMap(); - assertThat("The handled files should be the same", actualHandledFiles, hasSize(filesToHandleList.size())); + assertThat("The handled files should be the same", + actualHandledFiles.keySet(), hasSize(filesToHandleList.size())); assertThat("The handled files should be the same" - , actualHandledFiles, containsInAnyOrder(filesToHandleList.toArray(new String[0])) + , actualHandledFiles.keySet(), containsInAnyOrder(filesToHandleList.toArray(new String[0])) ); final List<ErrorMessage> validationErrorList = toscaDefinitionImportHandler.getErrors(); @@ -143,25 +157,30 @@ public class ToscaDefinitionImportHandlerTest { @Test public void testGivenDescriptorWithInvalidImportStatement_whenMainDescriptorImportsAreHandled_aInvalidImportStatementErrorIsReported() { final String mainDefinitionFile = "Definitions/MainWithInvalidImportedFile.yaml"; + descriptorFileMap + .put(mainDefinitionFile, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(mainDefinitionFile))); - final List<String> filesToHandleList = Arrays.asList(mainDefinitionFile, - "Definitions/descriptorInvalidImportStatement.yaml"); + final List<String> filesToHandleList = + Collections.singletonList("Definitions/descriptorInvalidImportStatement.yaml"); filesToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file))) ); final List<ErrorMessage> expectedErrorList = new ArrayList<>(); expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, - Messages.INVALID_IMPORT_STATEMENT.formatMessage("Definitions/descriptorInvalidImportStatement.yaml", "null"))); + Messages.INVALID_IMPORT_STATEMENT + .formatMessage("Definitions/descriptorInvalidImportStatement.yaml", "null")) + ); final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler( descriptorFileMap, mainDefinitionFile); - final Set<String> actualHandledFiles = toscaDefinitionImportHandler.getHandledDefinitionFilesList(); + final Map<String, ServiceTemplateReaderService> actualHandledFiles = toscaDefinitionImportHandler.getHandledImportDefinitionFileMap(); - assertThat("The handled files should be the same", actualHandledFiles, hasSize(filesToHandleList.size())); + assertThat("The handled files should be the same", + actualHandledFiles.keySet(), hasSize(filesToHandleList.size())); assertThat("The handled files should be the same" - , actualHandledFiles, containsInAnyOrder(filesToHandleList.toArray(new String[0])) + , actualHandledFiles.keySet(), containsInAnyOrder(filesToHandleList.toArray(new String[0])) ); final List<ErrorMessage> validationErrorList = toscaDefinitionImportHandler.getErrors(); @@ -179,20 +198,22 @@ public class ToscaDefinitionImportHandlerTest { final String mainDefinitionFilePath = "Definitions/Main1.yaml"; final String invalidMainDefinitionFilePath = "../Definitions/InvalidMainDefinitionFile.yaml"; - final List<String> filesToHandleList = Arrays.asList(mainDefinitionFilePath); + final List<String> filesToHandleList = Collections.singletonList(mainDefinitionFilePath); filesToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file))) ); final List<ErrorMessage> expectedErrorList = new ArrayList<>(); - expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, Messages.MISSING_IMPORT_FILE.formatMessage(invalidMainDefinitionFilePath))); + expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, + Messages.MISSING_MAIN_DEFINITION_FILE.formatMessage(invalidMainDefinitionFilePath))); final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler( descriptorFileMap, invalidMainDefinitionFilePath); - final Set<String> actualHandledFiles = toscaDefinitionImportHandler.getHandledDefinitionFilesList(); + final Map<String, ServiceTemplateReaderService> actualHandledFiles = + toscaDefinitionImportHandler.getHandledImportDefinitionFileMap(); - assertThat("No files should be handled", actualHandledFiles, hasSize(0)); + assertThat("No files should be handled", actualHandledFiles.keySet(), hasSize(0)); final List<ErrorMessage> validationErrorList = toscaDefinitionImportHandler.getErrors(); @@ -208,36 +229,27 @@ public class ToscaDefinitionImportHandlerTest { @Test public void testGivenInvalidYamlDescriptorFile_whenDescriptorIsHandled_aInvalidYamlFormatErrorIsReported() { final String mainDefinitionFile = "Definitions/descriptorInvalid.yaml"; - - final List<String> filesToHandleList = Arrays.asList(mainDefinitionFile); - filesToHandleList.forEach(file -> - descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file))) - ); - + descriptorFileMap.put(mainDefinitionFile, + getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(mainDefinitionFile))); final List<ErrorMessage> expectedErrorList = new ArrayList<>(); - expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, String.format(Messages.INVALID_YAML_FORMAT.getErrorMessage() - , "while scanning a simple key\n" - + " in 'string', line 5, column 3:\n" - + " template_author= onap\n" - + " ^\n" - + "could not find expected ':'\n" - + " in 'string', line 6, column 1:\n" - + " description: vCPE_vgw\n" - + " ^\n"))); + expectedErrorList + .add(new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_YAML_FORMAT.formatMessage(""))); - final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler( - descriptorFileMap, - mainDefinitionFile); - final Set<String> actualHandledFiles = toscaDefinitionImportHandler.getHandledDefinitionFilesList(); + final ToscaDefinitionImportHandler toscaDefinitionImportHandler = + new ToscaDefinitionImportHandler(descriptorFileMap, mainDefinitionFile); + final Map<String, ServiceTemplateReaderService> actualHandledFiles = + toscaDefinitionImportHandler.getHandledImportDefinitionFileMap(); - assertThat("No files should be handled", actualHandledFiles, hasSize(0)); + assertThat("No files should be handled", actualHandledFiles.keySet(), hasSize(0)); final List<ErrorMessage> validationErrorList = toscaDefinitionImportHandler.getErrors(); assertThat("The errors should be the same", validationErrorList, hasSize(expectedErrorList.size())); - assertThat("The errors should be the same" - , validationErrorList, containsInAnyOrder(expectedErrorList.toArray(new ErrorMessage[0])) - ); + final List<String> actualErrorListAsStringList = validationErrorList.stream() + .map(ErrorMessage::getMessage) + .collect(Collectors.toList()); + expectedErrorList.forEach(expectedString -> + assertThat(actualErrorListAsStringList, hasItem(containsString(expectedString.getMessage())))); } /** @@ -246,19 +258,24 @@ public class ToscaDefinitionImportHandlerTest { @Test public void testGivenDescriptorFiles_whenMainDescriptorWithDifferentImportStatementsIsHandled_noErrorsAreReported() { final String mainDefinitionFile = "Definitions/descriptorFileWithValidImportStatements.yaml"; + descriptorFileMap.put(mainDefinitionFile, + getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(mainDefinitionFile))); - final List<String> filesToHandleList = Arrays.asList(mainDefinitionFile, "Artifacts/descriptorCyclicReference.yaml"); - filesToHandleList.forEach(file -> + final List<String> importDescriptorToHandleList = + Collections.singletonList("Artifacts/descriptorCyclicReference.yaml"); + importDescriptorToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file))) ); final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler(descriptorFileMap, mainDefinitionFile); - final Set<String> actualHandledFiles = toscaDefinitionImportHandler.getHandledDefinitionFilesList(); + final Map<String, ServiceTemplateReaderService> actualHandledFiles = + toscaDefinitionImportHandler.getHandledImportDefinitionFileMap(); - assertThat("The handled files should be the same", actualHandledFiles, hasSize(filesToHandleList.size())); + assertThat("The handled files should be the same", + actualHandledFiles.keySet(), hasSize(importDescriptorToHandleList.size())); assertThat("The handled files should be the same" - , actualHandledFiles, containsInAnyOrder(filesToHandleList.toArray(new String[0])) + , actualHandledFiles.keySet(), containsInAnyOrder(importDescriptorToHandleList.toArray(new String[0])) ); final List<ErrorMessage> validationErrorList = toscaDefinitionImportHandler.getErrors(); @@ -271,8 +288,9 @@ public class ToscaDefinitionImportHandlerTest { @Test public void testGivenDescriptorFileWithNonexistentRelativeImport_whenIncorrectMainDescriptorIsHandled_aMissingFileErrorIsReported() { final String mainDefinitionFile = "Definitions/MainWithNonexistentReferences.yaml"; - - final List<String> filesToHandleList = Arrays.asList(mainDefinitionFile, + descriptorFileMap + .put(mainDefinitionFile, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(mainDefinitionFile))); + final List<String> filesToHandleList = Arrays.asList( "Definitions/descriptorNonexistentImport.yaml", "Artifacts/descriptorCyclicReference.yaml"); filesToHandleList.forEach(file -> descriptorFileMap.put(file, getResourceBytesOrFail(RESOURCES_FILE_PATH.resolve(file))) @@ -280,26 +298,24 @@ public class ToscaDefinitionImportHandlerTest { final List<ErrorMessage> expectedErrorList = new ArrayList<>(); expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, - String.format(Messages.MISSING_IMPORT_FILE.getErrorMessage(), - "Definitions/descriptorCyclicReference.yaml")) - ); + Messages.MISSING_IMPORT_FILE.formatMessage("Definitions/descriptorCyclicReference.yaml"))); expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, - String.format(Messages.MISSING_IMPORT_FILE.getErrorMessage(), - "Definitions/descriptorCyclicReference.yaml")) + Messages.MISSING_IMPORT_FILE.formatMessage("Definitions/descriptorCyclicReference.yaml")) ); expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, - String.format(Messages.MISSING_IMPORT_FILE.getErrorMessage(), - "Definitions/descriptorCyclicReference.yaml")) + Messages.MISSING_IMPORT_FILE.formatMessage("Definitions/descriptorCyclicReference.yaml")) ); final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler( descriptorFileMap, mainDefinitionFile); - final Set<String> actualHandledFiles = toscaDefinitionImportHandler.getHandledDefinitionFilesList(); + final Map<String, ServiceTemplateReaderService> actualHandledFiles = + toscaDefinitionImportHandler.getHandledImportDefinitionFileMap(); - assertThat("The handled files should be the same", actualHandledFiles, hasSize(filesToHandleList.size())); + assertThat("The handled files should be the same", + actualHandledFiles.keySet(), hasSize(filesToHandleList.size())); assertThat("The handled files should be the same" - , actualHandledFiles, containsInAnyOrder(filesToHandleList.toArray(new String[0])) + , actualHandledFiles.keySet(), containsInAnyOrder(filesToHandleList.toArray(new String[0])) ); final List<ErrorMessage> validationErrorList = toscaDefinitionImportHandler.getErrors(); |