diff options
Diffstat (limited to 'catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogicTest.java')
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogicTest.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogicTest.java new file mode 100644 index 0000000000..8e7949f108 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogicTest.java @@ -0,0 +1,82 @@ +package org.openecomp.sdc.be.components.merge.resource; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import java.util.Collections; + +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.merge.input.ComponentInputsMergeBL; +import org.openecomp.sdc.be.components.merge.property.ComponentInstanceInputsMergeBL; +import org.openecomp.sdc.be.components.merge.property.ComponentInstancePropertiesMergeBL; +import org.openecomp.sdc.be.components.utils.ObjectGenerator; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.model.Resource; + +public class ResourceDataMergeBusinessLogicTest { + + @InjectMocks + private ResourceDataMergeBusinessLogic testInstance; + + @Mock + private ComponentInstanceInputsMergeBL instanceInputsValueMergeBLMock; + + @Mock + private ComponentInstancePropertiesMergeBL instancePropertiesValueMergeBLMock; + + @Mock + private ComponentInputsMergeBL inputsValueMergeBLMock; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void mergeResourceInputs_allMergeClassesAreCalled() throws Exception { + Resource oldResource = ObjectGenerator.buildBasicResource(); + Resource newResource = ObjectGenerator.buildBasicResource(); + when(instancePropertiesValueMergeBLMock.mergeComponentInstancesProperties(oldResource, newResource)).thenReturn(ActionStatus.OK); + when(instanceInputsValueMergeBLMock.mergeComponentInstancesInputs(oldResource, newResource)).thenReturn(ActionStatus.OK); + when(inputsValueMergeBLMock.mergeAndRedeclareComponentInputs(oldResource, newResource, Collections.emptyList())).thenReturn(ActionStatus.OK); + ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource); + assertEquals(ActionStatus.OK, actionStatus); + } + + @Test + public void mergeResourceInputs_failToMergeProperties_dontCallOtherMergeMethods() throws Exception { + Resource oldResource = ObjectGenerator.buildBasicResource(); + Resource newResource = ObjectGenerator.buildBasicResource(); + when(instancePropertiesValueMergeBLMock.mergeComponentInstancesProperties(oldResource, newResource)).thenReturn(ActionStatus.GENERAL_ERROR); + ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource); + assertEquals(ActionStatus.GENERAL_ERROR, actionStatus); + verifyZeroInteractions(instanceInputsValueMergeBLMock, inputsValueMergeBLMock); + } + + @Test + public void mergeResourceInputs_failToMergeInstanceInputs_dontCallOtherMergeMethods() throws Exception { + Resource oldResource = ObjectGenerator.buildBasicResource(); + Resource newResource = ObjectGenerator.buildBasicResource(); + when(instancePropertiesValueMergeBLMock.mergeComponentInstancesProperties(oldResource, newResource)).thenReturn(ActionStatus.OK); + when(instanceInputsValueMergeBLMock.mergeComponentInstancesInputs(oldResource, newResource)).thenReturn(ActionStatus.GENERAL_ERROR); + ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource); + assertEquals(ActionStatus.GENERAL_ERROR, actionStatus); + verifyZeroInteractions(inputsValueMergeBLMock); + } + + @Test + public void mergeResourceInputs_failedToMergeInputs() throws Exception { + Resource oldResource = ObjectGenerator.buildBasicResource(); + Resource newResource = ObjectGenerator.buildBasicResource(); + when(instancePropertiesValueMergeBLMock.mergeComponentInstancesProperties(oldResource, newResource)).thenReturn(ActionStatus.OK); + when(instanceInputsValueMergeBLMock.mergeComponentInstancesInputs(oldResource, newResource)).thenReturn(ActionStatus.OK); + when(inputsValueMergeBLMock.mergeAndRedeclareComponentInputs(oldResource, newResource, Collections.emptyList())).thenReturn(ActionStatus.GENERAL_ERROR); + ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource); + assertEquals(ActionStatus.GENERAL_ERROR, actionStatus); + } +}
\ No newline at end of file |