aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java156
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java376
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java83
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java131
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java175
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclaratorTest.java50
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclaratorTest.java49
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java59
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclaratorTestBase.java4
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/InputsServletTest.java585
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java28
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaDataTypeTest.java60
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateTest.java21
14 files changed, 1594 insertions, 189 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java
new file mode 100644
index 0000000000..9219de1aac
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java
@@ -0,0 +1,156 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Fujitsu Limited. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+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.components.validation.UserValidations;
+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.DataTypeDefinition;
+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.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.user.IUserBusinessLogic;
+
+public class DataTypeBusinessLogicTest {
+
+ private static final String COMPONENT_INSTANCE_ID = "instanceId";
+ private static final String COMPONENT_ID = "componentId";
+ private static final String USER_ID = "userId";
+ private static final String INSTANCE_INPUT_ID = "inputId";
+ private static final String DATATYPE_NAME = "org.onap.datatypes.mytype";
+
+ @Mock
+ private ComponentsUtils componentsUtilsMock;
+
+ @Mock
+ private IUserBusinessLogic userAdminMock;
+
+ @Mock
+ private ToscaOperationFacade toscaOperationFacadeMock;
+
+ @Mock
+ private UserValidations userValidations;
+
+ @Mock
+ private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
+
+ @InjectMocks
+ private DataTypeBusinessLogic 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));
+ DataTypeDefinition dataType = new DataTypeDefinition();
+ dataType.setName(DATATYPE_NAME);
+ dataType.setDerivedFromName(ToscaPropertyType.Root.getType());
+ List<DataTypeDefinition> dataTypes = Arrays.asList(dataType);
+ service.setDataTypes(dataTypes);
+
+ 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);
+ when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(false))).thenReturn(new User());
+ when(userAdminMock.getUser(USER_ID, false)).thenReturn(Either.left(new User()));
+ }
+
+ @Test
+ public void test_getPrivateDataTypes() throws Exception {
+ setMockitoWhenGetToscaElementCalled();
+
+ Either<List<DataTypeDefinition>, StorageOperationStatus> result = testInstance.getPrivateDataTypes(COMPONENT_ID);
+ assertTrue(result.isLeft());
+ List<DataTypeDefinition> dataTypes = result.left().value();
+ assertEquals(service.getDataTypes(), dataTypes);
+ }
+
+ @Test
+ public void test_getPrivateDataType() throws Exception {
+ setMockitoWhenGetToscaElementCalled();
+
+ Either<DataTypeDefinition, StorageOperationStatus> result =
+ testInstance.getPrivateDataType(COMPONENT_ID, DATATYPE_NAME);
+ assertTrue(result.isLeft());
+ DataTypeDefinition dataType = result.left().value();
+ assertEquals(service.getDataTypes().get(0), dataType);
+ }
+
+ @Test
+ public void test_deletePrivateDataType1() throws Exception {
+ setMockitoWhenGetToscaElementCalled();
+ when(toscaOperationFacadeMock.deleteDataTypeOfComponent(service, DATATYPE_NAME))
+ .thenReturn(StorageOperationStatus.OK);
+
+ Either<DataTypeDefinition, StorageOperationStatus> result =
+ testInstance.deletePrivateDataType(COMPONENT_ID, DATATYPE_NAME);
+ assertTrue(result.isLeft());
+ DataTypeDefinition dataType = result.left().value();
+ assertEquals(service.getDataTypes().get(0), dataType);
+ }
+
+ @Test
+ public void test_deletePrivateDataType2() throws Exception {
+ when(toscaOperationFacadeMock.deleteDataTypeOfComponent(service, DATATYPE_NAME))
+ .thenReturn(StorageOperationStatus.OK);
+
+ Either<DataTypeDefinition, StorageOperationStatus> result =
+ testInstance.deletePrivateDataType(service, DATATYPE_NAME);
+ assertTrue(result.isLeft());
+ DataTypeDefinition dataType = result.left().value();
+ assertEquals(service.getDataTypes().get(0), dataType);
+ }
+
+ private void setMockitoWhenGetToscaElementCalled() {
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ }
+}
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 2ef3d463eb..b306b2ad72 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
@@ -21,18 +21,31 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
+import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.be.user.IUserBusinessLogic;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -40,9 +53,9 @@ 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.ArgumentMatchers.*;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class InputsBusinessLogicTest {
@@ -50,7 +63,13 @@ 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";
+ private static final String INSTANCE_INPUT_ID = "inputId";
+ private static final String LISTINPUT_NAME = "listInput";
+ private static final String LISTINPUT_SCHEMA_TYPE = "org.onap.datatypes.listinput";
+ private static final String LISTINPUT_PROP1_NAME = "prop1";
+ private static final String LISTINPUT_PROP1_TYPE = "string";
+ private static final String LISTINPUT_PROP2_NAME = "prop2";
+ private static final String LISTINPUT_PROP2_TYPE = "integer";
@Mock
private ComponentsUtils componentsUtilsMock;
@@ -67,26 +86,54 @@ public class InputsBusinessLogicTest {
@Mock
private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
+ @Mock
+ private IGraphLockOperation graphLockOperation;
+
+ @Mock
+ private PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
+
+ @Mock
+ private ApplicationDataTypeCache applicationDataTypeCache;
+
+ @Mock
+ private PropertyOperation propertyOperation;
+
+ @Mock
+ private TitanDao titanDao;
+
+ @Mock
+ private DataTypeBusinessLogic dataTypeBusinessLogic;
+
@InjectMocks
private InputsBusinessLogic testInstance;
private Service service;
+ @Captor
+ ArgumentCaptor<Map<String, DataTypeDefinition>> dataTypesMapCaptor;
+
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
service = new Service();
- service.setUniqueId(COMPONENT_INSTANCE_ID);
+ service.setUniqueId(COMPONENT_ID);
+ service.setLastUpdaterUserId(USER_ID);
+ service.setIsDeleted(false);
+ service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+
+ // add a ComponentInstance
ComponentInstance componentInstance = new ComponentInstance();
componentInstance.setUniqueId(COMPONENT_INSTANCE_ID);
service.setComponentInstances(Collections.singletonList(componentInstance));
+ // add inputs to the 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);
+
when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(false))).thenReturn(new User());
when(userAdminMock.getUser(USER_ID, false)).thenReturn(Either.left(new User()));
}
@@ -96,7 +143,7 @@ public class InputsBusinessLogicTest {
when(toscaOperationFacadeMock.getToscaElement(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);
+ verify(componentsUtilsMock).getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND);
}
@Test
@@ -263,4 +310,321 @@ public class InputsBusinessLogicTest {
Either<List<ComponentInstanceInput>, ResponseFormat> result = testInstance.getInputsForComponentInput("USR01", COMPONENT_ID,"INPO1");
assertEquals(true,result.isLeft());
}
+
+
+ private InputDefinition setUpListInput() {
+ InputDefinition listInput = new InputDefinition();
+ listInput.setName(LISTINPUT_NAME);
+ listInput.setType("list");
+ SchemaDefinition listInputSchema = new SchemaDefinition();
+ listInputSchema.setProperty(new PropertyDataDefinitionBuilder()
+ .setType(LISTINPUT_SCHEMA_TYPE)
+ .setIsRequired(false)
+ .build()
+ );
+ listInput.setSchema(listInputSchema);
+ return listInput;
+ }
+
+ private ComponentInstListInput setUpCreateListInputParams() {
+ ComponentInstListInput componentInstListInput = new ComponentInstListInput();
+
+ // Create a "list input"
+ InputDefinition listInput = setUpListInput();
+ componentInstListInput.setListInput(listInput);
+
+ // Create ComponentInstancePropInputs
+ // for inputs in the ComponentInstance
+ Map<String, List<ComponentInstancePropInput>> propInputsListMap = new HashMap<>();
+ // Add 2 PropInputs. property owner is COMPONENT_INSTANCE_ID
+ List<ComponentInstancePropInput> propInputsList = new ArrayList<>();
+ ComponentInstancePropInput propInput = new ComponentInstancePropInput();
+ propInput.setName(LISTINPUT_PROP1_NAME);
+ propInput.setType(LISTINPUT_PROP1_TYPE);
+ propInput.setUniqueId(COMPONENT_INSTANCE_ID+"."+LISTINPUT_PROP1_NAME);
+ propInputsList.add(propInput);
+ propInput = new ComponentInstancePropInput();
+ propInput.setName(LISTINPUT_PROP2_NAME);
+ propInput.setType(LISTINPUT_PROP2_TYPE);
+ propInput.setUniqueId(COMPONENT_INSTANCE_ID+"."+LISTINPUT_PROP2_NAME);
+ propInputsList.add(propInput);
+ propInputsListMap.put(COMPONENT_INSTANCE_ID, propInputsList);
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ componentInstInputsMap.setComponentInstanceInputsMap(propInputsListMap);
+ componentInstListInput.setComponentInstInputsMap(componentInstInputsMap);
+
+ return componentInstListInput;
+ }
+
+ @Test
+ public void test_createListInput_success() throws Exception {
+ ComponentInstListInput createListInputParams = setUpCreateListInputParams();
+ ComponentInstInputsMap componentInstInputsMap = createListInputParams.getComponentInstInputsMap();
+ List<ComponentInstancePropInput> propInputsList = componentInstInputsMap.getComponentInstanceInputsMap().get(COMPONENT_INSTANCE_ID);
+ InputDefinition listInput = createListInputParams.getListInput();
+
+ // set up mock returns
+ // for get component object:
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ // for data type creation (use captor):
+ when(toscaOperationFacadeMock.addDataTypesToComponent(dataTypesMapCaptor.capture(), eq(COMPONENT_ID))).thenReturn(Either.left(new ArrayList<>()));
+ when(propertyDeclarationOrchestrator.getPropOwnerId(componentInstInputsMap)).thenReturn(COMPONENT_INSTANCE_ID);
+ when(propertyDeclarationOrchestrator.declarePropertiesToListInput(service, componentInstInputsMap, listInput)).thenReturn(Either.left(listInput));
+ // for BaseOperation.getAllDataTypes:
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
+ // for BaseOperation.validatePropertyDefaultValue:
+ when(propertyOperation.isPropertyTypeValid(any())).thenReturn(true);
+ when(propertyOperation.isPropertyInnerTypeValid(any(),any())).thenReturn(new ImmutablePair<>(listInput.getSchemaType(), true));
+ when(propertyOperation.isPropertyDefaultValueValid(any(), any())).thenReturn(true);
+ // for createListInputsInGraph:
+ when(toscaOperationFacadeMock.addInputsToComponent(anyMap(), eq(COMPONENT_ID))).thenReturn(Either.left(Arrays.asList(listInput)));
+ // for rollback/commit:
+ when(titanDao.commit()).thenReturn(TitanOperationStatus.OK);
+ // for unlock resource
+ when(graphLockOperation.unlockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+
+ Either<List<InputDefinition>, ResponseFormat> result =
+ testInstance.createListInput(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, createListInputParams, true, false);
+ // validate result
+ assertEquals(true, result.isLeft());
+ List<InputDefinition> resultInputList = result.left().value();
+ assertEquals(1, resultInputList.size());
+ //InputDefinition resultInput = resultInputList.get(0);
+ Map<String, DataTypeDefinition> captoredDataTypeMap = dataTypesMapCaptor.getValue();
+ assertEquals(1, captoredDataTypeMap.size());
+ assertEquals(true, captoredDataTypeMap.containsKey(LISTINPUT_SCHEMA_TYPE));
+ DataTypeDefinition captoredDataType = captoredDataTypeMap.get(LISTINPUT_SCHEMA_TYPE);
+ assertEquals("tosca.datatypes.Root", captoredDataType.getDerivedFromName());
+ assertEquals( propInputsList.size(), captoredDataType.getProperties().size());
+ // confirm if corresponding property exists in data type
+ captoredDataType.getProperties().forEach(dataTypeProp -> {
+ Optional<ComponentInstancePropInput> find = propInputsList.stream()
+ .filter(propInput -> propInput.getName().equals(dataTypeProp.getName())).findAny();
+ assertEquals(true, find.isPresent());
+ });
+ }
+
+ @Test
+ public void test_createListInput_fail_getComponent() throws Exception {
+ ComponentInstListInput createListInputParams = setUpCreateListInputParams();
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ Either<List<InputDefinition>, ResponseFormat> result =
+ testInstance.createListInput(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, createListInputParams, true, false);
+ assertEquals(true, result.isRight());
+ }
+
+
+ @Test
+ public void test_createListInput_fail_lockComponent() throws Exception {
+ ComponentInstListInput createListInputParams = setUpCreateListInputParams();
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.FAILED_TO_LOCK_ELEMENT);
+ Either<List<InputDefinition>, ResponseFormat> result =
+ testInstance.createListInput(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, createListInputParams, true, false);
+ assertEquals(true, result.isRight());
+ }
+
+ @Test
+ public void test_createListInput_fail_getAllDataTypes() throws Exception {
+ ComponentInstListInput createListInputParams = setUpCreateListInputParams();
+ ComponentInstInputsMap componentInstInputsMap = createListInputParams.getComponentInstInputsMap();
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.addDataTypesToComponent(dataTypesMapCaptor.capture(), eq(COMPONENT_ID))).thenReturn(Either.left(new ArrayList<>()));
+ when(propertyDeclarationOrchestrator.getPropOwnerId(componentInstInputsMap)).thenReturn(COMPONENT_INSTANCE_ID);
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
+ when(componentsUtilsMock.getResponseFormat(ActionStatus.DATA_TYPE_CANNOT_BE_EMPTY)).thenReturn(new ResponseFormat());
+
+ Either<List<InputDefinition>, ResponseFormat> result =
+ testInstance.createListInput(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, createListInputParams, true, false);
+ assertEquals(true, result.isRight());
+ verify(applicationDataTypeCache, times(1)).getAll();
+ verify(componentsUtilsMock, times(1)).getResponseFormat(ActionStatus.DATA_TYPE_CANNOT_BE_EMPTY);
+ }
+
+ @Test
+ public void test_createListInput_fail_prepareAndValidateInput() throws Exception {
+ ComponentInstListInput createListInputParams = setUpCreateListInputParams();
+ ComponentInstInputsMap componentInstInputsMap = createListInputParams.getComponentInstInputsMap();
+ InputDefinition listInput = createListInputParams.getListInput();
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.addDataTypesToComponent(dataTypesMapCaptor.capture(), eq(COMPONENT_ID))).thenReturn(Either.left(new ArrayList<>()));
+ when(propertyDeclarationOrchestrator.getPropOwnerId(componentInstInputsMap)).thenReturn(COMPONENT_INSTANCE_ID);
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
+ // for BaseOperation.validatePropertyDefaultValue:
+ when(propertyOperation.isPropertyTypeValid(any())).thenReturn(false);
+
+ Either<List<InputDefinition>, ResponseFormat> result =
+ testInstance.createListInput(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, createListInputParams, true, false);
+ assertEquals(true, result.isRight());
+ verify(propertyOperation, times(1)).isPropertyTypeValid(any());
+ }
+
+ @Test
+ public void test_createListInput_fail_addInputsToComponent() throws Exception {
+ ComponentInstListInput createListInputParams = setUpCreateListInputParams();
+ ComponentInstInputsMap componentInstInputsMap = createListInputParams.getComponentInstInputsMap();
+ InputDefinition listInput = createListInputParams.getListInput();
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.addDataTypesToComponent(dataTypesMapCaptor.capture(), eq(COMPONENT_ID))).thenReturn(Either.left(new ArrayList<>()));
+ when(propertyDeclarationOrchestrator.getPropOwnerId(componentInstInputsMap)).thenReturn(COMPONENT_INSTANCE_ID);
+ when(applicationDataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
+ // for BaseOperation.validatePropertyDefaultValue:
+ when(propertyOperation.isPropertyTypeValid(any())).thenReturn(true);
+ when(propertyOperation.isPropertyInnerTypeValid(any(),any())).thenReturn(new ImmutablePair<>(listInput.getSchemaType(), true));
+ when(propertyOperation.isPropertyDefaultValueValid(any(), any())).thenReturn(true);
+ when(toscaOperationFacadeMock.addInputsToComponent(anyMap(), eq(COMPONENT_ID))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+
+ Either<List<InputDefinition>, ResponseFormat> result =
+ testInstance.createListInput(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, createListInputParams, true, false);
+ assertEquals(true, result.isRight());
+ verify(toscaOperationFacadeMock, times(1)).addInputsToComponent(anyMap(), eq(COMPONENT_ID));
+ }
+
+ @Test
+ public void test_deleteInput_listInput_fail_getComponent() throws Exception {
+ //ComponentInstListInput createListInputParams = setUpCreateListInputParams();
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+
+ Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, LISTINPUT_NAME);
+ assertEquals(true, result.isRight());
+ verify(toscaOperationFacadeMock, times(1)).getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class));
+ }
+
+
+ @Test
+ public void test_deleteInput_listInput_fail_validateInput() throws Exception {
+ InputDefinition listInput = setUpListInput();
+ String inputId = COMPONENT_ID + "." + listInput.getName();
+ listInput.setUniqueId(inputId);
+ service.setInputs(Collections.singletonList(listInput));
+ //ComponentInstListInput createListInputParams = setUpCreateListInputParams();
+ final String NONEXIST_INPUT_NAME = "myInput";
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+
+ Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, NONEXIST_INPUT_NAME);
+ assertEquals(true, result.isRight());
+ verify(toscaOperationFacadeMock, times(1)).getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class));
+ }
+
+
+ @Test
+ public void test_deleteInput_listInput_fail_lockComponent() throws Exception {
+ InputDefinition listInput = setUpListInput();
+ String inputId = COMPONENT_ID + "." + listInput.getName();
+ listInput.setUniqueId(inputId);
+ service.setInputs(Collections.singletonList(listInput));
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ //when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.NOT_FOUND);
+
+ Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, inputId);
+ assertEquals(true, result.isRight());
+ verify(toscaOperationFacadeMock, times(1)).getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class));
+ verify(graphLockOperation, times(1)).lockComponent(COMPONENT_ID, NodeTypeEnum.Service);
+ }
+
+
+ @Test
+ public void test_deleteInput_listInput_fail_deleteInput() throws Exception {
+ InputDefinition listInput = setUpListInput();
+ String inputId = COMPONENT_ID + "." + listInput.getName();
+ listInput.setUniqueId(inputId);
+ service.setInputs(Collections.singletonList(listInput));
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.deleteInputOfResource(service, listInput.getName())).thenReturn(StorageOperationStatus.BAD_REQUEST);
+ when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+
+ Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, inputId);
+ assertEquals(true, result.isRight());
+ verify(toscaOperationFacadeMock, times(1)).getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class));
+ verify(graphLockOperation, times(1)).lockComponent(COMPONENT_ID, NodeTypeEnum.Service);
+ verify(toscaOperationFacadeMock, times(1)).deleteInputOfResource(service, listInput.getName());
+ }
+
+
+ @Test
+ public void test_deleteInput_listInput_success() throws Exception {
+ InputDefinition listInput = setUpListInput();
+ String inputId = COMPONENT_ID + "." + listInput.getName();
+ listInput.setUniqueId(inputId);
+ listInput.setIsDeclaredListInput(true);
+ service.setInputs(Collections.singletonList(listInput));
+ ArgumentCaptor<String> schemaTypeCaptor = ArgumentCaptor.forClass(String.class);
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.deleteInputOfResource(service, listInput.getName())).thenReturn(StorageOperationStatus.OK);
+ //when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+ when(propertyDeclarationOrchestrator.unDeclarePropertiesAsListInputs(service, listInput)).thenReturn(StorageOperationStatus.OK);
+ when(dataTypeBusinessLogic.deletePrivateDataType(eq(service), schemaTypeCaptor.capture()))
+ .thenReturn(Either.left(new DataTypeDefinition())); // TODO: replace to return proper datatype
+ //when(propertyDeclarationOrchestrator.unDeclarePropertiesAsInputs(service, listInput)).thenReturn(StorageOperationStatus.OK);
+
+ Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, inputId);
+ assertEquals(true, result.isLeft());
+ verify(propertyDeclarationOrchestrator, times(1)).unDeclarePropertiesAsListInputs(service, listInput);
+ verify(dataTypeBusinessLogic, times(1)).deletePrivateDataType(service, listInput.getSchemaType());
+ assertEquals(listInput.getSchemaType(), schemaTypeCaptor.getValue());
+ }
+
+
+ @Test
+ public void test_deleteInput_input_fail_unDeclare() throws Exception {
+ InputDefinition listInput = setUpListInput();
+ String inputId = COMPONENT_ID + "." + listInput.getName();
+ listInput.setUniqueId(inputId);
+ listInput.setIsDeclaredListInput(false);
+ service.setInputs(Collections.singletonList(listInput));
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.deleteInputOfResource(service, listInput.getName())).thenReturn(StorageOperationStatus.OK);
+ //when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+ when(propertyDeclarationOrchestrator.unDeclarePropertiesAsInputs(service, listInput)).thenReturn(StorageOperationStatus.BAD_REQUEST);
+
+ Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, inputId);
+ assertEquals(true, result.isRight());
+ verify(propertyDeclarationOrchestrator, times(1)).unDeclarePropertiesAsInputs(service, listInput);
+ }
+
+
+ @Test
+ public void test_deleteInput_input_success() throws Exception {
+ InputDefinition listInput = setUpListInput();
+ String inputId = COMPONENT_ID + "." + listInput.getName();
+ listInput.setUniqueId(inputId);
+ listInput.setIsDeclaredListInput(false);
+ service.setInputs(Collections.singletonList(listInput));
+
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.deleteInputOfResource(service, listInput.getName())).thenReturn(StorageOperationStatus.OK);
+ //when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+ when(propertyDeclarationOrchestrator.unDeclarePropertiesAsInputs(service, listInput)).thenReturn(StorageOperationStatus.OK);
+
+ Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, inputId);
+ assertEquals(true, result.isLeft());
+ verify(propertyDeclarationOrchestrator, times(1)).unDeclarePropertiesAsInputs(service, listInput);
+ }
+
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java
index acfa721e74..f5d4aabd92 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java
@@ -1,6 +1,7 @@
package org.openecomp.sdc.be.components.property;
import fj.data.Either;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -8,19 +9,25 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.utils.AnnotationBuilder;
import org.openecomp.sdc.be.components.utils.InputsBuilder;
+import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.components.utils.ResourceBuilder;
import org.openecomp.sdc.be.datatypes.elements.Annotation;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstancePropInput;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -41,6 +48,12 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar
@Mock
private ToscaOperationFacade toscaOperationFacade;
+ @Mock
+ private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
+
+ @Mock
+ private PropertyOperation propertyOperation;
+
@Captor
private ArgumentCaptor<ComponentParametersView> inputsFilterCaptor;
@@ -50,8 +63,8 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar
@Before
public void setUp() throws Exception {
super.setUp();
- testInstance = new ComponentInstanceInputPropertyDeclarator(mockComponentUtils(), null,
- toscaOperationFacade, null, mockExceptionUtils());
+ testInstance = new ComponentInstanceInputPropertyDeclarator(mockComponentUtils(), propertyOperation,
+ toscaOperationFacade, componentInstanceBusinessLogic, mockExceptionUtils());
annotation1 = AnnotationBuilder.create()
.setType("annotationType1")
.setName("annotation1")
@@ -88,6 +101,55 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar
assertThatExceptionOfType(StorageException.class).isThrownBy(() -> testInstance.declarePropertiesAsInputs(resource, "inst1", propsToDeclare));
}
+ @Test
+ public void unDeclarePropertiesAsListInputsTest() {
+ InputDefinition inputToDelete = new InputDefinition();
+ inputToDelete.setUniqueId(INPUT_ID);
+ inputToDelete.setName(INPUT_ID);
+ inputToDelete.setIsDeclaredListInput(true);
+
+ Component component = createComponentWithListInput(INPUT_ID, "innerPropName");
+ PropertyDefinition prop = new PropertyDataDefinitionBuilder()
+ .setName("propName")
+ .setValue(generateGetInputValueAsListInput(INPUT_ID, "innerPropName"))
+ .setType("list")
+ .setUniqueId("propName")
+ .addGetInputValue(INPUT_ID)
+ .build();
+ component.setProperties(Collections.singletonList(prop));
+
+ List<ComponentInstanceInput> ciPropList = new ArrayList<>();
+ ComponentInstanceInput ciProp = new ComponentInstanceInput();
+ List<String> pathOfComponentInstances = new ArrayList<>();
+ pathOfComponentInstances.add("pathOfComponentInstances");
+ ciProp.setPath(pathOfComponentInstances);
+ ciProp.setUniqueId("componentInstanceId");
+ ciProp.setDefaultValue("default value");
+ ciProp.setComponentInstanceId("componentInstanceId");
+ ciProp.setComponentInstanceName("componentInstanceName");
+ ciProp.setValue(generateGetInputValueAsListInput(INPUT_ID, "innerPropName"));
+ ciPropList.add(ciProp);
+
+ when(componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(eq(component), eq(INPUT_ID))).thenReturn(ciPropList);
+ when(propertyOperation.findDefaultValueFromSecondPosition(eq(pathOfComponentInstances), eq(ciProp.getUniqueId()), eq(ciProp.getDefaultValue()))).thenReturn(Either.left(ciProp.getDefaultValue()));
+ when(toscaOperationFacade.updateComponentInstanceInputs(eq(component), eq(ciProp.getComponentInstanceId()), eq(ciPropList))).thenReturn(StorageOperationStatus.OK);
+ StorageOperationStatus storageOperationStatus = testInstance.unDeclarePropertiesAsListInputs(component, inputToDelete);
+
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ }
+
+ @Test
+ public void unDeclarePropertiesAsListInputsTest_whenNoListInput_returnOk() {
+ InputDefinition input = new InputDefinition();
+ input.setUniqueId(INPUT_ID);
+ input.setName(INPUT_ID);
+ input.setValue("value");
+ List<ComponentInstanceInput> resList = new ArrayList<>();
+ when(componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(eq(resource), eq(INPUT_ID))).thenReturn(resList);
+ StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input);
+ Assert.assertEquals(status, StorageOperationStatus.OK);
+ }
+
private void verifyInputAnnotations(InputDefinition inputDefinition) {
List<Annotation> annotations = inputDefinition.getAnnotations();
assertThat(annotations)
@@ -105,4 +167,19 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar
.build();
}
-} \ No newline at end of file
+ private Component createComponentWithListInput(String inputName, String propName) {
+ InputDefinition input = InputsBuilder.create()
+ .setName(inputName)
+ .build();
+
+ input.setUniqueId(INPUT_ID);
+ input.setName(INPUT_ID);
+ input.setDefaultValue("defaultValue");
+ input.setValue(generateGetInputValueAsListInput(inputName, propName));
+
+ return new ResourceBuilder()
+ .setUniqueId(RESOURCE_ID)
+ .addInput(input)
+ .build();
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java
index 5752ae272e..f59adada9a 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java
@@ -1,26 +1,25 @@
package org.openecomp.sdc.be.components.property;
import fj.data.Either;
+import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
+import org.mockito.*;
import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.utils.InputsBuilder;
import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
+import org.openecomp.sdc.be.components.utils.ResourceBuilder;
import org.openecomp.sdc.be.dao.utils.MapUtil;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
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.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -37,6 +36,11 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT
private ComponentInstancePropertyDeclarator testInstance;
@Mock
private ToscaOperationFacade toscaOperationFacade;
+ @Mock
+ private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
+ @Mock
+ private PropertyOperation propertyOperation;
+
@Captor
private ArgumentCaptor<Map<String, List<ComponentInstanceProperty>>> instancePropertiesCaptor;
@@ -98,6 +102,100 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT
verifyUpdatedComplexProperty(capturedInstanceProperties, inputs);
}
+ @Test
+ public void declarePropertiesAsListInput() {
+ // construct arguments
+ List<PropertyDataDefinition> properties = Arrays.asList(prop1, prop2);
+ List<ComponentInstancePropInput> propsToDeclare = createInstancePropInputList(properties);
+ InputDefinition input = new InputDefinition(new PropertyDataDefinitionBuilder()
+ .setName("listinput")
+ .setType("list")
+ .setDescription("description")
+ .setSchemaType("org.onap.datatype.listinput")
+ .build());
+ // mock returns
+ when(toscaOperationFacade.addComponentInstancePropertiesToComponent(eq(resource), instancePropertiesCaptor.capture())).thenReturn(Either.left(Collections.emptyMap()));
+ Either<InputDefinition, StorageOperationStatus> result = testInstance.declarePropertiesAsListInput(resource, "inst1", propsToDeclare, input);
+ // validate result
+ assertThat(result.isLeft()).isTrue();
+ List<ComponentInstanceProperty> capturedInstanceProperties = instancePropertiesCaptor.getValue().get(INSTANCE_ID);
+ assertThat(capturedInstanceProperties.size()).isEqualTo(2);
+ Map<String, PropertyDataDefinition> propertiesMap =
+ properties.stream().collect(Collectors.toMap(PropertyDataDefinition::getName, e->e));
+ for(ComponentInstanceProperty instanceProperty: capturedInstanceProperties) {
+ assertThat(propertiesMap.containsKey(instanceProperty.getName())).isTrue();
+ PropertyDataDefinition property = propertiesMap.get(instanceProperty.getName());
+ assertThat(instanceProperty.getType()).isEqualTo(property.getType());
+ assertThat(instanceProperty.isGetInputProperty()).isTrue();
+ }
+ }
+
+ @Test
+ public void declarePropertiesAsListInput_propertyOwnerNotFound() {
+ // construct arguments
+ List<PropertyDataDefinition> properties = Arrays.asList(prop1, prop2);
+ List<ComponentInstancePropInput> propsToDeclare = createInstancePropInputList(properties);
+ InputDefinition input = new InputDefinition(new PropertyDataDefinitionBuilder()
+ .setName("listinput")
+ .setType("list")
+ .setDescription("description")
+ .setSchemaType("org.onap.datatype.listinput")
+ .build());
+ Either<InputDefinition, StorageOperationStatus> result = testInstance.declarePropertiesAsListInput(resource, "inst2", propsToDeclare, input);
+ // validate result
+ assertThat(result.isRight()).isTrue();
+ assertThat(result.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND);
+ }
+
+ @Test
+ public void unDeclarePropertiesAsListInputsTest() {
+ InputDefinition inputToDelete = new InputDefinition();
+ inputToDelete.setUniqueId(INPUT_ID);
+ inputToDelete.setName(INPUT_ID);
+ inputToDelete.setIsDeclaredListInput(true);
+
+ Component component = createComponentWithListInput(INPUT_ID, "innerPropName");
+ PropertyDefinition prop = new PropertyDataDefinitionBuilder()
+ .setName("propName")
+ .setValue(generateGetInputValueAsListInput(INPUT_ID, "innerPropName"))
+ .setType("list")
+ .setUniqueId("propName")
+ .addGetInputValue(INPUT_ID)
+ .build();
+ component.setProperties(Collections.singletonList(prop));
+
+ List<ComponentInstanceProperty> ciPropList = new ArrayList<>();
+ ComponentInstanceProperty ciProp = new ComponentInstanceProperty();
+ List<String> pathOfComponentInstances = new ArrayList<>();
+ pathOfComponentInstances.add("pathOfComponentInstances");
+ ciProp.setPath(pathOfComponentInstances);
+ ciProp.setUniqueId("componentInstanceId");
+ ciProp.setDefaultValue("default value");
+ ciProp.setComponentInstanceId("componentInstanceId");
+ ciProp.setComponentInstanceName("componentInstanceName");
+ ciProp.setValue(generateGetInputValueAsListInput(INPUT_ID, "innerPropName"));
+ ciPropList.add(ciProp);
+
+ when(componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(eq(component), eq(INPUT_ID))).thenReturn(ciPropList);
+ when(propertyOperation.findDefaultValueFromSecondPosition(eq(pathOfComponentInstances), eq(ciProp.getUniqueId()), eq(ciProp.getDefaultValue()))).thenReturn(Either.left(ciProp.getDefaultValue()));
+ when(toscaOperationFacade.updateComponentInstanceProperties(eq(component), eq(ciProp.getComponentInstanceId()), eq(ciPropList))).thenReturn(StorageOperationStatus.OK);
+ StorageOperationStatus storageOperationStatus = testInstance.unDeclarePropertiesAsListInputs(component, inputToDelete);
+
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ }
+
+ @Test
+ public void unDeclarePropertiesAsListInputsTest_whenNoListInput_returnOk() {
+ InputDefinition input = new InputDefinition();
+ input.setUniqueId(INPUT_ID);
+ input.setName(INPUT_ID);
+ input.setValue("value");
+ List<ComponentInstanceProperty> resList = new ArrayList<>();
+ when(componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(eq(resource), eq(INPUT_ID))).thenReturn(resList);
+ StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input);
+ Assert.assertEquals(status, StorageOperationStatus.OK);
+ }
+
private void verifyUpdatedProperties(List<PropertyDataDefinition> properties, List<ComponentInstanceProperty> capturedInstanceProperties, List<InputDefinition> inputs) {
assertThat(capturedInstanceProperties).hasSize(properties.size());
Map<String, ComponentInstanceProperty> updatedPropertiesByName = MapUtil.toMap(capturedInstanceProperties, ComponentInstanceProperty::getName);
@@ -204,4 +302,19 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT
assertThat(input.getInstanceUniqueId()).isEqualTo(INSTANCE_ID);
}
-} \ No newline at end of file
+ private Component createComponentWithListInput(String inputName, String propName) {
+ InputDefinition input = InputsBuilder.create()
+ .setName(inputName)
+ .build();
+
+ input.setUniqueId(INPUT_ID);
+ input.setName(INPUT_ID);
+ input.setDefaultValue("defaultValue");
+ input.setValue(generateGetInputValueAsListInput(inputName, propName));
+
+ return new ResourceBuilder()
+ .setUniqueId(RESOURCE_ID)
+ .addInput(input)
+ .build();
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java
new file mode 100644
index 0000000000..7069fe84d7
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java
@@ -0,0 +1,175 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Fujitsu Limited. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.property;
+
+import fj.data.Either;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase {
+
+ @InjectMocks
+ private ComponentPropertyDeclarator testInstance;
+ @Mock
+ private PropertyBusinessLogic propertyBusinessLogic;
+ @Mock
+ private PropertyOperation propertyOperation;
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+
+ @Test
+ public void unDeclarePropertiesAsListInputsTest_whenPropertyUsedByOperation() {
+ InputDefinition input = new InputDefinition();
+ input.setUniqueId(INPUT_ID);
+ input.setName(INPUT_ID);
+ input.setValue("value");
+
+ PropertyDefinition propertyDefinition = new PropertyDefinition(input);
+
+ when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), eq(propertyDefinition))).thenReturn(true);
+ StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input);
+ Assert.assertEquals(status, StorageOperationStatus.DECLARED_INPUT_USED_BY_OPERATION);
+ }
+
+ @Test
+ public void unDeclarePropertiesAsListInputsTest_whenNotPresentPropertyToUpdateCandidate() {
+ InputDefinition input = new InputDefinition();
+ input.setUniqueId(INPUT_ID);
+ input.setName(INPUT_ID);
+ input.setValue("value");
+
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ resource.setProperties(Collections.singletonList(propertyDefinition));
+
+ when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), any(PropertyDefinition.class))).thenReturn(false);
+ StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input);
+ Assert.assertEquals(status, StorageOperationStatus.OK);
+ }
+
+ @Test
+ public void unDeclarePropertiesAsListInputsTest_whenPropertiesEmpty() {
+ InputDefinition input = new InputDefinition();
+ input.setUniqueId(INPUT_ID);
+ input.setName(INPUT_ID);
+ input.setValue("value");
+
+ resource.setProperties(new ArrayList<>());
+
+ when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), any(PropertyDefinition.class))).thenReturn(false);
+ StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input);
+ Assert.assertEquals(status, StorageOperationStatus.OK);
+ }
+
+ @Test
+ public void unDeclarePropertiesAsListInputsTest_whenPropertiesToUpdateIsEmpty() {
+ InputDefinition input = new InputDefinition();
+ input.setUniqueId(INPUT_ID);
+ input.setName(INPUT_ID);
+ input.setValue("value");
+
+ PropertyDefinition propertyDefinition = new PropertyDefinition(input);
+ resource.setProperties(Collections.singletonList(propertyDefinition));
+
+ when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), eq(propertyDefinition))).thenReturn(false);
+ StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input);
+ Assert.assertEquals(status, StorageOperationStatus.OK);
+ }
+
+ @Test
+ public void unDeclarePropertiesAsListInputsTest_singleProperty() {
+ InputDefinition input = new InputDefinition();
+ input.setUniqueId(INPUT_ID);
+ input.setName(INPUT_ID);
+ input.setValue("value");
+ input.setDefaultValue("default value");
+
+ PropertyDefinition propertyDefinition = new PropertyDefinition(input);
+ List<GetInputValueDataDefinition> getInputValueList = new ArrayList<>();
+ getInputValueList.add(buildGetInputValue(INPUT_ID));
+ getInputValueList.add(buildGetInputValue("otherInputId"));
+ propertyDefinition.setGetInputValues(getInputValueList);
+ propertyDefinition.setUniqueId("propertyId");
+ propertyDefinition.setDefaultValue("default value");
+ propertyDefinition.setValue(generateGetInputValueAsListInput(INPUT_ID, "innerPropName"));
+ resource.setProperties(Collections.singletonList(propertyDefinition));
+
+ when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), any())).thenReturn(false);
+ when(propertyOperation.findDefaultValueFromSecondPosition(eq(Collections.emptyList()), eq(propertyDefinition.getUniqueId()), eq(propertyDefinition.getDefaultValue()))).thenReturn(Either.left(propertyDefinition.getDefaultValue()));
+ when(toscaOperationFacade.updatePropertyOfComponent(eq(resource), any())).thenReturn(Either.left(propertyDefinition));
+ StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input);
+ Assert.assertEquals(status, StorageOperationStatus.OK);
+ }
+
+ @Test
+ public void unDeclarePropertiesAsListInputsTest_UnDeclareInputFail() {
+ InputDefinition input = new InputDefinition();
+ input.setUniqueId(INPUT_ID);
+ input.setName(INPUT_ID);
+ input.setValue("value");
+ input.setDefaultValue("default value");
+
+ PropertyDefinition propertyDefinition = new PropertyDefinition(input);
+ List<GetInputValueDataDefinition> getInputValueList = new ArrayList<>();
+ getInputValueList.add(buildGetInputValue(INPUT_ID));
+ getInputValueList.add(buildGetInputValue("otherInputId"));
+ propertyDefinition.setGetInputValues(getInputValueList);
+ propertyDefinition.setUniqueId("propertyId");
+ propertyDefinition.setDefaultValue("default value");
+ propertyDefinition.setValue(generateGetInputValueAsListInput(INPUT_ID, "innerPropName"));
+ resource.setProperties(Collections.singletonList(propertyDefinition));
+
+ when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), any())).thenReturn(false);
+ when(propertyOperation.findDefaultValueFromSecondPosition(eq(Collections.emptyList()), eq(propertyDefinition.getUniqueId()), eq(propertyDefinition.getDefaultValue()))).thenReturn(Either.left(propertyDefinition.getDefaultValue()));
+ when(toscaOperationFacade.updatePropertyOfComponent(eq(resource), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input);
+ Assert.assertEquals(status, StorageOperationStatus.NOT_FOUND);
+ }
+
+ private GetInputValueDataDefinition buildGetInputValue(String InputId) {
+ GetInputValueDataDefinition getInputValue = new GetInputValueDataDefinition();
+ getInputValue.setInputId(InputId);
+ getInputValue.setInputName(InputId);
+
+ return getInputValue;
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclaratorTest.java
index 63e39b5e61..72706db606 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclaratorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclaratorTest.java
@@ -136,6 +136,56 @@ public class GroupPropertyDeclaratorTest extends PropertyDeclaratorTestBase {
assertThat(updatedProperty.getUniqueId()).isEqualTo(getInputPropForInput.getUniqueId());
}
+ @Test
+ public void testUnDeclarePropertiesAsListInputs_whenComponentHasNoGroups_returnOk() {
+ Resource resource = new Resource();
+ StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input);
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ verifyZeroInteractions(groupOperation);
+ }
+
+ @Test
+ public void testUnDeclarePropertiesAsListInputs_whenNoPropertiesFromGroupMatchInputId_returnOk() {
+ StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsListInputs(createResourceWithGroup(), input);
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ verifyZeroInteractions(groupOperation);
+ }
+
+ @Test
+ public void whenFailingToUpdateDeclaredPropertiesAsListInputs_returnErrorStatus() {
+ Resource resource = createResourceWithGroups(GROUP_ID);
+ Optional<GroupDefinition> groupDefinition = resource.getGroupById(GROUP_ID);
+ assertThat(groupDefinition.isPresent()).isTrue();
+ PropertyDataDefinition getInputPropForInput = buildGetInputProperty(INPUT_ID);
+ groupDefinition.get().setProperties(Collections.singletonList(getInputPropForInput));
+ when(propertyOperation.findDefaultValueFromSecondPosition(Collections.emptyList(), getInputPropForInput.getUniqueId(), getInputPropForInput.getDefaultValue())).thenReturn(Either.left(getInputPropForInput.getDefaultValue()));
+ when(groupOperation.updateGroupProperties(eq(resource), eq(GROUP_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.GENERAL_ERROR);
+ StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input);
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.GENERAL_ERROR);
+ }
+
+ @Test
+ public void testUnDeclarePropertiesAsListInputs_propertiesUpdatedCorrectly() {
+ Resource resource = createResourceWithGroups(GROUP_ID, "groupId3");
+ Optional<GroupDefinition> groupDefinition = resource.getGroupById(GROUP_ID);
+ PropertyDataDefinition getInputPropForInput = buildGetInputProperty(INPUT_ID);
+ PropertyDataDefinition someOtherProperty = new PropertyDataDefinitionBuilder().build();
+ groupDefinition.get().setProperties(Arrays.asList(getInputPropForInput, someOtherProperty));
+
+ when(propertyOperation.findDefaultValueFromSecondPosition(Collections.emptyList(), getInputPropForInput.getUniqueId(), getInputPropForInput.getDefaultValue())).thenReturn(Either.left(getInputPropForInput.getDefaultValue()));
+ when(groupOperation.updateGroupProperties(eq(resource), eq(GROUP_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.OK);
+ StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input);
+
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ List<PropertyDataDefinition> updatedProperties = updatedPropsCapture.getValue();
+ assertThat(updatedProperties).hasSize(1);
+ PropertyDataDefinition updatedProperty = updatedProperties.get(0);
+ assertThat(updatedProperty.isGetInputProperty()).isFalse();
+ assertThat(updatedProperty.getValue()).isEmpty();
+ assertThat(updatedProperty.getDefaultValue()).isEqualTo(getInputPropForInput.getDefaultValue());
+ assertThat(updatedProperty.getUniqueId()).isEqualTo(getInputPropForInput.getUniqueId());
+ }
+
private Resource createResourceWithGroup() {
return createResourceWithGroups(GROUP_ID);
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclaratorTest.java
index 72c26541f1..f85388a06b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclaratorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclaratorTest.java
@@ -134,6 +134,55 @@ public class PolicyPropertyDeclaratorTest extends PropertyDeclaratorTestBase {
assertThat(updatedProperty.getUniqueId()).isEqualTo(getInputPropForInput.getUniqueId());
}
+ @Test
+ public void testUnDeclarePropertiesAsListInputs_whenComponentHasNoPolicies_returnOk() {
+ Resource resource = new Resource();
+ StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input);
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ verifyZeroInteractions(policyOperation);
+ }
+
+ @Test
+ public void testUnDeclarePropertiesAsListInputs_whenNoPropertiesFromPolicyMatchInputId_returnOk() {
+ StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsListInputs(createResourceWithPolicy(), input);
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ verifyZeroInteractions(policyOperation);
+ }
+
+ @Test
+ public void whenFailingToUpdateDeclaredPropertiesAsListInputs_returnErrorStatus() {
+ Resource resource = createResourceWithPolicies(POLICY_ID);
+ PolicyDefinition policyDefinition = resource.getPolicies().get(POLICY_ID);
+ PropertyDataDefinition getInputPropForInput = buildGetInputProperty(INPUT_ID);
+ policyDefinition.setProperties(Collections.singletonList(getInputPropForInput));
+ when(propertyOperation.findDefaultValueFromSecondPosition(Collections.emptyList(), getInputPropForInput.getUniqueId(), getInputPropForInput.getDefaultValue())).thenReturn(Either.left(getInputPropForInput.getDefaultValue()));
+ when(policyOperation.updatePolicyProperties(eq(resource), eq(POLICY_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.GENERAL_ERROR);
+ StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input);
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.GENERAL_ERROR);
+ }
+
+ @Test
+ public void testUnDeclarePropertiesAsListInputs_propertiesUpdatedCorrectly() {
+ Resource resource = createResourceWithPolicies(POLICY_ID, "policyId3");
+ PolicyDefinition policyDefinition = resource.getPolicies().get(POLICY_ID);
+ PropertyDataDefinition getInputPropForInput = buildGetInputProperty(INPUT_ID);
+ PropertyDataDefinition someOtherProperty = new PropertyDataDefinitionBuilder().build();
+ policyDefinition.setProperties(Arrays.asList(getInputPropForInput, someOtherProperty));
+
+ when(propertyOperation.findDefaultValueFromSecondPosition(Collections.emptyList(), getInputPropForInput.getUniqueId(), getInputPropForInput.getDefaultValue())).thenReturn(Either.left(getInputPropForInput.getDefaultValue()));
+ when(policyOperation.updatePolicyProperties(eq(resource), eq(POLICY_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.OK);
+ StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input);
+
+ assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK);
+ List<PropertyDataDefinition> updatedProperties = updatedPropsCapture.getValue();
+ assertThat(updatedProperties).hasSize(1);
+ PropertyDataDefinition updatedProperty = updatedProperties.get(0);
+ assertThat(updatedProperty.isGetInputProperty()).isFalse();
+ assertThat(updatedProperty.getValue()).isEmpty();
+ assertThat(updatedProperty.getDefaultValue()).isEqualTo(getInputPropForInput.getDefaultValue());
+ assertThat(updatedProperty.getUniqueId()).isEqualTo(getInputPropForInput.getUniqueId());
+ }
+
private Resource createResourceWithPolicy() {
return createResourceWithPolicies(POLICY_ID);
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java
index 1a2a76e433..ef1d45dbaa 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java
@@ -4,23 +4,32 @@ import fj.data.Either;
import mockit.Deencapsulation;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Answers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstancePropInput;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
public class PropertyDecelerationOrchestratorTest {
@InjectMocks
PropertyDeclarationOrchestrator testSubject;
- @Mock
+ @Mock(answer = Answers.CALLS_REAL_METHODS)
List<PropertyDeclarator> propertyDeceleratorsMock;
-
+
@Mock
private ComponentInstanceInputPropertyDeclarator componentInstanceInputPropertyDecelerator;
@Mock
@@ -45,6 +54,21 @@ public class PropertyDecelerationOrchestratorTest {
}
@Test
+ public void testDeclarePropertiesToListInputs() throws Exception {
+ Component component = new Resource();
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ Map<String, List<ComponentInstancePropInput>> componentInstanceInputsMap = new HashMap<>();
+ List<ComponentInstancePropInput> value = new LinkedList<>();
+ componentInstanceInputsMap.put("mock", value);
+ componentInstInputsMap.setComponentInstanceInputsMap(componentInstanceInputsMap);
+ InputDefinition input = new InputDefinition();
+ Either<InputDefinition, StorageOperationStatus> result;
+
+ // default test
+ result = testSubject.declarePropertiesToListInput(component, componentInstInputsMap, input);
+ }
+
+ @Test
public void testUnDeclarePropertiesAsInputs() throws Exception {
Component component = new Resource();
InputDefinition inputToDelete = new InputDefinition();
@@ -58,6 +82,33 @@ public class PropertyDecelerationOrchestratorTest {
result = testSubject.unDeclarePropertiesAsInputs(component, inputToDelete);
}
+ @Test
+ public void testUnDeclarePropertiesAsListInputs() throws Exception {
+ Component component = new Resource();
+ InputDefinition inputToDelete = new InputDefinition();
+ StorageOperationStatus result;
+
+ Iterator<PropertyDeclarator> mockIter = Mockito.mock(Iterator.class);
+ Mockito.when(propertyDeceleratorsMock.iterator()).thenReturn(mockIter);
+ Mockito.when(mockIter.hasNext()).thenReturn(false);
+
+ // default test
+ result = testSubject.unDeclarePropertiesAsListInputs(component, inputToDelete);
+ }
+
+ @Test
+ public void testGetPropOwnerId() throws Exception {
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ Map<String, List<ComponentInstancePropInput>> componentInstanceInputsMap = new HashMap<>();
+ List<ComponentInstancePropInput> value = new LinkedList<>();
+ componentInstanceInputsMap.put("mock", value);
+ componentInstInputsMap.setComponentInstanceInputsMap(componentInstanceInputsMap);
+ String result;
+
+ // default test
+ result = Deencapsulation.invoke(testSubject, "getPropOwnerId", componentInstInputsMap);
+ }
+
@Test(expected = IllegalStateException.class)
public void testGetPropertyDecelerator() throws Exception {
ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclaratorTestBase.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclaratorTestBase.java
index bd21f683ad..f1f4d0aac7 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclaratorTestBase.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclaratorTestBase.java
@@ -77,6 +77,10 @@ public class PropertyDeclaratorTestBase {
return String.format("{\"%s\":\"%s\"}", GET_INPUT, value);
}
+ String generateGetInputValueAsListInput(String inputName, String inputProperty) {
+ return String.format("{\"%s\":[\"%s\",\"INDEX\",\"%s\"]}", GET_INPUT, inputName, inputProperty);
+ }
+
private void verifyInputPropertiesList(PropertyDataDefinition updatedProperty, InputDefinition input) {
assertThat(input.getProperties()).hasSize(1);
assertThat(new ComponentInstanceProperty(updatedProperty)).isEqualTo(input.getProperties().get(0));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
index eb123771a9..3922dd8de7 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
@@ -218,14 +218,16 @@ public class UiComponentDataConverterTest {
public void getUiDataTransferFromResourceByParams_policies() {
Resource resourceWithPolicies = buildResourceWithPolicies();
UiComponentDataTransfer componentDTO = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resourceWithPolicies, Collections.singletonList("policies"));
- assertThat(componentDTO.getPolicies()).isEqualTo(resourceWithPolicies.resolvePoliciesList());
+ List<PolicyDefinition> expectedPolicies = resourceWithPolicies.resolvePoliciesList();
+ assertThat(componentDTO.getPolicies()).containsExactlyInAnyOrder((PolicyDefinition[]) expectedPolicies.toArray(new PolicyDefinition[expectedPolicies.size()]));
}
@Test
public void getUiDataTransferFromServiceByParams_policies() {
Service resourceWithPolicies = buildServiceWithPolicies();
UiComponentDataTransfer componentDTO = uiComponentDataConverter.getUiDataTransferFromServiceByParams(resourceWithPolicies, Collections.singletonList("policies"));
- assertThat(componentDTO.getPolicies()).isEqualTo(resourceWithPolicies.resolvePoliciesList());
+ List<PolicyDefinition> expectedPolicies = resourceWithPolicies.resolvePoliciesList();
+ assertThat(componentDTO.getPolicies()).containsExactlyInAnyOrder((PolicyDefinition[]) expectedPolicies.toArray(new PolicyDefinition[expectedPolicies.size()]));
}
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/InputsServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/InputsServletTest.java
index 9ff55c22f0..07184704d4 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/InputsServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/InputsServletTest.java
@@ -1,166 +1,437 @@
-package org.openecomp.sdc.be.servlets;
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Fujitsu Limited. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Response;
+package org.openecomp.sdc.be.servlets;
+import fj.data.Either;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.grizzly.http.util.HttpStatus;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
+import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstListInput;
+import org.openecomp.sdc.be.model.ComponentInstancePropInput;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.web.context.WebApplicationContext;
-import fj.data.Either;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
+
+public class InputsServletTest extends JerseySpringBaseTest {
+
+ /* Constants */
+ private static final String RESOURCE_ID = "serviceId";
+ private static final String USER_ID = "userId";
+ private static final String COMPONENT_INSTANCE_ID = "instanceId";
+ private static final String COMPONENT_ID = "componentId";
+ private static final String INSTANCE_INPUT_ID = "inputId";
+ private static final String LISTINPUT_NAME = "listInput";
+ private static final String LISTINPUT_SCHEMA_TYPE = "org.onap.datatypes.listinput";
+ private static final String LISTINPUT_PROP1_NAME = "prop1";
+ private static final String LISTINPUT_PROP1_TYPE = "string";
+ private static final String LISTINPUT_PROP2_NAME = "prop2";
+ private static final String LISTINPUT_PROP2_TYPE = "integer";
+
+ /* Test subject */
+ private InputsServletForTest testSubject;
+
+ /* Mocks */
+ private InputsBusinessLogic inputsBusinessLogic;
+ private DataTypeBusinessLogic dataTypeBusinessLogic;
+ private HttpSession httpSession;
+ private ServletContext servletContext;
+ private WebApplicationContext webApplicationContext;
+ private ComponentsUtils componentsUtils;
+ private ServletUtils servletUtils;
+
+ /**
+ * This class extends the original InputsServlet
+ * and provides methods to inject mocks
+ */
+ class InputsServletForTest extends InputsServlet {
+ public void setComponentsUtils(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ public void setServletUtils(ServletUtils servletUtils) {
+ this.servletUtils = servletUtils;
+ }
+ }
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ inputsBusinessLogic = mock(InputsBusinessLogic.class);
+ dataTypeBusinessLogic = mock(DataTypeBusinessLogic.class);
+ servletContext = mock(ServletContext.class);
+ httpSession = mock(HttpSession.class);
+ webApplicationContext = mock(WebApplicationContext.class);
+ componentsUtils = mock(ComponentsUtils.class);
+ servletUtils = mock(ServletUtils.class);
+ when(request.getSession()).thenReturn(httpSession);
+ when(httpSession.getServletContext()).thenReturn(servletContext);
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(new WebAppContextWrapper());
+ when(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).thenReturn(webApplicationContext);
+ when(webApplicationContext.getBean(InputsBusinessLogic.class)).thenReturn(inputsBusinessLogic);
+ when(webApplicationContext.getBean(DataTypeBusinessLogic.class)).thenReturn(dataTypeBusinessLogic);
+ testSubject.setComponentsUtils(componentsUtils);
+ testSubject.setServletUtils(servletUtils);
+ when(servletUtils.getComponentsUtils()).thenReturn(componentsUtils);
+ }
+
+
+ @Override
+ protected ResourceConfig configure() {
+ testSubject = new InputsServletForTest();
+ return super.configure().register(testSubject);
+ }
+
+
+ private InputDefinition setUpListInput() {
+ InputDefinition listInput = new InputDefinition();
+ listInput.setName(LISTINPUT_NAME);
+ listInput.setType("list");
+ SchemaDefinition listInputSchema = new SchemaDefinition();
+ listInputSchema.setProperty(new PropertyDataDefinitionBuilder()
+ .setType(LISTINPUT_SCHEMA_TYPE)
+ .setIsRequired(false)
+ .build()
+ );
+ listInput.setSchema(listInputSchema);
+ return listInput;
+ }
+
+ private ComponentInstListInput setUpCreateListInputParams() {
+ ComponentInstListInput componentInstListInput = new ComponentInstListInput();
+
+ // Create a "list input"
+ InputDefinition listInput = setUpListInput();
+ componentInstListInput.setListInput(listInput);
+
+ // Create ComponentInstancePropInputs
+ // for inputs in the ComponentInstance
+ Map<String, List<ComponentInstancePropInput>> propInputsListMap = new HashMap<>();
+ // Add 2 PropInputs. property owner is COMPONENT_INSTANCE_ID
+ List<ComponentInstancePropInput> propInputsList = new ArrayList<>();
+ ComponentInstancePropInput propInput = new ComponentInstancePropInput();
+ propInput.setName(LISTINPUT_PROP1_NAME);
+ propInput.setType(LISTINPUT_PROP1_TYPE);
+ propInput.setUniqueId(COMPONENT_INSTANCE_ID + "." + LISTINPUT_PROP1_NAME);
+ propInputsList.add(propInput);
+ propInput = new ComponentInstancePropInput();
+ propInput.setName(LISTINPUT_PROP2_NAME);
+ propInput.setType(LISTINPUT_PROP2_TYPE);
+ propInput.setUniqueId(COMPONENT_INSTANCE_ID + "." + LISTINPUT_PROP2_NAME);
+ propInputsList.add(propInput);
+ propInputsListMap.put(COMPONENT_INSTANCE_ID, propInputsList);
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ componentInstInputsMap.setComponentInstanceInputsMap(propInputsListMap);
+ componentInstListInput.setComponentInstInputsMap(componentInstInputsMap);
+
+ return componentInstListInput;
+ }
+
+ @Test
+ public void test_createListInput_success() throws Exception {
+ ComponentInstListInput requestBodyObj = setUpCreateListInputParams();
+ Entity<ComponentInstListInput> entity = Entity.entity(requestBodyObj, MediaType.APPLICATION_JSON);
+
+ // for parseToComponentInstListInput
+ when(componentsUtils.convertJsonToObjectUsingObjectMapper(any(), any(), eq(ComponentInstListInput.class),
+ eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE)))
+ .thenReturn(Either.left(requestBodyObj));
+
+ when(inputsBusinessLogic.createListInput(eq(USER_ID), eq(RESOURCE_ID), eq(ComponentTypeEnum.SERVICE),
+ any(), eq(true), eq(false)))
+ .thenReturn(Either.left(Collections.emptyList()));
+ when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
+
+ Response response = buildCreateListInputCall().post(entity);
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
+ verify(inputsBusinessLogic, times(1)).createListInput(USER_ID, RESOURCE_ID,
+ ComponentTypeEnum.SERVICE, requestBodyObj, true, false);
+ }
+
+ @Test
+ public void test_createListInput_fail_parse() throws Exception {
+ ComponentInstListInput requestBodyObj = setUpCreateListInputParams();
+ Entity<ComponentInstListInput> entity = Entity.entity(requestBodyObj, MediaType.APPLICATION_JSON);
+
+ // for parseToComponentInstListInput
+ ArgumentCaptor<User> userCaptor = ArgumentCaptor.forClass(User.class);
+ when(componentsUtils.convertJsonToObjectUsingObjectMapper(any(), userCaptor.capture(), eq(ComponentInstListInput.class),
+ eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE)))
+ .thenReturn(Either.right(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode())));
+
+ when(inputsBusinessLogic.createListInput(eq(USER_ID), eq(RESOURCE_ID), eq(ComponentTypeEnum.SERVICE),
+ any(), eq(true), eq(false)))
+ .thenReturn(Either.left(Collections.emptyList()));
+
+ Response response = buildCreateListInputCall().post(entity);
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ verify(componentsUtils, times(1))
+ .convertJsonToObjectUsingObjectMapper(any(), any(), eq(ComponentInstListInput.class),
+ eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE));
+ assertThat(userCaptor.getValue().getUserId()).isEqualTo(USER_ID);
+ verify(inputsBusinessLogic, never()).createListInput(USER_ID, RESOURCE_ID,
+ ComponentTypeEnum.SERVICE, requestBodyObj, true, false);
+ }
+
+
+ @Test
+ public void test_createListInput_fail_createInput() throws Exception {
+ ComponentInstListInput requestBodyObj = setUpCreateListInputParams();
+ Entity<ComponentInstListInput> entity = Entity.entity(requestBodyObj, MediaType.APPLICATION_JSON);
+
+ // for parseToComponentInstListInput
+ ArgumentCaptor<User> userCaptor = ArgumentCaptor.forClass(User.class);
+ when(componentsUtils.convertJsonToObjectUsingObjectMapper(any(), userCaptor.capture(), eq(ComponentInstListInput.class),
+ eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE)))
+ .thenReturn(Either.left(requestBodyObj));
+
+ when(inputsBusinessLogic.createListInput(eq(USER_ID), eq(RESOURCE_ID), eq(ComponentTypeEnum.SERVICE),
+ any(), eq(true), eq(false)))
+ .thenReturn(Either.right(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode())));
+
+ Response response = buildCreateListInputCall().post(entity);
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ verify(inputsBusinessLogic, times(1))
+ .createListInput(eq(USER_ID), eq(RESOURCE_ID), eq(ComponentTypeEnum.SERVICE),
+ any(), eq(true), eq(false));
+ }
+
+
+ @Test
+ public void test_createListInput_fail_exception() throws Exception {
+ ComponentInstListInput requestBodyObj = setUpCreateListInputParams();
+ Entity<ComponentInstListInput> entity = Entity.entity(requestBodyObj, MediaType.APPLICATION_JSON);
+
+ when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode()));
+
+ Response response = buildCreateListInputCall().post(entity);
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ }
+
+ @Test
+ public void test_getDataType_success() throws Exception {
+ when(dataTypeBusinessLogic.getPrivateDataType(eq(RESOURCE_ID),eq(LISTINPUT_SCHEMA_TYPE))).thenReturn(Either.left(new DataTypeDefinition()));
+
+ ResponseFormat responseFormat = new ResponseFormat();
+ responseFormat.setStatus(HttpStatus.OK_200.getStatusCode());
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.OK))).thenReturn(responseFormat);
+
+ Response response = buildGetDataTypeCall().get();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
+ }
+
+ @Test
+ public void test_getDataType_fail() throws Exception {
+ when(dataTypeBusinessLogic.getPrivateDataType(eq(RESOURCE_ID),eq(LISTINPUT_SCHEMA_TYPE))).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+
+ ResponseFormat responseFormat = new ResponseFormat();
+ responseFormat.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode());
+ when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.BAD_REQUEST))).thenReturn(ActionStatus.GENERAL_ERROR);
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.GENERAL_ERROR))).thenReturn(responseFormat);
+
+ Response response = buildGetDataTypeCall().get();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode());
+ }
+
+ @Test
+ public void test_getDataType_fail_exception() throws Exception {
+ when(dataTypeBusinessLogic.getPrivateDataType(eq(RESOURCE_ID),eq(LISTINPUT_SCHEMA_TYPE))).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.GENERAL_ERROR))).thenReturn(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode()));
+
+ Response response = buildGetDataTypeCall().get();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ }
+
+ @Test
+ public void test_getDataTypes_success() throws Exception {
+ when(dataTypeBusinessLogic.getPrivateDataTypes(eq(RESOURCE_ID))).thenReturn(Either.left(Collections.emptyList()));
+
+ ResponseFormat responseFormat = new ResponseFormat();
+ responseFormat.setStatus(HttpStatus.OK_200.getStatusCode());
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.OK))).thenReturn(responseFormat);
+
+ Response response = buildGetDataTypesCall().get();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
+ }
+
+ @Test
+ public void test_getDataTypes_fail() throws Exception {
+ when(dataTypeBusinessLogic.getPrivateDataTypes(eq(RESOURCE_ID))).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+
+ ResponseFormat responseFormat = new ResponseFormat();
+ responseFormat.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode());
+ when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.BAD_REQUEST))).thenReturn(ActionStatus.GENERAL_ERROR);
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.GENERAL_ERROR))).thenReturn(responseFormat);
+
+ Response response = buildGetDataTypesCall().get();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode());
+ }
+
+ @Test
+ public void test_getDataTypes_fail_exception() throws Exception {
+ when(dataTypeBusinessLogic.getPrivateDataType(eq(RESOURCE_ID),eq(LISTINPUT_SCHEMA_TYPE))).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.GENERAL_ERROR))).thenReturn(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode()));
+
+ Response response = buildGetDataTypesCall().get();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ }
+
+
+ @Test
+ public void test_deleteDataType_success() throws Exception {
+ when(dataTypeBusinessLogic.deletePrivateDataType(RESOURCE_ID, LISTINPUT_SCHEMA_TYPE)).thenReturn(Either.left(new DataTypeDefinition()));
+
+ when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
+
+ Response response = buildGetDataTypeCall().delete();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
+ }
+
+ @Test
+ public void test_deleteDataType_failure_exception() throws Exception {
+ when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
+ when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(new ResponseFormat(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode()));
+ Response response = buildGetDataTypeCall().delete();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode());
+ verify(componentsUtils, never()).getResponseFormat(ActionStatus.OK);
+ }
+
+ @Test
+ public void test_deleteDataType_failure_notFound() throws Exception {
+ when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
+ when(dataTypeBusinessLogic.deletePrivateDataType(RESOURCE_ID, LISTINPUT_SCHEMA_TYPE)).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND)).thenReturn(ActionStatus.ARTIFACT_NOT_FOUND);
+ when(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND)).thenReturn(new ResponseFormat(HttpStatus.NOT_FOUND_404.getStatusCode()));
+ Response response = buildGetDataTypeCall().delete();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND_404.getStatusCode());
+ verify(componentsUtils, never()).getResponseFormat(ActionStatus.OK);
+ }
+
+ @Test
+ public void test_deleteInput_success() throws Exception {
+ when(inputsBusinessLogic.deleteInput(RESOURCE_ID, USER_ID, LISTINPUT_NAME))
+ .thenReturn(Either.left(new InputDefinition()));
+ when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
+
+ // invoke delete call
+ Response response = target("/v1/catalog/services/{id}/delete/{inputId}/input")
+ .resolveTemplate("id", RESOURCE_ID)
+ .resolveTemplate("inputId", LISTINPUT_NAME)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, USER_ID)
+ .delete();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
+ verify(inputsBusinessLogic, times(1)).deleteInput(RESOURCE_ID, USER_ID, LISTINPUT_NAME);
+ }
+
+
+ @Test
+ public void test_deleteInput_failure_deleteInput() throws Exception {
+ when(inputsBusinessLogic.deleteInput(RESOURCE_ID, USER_ID, LISTINPUT_NAME))
+ .thenReturn(Either.right(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode())));
+ when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
+
+ // invoke delete call
+ Response response = target("/v1/catalog/services/{id}/delete/{inputId}/input")
+ .resolveTemplate("id", RESOURCE_ID)
+ .resolveTemplate("inputId", LISTINPUT_NAME)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, USER_ID)
+ .delete();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ verify(componentsUtils, never()).getResponseFormat(ActionStatus.OK);
+ }
+
+
+ @Test
+ public void test_deleteInput_failure_exception() throws Exception {
+ when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
+ when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode()));
+
+ // invoke delete call
+ Response response = target("/v1/catalog/services/{id}/delete/{inputId}/input")
+ .resolveTemplate("id", RESOURCE_ID)
+ .resolveTemplate("inputId", LISTINPUT_NAME)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, USER_ID)
+ .delete();
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
+ verify(componentsUtils, never()).getResponseFormat(ActionStatus.OK);
+ }
+
+
+ private Invocation.Builder buildCreateListInputCall() {
+ return target("/v1/catalog/services/{id}/create/listInput")
+ .resolveTemplate("id", RESOURCE_ID)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, USER_ID);
+ }
+
+ private Invocation.Builder buildGetDataTypeCall() {
+ return target("/v1/catalog/services/{id}/dataType/{dataTypeName}")
+ .resolveTemplate("id", RESOURCE_ID)
+ .resolveTemplate("dataTypeName", LISTINPUT_SCHEMA_TYPE)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, USER_ID);
+ }
+
+ private Invocation.Builder buildGetDataTypesCall() {
+ return target("/v1/catalog/services/{id}/dataTypes")
+ .resolveTemplate("id", RESOURCE_ID)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, USER_ID);
+ }
-public class InputsServletTest {
-
- private InputsServlet createTestSubject() {
- return new InputsServlet();
- }
-
-
- @Test
- public void testGetComponentInputs() throws Exception {
- InputsServlet testSubject;
- String componentType = "";
- String componentId = "";
- HttpServletRequest request = null;
- String fromName = "";
- int amount = 0;
- String userId = "";
- Response result;
-
- // default test
- testSubject = createTestSubject();
- }
-
-
- @Test
- public void testUpdateComponentInputs() throws Exception {
- InputsServlet testSubject;
- String containerComponentType = "";
- String componentId = "";
- String data = "";
- HttpServletRequest request = null;
- Response result;
-
- // default test
- testSubject = createTestSubject();
- }
-
-
- @Test
- public void testGetComponentInstanceInputs() throws Exception {
- InputsServlet testSubject;
- String componentType = "";
- String componentId = "";
- String instanceId = "";
- String originComonentUid = "";
- HttpServletRequest request = null;
- String userId = "";
- Response result;
-
- // default test
- testSubject = createTestSubject();
- }
-
-
- @Test
- public void testGetInputPropertiesForComponentInstance() throws Exception {
- InputsServlet testSubject;
- String componentType = "";
- String componentId = "";
- String instanceId = "";
- String inputId = "";
- HttpServletRequest request = null;
- String userId = "";
- Response result;
-
- // default test
- testSubject = createTestSubject();
- }
-
-
- @Test
- public void testGetInputsForComponentInput() throws Exception {
- InputsServlet testSubject;
- String componentType = "";
- String componentId = "";
- String inputId = "";
- HttpServletRequest request = null;
- String userId = "";
- Response result;
-
- // default test
- testSubject = createTestSubject();
- }
-
-
- @Test
- public void testGetInputsAndPropertiesForComponentInput() throws Exception {
- InputsServlet testSubject;
- String componentType = "";
- String componentId = "";
- String inputId = "";
- HttpServletRequest request = null;
- String userId = "";
- Response result;
-
- // default test
- testSubject = createTestSubject();
- }
-
-
- @Test
- public void testParseToComponentInstanceMap() throws Exception {
- InputsServlet testSubject;
- String serviceJson = "";
- User user = null;
- Either<ComponentInstInputsMap, ResponseFormat> result;
-
- // default test
- testSubject = createTestSubject();
- }
-
-
- @Test
- public void testCreateMultipleInputs() throws Exception {
- InputsServlet testSubject;
- String componentType = "";
- String componentId = "";
- HttpServletRequest request = null;
- String userId = "";
- String componentInstInputsMapObj = "";
- Response result;
-
- // default test
- testSubject = createTestSubject();
- }
-
-
- @Test
- public void testDeleteInput() throws Exception {
- InputsServlet testSubject;
- String componentType = "";
- String componentId = "";
- String inputId = "";
- HttpServletRequest request = null;
- String userId = "";
- String componentInstInputsMapObj = "";
- Response result;
-
- // default test
- testSubject = createTestSubject();
- }
-
-
- @Test
- public void testGetInputBL() throws Exception {
- InputsServlet testSubject;
- ServletContext context = null;
- InputsBusinessLogic result;
-
- // default test
- testSubject = createTestSubject();
- }
-} \ No newline at end of file
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
index d46d234595..78ed40a9e6 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
@@ -1,12 +1,14 @@
package org.openecomp.sdc.be.tosca;
+import fj.data.Either;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.function.Supplier;
-
+import java.util.stream.Collectors;
+import mockit.Deencapsulation;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Triple;
import org.junit.Before;
@@ -17,10 +19,12 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.BeConfDependentTest;
+import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
@@ -56,9 +60,6 @@ import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement;
import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate;
-
-import fj.data.Either;
-import mockit.Deencapsulation;
import org.openecomp.sdc.be.tosca.utils.InputConverter;
public class ToscaExportHandlerTest extends BeConfDependentTest {
@@ -98,6 +99,20 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
CategoryDefinition category = new CategoryDefinition();
List<SubCategoryDefinition> subcategories = new ArrayList<>();
SubCategoryDefinition subcategory = new SubCategoryDefinition();
+ List<DataTypeDefinition> dataTypes = new ArrayList<>();
+ DataTypeDefinition dataType = new DataTypeDefinition();
+ dataType.setName("dataTypeName");
+ dataType.setDerivedFromName("tosca.datatypes.Root");
+ PropertyDataDefinition propData = new PropertyDataDefinitionBuilder()
+ .setName("property")
+ .setType("type")
+ .build();
+ List<PropertyDataDefinition> propDataList = Arrays.asList(propData);
+ dataType.setPropertiesData(propDataList);
+ List<PropertyDefinition> propList = propDataList.stream().map(PropertyDefinition::new)
+ .collect(Collectors.toList());
+ dataType.setProperties(propList);
+ dataTypes.add(dataType);
subcategory.setName("name");
subcategories.add(subcategory);
@@ -110,6 +125,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
resource.setVendorName("vendorName");
resource.setVendorRelease("vendorRelease");
resource.setResourceVendorModelNumber("resourceVendorModelNumber");
+ resource.setDataTypes(dataTypes);
return resource;
}
@@ -1193,4 +1209,4 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
// default test
result = Deencapsulation.invoke(testSubject, "convertCapabilities", component, nodeType, dataTypes);
}
-} \ No newline at end of file
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaDataTypeTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaDataTypeTest.java
new file mode 100644
index 0000000000..94a7d055b7
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaDataTypeTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Fujitsu Limited. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class ToscaDataTypeTest {
+ private static final String DERIVED_FROM = "tosca.datatypes.Root";
+ private static final String VERSION = "1.1";
+ private static final String DESCRIPTION = "data type description";
+ private static final String PROPERTY_NAME = "prop1";
+ private static final String METADATA_KEY = "foo";
+ private static final String METADATA_VALUE = "bar";
+
+ private ToscaDataType testSubject;
+
+ @Test
+ public void testToscaDataType() throws Exception {
+ testSubject = new ToscaDataType();
+ testSubject.setDerived_from(DERIVED_FROM);
+ testSubject.setVersion(VERSION);
+ testSubject.setDescription(DESCRIPTION);
+ Map<String, String> metadata = new HashMap<>();
+ metadata.put(METADATA_KEY, METADATA_VALUE);
+ testSubject.setMetadata(metadata);
+ Map<String, ToscaProperty> properties = new HashMap<>();
+ properties.put(PROPERTY_NAME, new ToscaProperty());
+ testSubject.setProperties(properties);
+
+ assertThat(testSubject.getDerived_from(), is(DERIVED_FROM));
+ assertThat(testSubject.getVersion(), is(VERSION));
+ assertThat(testSubject.getDescription(), is(DESCRIPTION));
+ assertThat(testSubject.getMetadata(), is(metadata));
+ assertThat(testSubject.getProperties(), is(properties));
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateTest.java
index 613c7ed457..c250b4eec9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateTest.java
@@ -1,10 +1,12 @@
package org.openecomp.sdc.be.tosca.model;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
+import static org.junit.Assert.*;
public class ToscaTemplateTest {
@@ -122,9 +124,24 @@ public class ToscaTemplateTest {
testSubject.setTopology_template(topology_template);
}
-
+ @Test
+ public void testGetSetData_types() throws Exception {
+ ToscaTemplate testSubject = createTestSubject();
+ Map<String, ToscaDataType> dataTypes = new HashMap<>();
+ dataTypes.put("datatype", new ToscaDataType());
+ testSubject.setData_types(dataTypes);
+ assertEquals(dataTypes, testSubject.getData_types());
+ }
-
+
+ @Test
+ public void testGetSetInterface_types() throws Exception {
+ ToscaTemplate testSubject = createTestSubject();
+ Map<String, Object> interfaceTypes = new HashMap<>();
+ interfaceTypes.put("id", new Object());
+ testSubject.setInterface_types(interfaceTypes);
+ assertEquals(interfaceTypes, testSubject.getInterface_types());
+ }
} \ No newline at end of file