From a1f23ec5e7cd191b76271b5f33c237bad38c61c6 Mon Sep 17 00:00:00 2001 From: "isaac.manuelraj" Date: Wed, 28 Nov 2018 15:19:51 +0530 Subject: Add new test cases on existing test class. Added new test cases for more coverage on top of existing class. Issue-ID: SDC-1774 Change-Id: Ibbf33eb594e1cc4db6dc233bc89fc1f63ab3a1c2 Signed-off-by: isaac.manuelraj --- .../components/impl/InputsBusinessLogicTest.java | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'catalog-be') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java index 934a35e98a..1e6370e095 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java @@ -32,6 +32,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.user.IUserBusinessLogic; import org.openecomp.sdc.exception.ResponseFormat; @@ -39,6 +40,7 @@ import java.util.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -49,6 +51,7 @@ public class InputsBusinessLogicTest { private static final String COMPONENT_ID = "componentId"; private static final String USER_ID = "userId"; public static final String INSTANCE_INPUT_ID = "inputId"; + @Mock private ComponentsUtils componentsUtilsMock; @@ -64,6 +67,9 @@ public class InputsBusinessLogicTest { @Mock private ComponentInstanceBusinessLogic componentInstanceBusinessLogic; + @Mock + private ComponentInstanceBusinessLogic componentInstanceBusinessLogic; + @InjectMocks private InputsBusinessLogic testInstance; @@ -153,4 +159,111 @@ public class InputsBusinessLogicTest { assertEquals(Collections.emptyList(), componentInstanceInputs.left().value()); } + @Test + public void testgetInputs_ARTIFACT_NOT_FOUND() throws Exception { + + when(componentsUtilsMock.convertFromStorageResponse(StorageOperationStatus.ARTIFACT_NOT_FOUND)).thenReturn(ActionStatus.ARTIFACT_NOT_FOUND); + when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND)); + Either, ResponseFormat> responseFormatEither = testInstance.getInputs("USR01", COMPONENT_ID); + assertEquals(true,responseFormatEither.isRight()); + + } + + @Test + public void testgetInputs_SUCCESS() throws Exception { + Component component = new Service(); + InputDefinition input= new InputDefinition(); + List inputlist = new ArrayList<>(); + inputlist.add(input); + component.setInputs(inputlist); + when(componentsUtilsMock.convertFromStorageResponse(StorageOperationStatus.ARTIFACT_NOT_FOUND)).thenReturn(ActionStatus.ARTIFACT_NOT_FOUND); + when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(component)); + Either, ResponseFormat> responseFormatEither = testInstance.getInputs("USR01", COMPONENT_ID); + assertEquals(inputlist,responseFormatEither.left().value()); + } + + @Test + public void testgetComponentInstancePropertiesByInputId_Artifactnotfound() throws Exception + { + Component component = new Service(); + InputDefinition input= new InputDefinition(); + List inputlist = new ArrayList<>(); + inputlist.add(input); + component.setInputs(inputlist); + when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND)); + Either, ResponseFormat> responseFormatEither = testInstance.getComponentInstancePropertiesByInputId("USR01", COMPONENT_ID,"INST0.1", "INPO1"); + assertEquals(true,responseFormatEither.isRight()); + } + + @Test + public void testgetComponentInstancePropertiesByInputId_PARENT_ARTIFACT_NOT_FOUND() throws Exception + { + Component component = new Service(); + InputDefinition input= new InputDefinition(); + List inputlist = new ArrayList<>(); + inputlist.add(input); + component.setInputs(inputlist); + ComponentInstance componentInstance = new ComponentInstance(); + componentInstance.setUniqueId("INST0.1"); + componentInstance.setComponentUid("RES0.1"); + List compinstancelist = new ArrayList<>(); + compinstancelist.add(componentInstance); + component.setComponentInstances(compinstancelist); + when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(component)); + when(toscaOperationFacadeMock.getToscaElement(eq("RES0.1"), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND)); + Either, ResponseFormat> responseFormatEither = testInstance.getComponentInstancePropertiesByInputId("USR01", COMPONENT_ID,"INST0.1", "INPO1"); + assertEquals(true,responseFormatEither.isRight()); + } + + @Test + public void testgetComponentInstancePropertiesByInputId() throws Exception + { + Component component = new Service(); + InputDefinition input= new InputDefinition(); + input.setUniqueId("INPO1"); + List inputlist = new ArrayList<>(); + inputlist.add(input); + component.setInputs(inputlist); + ComponentInstance componentInstance = new ComponentInstance(); + componentInstance.setUniqueId("INST0.1"); + componentInstance.setComponentUid("RES0.1"); + List compinstancelist = new ArrayList<>(); + compinstancelist.add(componentInstance); + component.setComponentInstances(compinstancelist); + when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(component)); + when(componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(Mockito.any(Component.class),eq("INPO1"))).thenReturn(compinstancelist); + //when(toscaOperationFacadeMock.getToscaElement(eq("RES0.1"), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND)); + when(toscaOperationFacadeMock.getToscaElement(eq("RES0.1"), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(component)); + Either, ResponseFormat> responseFormatEither = testInstance.getComponentInstancePropertiesByInputId("USR01", COMPONENT_ID,"INST0.1", "INPO1"); + assertEquals(compinstancelist,responseFormatEither.left().value()); + } + + @Test + public void testgetInputsForComponentInput_ARTIFACT_NOT_FOUND() throws Exception + { + when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND)); + Either, ResponseFormat> result = testInstance.getInputsForComponentInput("USR01", COMPONENT_ID,"INPO1"); + assertEquals(true,result.isRight()); + } + + @Test + public void testgetInputsForComponentInput() throws Exception + { + Component component = new Service(); + InputDefinition input= new InputDefinition(); + input.setUniqueId("INPO1"); + List inputlist = new ArrayList<>(); + inputlist.add(input); + component.setInputs(inputlist); + ComponentInstance componentInstance = new ComponentInstance(); + componentInstance.setUniqueId("INST0.1"); + componentInstance.setComponentUid("RES0.1"); + List compinstancelist = new ArrayList<>(); + compinstancelist.add(componentInstance); + component.setComponentInstances(compinstancelist); + when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(component)); + when(componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(Mockito.any(Component.class),eq("INPO1"))).thenReturn(compinstancelist); + Either, ResponseFormat> result = testInstance.getInputsForComponentInput("USR01", COMPONENT_ID,"INPO1"); + assertEquals(true,result.isLeft()); + } } -- cgit 1.2.3-korg