summaryrefslogtreecommitdiffstats
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/DataTypeOperationTest.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java
index 0efb751124..1f448fd875 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -43,8 +44,11 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.exception.OperationException;
+import org.openecomp.sdc.be.exception.supplier.DataTypeOperationExceptionSupplier;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.Model;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.resources.data.DataTypeData;
import org.springframework.test.context.ContextConfiguration;
@@ -57,6 +61,8 @@ class DataTypeOperationTest {
private ModelOperation modelOperation;
@Mock
private HealingJanusGraphGenericDao janusGraphGenericDao;
+ @Mock
+ private PropertyOperation propertyOperation;
private final String modelName = "ETSI-SDC-MODEL-TEST";
private final List<DataTypeData> dataTypesWithoutModel = new ArrayList<>();
@@ -69,6 +75,7 @@ class DataTypeOperationTest {
void beforeEachInit() {
MockitoAnnotations.openMocks(this);
dataTypeOperation.setModelOperation(modelOperation);
+ dataTypeOperation.setPropertyOperation(propertyOperation);
initTestData();
}
@@ -135,6 +142,51 @@ class DataTypeOperationTest {
assertTrue(result.isEmpty());
}
+ @Test
+ void findAllPropertiesTest_Success() {
+ final PropertyDefinition property1 = new PropertyDefinition();
+ property1.setName("property1");
+ final PropertyDefinition property2 = new PropertyDefinition();
+ property2.setName("property2");
+ final PropertyDefinition property3 = new PropertyDefinition();
+ property3.setName("property3");
+
+ when(propertyOperation.findPropertiesOfNode(NodeTypeEnum.DataType, "uniqueId"))
+ .thenReturn(Either.left(Map.of(property3.getName(), property3, property1.getName(), property1, property2.getName(), property2)));
+ final List<PropertyDefinition> dataTypeProperties = dataTypeOperation.findAllProperties("uniqueId");
+ assertEquals(3, dataTypeProperties.size());
+ assertEquals(property1.getName(), dataTypeProperties.get(0).getName());
+ assertEquals(property2.getName(), dataTypeProperties.get(1).getName());
+ assertEquals(property3.getName(), dataTypeProperties.get(2).getName());
+ }
+
+ @Test
+ void findAllPropertiesTest_propertiesNotFoundSuccess() {
+ when(propertyOperation.findPropertiesOfNode(NodeTypeEnum.DataType, "uniqueId"))
+ .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ final List<PropertyDefinition> dataTypeProperties = dataTypeOperation.findAllProperties("uniqueId");
+ assertTrue(dataTypeProperties.isEmpty());
+ }
+
+ @Test
+ void findAllPropertiesTest_emptyPropertiesSuccess() {
+ when(propertyOperation.findPropertiesOfNode(NodeTypeEnum.DataType, "uniqueId"))
+ .thenReturn(Either.left(Map.of()));
+ final List<PropertyDefinition> dataTypeProperties = dataTypeOperation.findAllProperties("uniqueId");
+ assertTrue(dataTypeProperties.isEmpty());
+ }
+
+ @Test
+ void findAllPropertiesTest_unknownError() {
+ final String uniqueId = "uniqueId";
+ when(propertyOperation.findPropertiesOfNode(NodeTypeEnum.DataType, uniqueId))
+ .thenReturn(Either.right(JanusGraphOperationStatus.GENERAL_ERROR));
+ final OperationException actualException = assertThrows(OperationException.class, () -> dataTypeOperation.findAllProperties(uniqueId));
+ final OperationException expectedException =
+ DataTypeOperationExceptionSupplier.unexpectedErrorWhileFetchingProperties(uniqueId).get();
+ assertEquals(expectedException.getMessage(), actualException.getMessage());
+ }
+
private void initTestData() {
model = new Model(modelName, ModelTypeEnum.NORMATIVE);
final String TEST_DATA_TYPE_001 = "test.data.type001";