From 6e60006d2e22665b491d176ca9e91b74326bfabc Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Mon, 19 Jun 2017 19:51:24 +0300 Subject: [sdc] update to the current code base and support http Change-Id: I2fb35494b40126a8395b1e309a180db4127754b7 Signed-off-by: Michael Lando --- .../be/components/impl/ArtifactResolverTest.java | 2 - .../components/impl/InputsBusinessLogicTest.java | 109 +++++++++++++++++++++ 2 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java (limited to 'catalog-be/src/test/java/org') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactResolverTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactResolverTest.java index fd7717a769..1ff6f853d9 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactResolverTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactResolverTest.java @@ -8,14 +8,12 @@ import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.Service; - import java.util.Collections; import java.util.Map; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; - public class ArtifactResolverTest { private ArtifactResolverImpl testInstance = new ArtifactResolverImpl(); 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 new file mode 100644 index 0000000000..97b425db05 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java @@ -0,0 +1,109 @@ +package org.openecomp.sdc.be.components.impl; + +import fj.data.Either; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +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.ComponentParametersView; +import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; +import org.openecomp.sdc.be.model.operations.impl.PropertyOperation; +import org.openecomp.sdc.be.user.IUserBusinessLogic; +import org.openecomp.sdc.exception.ResponseFormat; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class InputsBusinessLogicTest { + + private static final String COMPONENT_INSTANCE_ID = "instanceId"; + 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; + + @Mock + private IUserBusinessLogic userAdminMock; + + @Mock + private ToscaOperationFacade toscaOperationFacadeMock; + + @InjectMocks + private InputsBusinessLogic testInstance; + + private Service service; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + service = new Service(); + service.setUniqueId(COMPONENT_INSTANCE_ID); + ComponentInstance componentInstance = new ComponentInstance(); + componentInstance.setUniqueId(COMPONENT_INSTANCE_ID); + service.setComponentInstances(Collections.singletonList(componentInstance)); + + Map> instanceInputMap = new HashMap<>(); + ComponentInstanceInput componentInstanceInput = new ComponentInstanceInput(); + componentInstanceInput.setInputId(INSTANCE_INPUT_ID); + instanceInputMap.put(COMPONENT_INSTANCE_ID, Collections.singletonList(componentInstanceInput)); + instanceInputMap.put("someInputId", Collections.singletonList(new ComponentInstanceInput())); + service.setComponentInstancesInputs(instanceInputMap); + + Mockito.when(userAdminMock.getUser(USER_ID, false)).thenReturn(Either.left(new User())); + } + + @Test + public void getComponentInstanceInputs_ComponentInstanceNotExist() throws Exception { + Mockito.when(toscaOperationFacadeMock.getToscaElement(Mockito.eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(service)); + Either, ResponseFormat> componentInstanceInputs = testInstance.getComponentInstanceInputs(USER_ID, COMPONENT_ID, "nonExisting"); + assertTrue(componentInstanceInputs.isRight()); + Mockito.verify(componentsUtilsMock).getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND); + } + + @Test + public void getComponentInstanceInputs_emptyInputsMap() throws Exception { + service.setComponentInstancesInputs(Collections.emptyMap()); + getComponents_emptyInputs(service); + } + + @Test + public void getComponentInstanceInputs_nullInputsMap() throws Exception { + service.setComponentInstancesInputs(null); + getComponents_emptyInputs(service); + } + + @Test + public void getComponentInstanceInputs_instanceHasNoInputs() throws Exception { + service.setComponentInstancesInputs(Collections.singletonMap("someInputId", new ArrayList<>())); + getComponents_emptyInputs(service); + } + + @Test + public void getComponentInstanceInputs() throws Exception { + Mockito.when(toscaOperationFacadeMock.getToscaElement(Mockito.eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(service)); + Either, ResponseFormat> componentInstanceInputs = testInstance.getComponentInstanceInputs(USER_ID, COMPONENT_ID, COMPONENT_INSTANCE_ID); + assertEquals("inputId", componentInstanceInputs.left().value().get(0).getInputId()); + } + + private void getComponents_emptyInputs(Service service) { + Mockito.when(toscaOperationFacadeMock.getToscaElement(Mockito.eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(service)); + Either, ResponseFormat> componentInstanceInputs = testInstance.getComponentInstanceInputs(USER_ID, COMPONENT_ID, COMPONENT_INSTANCE_ID); + assertEquals(Collections.emptyList(), componentInstanceInputs.left().value()); + } + +} -- cgit 1.2.3-korg