diff options
author | Sindhuri.A <arcot.sindhuri@huawei.com> | 2018-09-07 13:53:56 +0530 |
---|---|---|
committer | Michael Lando <michael.lando@intl.att.com> | 2018-10-16 16:44:31 +0000 |
commit | 2e6a7eb218ad07a19fd1cc09b94e1f6a82e05360 (patch) | |
tree | f7fb008af54738f0771b459c92e809e2c2e70544 /catalog-be/src/test/java | |
parent | e6c3c72677709af1135948b490a99d8f0c6a48bd (diff) |
Single node copy paste keyboard shorcut on canvas
Keyboard Shortcut copy paste for single node on Composition page canvas for services
Issue-ID: SDC-1736
Change-Id: I669a728d3641a59ba7a4d8cc18fdae1000a0377f
Signed-off-by: Sindhuri.A <arcot.sindhuri@huawei.com>
Diffstat (limited to 'catalog-be/src/test/java')
2 files changed, 256 insertions, 4 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 1a6483009d..929bb97281 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,6 +1,5 @@ package org.openecomp.sdc.be.components.impl; -import static org.junit.Assert.assertSame; import static org.assertj.core.api.Assertions.assertThat; import fj.data.Either; @@ -16,14 +15,18 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.jsongraph.TitanDao; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; +import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; import org.openecomp.sdc.be.datatypes.elements.*; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.info.CreateAndAssotiateInfo; @@ -32,19 +35,22 @@ import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.jsontitan.operations.ForwardingPathOperation; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation; import org.openecomp.sdc.be.user.UserBusinessLogic; +import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; import org.openecomp.sdc.exception.ResponseFormat; import java.util.function.BiPredicate; import static org.junit.Assert.assertTrue; +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.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; @@ -86,6 +92,13 @@ public class ComponentInstanceBusinessLogicTest { private User user; @Mock private UserValidations userValidations; + @Mock + private TitanDao titanDao; + @Mock + private ArtifactsBusinessLogic artifactBusinessLogic; + @Mock + private GraphLockOperation graphLockOperation; + private Component service; private Component resource; private ComponentInstance toInstance; @@ -158,8 +171,8 @@ public class ComponentInstanceBusinessLogicTest { Either<Set<String>, ResponseFormat> resultOp = componentInstanceBusinessLogic.forwardingPathOnVersionChange (containerComponentParam,containerComponentID,componentInstanceID,newComponentInstance); - Assert.assertEquals(1,resultOp.left().value().size()); - Assert.assertEquals("FP-ID-1",resultOp.left().value().iterator().next()); + assertEquals(1,resultOp.left().value().size()); + assertEquals("FP-ID-1",resultOp.left().value().iterator().next()); } @@ -1067,4 +1080,205 @@ public class ComponentInstanceBusinessLogicTest { when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource)); result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, properties, userId); } + + @Test + public void testCopyComponentInstanceWrongUserId() { + + Either<Map<String, ComponentInstance>, ResponseFormat> result; + ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource); + String containerComponentId = service.getUniqueId(); + String componentInstanceId = resource.getUniqueId(); + String oldLastUpdatedUserId = service.getLastUpdaterUserId(); + service.setLastUpdaterUserId("wrong user id"); + + Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service); + when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp); + when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class))) + .thenReturn(leftServiceOp); + when(titanDao.rollback()).thenReturn(TitanOperationStatus.OK); + when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + + result = componentInstanceBusinessLogic + .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID); + + service.setLastUpdaterUserId(oldLastUpdatedUserId); + + assertThat(result.isRight()); + } + + @Test + public void testCopyComponentInstanceComponentWrongState() { + Either<Map<String, ComponentInstance>, ResponseFormat> result; + ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource); + String containerComponentId = service.getUniqueId(); + String componentInstanceId = resource.getUniqueId(); + String oldServiceLastUpdatedUserId = service.getLastUpdaterUserId(); + service.setLastUpdaterUserId(USER_ID); + + Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service); + when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp); + when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class))) + .thenReturn(leftServiceOp); + when(titanDao.rollback()).thenReturn(TitanOperationStatus.OK); + when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + Either<Component, StorageOperationStatus> getComponentRes = Either.left(resource); + when(toscaOperationFacade.getToscaFullElement(inputComponentInstance.getComponentUid())) + .thenReturn(getComponentRes); + + result = componentInstanceBusinessLogic + .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID); + + service.setLastUpdaterUserId(oldServiceLastUpdatedUserId); + + assertThat(result.isRight()); + } + + @Test + public void testCopyComponentInstance() { + Either<Map<String, ComponentInstance>, ResponseFormat> result; + ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource); + String containerComponentId = service.getUniqueId(); + String componentInstanceId = resource.getUniqueId(); + String oldServiceLastUpdatedUserId = service.getLastUpdaterUserId(); + service.setLastUpdaterUserId(USER_ID); + LifecycleStateEnum oldResourceLifeCycle = resource.getLifecycleState(); + resource.setLifecycleState(LifecycleStateEnum.CERTIFIED); + + Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service); + when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp); + when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class))) + .thenReturn(leftServiceOp); + when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service))) + .thenReturn(StorageOperationStatus.OK); + Either<Component, StorageOperationStatus> getComponentRes = Either.left(resource); + when(toscaOperationFacade.getToscaFullElement(inputComponentInstance.getComponentUid())) + .thenReturn(getComponentRes); + ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, TO_INSTANCE_ID); + Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair); + when(toscaOperationFacade + .addComponentInstanceToTopologyTemplate(eq(service), eq(resource), eq(inputComponentInstance), eq(false), + isNull(User.class))).thenReturn(result2); + Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = Either + .left(new HashMap<String, ArtifactDefinition>()); + when(artifactBusinessLogic.getArtifacts(eq(inputComponentInstance.getComponentUid()), eq(NodeTypeEnum.Resource), + eq(ArtifactGroupTypeEnum.DEPLOYMENT), isNull(String.class))).thenReturn(getResourceDeploymentArtifacts); + StorageOperationStatus artStatus = StorageOperationStatus.OK; + when(toscaOperationFacade + .addInformationalArtifactsToInstance(eq(resource.getUniqueId()), eq(inputComponentInstance), + isNull(Map.class))).thenReturn(artStatus); + + result = componentInstanceBusinessLogic + .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID); + + service.setLastUpdaterUserId(oldServiceLastUpdatedUserId); + resource.setLifecycleState(oldResourceLifeCycle); + + assertThat(result.isLeft()); + } + + @Test + public void testCreateOrUpdateAttributeValueForCopyPaste() { + ComponentInstance serviceComponentInstance = createComponetInstanceFromComponent(service); + ComponentInstanceProperty attribute = new ComponentInstanceProperty(); + attribute.setType("string"); + attribute.setUniqueId("testCreateOrUpdateAttributeValueForCopyPaste"); + SchemaDefinition def = Mockito.mock(SchemaDefinition.class); + attribute.setSchema(def); + LifecycleStateEnum oldLifeCycleState = service.getLifecycleState(); + String oldLastUpdatedUserId = service.getLastUpdaterUserId(); + service.setLastUpdaterUserId(USER_ID); + service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); + + Map<String, List<ComponentInstanceProperty>> instAttrsMap = new HashMap<String, List<ComponentInstanceProperty>>(); + List<ComponentInstanceProperty> instAttrsList = new ArrayList<ComponentInstanceProperty>(); + ComponentInstanceProperty prop = new ComponentInstanceProperty(); + prop.setUniqueId(attribute.getUniqueId()); + instAttrsList.add(prop); + instAttrsMap.put(toInstance.getUniqueId(), instAttrsList); + service.setComponentInstancesAttributes(instAttrsMap); + + Either<Component, StorageOperationStatus> serviceEitherLeft = Either.left(service); + when(toscaOperationFacade.getToscaElement(serviceComponentInstance.getUniqueId(), JsonParseFlagEnum.ParseAll)).thenReturn(serviceEitherLeft); + when(toscaOperationFacade.updateComponentInstanceAttribute(service, toInstance.getUniqueId(), attribute)).thenReturn(StorageOperationStatus.OK); + when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service)).thenReturn(serviceEitherLeft); + + Either<ComponentInstanceProperty, ResponseFormat> result = Deencapsulation.invoke(componentInstanceBusinessLogic, "createOrUpdateAttributeValueForCopyPaste", ComponentTypeEnum.SERVICE, + serviceComponentInstance.getUniqueId(), + toInstance.getUniqueId(), + attribute, + USER_ID); + + service.setLastUpdaterUserId(oldLastUpdatedUserId); + service.setLifecycleState(oldLifeCycleState); + + assertTrue(result.isLeft()); + ComponentInstanceProperty resultProp = result.left().value(); + assertEquals(resultProp.getPath().size(), 1); + assertEquals(resultProp.getPath().get(0), toInstance.getUniqueId()); + } + + @Test + public void testUpdateComponentInstanceProperty() { + + String containerComponentId = service.getUniqueId(); + String componentInstanceId = "dummy_id"; + ComponentInstanceProperty property = Mockito.mock(ComponentInstanceProperty.class); + + Either<Component, StorageOperationStatus> getComponent = Either.left(service); + when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(getComponent); + StorageOperationStatus status = StorageOperationStatus.OK; + when(toscaOperationFacade.updateComponentInstanceProperty(service, componentInstanceId, property)) + .thenReturn(status); + Either<Component, StorageOperationStatus> updateContainerRes = Either.left(service); + when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service)) + .thenReturn(updateContainerRes); + + Either<String, ResponseFormat> result = Deencapsulation + .invoke(componentInstanceBusinessLogic, "updateComponentInstanceProperty", containerComponentId, + componentInstanceId, property); + + assertTrue(result.isLeft()); + } + + @Test + public void testGetInputListDefaultValue() { + Component component = service; + String inputId = "dummy_id"; + String defaultValue = "dummy_default_value"; + List<InputDefinition> newInputs = new ArrayList<InputDefinition>(); + InputDefinition in = new InputDefinition(); + in.setUniqueId(inputId); + in.setDefaultValue(defaultValue); + newInputs.add(in); + List<InputDefinition> oldInputs = service.getInputs(); + service.setInputs(newInputs); + + Either<String, ResponseFormat> result = Deencapsulation + .invoke(componentInstanceBusinessLogic, "getInputListDefaultValue", component, inputId); + + service.setInputs(oldInputs); + + assertEquals(result.left().value(), defaultValue); + } + + private ComponentInstance createComponetInstanceFromComponent(Component component) { + ComponentInstance componentInst = new ComponentInstance(); + componentInst.setUniqueId(component.getUniqueId()); + componentInst.setComponentUid(component.getUniqueId() + "_test"); + componentInst.setPosX("10"); + componentInst.setPosY("10"); + componentInst.setCapabilities(component.getCapabilities()); + componentInst.setRequirements(component.getRequirements()); + componentInst.setArtifacts(component.getArtifacts()); + componentInst.setDeploymentArtifacts(component.getDeploymentArtifacts()); + return componentInst; + } } 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 0c91b49fee..d8e7896d71 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 @@ -1,6 +1,10 @@ package org.openecomp.sdc.be.servlets; import fj.data.Either; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.ws.rs.client.Entity; import org.eclipse.jetty.http.HttpStatus; import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.server.ResourceConfig; @@ -16,7 +20,10 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.impl.WebAppContextWrapper; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; +import org.openecomp.sdc.be.model.RequirementDefinition; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.context.ApplicationContext; @@ -31,6 +38,7 @@ 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; @@ -94,6 +102,36 @@ public class ComponentInstanceServletTest extends JerseyTest { assertEquals(response.getStatus(), HttpStatus.BAD_REQUEST_400); } + @Test + public void testCopyComponentInstanceSuccess(){ + + String componentId = "componentId"; + String componentInstanceId = "componentInstanceId"; + String path = "/v1/catalog/services/" + componentId + "/copyComponentInstance/" + componentInstanceId; + + Either<Map<String, ComponentInstance>, ResponseFormat> successResponse = Either.left(new HashMap<String, ComponentInstance>()); + when(componentInstanceBusinessLogic.copyComponentInstance(any(ComponentInstance.class), eq(componentId), eq(componentInstanceId), eq(USER_ID))).thenReturn(successResponse); + when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200); + when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat); + + ComponentInstance c = new ComponentInstance(); + c.setName("comp1"); + c.setUniqueId("comp1"); + c.setComponentUid("comp1"); + c.setPosX("10"); + c.setPosY("10"); + c.setCapabilities(new HashMap<String, List<CapabilityDefinition>>()); + c.setRequirements(new HashMap<String, List<RequirementDefinition>>()); + + Response response = target() + .path(path) + .request(MediaType.APPLICATION_JSON) + .header("USER_ID", USER_ID) + .post(Entity.json(c)); + + assertEquals(response.getStatus(), HttpStatus.OK_200); + } + @Override protected ResourceConfig configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); |