summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-02-21 14:07:50 +0000
committerMichael Morris <michael.morris@est.tech>2023-02-22 14:16:42 +0000
commit9b8d90c9cdc012ca444d35465dc2e77662e4becf (patch)
treeef9f5f6d99a5bcc5eb40d965829d9a5c0128ea76 /catalog-model/src/test
parent8aa94a97ebfff1205e85470d78202f598632dbd6 (diff)
Support delete non-normative data types
Issue-ID: SDC-4411 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: I246e50d848a17178369bfb643989d5447a887017
Diffstat (limited to 'catalog-model/src/test')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java66
-rw-r--r--catalog-model/src/test/resources/modelOperation/expected-additional_types-5.yaml7
-rw-r--r--catalog-model/src/test/resources/modelOperation/expected-additional_types-6.yaml5
-rw-r--r--catalog-model/src/test/resources/modelOperation/original-additional_types-3.yaml7
4 files changed, 85 insertions, 0 deletions
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 1bd4d9dbac..c68ed71a07 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
@@ -630,6 +630,72 @@ class ModelOperationTest extends ModelTestBase {
assertEquals(expectedAdditionalTypesImport.getContent(), actualAdditionalTypesImport.getContent());
}
+ @Test
+ void removeDataTypeFromAdditionalType() throws IOException {
+ var modelName = "model";
+ final Path testResourcePath = Path.of("src/test/resources/modelOperation");
+
+ var originalAdditionalTypesImport = new ToscaImportByModel();
+ originalAdditionalTypesImport.setModelId(modelName);
+ originalAdditionalTypesImport.setFullPath(ADDITIONAL_TYPE_DEFINITIONS_PATH.toString());
+ final Path originalAdditionalTypesImportPath = testResourcePath.resolve(Path.of("original-additional_types-1.yaml"));
+ originalAdditionalTypesImport.setContent(Files.readString(originalAdditionalTypesImportPath));
+
+ final List<ToscaImportByModel> modelImports = new ArrayList<>();
+ modelImports.add(originalAdditionalTypesImport);
+ when(toscaModelImportCassandraDao.findAllByModel(modelName)).thenReturn(modelImports);
+
+ String dataTypeName = "tosca.datatypes.nfv.PreviouslyExistingType1";
+ modelOperation.removeDataTypeFromAdditionalType(ElementTypeEnum.DATA_TYPE, modelName, dataTypeName);
+ ArgumentCaptor<List<ToscaImportByModel>> importListArgumentCaptor = ArgumentCaptor.forClass(List.class);
+ verify(toscaModelImportCassandraDao).saveAll(eq(modelName), importListArgumentCaptor.capture());
+
+ final List<ToscaImportByModel> actualImportList = importListArgumentCaptor.getValue();
+ assertEquals(1, actualImportList.size());
+
+ 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-5.yaml"))));
+ final ToscaImportByModel actualAdditionalTypesImport =
+ actualImportList.stream().filter(expectedAdditionalTypesImport::equals).findFirst().orElse(null);
+ assertNotNull(actualAdditionalTypesImport);
+ assertEquals(expectedAdditionalTypesImport.getContent(), actualAdditionalTypesImport.getContent());
+ }
+
+ @Test
+ void removeOnlyDataTypeFromAdditionalType() throws IOException {
+ var modelName = "model";
+ final Path testResourcePath = Path.of("src/test/resources/modelOperation");
+
+ var originalAdditionalTypesImport = new ToscaImportByModel();
+ originalAdditionalTypesImport.setModelId(modelName);
+ originalAdditionalTypesImport.setFullPath(ADDITIONAL_TYPE_DEFINITIONS_PATH.toString());
+ final Path originalAdditionalTypesImportPath = testResourcePath.resolve(Path.of("original-additional_types-3.yaml"));
+ originalAdditionalTypesImport.setContent(Files.readString(originalAdditionalTypesImportPath));
+
+ final List<ToscaImportByModel> modelImports = new ArrayList<>();
+ modelImports.add(originalAdditionalTypesImport);
+ when(toscaModelImportCassandraDao.findAllByModel(modelName)).thenReturn(modelImports);
+
+ String dataTypeName = "tosca.datatypes.nfv.PreviouslyExistingType1";
+ modelOperation.removeDataTypeFromAdditionalType(ElementTypeEnum.DATA_TYPE, modelName, dataTypeName);
+ ArgumentCaptor<List<ToscaImportByModel>> importListArgumentCaptor = ArgumentCaptor.forClass(List.class);
+ verify(toscaModelImportCassandraDao).saveAll(eq(modelName), importListArgumentCaptor.capture());
+
+ final List<ToscaImportByModel> actualImportList = importListArgumentCaptor.getValue();
+ assertEquals(1, actualImportList.size());
+
+ 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-6.yaml"))));
+ final ToscaImportByModel actualAdditionalTypesImport =
+ actualImportList.stream().filter(expectedAdditionalTypesImport::equals).findFirst().orElse(null);
+ assertNotNull(actualAdditionalTypesImport);
+ assertEquals(expectedAdditionalTypesImport.getContent(), actualAdditionalTypesImport.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-5.yaml b/catalog-model/src/test/resources/modelOperation/expected-additional_types-5.yaml
new file mode 100644
index 0000000000..2fe94dc9cb
--- /dev/null
+++ b/catalog-model/src/test/resources/modelOperation/expected-additional_types-5.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.
+data_types:
+ tosca.datatypes.nfv.PreviouslyExistingType2:
+ derived_from: tosca.datatypes.Root
+ description: additional type
diff --git a/catalog-model/src/test/resources/modelOperation/expected-additional_types-6.yaml b/catalog-model/src/test/resources/modelOperation/expected-additional_types-6.yaml
new file mode 100644
index 0000000000..48362a9730
--- /dev/null
+++ b/catalog-model/src/test/resources/modelOperation/expected-additional_types-6.yaml
@@ -0,0 +1,5 @@
+tosca_definitions_version: tosca_simple_yaml_1_3
+description: Auto-generated file that contains package custom types or types added
+ after system installation.
+data_types: {
+ }
diff --git a/catalog-model/src/test/resources/modelOperation/original-additional_types-3.yaml b/catalog-model/src/test/resources/modelOperation/original-additional_types-3.yaml
new file mode 100644
index 0000000000..98d44c4412
--- /dev/null
+++ b/catalog-model/src/test/resources/modelOperation/original-additional_types-3.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.
+data_types:
+ tosca.datatypes.nfv.PreviouslyExistingType1:
+ derived_from: tosca.datatypes.Root
+ description: additional type