From 129f40e169a572b9dd5cfe6ad66bc0ee74b922d9 Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 17 Jan 2022 14:29:03 +0000 Subject: [PATCH] Add sdc-be-init support for artifact types Change-Id: Id9fdaf7b7bf0cd5d583434fbe97741dd9836df9d Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3845 --- .../components/impl/ArtifactTypeImportManager.java | 2 +- .../import/tosca/artifact-types/artifactTypes.yml | 43 +++---- .../resources/scripts/sdcBePy/tosca/imports/run.py | 3 +- .../sdcBePy/tosca/models/normativeElementsList.py | 67 ++++++----- .../operations/impl/ArtifactTypeOperation.java | 2 +- .../model/operations/impl/ModelOperationTest.java | 128 ++++++++++++++++++--- .../expected-additional_types-3.yaml | 11 ++ .../modelOperation/expected-import-3.yaml | 9 ++ .../modelOperation/input-artifact_types.yaml | 6 + .../original-additional_types-2.yaml | 7 ++ .../modelOperation/original-import-3.yaml | 10 ++ 11 files changed, 224 insertions(+), 64 deletions(-) create mode 100644 catalog-model/src/test/resources/modelOperation/expected-additional_types-3.yaml create mode 100644 catalog-model/src/test/resources/modelOperation/expected-import-3.yaml create mode 100644 catalog-model/src/test/resources/modelOperation/input-artifact_types.yaml create mode 100644 catalog-model/src/test/resources/modelOperation/original-additional_types-2.yaml create mode 100644 catalog-model/src/test/resources/modelOperation/original-import-3.yaml diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManager.java index e6ff100fc1..441dfa741a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManager.java @@ -60,7 +60,7 @@ public class ArtifactTypeImportManager { return Either.right(componentsUtils.getResponseFormat(artifactTypes.right().value())); } final List elementTypes = createArtifactTypesByDao(artifactTypes.left().value()); - if (includeToModelDefaultImports) { + if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) { commonImportManager.addTypesToDefaultImports(ElementTypeEnum.ARTIFACT_TYPE, artifactTypesYml, modelName); } return Either.left(elementTypes); diff --git a/catalog-be/src/main/resources/import/tosca/artifact-types/artifactTypes.yml b/catalog-be/src/main/resources/import/tosca/artifact-types/artifactTypes.yml index bfd078923b..97d00e5b51 100644 --- a/catalog-be/src/main/resources/import/tosca/artifact-types/artifactTypes.yml +++ b/catalog-be/src/main/resources/import/tosca/artifact-types/artifactTypes.yml @@ -1,39 +1,40 @@ tosca.artifacts.Root: - description: This is the default (root) TOSCA Artifact Type definition that all other TOSCA base Artifact Types derive from. + description: This is the default (root) TOSCA Artifact Type definition that all other TOSCA base Artifact Types derive from. tosca.artifacts.Deployment.Image: - derived_from: tosca.artifacts.Deployment - description: This artifact type represents a parent type for any "image" which is an opaque packaging of a TOSCA Node's deployment (whether real or virtual) whose contents are typically already installed and pre-configured (i.e., "stateful") and prepared to be run on a known target container. + derived_from: tosca.artifacts.Deployment + description: This artifact type represents a parent type for any "image" which is an opaque packaging of a TOSCA Node's deployment (whether real or virtual) whose contents are typically already installed and pre-configured (i.e., "stateful") and prepared to be run on a known target container. tosca.artifacts.Implementation.Bash: - derived_from: tosca.artifacts.Implementation - description: This artifact type represents a Bash script type that contains Bash commands that can be executed on the Unix Bash shell. + derived_from: tosca.artifacts.Implementation + description: This artifact type represents a Bash script type that contains Bash commands that can be executed on the Unix Bash shell. tosca.artifacts.Deployment.Image.VM: - derived_from: tosca.artifacts.Deployment - description: This artifact represents the parent type for all Virtual Machine (VM) image and container formatted deployment artifacts. These images contain a stateful capture of a machine (e.g., server) including operating system and installed software along with any configurations and can be run on another machine using a hypervisor which virtualizes typical server (i.e., hardware) resources. + derived_from: tosca.artifacts.Deployment + description: This artifact represents the parent type for all Virtual Machine (VM) image and container formatted deployment artifacts. These images contain a stateful capture of a machine (e.g., server) including operating system and installed software along with any configurations and can be run on another machine using a hypervisor which virtualizes typical server (i.e., hardware) resources. tosca.artifacts.Implementation.Python: - derived_from: tosca.artifacts.Implementation - description: This artifact type represents a Python file that contains Python language constructs that can be executed within a Python interpreter. + derived_from: tosca.artifacts.Implementation + description: This artifact type represents a Python file that contains Python language constructs that can be executed within a Python interpreter. tosca.artifacts.Deployment: - derived_from: tosca.artifacts.Root - description: This artifact type represents the parent type for all deployment artifacts in TOSCA. This class of artifacts typically represents a binary packaging of an application or service that is used to install/create or deploy it as part of a node's lifecycle. + derived_from: tosca.artifacts.Root + description: This artifact type represents the parent type for all deployment artifacts in TOSCA. This class of artifacts typically represents a binary packaging of an application or service that is used to install/create or deploy it as part of a node's lifecycle. tosca.artifacts.File: - derived_from: tosca.artifacts.Root - description: This artifact type is used when an artifact definition needs to have its associated file simply treated as a file and no special handling/handlers are invoked (i.e., it is not treated as either an implementation or deployment artifact type). + derived_from: tosca.artifacts.Root + description: This artifact type is used when an artifact definition needs to have its associated file simply treated as a file and no special handling/handlers are invoked (i.e., it is not treated as either an implementation or deployment artifact type). tosca.artifacts.Implementation: - derived_from: tosca.artifacts.Root - description: This artifact type represents the parent type for all implementation artifacts in TOSCA. These artifacts are used to implement operations of TOSCA interfaces either directly (e.g., scripts) or indirectly (e.g., config. files). + derived_from: tosca.artifacts.Root + description: This artifact type represents the parent type for all implementation artifacts in TOSCA. These artifacts are used to implement operations of TOSCA interfaces either directly (e.g., scripts) or indirectly (e.g., config. files). tosca.artifacts.nfv.SwImage: - derived_from: tosca.artifacts.Deployment.Image - description: describes the software image which is directly loaded on the virtualisation container realizing of the VDU or is to be loaded on a virtual + derived_from: tosca.artifacts.Deployment.Image + description: describes the software image which is directly loaded on the virtualisation container realizing of the VDU or is to be loaded on a virtual + tosca.artifacts.Implementation.nfv.Mistral: - derived_from: tosca.artifacts.Implementation - description: artifacts for Mistral workflows - mime_type: application/x-yaml - file_ext: [ yaml ] + derived_from: tosca.artifacts.Implementation + description: artifacts for Mistral workflows + mime_type: application/x-yaml + file_ext: [ yaml ] diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py index db6e91481c..9ba770d895 100644 --- a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py +++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py @@ -24,7 +24,7 @@ def main(sdc_be_proxy, update_version): process_element_list(normativeElementsList.get_normative_element_candidate_list(base_file_location), sdc_be_proxy) process_type_list(normativeTypesList.get_normative_type_candidate_list(base_file_location), sdc_be_proxy, update_version) process_element_list(normativeElementsList.get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy) - #Add model based normatives + # Add model based normatives model_import_manager = ModelImportManager(Path(base_file_location) / 'models', ModelClient(sdc_be_proxy), NodeTypeClient(sdc_be_proxy)) model_import_manager.deploy_models() @@ -37,6 +37,7 @@ def main(sdc_be_proxy, update_version): logger.log("Script end ->", "All normatives imported successfully!") logger.print_and_exit(0, None) + def run(): sdc_be_proxy, update_version = parse_and_create_proxy() main(sdc_be_proxy, update_version) diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementsList.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementsList.py index ffd412f38f..6d00bb08ed 100644 --- a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementsList.py +++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/models/normativeElementsList.py @@ -1,78 +1,91 @@ from os import path + from sdcBePy.tosca.models.normativeElementCandidate import NormativeElementCandidate + def get_normative_element_candidate_list(base_file_location): return [ get_data(base_file_location), get_capability(base_file_location), get_relationship(base_file_location), get_interface_lifecycle(base_file_location), - get_categories(base_file_location) + get_categories(base_file_location), + get_artifacts(base_file_location) ] + def get_normative_element_with_metadata_list(base_file_location): return [ get_group(base_file_location), get_policy(base_file_location) ] + def get_normative_candidate(base_file_location, url, filename, zip_name, with_metadata=False): if path.isdir(base_file_location): return NormativeElementCandidate(base_file_location, url, filename, zip_name, with_metadata=with_metadata) + def get_data(base_file_location="/"): return get_normative_candidate(base_file_location + "data-types/", - "/sdc2/rest/v1/catalog/uploadType/datatypes", - "dataTypes", - "dataTypesZip") + "/sdc2/rest/v1/catalog/uploadType/datatypes", + "dataTypes", + "dataTypesZip") def get_capability(base_file_location="/"): return get_normative_candidate(base_file_location + "capability-types/", - "/sdc2/rest/v1/catalog/uploadType/capability", - "capabilityTypes", - "capabilityTypeZip") + "/sdc2/rest/v1/catalog/uploadType/capability", + "capabilityTypes", + "capabilityTypeZip") def get_relationship(base_file_location="/"): return get_normative_candidate(base_file_location + "relationship-types/", - "/sdc2/rest/v1/catalog/uploadType/relationship", - "relationshipTypes", - "relationshipTypeZip") + "/sdc2/rest/v1/catalog/uploadType/relationship", + "relationshipTypes", + "relationshipTypeZip") def get_interface_lifecycle(base_file_location="../../../import/tosca/"): return get_normative_candidate(base_file_location + "interface-lifecycle-types/", - "/sdc2/rest/v1/catalog/uploadType/interfaceLifecycle", - "interfaceLifecycleTypes", - "interfaceLifecycleTypeZip") + "/sdc2/rest/v1/catalog/uploadType/interfaceLifecycle", + "interfaceLifecycleTypes", + "interfaceLifecycleTypeZip") def get_categories(base_file_location="/"): return get_normative_candidate(base_file_location + "categories/", - "/sdc2/rest/v1/catalog/uploadType/categories", - "categoryTypes", - "categoriesZip") + "/sdc2/rest/v1/catalog/uploadType/categories", + "categoryTypes", + "categoriesZip") + + +def get_artifacts(base_file_location="/"): + return get_normative_candidate(base_file_location + "artifact-types/", + "/sdc2/rest/v1/catalog/uploadType/artifactTypes", + "artifactTypes", + "artifactsZip") def get_group(base_file_location="/"): return get_normative_candidate(base_file_location + "group-types/", - "/sdc2/rest/v1/catalog/uploadType/grouptypes", - "groupTypes", - "groupTypesZip", - with_metadata=True) + "/sdc2/rest/v1/catalog/uploadType/grouptypes", + "groupTypes", + "groupTypesZip", + with_metadata=True) def get_policy(base_file_location="/"): return get_normative_candidate(base_file_location + "policy-types/", - "/sdc2/rest/v1/catalog/uploadType/policytypes", - "policyTypes", - "policyTypesZip", - with_metadata=True) + "/sdc2/rest/v1/catalog/uploadType/policytypes", + "policyTypes", + "policyTypesZip", + with_metadata=True) def get_annotation(base_file_location="/"): return get_normative_candidate(base_file_location + "annotation-types/", - "/sdc2/rest/v1/catalog/uploadType/annotationtypes", - "annotationTypes", - "annotationTypesZip") + "/sdc2/rest/v1/catalog/uploadType/annotationtypes", + "annotationTypes", + "annotationTypesZip") diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ArtifactTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ArtifactTypeOperation.java index 4b1dcfba97..d8a78cdd7d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ArtifactTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ArtifactTypeOperation.java @@ -204,7 +204,7 @@ public class ArtifactTypeOperation implements IArtifactTypeOperation { private void addDerivedFromRelation(final ArtifactTypeDefinition artifactType) { final String derivedFrom = artifactType.getDerivedFrom(); final String artifactId = artifactType.getUniqueId(); - if (derivedFrom.isEmpty()) { + if (derivedFrom == null || derivedFrom.isEmpty()) { return; } final var getArtifactTypeOptional = getLatestArtifactTypeByType(derivedFrom, artifactType.getModel()); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java index a27177ac21..42f52982a8 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java @@ -81,6 +81,7 @@ import org.springframework.test.context.ContextConfiguration; @ContextConfiguration("classpath:application-context-test.xml") class ModelOperationTest extends ModelTestBase { + private static final String modelName = "ETSI-SDC-MODEL-TEST"; @InjectMocks private ModelOperation modelOperation; @Mock @@ -92,8 +93,6 @@ class ModelOperationTest extends ModelTestBase { @Mock private DerivedFromOperation derivedFromOperation; - private final String modelName = "ETSI-SDC-MODEL-TEST"; - @BeforeAll static void beforeAllInit() { init(); @@ -106,26 +105,28 @@ class ModelOperationTest extends ModelTestBase { @Test void createModelSuccessTest() { - final ModelData modelData = new ModelData(modelName, UniqueIdBuilder.buildModelUid(modelName), ModelTypeEnum.NORMATIVE); - when(janusGraphGenericDao.createNode(any(),any())).thenReturn(Either.left(modelData)); + final ModelData modelData = new ModelData(modelName, UniqueIdBuilder.buildModelUid(modelName), ModelTypeEnum.NORMATIVE); + when(janusGraphGenericDao.createNode(any(), any())).thenReturn(Either.left(modelData)); final Model createdModel = modelOperation.createModel(new Model(modelName, ModelTypeEnum.NORMATIVE), false); assertThat(createdModel).isNotNull(); assertThat(createdModel.getName()).isEqualTo(modelName); } - + @Test void createDerivedModelSuccessTest() { final String derivedModelName = "derivedModel"; - final ModelData modelData = new ModelData(derivedModelName, UniqueIdBuilder.buildModelUid(derivedModelName), ModelTypeEnum.NORMATIVE); - when(janusGraphGenericDao.createNode(any(),any())).thenReturn(Either.left(modelData)); - + final ModelData modelData = new ModelData(derivedModelName, UniqueIdBuilder.buildModelUid(derivedModelName), ModelTypeEnum.NORMATIVE); + when(janusGraphGenericDao.createNode(any(), any())).thenReturn(Either.left(modelData)); + final GraphVertex modelVertex = new GraphVertex(); modelVertex.addMetadataProperty(GraphPropertyEnum.NAME, "baseModel"); modelVertex.addMetadataProperty(GraphPropertyEnum.MODEL_TYPE, ModelTypeEnum.NORMATIVE.getValue()); when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.MODEL), anyMap())).thenReturn(Either.left(Collections.singletonList(modelVertex))); - when(janusGraphGenericDao.getChild(eq("uid"), anyString(), eq(GraphEdgeLabels.DERIVED_FROM), eq(NodeTypeEnum.Model), eq(ModelData.class))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); - when(derivedFromOperation.addDerivedFromRelation("model.derivedModel", "model.baseModel", NodeTypeEnum.Model)).thenReturn(Either.left(new GraphRelation())); - + when(janusGraphGenericDao.getChild(eq("uid"), anyString(), eq(GraphEdgeLabels.DERIVED_FROM), eq(NodeTypeEnum.Model), + eq(ModelData.class))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); + when(derivedFromOperation.addDerivedFromRelation("model.derivedModel", "model.baseModel", NodeTypeEnum.Model)).thenReturn( + Either.left(new GraphRelation())); + final Model createdModel = modelOperation.createModel(new Model(derivedModelName, modelName, ModelTypeEnum.NORMATIVE), false); assertThat(createdModel).isNotNull(); assertThat(createdModel.getName()).isEqualTo(derivedModelName); @@ -133,14 +134,14 @@ class ModelOperationTest extends ModelTestBase { @Test void createModelFailWithModelAlreadyExistTest() { - when(janusGraphGenericDao.createNode(any(),any())).thenReturn(Either.right(JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION)); + when(janusGraphGenericDao.createNode(any(), any())).thenReturn(Either.right(JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION)); final var model = new Model(modelName, ModelTypeEnum.NORMATIVE); assertThrows(OperationException.class, () -> modelOperation.createModel(model, false)); } @Test void createModelFailTest() { - when(janusGraphGenericDao.createNode(any(),any())).thenReturn(Either.right(JanusGraphOperationStatus.GRAPH_IS_NOT_AVAILABLE)); + when(janusGraphGenericDao.createNode(any(), any())).thenReturn(Either.right(JanusGraphOperationStatus.GRAPH_IS_NOT_AVAILABLE)); final var model = new Model(modelName, ModelTypeEnum.NORMATIVE); assertThrows(OperationException.class, () -> modelOperation.createModel(model, false)); } @@ -404,6 +405,53 @@ class ModelOperationTest extends ModelTestBase { assertEquals(expectedImport2.getContent(), actualImport2.getContent()); } + @Test + void addArtifactsToDefaultImportsTest_nonExistingAdditionalTypesImport() throws IOException { + var modelName = "model"; + final Path testResourcePath = Path.of("src/test/resources/modelOperation"); + + final var dataTypesPath = testResourcePath.resolve(Path.of("input-artifact_types.yaml")); + final var dataTypes = Files.readString(dataTypesPath); + + final Path import1RelativePath = Path.of("original-import-3.yaml"); + final Path import1Path = testResourcePath.resolve(import1RelativePath); + + var toscaImportByModel1 = new ToscaImportByModel(); + toscaImportByModel1.setModelId(modelName); + toscaImportByModel1.setFullPath(import1RelativePath.toString()); + toscaImportByModel1.setContent(Files.readString(import1Path)); + + final List modelImports = new ArrayList<>(); + modelImports.add(toscaImportByModel1); + when(toscaModelImportCassandraDao.findAllByModel(modelName)).thenReturn(modelImports); + + modelOperation.addTypesToDefaultImports(ElementTypeEnum.ARTIFACT_TYPE, dataTypes, modelName); + ArgumentCaptor> importListArgumentCaptor = ArgumentCaptor.forClass(List.class); + verify(toscaModelImportCassandraDao).saveAll(eq(modelName), importListArgumentCaptor.capture()); + + final List actualImportList = importListArgumentCaptor.getValue(); + assertEquals(2, actualImportList.size()); + assertTrue(actualImportList.contains(toscaImportByModel1)); + + var expectedAdditionalTypesImport = new ToscaImportByModel(); + expectedAdditionalTypesImport.setModelId(modelName); + expectedAdditionalTypesImport.setFullPath(ADDITIONAL_TYPE_DEFINITIONS_PATH.toString()); + expectedAdditionalTypesImport.setContent(Files.readString(testResourcePath.resolve(Path.of("expected-additional_types-3.yaml")))); + final ToscaImportByModel actualAdditionalTypesImport = + actualImportList.stream().filter(expectedAdditionalTypesImport::equals).findFirst().orElse(null); + assertNotNull(actualAdditionalTypesImport); + assertEquals(expectedAdditionalTypesImport.getContent(), actualAdditionalTypesImport.getContent()); + + var expectedImport1 = new ToscaImportByModel(); + expectedImport1.setModelId(modelName); + expectedImport1.setFullPath(import1RelativePath.toString()); + expectedImport1.setContent(Files.readString(testResourcePath.resolve(Path.of("expected-import-3.yaml")))); + final ToscaImportByModel actualImport1 = actualImportList.stream().filter(expectedImport1::equals).findFirst().orElse(null); + assertNotNull(actualImport1); + assertEquals(expectedImport1.getContent(), actualImport1.getContent()); + + } + @Test void addTypesToDefaultImportsTest_existingAdditionalTypesImport() throws IOException { var modelName = "model"; @@ -458,6 +506,60 @@ class ModelOperationTest extends ModelTestBase { } + @Test + void addArtifactsToDefaultImportsTest_existingAdditionalTypesImport() throws IOException { + var modelName = "model"; + final Path testResourcePath = Path.of("src/test/resources/modelOperation"); + + final var dataTypesPath = testResourcePath.resolve(Path.of("input-artifact_types.yaml")); + final var dataTypes = Files.readString(dataTypesPath); + + final Path import1RelativePath = Path.of("original-import-3.yaml"); + final Path import1Path = testResourcePath.resolve(import1RelativePath); + + var toscaImportByModel1 = new ToscaImportByModel(); + toscaImportByModel1.setModelId(modelName); + toscaImportByModel1.setFullPath(import1RelativePath.toString()); + toscaImportByModel1.setContent(Files.readString(import1Path)); + + var originalAdditionalTypesImport = new ToscaImportByModel(); + originalAdditionalTypesImport.setModelId(modelName); + originalAdditionalTypesImport.setFullPath(ADDITIONAL_TYPE_DEFINITIONS_PATH.toString()); + final Path originalAdditionalTypesImportPath = testResourcePath.resolve(Path.of("original-additional_types-2.yaml")); + originalAdditionalTypesImport.setContent(Files.readString(originalAdditionalTypesImportPath)); + + final List modelImports = new ArrayList<>(); + modelImports.add(toscaImportByModel1); + modelImports.add(originalAdditionalTypesImport); + when(toscaModelImportCassandraDao.findAllByModel(modelName)).thenReturn(modelImports); + + modelOperation.addTypesToDefaultImports(ElementTypeEnum.ARTIFACT_TYPE, dataTypes, modelName); + ArgumentCaptor> importListArgumentCaptor = ArgumentCaptor.forClass(List.class); + verify(toscaModelImportCassandraDao).saveAll(eq(modelName), importListArgumentCaptor.capture()); + + final List actualImportList = importListArgumentCaptor.getValue(); + assertEquals(2, actualImportList.size()); + assertTrue(actualImportList.contains(toscaImportByModel1)); + + var expectedAdditionalTypesImport = new ToscaImportByModel(); + expectedAdditionalTypesImport.setModelId(modelName); + expectedAdditionalTypesImport.setFullPath(ADDITIONAL_TYPE_DEFINITIONS_PATH.toString()); + expectedAdditionalTypesImport.setContent(Files.readString(testResourcePath.resolve(Path.of("expected-additional_types-3.yaml")))); + final ToscaImportByModel actualAdditionalTypesImport = + actualImportList.stream().filter(expectedAdditionalTypesImport::equals).findFirst().orElse(null); + assertNotNull(actualAdditionalTypesImport); + assertEquals(expectedAdditionalTypesImport.getContent(), actualAdditionalTypesImport.getContent()); + + var expectedImport1 = new ToscaImportByModel(); + expectedImport1.setModelId(modelName); + expectedImport1.setFullPath(import1RelativePath.toString()); + expectedImport1.setContent(Files.readString(testResourcePath.resolve(Path.of("expected-import-3.yaml")))); + final ToscaImportByModel actualImport1 = actualImportList.stream().filter(expectedImport1::equals).findFirst().orElse(null); + assertNotNull(actualImport1); + assertEquals(expectedImport1.getContent(), actualImport1.getContent()); + + } + private ToscaImportByModel createModelImport(final String parentModelName, final String importPath) { var toscaImportByModel = new ToscaImportByModel(); toscaImportByModel.setModelId(parentModelName); diff --git a/catalog-model/src/test/resources/modelOperation/expected-additional_types-3.yaml b/catalog-model/src/test/resources/modelOperation/expected-additional_types-3.yaml new file mode 100644 index 0000000000..3284b491e0 --- /dev/null +++ b/catalog-model/src/test/resources/modelOperation/expected-additional_types-3.yaml @@ -0,0 +1,11 @@ +tosca_definitions_version: tosca_simple_yaml_1_3 +description: Auto-generated file that contains package custom types or types added + after system installation. +artifact_types: + tosca.artifacts.Implementation.Python: + derived_from: tosca.artifacts.Implementation + description: Python replacement. + tosca.artifacts.Implementation.Python.V3: + derived_from: tosca.artifacts.Implementation.Python + description: This artifact type represents a Python3 file that contains Python + language constructs that can be executed within a Python interpreter. diff --git a/catalog-model/src/test/resources/modelOperation/expected-import-3.yaml b/catalog-model/src/test/resources/modelOperation/expected-import-3.yaml new file mode 100644 index 0000000000..a59439b794 --- /dev/null +++ b/catalog-model/src/test/resources/modelOperation/expected-import-3.yaml @@ -0,0 +1,9 @@ +tosca_definitions_version: tosca_simple_yaml_1_2 +description: ETSI NFV SOL 001 nsd types definitions version 2.5.1 +artifact_types: + tosca.artifacts.File: + derived_from: tosca.artifacts.Root + description: This artifact type is used when an artifact definition needs to have + its associated file simply treated as a file and no special handling/handlers + are invoked (i.e., it is not treated as either an implementation or deployment + artifact type). diff --git a/catalog-model/src/test/resources/modelOperation/input-artifact_types.yaml b/catalog-model/src/test/resources/modelOperation/input-artifact_types.yaml new file mode 100644 index 0000000000..90240ba609 --- /dev/null +++ b/catalog-model/src/test/resources/modelOperation/input-artifact_types.yaml @@ -0,0 +1,6 @@ +tosca.artifacts.Implementation.Python: + derived_from: tosca.artifacts.Implementation + description: Python replacement. +tosca.artifacts.Implementation.Python.V3: + derived_from: tosca.artifacts.Implementation.Python + description: This artifact type represents a Python3 file that contains Python language constructs that can be executed within a Python interpreter. diff --git a/catalog-model/src/test/resources/modelOperation/original-additional_types-2.yaml b/catalog-model/src/test/resources/modelOperation/original-additional_types-2.yaml new file mode 100644 index 0000000000..8395bbacb2 --- /dev/null +++ b/catalog-model/src/test/resources/modelOperation/original-additional_types-2.yaml @@ -0,0 +1,7 @@ +tosca_definitions_version: tosca_simple_yaml_1_3 +description: Auto-generated file that contains package custom types or types added + after system installation. +artifact_types: + tosca.artifacts.Implementation.Python: + derived_from: tosca.artifacts.Implementation + description: Python replacement. diff --git a/catalog-model/src/test/resources/modelOperation/original-import-3.yaml b/catalog-model/src/test/resources/modelOperation/original-import-3.yaml new file mode 100644 index 0000000000..7853411821 --- /dev/null +++ b/catalog-model/src/test/resources/modelOperation/original-import-3.yaml @@ -0,0 +1,10 @@ +tosca_definitions_version: tosca_simple_yaml_1_2 +description: ETSI NFV SOL 001 nsd types definitions version 2.5.1 + +artifact_types: + tosca.artifacts.Implementation.Python: + derived_from: tosca.artifacts.Implementation + description: Python replacement. + tosca.artifacts.File: + derived_from: tosca.artifacts.Root + description: This artifact type is used when an artifact definition needs to have its associated file simply treated as a file and no special handling/handlers are invoked (i.e., it is not treated as either an implementation or deployment artifact type). -- 2.16.6