summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-06-19 19:51:24 +0300
committerMichael Lando <ml636r@att.com>2017-06-19 19:54:06 +0300
commit6e60006d2e22665b491d176ca9e91b74326bfabc (patch)
tree47e30ee9661e172e73f0e35bf198d5b3c70db8dd /catalog-be/src/test
parent4d97d5fac309ce0d66938e5ccd0349e2660d4e23 (diff)
[sdc] update to the current code base
and support http Change-Id: I2fb35494b40126a8395b1e309a180db4127754b7 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactResolverTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java109
2 files changed, 109 insertions, 2 deletions
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<String, List<ComponentInstanceInput>> 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<List<ComponentInstanceInput>, 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<List<ComponentInstanceInput>, 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<List<ComponentInstanceInput>, ResponseFormat> componentInstanceInputs = testInstance.getComponentInstanceInputs(USER_ID, COMPONENT_ID, COMPONENT_INSTANCE_ID);
+ assertEquals(Collections.emptyList(), componentInstanceInputs.left().value());
+ }
+
+}