From 0514ec6635a08cdbaac5d664c3a4f13bcb0cbf51 Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Wed, 14 Jul 2021 14:21:47 +0100 Subject: Consider component model when retrieving relationship types Issue-ID: SDC-3640 Signed-off-by: MichaelMorris Change-Id: Ic06a9085b8aa2f44b8d33d7de12eadf691106131 Signed-off-by: Vasyl Razinkov Signed-off-by: KrupaNagabhushan --- .../operations/impl/RelationshipTypeOperation.java | 9 ++++----- .../impl/RelationshipTypeOperationTest.java | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperation.java index f02fc2da7d..1b3fee97c1 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperation.java @@ -20,8 +20,6 @@ package org.openecomp.sdc.be.model.operations.impl; import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR; - -import fj.data.Either; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -47,6 +45,7 @@ import org.openecomp.sdc.be.resources.data.UniqueIdData; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import fj.data.Either; @Component("relationship-type-operation") public class RelationshipTypeOperation extends AbstractOperation { @@ -72,7 +71,7 @@ public class RelationshipTypeOperation extends AbstractOperation { return getRelationshipTypeDefinition(relationshipTypesRes.left().value()); } - public Either getRelationshipTypeDefinition(final RelationshipTypeData relationshipTypeData) { + private Either getRelationshipTypeDefinition(final RelationshipTypeData relationshipTypeData) { RelationshipTypeDefinition relationshipTypeDefinition = new RelationshipTypeDefinition( relationshipTypeData.getRelationshipTypeDataDefinition()); Either, JanusGraphOperationStatus> propertiesStatus = OperationUtils @@ -364,11 +363,11 @@ public class RelationshipTypeOperation extends AbstractOperation { DaoStatusConverter::convertJanusGraphStatusToStorageStatus); } - public Either, JanusGraphOperationStatus> getAllRelationshipTypes() { + public Either, JanusGraphOperationStatus> getAllRelationshipTypes(final String model) { Map relationshipTypeDefinitionMap = new HashMap<>(); Either, JanusGraphOperationStatus> result = Either.left(relationshipTypeDefinitionMap); Either, JanusGraphOperationStatus> getAllRelationshipTypes = janusGraphGenericDao - .getByCriteria(NodeTypeEnum.RelationshipType, null, RelationshipTypeData.class); + .getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, model, RelationshipTypeData.class); if (getAllRelationshipTypes.isRight()) { JanusGraphOperationStatus status = getAllRelationshipTypes.right().value(); if (status != JanusGraphOperationStatus.NOT_FOUND) { diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java index 1cc13364a5..6551a13981 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Map.Entry; import fj.data.Either; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.Before; @@ -155,9 +156,9 @@ public class RelationshipTypeOperationTest extends ModelTestBase { @Test public void testGetAllRelationshipTypesNotFound() { Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when( - janusGraphGenericDao).getByCriteria(NodeTypeEnum.RelationshipType, null, + janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, null, RelationshipTypeData.class); - Either, JanusGraphOperationStatus> either = relationshipTypeOperation.getAllRelationshipTypes(); + Either, JanusGraphOperationStatus> either = relationshipTypeOperation.getAllRelationshipTypes(null); assertTrue(either.isLeft() && MapUtils.isEmpty(either.left().value())); } @@ -165,9 +166,9 @@ public class RelationshipTypeOperationTest extends ModelTestBase { @Test public void testGetAllRelationshipTypesNotConnnected() { Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_CONNECTED)).when( - janusGraphGenericDao).getByCriteria(NodeTypeEnum.RelationshipType, null, + janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, null, RelationshipTypeData.class); - Either, JanusGraphOperationStatus> either = relationshipTypeOperation.getAllRelationshipTypes(); + Either, JanusGraphOperationStatus> either = relationshipTypeOperation.getAllRelationshipTypes(null); assertTrue(either.isRight() && JanusGraphOperationStatus.NOT_CONNECTED == either.right().value()); } @@ -185,7 +186,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { relationshipTypeDataList.add(relationshipTypeData1); Mockito.doReturn(Either.left(relationshipTypeDataList)) - .when(janusGraphGenericDao).getByCriteria(NodeTypeEnum.RelationshipType, null, + .when(janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, null, RelationshipTypeData.class); Mockito.doReturn(Either.left(relationshipTypeData1)).when(janusGraphGenericDao) @@ -203,11 +204,18 @@ public class RelationshipTypeOperationTest extends ModelTestBase { .getDerivedFromChild("tosca.relationships.Root1", NodeTypeEnum.RelationshipType, RelationshipTypeData.class); Either, JanusGraphOperationStatus> either = - relationshipTypeOperation.getAllRelationshipTypes(); + relationshipTypeOperation.getAllRelationshipTypes(null); assertTrue(either.isLeft()); RelationshipTypeDefinition relationshipTypeDefinition = either.left().value().get("tosca.relationships.Root1"); assertEquals("tosca.relationships.Parent", relationshipTypeDefinition.getDerivedFrom()); + + Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)) + .when(janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, "modelA", + RelationshipTypeData.class); + either = relationshipTypeOperation.getAllRelationshipTypes("modelA"); + assertTrue(either.isLeft()); + assertTrue(MapUtils.isEmpty(either.left().value())); } public RelationshipTypeDefinition createRelationship(String relationshipTypeName) { -- cgit 1.2.3-korg