summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/property
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test/java/org/openecomp/sdc/be/components/property')
-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
7 files changed, 535 insertions, 16 deletions
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));