From 51d50f0ef642e0f996a1c8b8d2ef4838bdfec892 Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Sun, 10 Dec 2017 18:55:03 +0200 Subject: Final commit to master merge from Change-Id: Ib464f9a8828437c86fe6def8af238aaf83473507 Issue-ID: SDC-714 Signed-off-by: Tal Gitelman --- .../ComponentInstanceInputsMergeBLTest.java | 120 +++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstanceInputsMergeBLTest.java (limited to 'catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstanceInputsMergeBLTest.java') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstanceInputsMergeBLTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstanceInputsMergeBLTest.java new file mode 100644 index 0000000000..0a858c9a29 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/ComponentInstanceInputsMergeBLTest.java @@ -0,0 +1,120 @@ +package org.openecomp.sdc.be.components.merge.property; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder; +import org.openecomp.sdc.be.components.utils.ResourceBuilder; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.ComponentInstanceInput; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; + +import fj.data.Either; + +public class ComponentInstanceInputsMergeBLTest { + + public static final String INSTANCE1 = "instance1"; + public static final String INSTANCE2 = "instance2"; + @InjectMocks + private ComponentInstanceInputsMergeBL testInstance; + + @Mock + private DataDefinitionsValuesMergingBusinessLogic propertyValuesMergingBusinessLogic; + + @Mock + private ToscaOperationFacade toscaOperationFacade; + + @Mock + private ComponentsUtils componentsUtils; + + private Resource oldResource, newResource; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + ComponentInstance instance1 = new ComponentInstanceBuilder().setId(INSTANCE1).setName(INSTANCE1).build(); + ComponentInstance instance2 = new ComponentInstanceBuilder().setId(INSTANCE2).setName(INSTANCE2).build(); + + oldResource = new ResourceBuilder() + .addInstanceInput(INSTANCE1, "property1") + .addInstanceInput(INSTANCE1, "property2") + .addInstanceInput(INSTANCE2, "property3") + .addComponentInstance(instance1) + .addComponentInstance(instance2) + .addInput("input1") + .addInput("input2").build(); + + newResource = new ResourceBuilder() + .addInstanceInput(INSTANCE1, "property11") + .addInstanceInput(INSTANCE1, "property12") + .addInstanceInput(INSTANCE2, "property13") + .addComponentInstance(instance1) + .addComponentInstance(instance2) + .addInput("input11") + .addInput("input12").build(); + } + + @Test + public void mergeInstancesInputs() throws Exception { + when(toscaOperationFacade.updateComponentInstanceInputsToComponent(newResource.getComponentInstancesInputs(), newResource.getUniqueId())).thenReturn(Either.left(Collections.emptyMap())); + ActionStatus actionStatus = testInstance.mergeComponentInstancesInputs(oldResource, newResource); + assertEquals(actionStatus, ActionStatus.OK); + verifyMergeBLCalled(oldResource, newResource); + } + + @Test + public void mergeInstancesInputs_failure() throws Exception { + when(toscaOperationFacade.updateComponentInstanceInputsToComponent(newResource.getComponentInstancesInputs(), newResource.getUniqueId())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR)); + when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.GENERAL_ERROR)).thenReturn(ActionStatus.GENERAL_ERROR); + verifyNoMoreInteractions(toscaOperationFacade, propertyValuesMergingBusinessLogic); + ActionStatus actionStatus = testInstance.mergeComponentInstancesInputs(oldResource, newResource); + assertEquals(ActionStatus.GENERAL_ERROR, actionStatus); + } + + @Test + public void mergeInstanceProps() throws Exception { + List newInstanceInputs = newResource.safeGetComponentInstanceInput(INSTANCE1); + List oldInstInputs = oldResource.safeGetComponentInstanceInput(INSTANCE1); + when(toscaOperationFacade.updateComponentInstanceInputs(newResource, INSTANCE1, newInstanceInputs)) + .thenReturn(StorageOperationStatus.OK); + ActionStatus actionStatus = testInstance.mergeComponentInstanceInputs(oldInstInputs, oldResource.getInputs(), newResource, INSTANCE1); + assertEquals(actionStatus, ActionStatus.OK); + verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(oldInstInputs, oldResource.getInputs(), newInstanceInputs, newResource.getInputs()); + } + + @Test + public void mergeInstanceProps_failure() throws Exception { + List newInstanceInputs = newResource.safeGetComponentInstanceInput(INSTANCE1); + List oldInstInputs = oldResource.safeGetComponentInstanceInput(INSTANCE1); + when(toscaOperationFacade.updateComponentInstanceInputs(newResource, INSTANCE1, newInstanceInputs)) + .thenReturn(StorageOperationStatus.GENERAL_ERROR); + when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.GENERAL_ERROR)).thenReturn(ActionStatus.GENERAL_ERROR); + ActionStatus actionStatus = testInstance.mergeComponentInstanceInputs(oldInstInputs, oldResource.getInputs(), newResource, INSTANCE1); + assertEquals(actionStatus, ActionStatus.GENERAL_ERROR); + verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(oldInstInputs, oldResource.getInputs(), newInstanceInputs, newResource.getInputs()); + } + + private void verifyMergeBLCalled(Resource oldResource, Resource newResource) { + List instance1oldInputs = oldResource.getComponentInstancesInputs().get(INSTANCE1); + List instance1newInputs = newResource.getComponentInstancesInputs().get(INSTANCE1); + List instance2oldInputs = oldResource.getComponentInstancesInputs().get(INSTANCE2); + List instance2newInputs = newResource.getComponentInstancesInputs().get(INSTANCE2); + verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(instance1oldInputs, oldResource.getInputs(), instance1newInputs, newResource.getInputs()); + verify(propertyValuesMergingBusinessLogic).mergeInstanceDataDefinitions(instance2oldInputs, oldResource.getInputs(), instance2newInputs, newResource.getInputs()); + } + +} \ No newline at end of file -- cgit 1.2.3-korg