diff options
author | andre.schmid <andre.schmid@est.tech> | 2021-08-27 15:07:43 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2021-08-30 14:17:08 +0000 |
commit | a1cdcda28701f603cf95f591ba447bd723273622 (patch) | |
tree | 3d9d36dbbfa5aca12bdeb3cfcddae04ee2cd34a3 /catalog-model/src/test | |
parent | 37d9a984c45a2a3389b70fca38513fd4bd821e28 (diff) |
Include custom data types from VSP in csar imports
When a model with custom data types is created, the data types
are now being added as part of the default model imports files.
When a CSAR is generated from a Service Template that is
associated to a derived model, the default imports from the
parent model are also included in the package.
Change-Id: I027d25d7237989a40085edec7fdd399ac09c4db1
Issue-ID: SDC-3692
Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-model/src/test')
-rw-r--r-- | catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java | 56 |
1 files changed, 51 insertions, 5 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 6071b4d59d..e7c5ddba16 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 @@ -35,11 +35,14 @@ import static org.mockito.Mockito.when; import fj.data.Either; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.TreeMap; +import java.util.stream.Stream; +import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -49,11 +52,12 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.cassandra.ToscaModelImportCassandraDao; +import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.data.model.ToscaImportByModel; @@ -228,8 +232,8 @@ class ModelOperationTest extends ModelTestBase { when(expectedVertex.getMetadataProperty(GraphPropertyEnum.NAME)).thenReturn(modelName); when(expectedVertex.getMetadataProperty(GraphPropertyEnum.MODEL_TYPE)).thenReturn(ModelTypeEnum.NORMATIVE.getValue()); when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.MODEL), mapArgumentCaptor.capture())).thenReturn(Either.left(List.of(expectedVertex))); - when(janusGraphGenericDao.getChild("uid", UniqueIdBuilder.buildModelUid(modelName), GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Model, - ModelData.class)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); + when(janusGraphGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Model), UniqueIdBuilder.buildModelUid(modelName), + GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Model, ModelData.class)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); final Optional<Model> modelByNameOpt = modelOperation.findModelByName(modelName); final Map<GraphPropertyEnum, Object> value = mapArgumentCaptor.getValue(); @@ -263,8 +267,8 @@ class ModelOperationTest extends ModelTestBase { when(expectedVertex.getMetadataProperty(GraphPropertyEnum.NAME)).thenReturn(modelName); when(expectedVertex.getMetadataProperty(GraphPropertyEnum.MODEL_TYPE)).thenReturn(ModelTypeEnum.NORMATIVE.getValue()); when(janusGraphDao.getByCriteria(VertexTypeEnum.MODEL, Collections.emptyMap())).thenReturn(Either.left(List.of(expectedVertex))); - when(janusGraphGenericDao.getChild("uid", UniqueIdBuilder.buildModelUid(modelName), GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Model, - ModelData.class)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); + when(janusGraphGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Model), UniqueIdBuilder.buildModelUid(modelName), + GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Model, ModelData.class)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); final List<Model> actualModelList = modelOperation.findAllModels(); assertFalse(actualModelList.isEmpty()); @@ -295,4 +299,46 @@ class ModelOperationTest extends ModelTestBase { final var expectedException = ModelOperationExceptionSupplier.failedToRetrieveModels(JanusGraphOperationStatus.GENERAL_ERROR).get(); assertEquals(expectedException.getMessage(), actualException.getMessage()); } + + @Test + void findAllModelImportsTest() { + //given + final var modelName = "modelName"; + final var parentModelName = "parentModelName"; + final GraphVertex expectedVertex = mock(GraphVertex.class); + when(expectedVertex.getMetadataProperty(GraphPropertyEnum.NAME)).thenReturn(modelName); + when(expectedVertex.getMetadataProperty(GraphPropertyEnum.MODEL_TYPE)).thenReturn(ModelTypeEnum.NORMATIVE_EXTENSION.getValue()); + when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.MODEL), anyMap())).thenReturn(Either.left(List.of(expectedVertex))); + + final var modelData = new ModelData(parentModelName, parentModelName, ModelTypeEnum.NORMATIVE); + final ImmutablePair<ModelData, GraphEdge> modelDataGraphEdgePair = new ImmutablePair<>(modelData, null); + + when(janusGraphGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Model), UniqueIdBuilder.buildModelUid(modelName), + GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Model, ModelData.class)).thenReturn(Either.left(modelDataGraphEdgePair)); + + final ArrayList<ToscaImportByModel> childModelImportList = new ArrayList<>(); + childModelImportList.add(createModelImport(modelName, "anyPath1")); + childModelImportList.add(createModelImport(modelName, "anyPath2")); + when(toscaModelImportCassandraDao.findAllByModel(modelName)).thenReturn(new ArrayList<>(childModelImportList)); + final ArrayList<ToscaImportByModel> parentModelImportList = new ArrayList<>(); + parentModelImportList.add(createModelImport(parentModelName, "anyPath1")); + parentModelImportList.add(createModelImport(parentModelName, "anyPath2")); + when(toscaModelImportCassandraDao.findAllByModel(parentModelName)).thenReturn(parentModelImportList); + + //when + final List<ToscaImportByModel> actualModelImportList = modelOperation.findAllModelImports(modelName, true); + + //then + assertFalse(actualModelImportList.isEmpty()); + assertEquals(childModelImportList.size() + parentModelImportList.size(), actualModelImportList.size()); + Stream.concat(childModelImportList.stream(), parentModelImportList.stream()) + .forEach(toscaImportByModel -> assertTrue(actualModelImportList.contains(toscaImportByModel))); + } + + private ToscaImportByModel createModelImport(final String parentModelName, final String importPath) { + var toscaImportByModel = new ToscaImportByModel(); + toscaImportByModel.setModelId(parentModelName); + toscaImportByModel.setFullPath(importPath); + return toscaImportByModel; + } } |