From 3fac426ccbba4a1e4e52e17c8496f342093fcf42 Mon Sep 17 00:00:00 2001 From: "Sindhuri.A" Date: Sat, 24 Nov 2018 12:28:45 +0530 Subject: UT-ToscaOperationFacade 6 UT for catalog be ToscaOperationFacade class Issue-ID: SDC-1775 Change-Id: I764b9c0f95414b47a757e9b946009b68afd49c72 Signed-off-by: Sindhuri.A --- .../operations/ToscaOperationFacadeTest.java | 123 ++++++++++++++++++++- 1 file changed, 119 insertions(+), 4 deletions(-) diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java index 9bcd9ff239..708611014a 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java @@ -60,6 +60,7 @@ import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement; import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum; import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; + import static org.assertj.core.api.Assertions.assertThat; import java.util.HashMap; @@ -67,6 +68,8 @@ import java.util.List; import java.util.Map; import java.util.ArrayList; import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -191,8 +194,7 @@ public class ToscaOperationFacadeTest { props.put(GraphPropertyEnum.UUID, component.getUUID()); props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); - TopologyTemplate toscaElement = new TopologyTemplate(); - toscaElement.setComponentType(ComponentTypeEnum.RESOURCE); + ToscaElement toscaElement = getToscaElementForTest(); when(topologyTemplateOperationMock.getToscaElement(ArgumentMatchers.eq(graphVertex),any(ComponentParametersView.class))).thenReturn(Either.left(toscaElement)); when(titanDaoMock.getByCriteria(ModelConverter.getVertexType(component), props)).thenReturn(Either.left(list)); result = testInstance.findLastCertifiedToscaElementByUUID(component); @@ -345,8 +347,7 @@ public class ToscaOperationFacadeTest { Either result; String id = "id"; GraphVertex graphVertex = getTopologyTemplateVertex(); - ToscaElement toscaElement = new TopologyTemplate(); - toscaElement.setComponentType(ComponentTypeEnum.RESOURCE); + ToscaElement toscaElement = getToscaElementForTest(); when(titanDaoMock.getVertexById(id, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(graphVertex)); when(topologyTemplateOperationMock.getToscaElement(any(GraphVertex.class), any(ComponentParametersView.class))).thenReturn(Either.left(toscaElement)); result = testInstance.getToscaElement(id, JsonParseFlagEnum.ParseAll); @@ -366,6 +367,120 @@ public class ToscaOperationFacadeTest { assertEquals(result, StorageOperationStatus.OK); } + @Test + public void testDelToscaComponent() { + Either result; + String componentId = "compId"; + GraphVertex graphVertex = getTopologyTemplateVertex(); + ToscaElement toscaElement = getToscaElementForTest(); + when(titanDaoMock.getVertexById(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(graphVertex)); + when(topologyTemplateOperationMock.deleteToscaElement(graphVertex)).thenReturn(Either.left(toscaElement)); + result = testInstance.deleteToscaComponent(componentId); + assertTrue(result.isLeft()); + } + + @Test + public void testGetLatestByToscaResourceName() { + Either result; + String toscaResourceName = "name"; + ToscaElement toscaElement = getToscaElementForTest(); + + Map propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); + propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName); + propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); + Map propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); + propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); + + List graphVertexList = new ArrayList<>(); + GraphVertex graphVertex = getTopologyTemplateVertex(); + graphVertex.setUniqueId(toscaResourceName); + Map props = new HashMap<>(); + props.put(GraphPropertyEnum.VERSION, "1.0"); + graphVertex.setMetadataProperties(props); + graphVertexList.add(graphVertex); + + when(titanDaoMock.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.left(graphVertexList)); + when(topologyTemplateOperationMock.getToscaElement(any(GraphVertex.class), any(ComponentParametersView.class))).thenReturn(Either.left(toscaElement)); + result = testInstance.getLatestByToscaResourceName(toscaResourceName); + assertTrue(result.isLeft()); + } + + @Test + public void testGetFollowed() { + Either, StorageOperationStatus> result; + String userId = "id"; + Set lifecycleStates = new HashSet<>(); + Set lastStateStates = new HashSet<>(); + lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); + lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); + lifecycleStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION); + lifecycleStates.add(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS); + lifecycleStates.add(LifecycleStateEnum.CERTIFIED); + lastStateStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION); + ComponentTypeEnum componentType = ComponentTypeEnum.RESOURCE; + List toscaEleList = new ArrayList<>(); + ToscaElement toscaElement = getToscaElementForTest(); + toscaEleList.add(toscaElement); + when(nodeTypeOperation.getFollowedComponent(userId, lifecycleStates, lastStateStates, componentType)).thenReturn(Either.left(toscaEleList)); + result = testInstance.getFollowed(userId, lifecycleStates, lastStateStates, componentType); + assertTrue(result.isLeft()); + assertEquals(1, result.left().value().size()); + } + + @Test + public void testGetBySystemName() { + Either, StorageOperationStatus> result; + String sysName = "sysName"; + ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE; + ToscaElement toscaElement = getToscaElementForTest(); + List componentVertices = new ArrayList<>(); + GraphVertex graphVertex = getTopologyTemplateVertex(); + componentVertices.add(graphVertex); + Map propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); + Map propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); + + propertiesToMatch.put(GraphPropertyEnum.SYSTEM_NAME, sysName); + propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentTypeEnum.name()); + + propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); + + when(titanDaoMock.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(componentVertices)); + when(topologyTemplateOperationMock.getToscaElement(any(GraphVertex.class), any(ComponentParametersView.class))).thenReturn(Either.left(toscaElement)); + result = testInstance.getBySystemName(componentTypeEnum, sysName); + assertTrue(result.isLeft()); + assertEquals(1, result.left().value().size()); + } + + @Test + public void testGetCompByNameAndVersion() { + Either result; + ComponentTypeEnum componentType = ComponentTypeEnum.RESOURCE; + String name = "name"; + String version = "1.0"; + JsonParseFlagEnum parseFlag = JsonParseFlagEnum.ParseAll; + List graphVertexList = new ArrayList<>(); + GraphVertex graphVertex = getTopologyTemplateVertex(); + graphVertexList.add(graphVertex); + ToscaElement toscaElement = getToscaElementForTest(); + Map hasProperties = new EnumMap<>(GraphPropertyEnum.class); + Map hasNotProperties = new EnumMap<>(GraphPropertyEnum.class); + + hasProperties.put(GraphPropertyEnum.NAME, name); + hasProperties.put(GraphPropertyEnum.VERSION, version); + hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true); + hasProperties.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name()); + when(titanDaoMock.getByCriteria(null, hasProperties, hasNotProperties, parseFlag)).thenReturn(Either.left(graphVertexList)); + when(topologyTemplateOperationMock.getToscaElement(any(GraphVertex.class), any(ComponentParametersView.class))).thenReturn(Either.left(toscaElement)); + result = testInstance.getComponentByNameAndVersion(componentType, name, version, parseFlag); + assertTrue(result.isLeft()); + } + + private ToscaElement getToscaElementForTest() { + ToscaElement toscaElement = new TopologyTemplate(); + toscaElement.setComponentType(ComponentTypeEnum.RESOURCE); + return toscaElement; + } + private Either associatePolicyToComponentWithStatus(StorageOperationStatus status) { PolicyDefinition policy = new PolicyDefinition(); String componentId = "componentId"; -- cgit 1.2.3-korg