diff options
author | Sindhuri.A <arcot.sindhuri@huawei.com> | 2018-10-17 13:25:27 +0530 |
---|---|---|
committer | Tal Gitelman <tal.gitelman@att.com> | 2018-11-03 13:54:27 +0000 |
commit | 4eb4059162269fea685136572257a48345873ec7 (patch) | |
tree | ca8b99cbf45376b52ef2614ca0c52a5755873cfc /catalog-be/src/test/java/org | |
parent | c5f4d83f7841a6937346da80a35b608e6624d54b (diff) |
Batch delete keyboard shorcut on canvas
Keyboard Shortcut for batch delete (multiple select nodes and delete) on Composition page canvas
Issue-ID: SDC-1734
Change-Id: I7de5d95a1ca6ea27cdd257b20bfdc1ed9b0ce102
Signed-off-by: Sindhuri.A <arcot.sindhuri@huawei.com>
Diffstat (limited to 'catalog-be/src/test/java/org')
2 files changed, 306 insertions, 16 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java index 929bb97281..b5d937e0e8 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java @@ -1,3 +1,22 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ package org.openecomp.sdc.be.components.impl; import static org.assertj.core.api.Assertions.assertThat; @@ -47,12 +66,10 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anySet; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.when; /** * The test suite designed for test functionality of ComponentInstanceBusinessLogic class @@ -98,7 +115,7 @@ public class ComponentInstanceBusinessLogicTest { private ArtifactsBusinessLogic artifactBusinessLogic; @Mock private GraphLockOperation graphLockOperation; - + private Component service; private Component resource; private ComponentInstance toInstance; @@ -170,7 +187,7 @@ public class ComponentInstanceBusinessLogicTest { when(toscaOperationFacade.getToscaFullElement(eq(new_Comp_UID))).thenReturn(Either.left(component2)); Either<Set<String>, ResponseFormat> resultOp = componentInstanceBusinessLogic.forwardingPathOnVersionChange - (containerComponentParam,containerComponentID,componentInstanceID,newComponentInstance); + (containerComponentParam,containerComponentID,componentInstanceID,newComponentInstance); assertEquals(1,resultOp.left().value().size()); assertEquals("FP-ID-1",resultOp.left().value().iterator().next()); @@ -185,7 +202,7 @@ public class ComponentInstanceBusinessLogicTest { String componentInstanceID = "NodeA1"; Service component = new Service(); component.setComponentInstances(Arrays.asList(createComponentIstance("NodeA2"),createComponentIstance("NodeB2"), - createComponentIstance(componentInstanceID))); + createComponentIstance(componentInstanceID))); component.addForwardingPath(createPath("path1", componentInstanceID, "NodeB1", "1")); component.addForwardingPath(createPath("Path2", "NodeA2","NodeB2", "2")); @@ -195,7 +212,7 @@ public class ComponentInstanceBusinessLogicTest { final ComponentInstance ci = new ComponentInstance(); ci.setName(componentInstanceID); Either<ComponentInstance, ResponseFormat> responseFormatEither = componentInstanceBusinessLogic.deleteForwardingPathsRelatedTobeDeletedComponentInstance( - containerComponentID, containerComponentType, Either.left(ci)); + containerComponentID, containerComponentType, Either.left(ci)); assertThat(responseFormatEither.isLeft()).isEqualTo(true); } @@ -228,18 +245,18 @@ public class ComponentInstanceBusinessLogicTest { forwardingPath.setDestinationPortNumber("DestinationPortNumber"); forwardingPath.setUniqueId("FP-ID-1"); ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition = - new ListDataDefinition<>(); + new ListDataDefinition<>(); forwardingPathElementListDataDefinition.add( - new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY", - "nodeBcpType" , "nodeDcpName", - "nodeBcpName")); + new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY", + "nodeBcpType" , "nodeDcpName", + "nodeBcpName")); forwardingPath.setPathElements(forwardingPathElementListDataDefinition); Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>(); forwardingPaths.put("1122", forwardingPath); return forwardingPaths; } - @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") private void getServiceRelationByIdSuccess(Component component){ Either<Component, StorageOperationStatus> getComponentRes = Either.left(component); when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(getComponentRes); @@ -534,8 +551,8 @@ public class ComponentInstanceBusinessLogicTest { } @Ignore("test failing skipping for now") - @Test - public void testCreateComponentInstanceOnGraph2() { + @Test + public void testCreateComponentInstanceOnGraph2() { ComponentInstanceBusinessLogic testSubject; createResource(); resource.setName("name"); @@ -552,7 +569,7 @@ public class ComponentInstanceBusinessLogicTest { // default test testSubject=createTestSubject(); result=Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph", new Object[]{resource, resource, toInstance, user}); - } + } @Test public void testUpdateComponentInstanceMetadata() { @@ -1174,7 +1191,7 @@ public class ComponentInstanceBusinessLogicTest { when(toscaOperationFacade .addInformationalArtifactsToInstance(eq(resource.getUniqueId()), eq(inputComponentInstance), isNull(Map.class))).thenReturn(artStatus); - + result = componentInstanceBusinessLogic .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID); @@ -1269,6 +1286,169 @@ public class ComponentInstanceBusinessLogicTest { assertEquals(result.left().value(), defaultValue); } + @Test + public void testBatchDeleteComponentInstanceFailureWrongType() { + Map<String, List<String>> result; + List<String> componentInstanceIdList = new ArrayList<>(); + String containerComponentParam = "WRONG_TYPE"; + String containerComponentId = "containerComponentId"; + String componentInstanceId = "componentInstanceId"; + componentInstanceIdList.add(componentInstanceId); + String userId = USER_ID; + Map<String, List<String>> deleteErrorMap = new HashMap<>(); + List<String> deleteErrorIds = new ArrayList<>(); + deleteErrorIds.add(componentInstanceId); + deleteErrorMap.put("deleteFailedIds", deleteErrorIds); + + result = componentInstanceBusinessLogic + .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList, + userId); + + assertEquals(deleteErrorMap, result); + } + + @Test + public void testBatchDeleteComponentInstanceFailureCompIds() { + Map<String, List<String>> result; + String containerComponentParam = ComponentTypeEnum.SERVICE_PARAM_NAME; + String containerComponentId = "containerComponentId"; + String componentInstanceId = "componentInstanceId"; + List<String> componentInstanceIdList = new ArrayList<>(); + componentInstanceIdList.add(componentInstanceId); + String userId = USER_ID; + Map<String, List<String>> deleteErrorMap = new HashMap<>(); + List<String> deleteErrorIds = new ArrayList<>(); + deleteErrorIds.add(componentInstanceId); + deleteErrorMap.put("deleteFailedIds", deleteErrorIds); + + Either<Component, StorageOperationStatus> err = Either.right(StorageOperationStatus.GENERAL_ERROR); + when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class))) + .thenReturn(err); + + result = componentInstanceBusinessLogic + .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList, + userId); + + assertEquals(deleteErrorMap, result); + } + + @Test + public void testBatchDeleteComponentInstanceSuccess() { + Map<String, List<String>> result; + String containerComponentParam = ComponentTypeEnum.SERVICE_PARAM_NAME; + LifecycleStateEnum oldLifeCycleState = service.getLifecycleState(); + String oldLastUpdatedUserId = service.getLastUpdaterUserId(); + service.setLastUpdaterUserId(USER_ID); + service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); + String containerComponentId = service.getUniqueId(); + String componentInstanceId = TO_INSTANCE_ID; + String userId = USER_ID; + List<String> componentInstanceIdList = new ArrayList<>(); + componentInstanceIdList.add(componentInstanceId); + Map<String, List<String>> deleteErrorMap = new HashMap<>(); + List<String> deleteErrorIds = new ArrayList<>(); + deleteErrorMap.put("deleteFailedIds", deleteErrorIds); + + Either<Component, StorageOperationStatus> cont = Either.left(service); + when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, TO_INSTANCE_ID); + Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair); + when(toscaOperationFacade.deleteComponentInstanceFromTopologyTemplate(service, componentInstanceId)) + .thenReturn(result2); + when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class))) + .thenReturn(cont); + when(titanDao.commit()).thenReturn(TitanOperationStatus.OK); + + result = componentInstanceBusinessLogic + .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList, userId); + + service.setLastUpdaterUserId(oldLastUpdatedUserId); + service.setLifecycleState(oldLifeCycleState); + assertEquals(deleteErrorMap,result); + } + + @Test + public void testDissociateRIFromRIFailDissociate() { + + List<RequirementCapabilityRelDef> result; + RequirementCapabilityRelDef ref = new RequirementCapabilityRelDef(); + ref.setFromNode(FROM_INSTANCE_ID); + ref.setToNode(TO_INSTANCE_ID); + List<CapabilityRequirementRelationship> relationships = new ArrayList<>(); + CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship(); + RelationshipInfo ri = new RelationshipInfo(); + ri.setRequirement(REQUIREMENT_NAME); + relationship.setRelation(ri); + relationships.add(relationship); + ref.setRelationships(relationships); + List<RequirementCapabilityRelDef> requirementDefList = new ArrayList<>(); + requirementDefList.add(ref); + ComponentTypeEnum componentTypeEnum = service.getComponentType(); + String componentId = service.getUniqueId(); + String userId = USER_ID; + LifecycleStateEnum oldLifeCycleState = service.getLifecycleState(); + String oldLastUpdatedUserId = service.getLastUpdaterUserId(); + service.setLastUpdaterUserId(USER_ID); + service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); + + Either<Component, StorageOperationStatus> cont = Either.left(service); + when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class))) + .thenReturn(cont); + when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + Either<RequirementCapabilityRelDef, StorageOperationStatus> resultEither; + resultEither = Either.right(StorageOperationStatus.OK); + when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither); + + result = componentInstanceBusinessLogic + .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum); + + service.setLastUpdaterUserId(oldLastUpdatedUserId); + service.setLifecycleState(oldLifeCycleState); + + assertEquals(new ArrayList<>(), result); + } + + @Test + public void testDissociateRIFromRISuccess() { + + List<RequirementCapabilityRelDef> result; + RequirementCapabilityRelDef ref = new RequirementCapabilityRelDef(); + List<RequirementCapabilityRelDef> requirementDefList = new ArrayList<>(); + requirementDefList.add(ref); + ComponentTypeEnum componentTypeEnum = service.getComponentType(); + String componentId = service.getUniqueId(); + String userId = USER_ID; + LifecycleStateEnum oldLifeCycleState = service.getLifecycleState(); + String oldLastUpdatedUserId = service.getLastUpdaterUserId(); + service.setLastUpdaterUserId(USER_ID); + service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); + + Either<Component, StorageOperationStatus> cont = Either.left(service); + when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class))) + .thenReturn(cont); + when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + Either<RequirementCapabilityRelDef, StorageOperationStatus> resultEither; + resultEither = Either.left(ref); + when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither); + + result = componentInstanceBusinessLogic + .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum); + + service.setLastUpdaterUserId(oldLastUpdatedUserId); + service.setLifecycleState(oldLifeCycleState); + + assertEquals(requirementDefList, result); + } + private ComponentInstance createComponetInstanceFromComponent(Component component) { ComponentInstance componentInst = new ComponentInstance(); componentInst.setUniqueId(component.getUniqueId()); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java index d8e7896d71..7d05c697d5 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentInstanceServletTest.java @@ -4,6 +4,7 @@ import fj.data.Either; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.ArrayList; import javax.ws.rs.client.Entity; import org.eclipse.jetty.http.HttpStatus; import org.glassfish.hk2.utilities.binding.AbstractBinder; @@ -12,6 +13,7 @@ import org.glassfish.jersey.test.JerseyTest; import org.glassfish.jersey.test.TestProperties; import org.junit.BeforeClass; import org.junit.Test; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.config.SpringConfig; @@ -29,6 +31,8 @@ import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.web.context.WebApplicationContext; +import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.model.User; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -37,10 +41,11 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.nullable; /** * The test suite designed for test functionality of ComponentInstanceServlet class @@ -132,6 +137,111 @@ public class ComponentInstanceServletTest extends JerseyTest { assertEquals(response.getStatus(), HttpStatus.OK_200); } + @Test + public void testBatchDeleteResourceInstancesSuccess() { + + String componentId = "componentId"; + String containerComponentType = ComponentTypeEnum.SERVICE_PARAM_NAME; + String compId1 = "compId1"; + String[] delCompIds = new String[1]; + delCompIds[0] = compId1; + List<ComponentInstance> compInsts = new ArrayList<ComponentInstance>(); + String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/batchDeleteResourceInstances"; + + ComponentInstance compInst = new ComponentInstance(); + compInst.setName(compId1); + compInst.setUniqueId(compId1); + compInst.setComponentUid(compId1); + compInst.setInvariantName(compId1); + compInsts.add(compInst); + + when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200); + when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat); + Either<String[], ResponseFormat> convertStatusEither = Either.left(delCompIds); + when(componentsUtils + .convertJsonToObjectUsingObjectMapper(anyString(), any(User.class), ArgumentMatchers.<Class<String[]>>any(), + nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class))).thenReturn(convertStatusEither); + when(componentInstanceBusinessLogic + .batchDeleteComponentInstance(eq(containerComponentType), eq(componentId), any(List.class), + eq(USER_ID))).thenReturn(Mockito.mock(Map.class)); + + Response response = target() + .path(path) + .request(MediaType.APPLICATION_JSON) + .header("USER_ID", USER_ID) + .post(Entity.json(compInsts)); + + assertEquals(HttpStatus.OK_200, response.getStatus()); + } + + @Test + public void testBatchDeleteResourceInstancesFailure() { + + String componentId = "componentId"; + String containerComponentType = ComponentTypeEnum.SERVICE_PARAM_NAME; + String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/batchDeleteResourceInstances"; + + when(responseFormat.getStatus()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR_500); + when(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(responseFormat); + + Response response = target() + .path(path) + .request(MediaType.APPLICATION_JSON) + .header("USER_ID", USER_ID) + .post(Entity.json("")); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus()); + } + + @Test + public void testBatchDissociateRIFromRISuccess() { + + String componentId = "componentId"; + String containerComponentType = ComponentTypeEnum.SERVICE_PARAM_NAME; + String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/resourceInstance/batchDissociate"; + RequirementCapabilityRelDef[] refs = new RequirementCapabilityRelDef[1]; + RequirementCapabilityRelDef ref = new RequirementCapabilityRelDef(); + refs[0] = ref; + + when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200); + when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat); + Either<RequirementCapabilityRelDef[], ResponseFormat> convertReqEither = Either.left(refs); + when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class), + ArgumentMatchers.<Class<RequirementCapabilityRelDef[]>>any(), + nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class))).thenReturn(convertReqEither); + Either<RequirementCapabilityRelDef, ResponseFormat> actionResponseEither = Either.left(ref); + when(componentInstanceBusinessLogic + .dissociateRIFromRI(componentId, USER_ID, ref, ComponentTypeEnum.findByParamName(containerComponentType))) + .thenReturn(actionResponseEither); + + Response response = target() + .path(path) + .request(MediaType.APPLICATION_JSON) + .header("USER_ID", USER_ID) + .put(Entity.json(refs)); + + assertEquals(HttpStatus.OK_200, response.getStatus()); + } + + @Test + public void testBatchDissociateRIFromRIFailure() { + + String componentId = "componentId"; + String containerComponentType = ComponentTypeEnum.SERVICE_PARAM_NAME; + String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/resourceInstance/batchDissociate"; + + when(responseFormat.getStatus()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR_500); + when(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(responseFormat); + + Response response = target() + .path(path) + .request(MediaType.APPLICATION_JSON) + .header("USER_ID", USER_ID) + .put(Entity.json("")); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus()); + } + @Override protected ResourceConfig configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); |