aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/test')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java128
-rw-r--r--catalog-model/src/test/resources/modelOperation/expected-additional_types-3.yaml11
-rw-r--r--catalog-model/src/test/resources/modelOperation/expected-import-3.yaml9
-rw-r--r--catalog-model/src/test/resources/modelOperation/input-artifact_types.yaml6
-rw-r--r--catalog-model/src/test/resources/modelOperation/original-additional_types-2.yaml7
-rw-r--r--catalog-model/src/test/resources/modelOperation/original-import-3.yaml10
6 files changed, 158 insertions, 13 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 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));
}
@@ -405,6 +406,53 @@ class ModelOperationTest extends ModelTestBase {
}
@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<ToscaImportByModel> modelImports = new ArrayList<>();
+ modelImports.add(toscaImportByModel1);
+ when(toscaModelImportCassandraDao.findAllByModel(modelName)).thenReturn(modelImports);
+
+ modelOperation.addTypesToDefaultImports(ElementTypeEnum.ARTIFACT_TYPE, dataTypes, modelName);
+ ArgumentCaptor<List<ToscaImportByModel>> importListArgumentCaptor = ArgumentCaptor.forClass(List.class);
+ verify(toscaModelImportCassandraDao).saveAll(eq(modelName), importListArgumentCaptor.capture());
+
+ final List<ToscaImportByModel> 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";
final Path testResourcePath = Path.of("src/test/resources/modelOperation");
@@ -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<ToscaImportByModel> modelImports = new ArrayList<>();
+ modelImports.add(toscaImportByModel1);
+ modelImports.add(originalAdditionalTypesImport);
+ when(toscaModelImportCassandraDao.findAllByModel(modelName)).thenReturn(modelImports);
+
+ modelOperation.addTypesToDefaultImports(ElementTypeEnum.ARTIFACT_TYPE, dataTypes, modelName);
+ ArgumentCaptor<List<ToscaImportByModel>> importListArgumentCaptor = ArgumentCaptor.forClass(List.class);
+ verify(toscaModelImportCassandraDao).saveAll(eq(modelName), importListArgumentCaptor.capture());
+
+ final List<ToscaImportByModel> 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).