diff options
author | andre.schmid <andre.schmid@est.tech> | 2021-06-21 22:25:28 +0100 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2021-07-05 09:21:57 +0000 |
commit | b835031b83230c36649c6e77787867a465e0ac47 (patch) | |
tree | c988e23a137da1f2a757693f56ab1a457394444f /catalog-model/src/test/java/org/openecomp | |
parent | 70975c212b58b793d3893e131a3d23d8144f5df9 (diff) |
Create REST endpoint to retrieve models
Change-Id: Ifca0095d84d5da4ab4b055942d893e9c6a259eb7
Issue-ID: SDC-3622
Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-model/src/test/java/org/openecomp')
-rw-r--r-- | catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java | 36 |
1 files changed, 36 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 620c7f76a6..c48a1524b8 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 @@ -20,6 +20,7 @@ package org.openecomp.sdc.be.model.operations.impl; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -55,6 +56,7 @@ import org.openecomp.sdc.be.data.model.ToscaImportByModel; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.model.Model; import org.openecomp.sdc.be.model.ModelTestBase; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ModelOperationExceptionSupplier; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException; import org.openecomp.sdc.be.resources.data.ModelData; import org.springframework.test.context.ContextConfiguration; @@ -225,4 +227,38 @@ class ModelOperationTest extends ModelTestBase { assertTrue(modelOperation.findModelByName(null).isEmpty()); } + @Test + void findAllModelsSuccessTest() { + final GraphVertex expectedVertex = mock(GraphVertex.class); + when(expectedVertex.getMetadataProperty(GraphPropertyEnum.NAME)).thenReturn(modelName); + when(janusGraphDao.getByCriteria(VertexTypeEnum.MODEL, Collections.emptyMap())).thenReturn(Either.left(List.of(expectedVertex))); + final List<Model> actualModelList = modelOperation.findAllModels(); + assertFalse(actualModelList.isEmpty()); + assertEquals(1, actualModelList.size()); + assertEquals(modelName, actualModelList.get(0).getName()); + } + + @Test + void findAllModelsTest_noModelsFound() { + when(janusGraphDao.getByCriteria(VertexTypeEnum.MODEL, Collections.emptyMap())).thenReturn(Either.left(Collections.emptyList())); + final List<Model> actualModelList = modelOperation.findAllModels(); + assertTrue(actualModelList.isEmpty()); + } + + @Test + void findAllModelsTest_janusGraphNotFound() { + when(janusGraphDao.getByCriteria(VertexTypeEnum.MODEL, Collections.emptyMap())) + .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); + final List<Model> actualModelList = modelOperation.findAllModels(); + assertTrue(actualModelList.isEmpty()); + } + + @Test + void findAllModelsTest_janusGraphError() { + when(janusGraphDao.getByCriteria(VertexTypeEnum.MODEL, Collections.emptyMap())) + .thenReturn(Either.right(JanusGraphOperationStatus.GENERAL_ERROR)); + final var actualException = assertThrows(OperationException.class, () -> modelOperation.findAllModels()); + final var expectedException = ModelOperationExceptionSupplier.failedToRetrieveModels(JanusGraphOperationStatus.GENERAL_ERROR).get(); + assertEquals(expectedException.getMessage(), actualException.getMessage()); + } } |