aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorisaac.manuelraj <isaac.manuelraj@huawei.com>2018-11-28 15:19:51 +0530
committerTal Gitelman <tal.gitelman@att.com>2019-01-08 15:37:03 +0000
commita1f23ec5e7cd191b76271b5f33c237bad38c61c6 (patch)
treef7bbf3ec53cbe7cdcb5cec571738aad0b6dea075
parentbf3624457b4747338b07379aab70a840adaa96ad (diff)
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 <isaac.manuelraj@huawei.com>
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java113
1 files changed, 113 insertions, 0 deletions
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<List<InputDefinition>, 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<List<InputDefinition>, 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<List<ComponentInstanceProperty>, 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<List<ComponentInstanceProperty>, 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<List<ComponentInstanceProperty>, 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<List<ComponentInstanceInput>, 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<List<ComponentInstanceInput>, ResponseFormat> result = testInstance.getInputsForComponentInput("USR01", COMPONENT_ID,"INPO1");
+ assertEquals(true,result.isLeft());
+ }
}