aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java38
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java20
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java32
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/PropertiesUtilsTest.java131
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportUtilsTest.java40
5 files changed, 170 insertions, 91 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java
index 7bea8356a7..613ced6454 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java
@@ -16,11 +16,14 @@
package org.openecomp.sdc.be.components.utils;
+import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
@@ -29,6 +32,8 @@ import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.collections4.ListUtils;
+import org.apache.commons.collections4.SetUtils;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
@@ -39,8 +44,6 @@ import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
-import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
-
public class PropertiesUtils {
private PropertiesUtils() {
@@ -53,16 +56,33 @@ public class PropertiesUtils {
properties = new ArrayList<>();
}
Set<PropertyDefinition> serviceProperties = new HashSet<>(properties);
- if (service.getInputs() != null) {
- Set<PropertyDefinition> inputs = service.getInputs().stream().map(PropertyDefinition::new)
- .collect(Collectors.toSet());
- serviceProperties.addAll(inputs);
- }
- serviceProperties =
- serviceProperties.stream().filter(distinctByKey(PropertyDefinition::getName)).collect(Collectors.toSet());
+ SetUtils.emptyIfNull(serviceProperties)
+ .forEach(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition,
+ service.getInputs()));
+ Set<PropertyDefinition> inputs = ListUtils.emptyIfNull(service.getInputs()).stream()
+ .map(PropertyDefinition::new)
+ .collect(Collectors.toSet());
+ serviceProperties.addAll(inputs);
+ serviceProperties = serviceProperties.stream()
+ .filter(distinctByKey(PropertyDefinition::getName))
+ .collect(Collectors.toSet());
return new ArrayList<>(serviceProperties);
}
+ public static PropertyDefinition resolvePropertyValueFromInput(PropertyDefinition propertyDefinition,
+ List<InputDefinition> componentInputs) {
+ if (Objects.isNull(propertyDefinition) || CollectionUtils.isEmpty(componentInputs)) {
+ return propertyDefinition;
+ }
+ Optional<InputDefinition> mappedInput = componentInputs.stream()
+ .filter(componentInput -> Objects.nonNull(componentInput.getPropertyId())
+ && componentInput.getPropertyId().equals(propertyDefinition.getUniqueId()))
+ .findFirst();
+ mappedInput.ifPresent(inputDefinition -> propertyDefinition.setValue(inputDefinition.getValue()));
+ return propertyDefinition;
+ }
+
+
public static Optional<ComponentInstanceProperty> isCapabilityProperty(String propertyUniqueId,
Component containerComponent) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 1301a1c7a9..e6e69bf8de 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -75,12 +75,12 @@ import java.util.stream.Collectors;
import static org.apache.commons.collections.CollectionUtils.isEmpty;
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
import static org.apache.commons.collections.MapUtils.isNotEmpty;
+import static org.openecomp.sdc.be.components.utils.PropertiesUtils.resolvePropertyValueFromInput;
import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.addInterfaceDefinitionElement;
import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.addInterfaceTypeElement;
import static org.openecomp.sdc.be.tosca.utils.ToscaExportUtils.addInputsToProperties;
import static org.openecomp.sdc.be.tosca.utils.ToscaExportUtils.getProxyNodeTypeInterfaces;
import static org.openecomp.sdc.be.tosca.utils.ToscaExportUtils.getProxyNodeTypeProperties;
-import static org.openecomp.sdc.be.tosca.utils.ToscaExportUtils.resolvePropertyDefaultValueFromInput;
@org.springframework.stereotype.Component("tosca-export-handler")
public class ToscaExportHandler {
@@ -563,15 +563,15 @@ public class ToscaExportHandler {
if(CollectionUtils.isNotEmpty(component.getProperties())) {
List<PropertyDefinition> properties = component.getProperties();
- Map<String, ToscaProperty> convertedProperties = properties.stream().collect(Collectors.toMap(
- PropertyDataDefinition::getName,
- property -> propertyConvertor.convertProperty(dataTypes, property,
- PropertyConvertor.PropertyType.PROPERTY)));
+ Map<String, ToscaProperty> convertedProperties = properties.stream()
+ .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition, component.getInputs()))
+ .collect(Collectors.toMap(PropertyDataDefinition::getName,
+ property -> propertyConvertor.convertProperty(dataTypes, property,
+ PropertyConvertor.PropertyType.PROPERTY)));
// merge component properties and inputs properties
mergedProperties.putAll(convertedProperties);
}
if (MapUtils.isNotEmpty(mergedProperties)) {
- resolvePropertyDefaultValueFromInput(inputDef, mergedProperties, dataTypes);
toscaNodeType.setProperties(mergedProperties);
}
@@ -705,14 +705,14 @@ public class ToscaExportHandler {
addPropertiesOfParentComponent(dataTypes, originalComponent, props);
}
- if (null != componentInstancesProperties && componentInstancesProperties.containsKey(instanceUniqueId)
- && !isComponentOfTypeServiceProxy(componentInstance)) {
- addPropertiesOfComponentInstance(componentInstancesProperties, dataTypes,
- instanceUniqueId, props);
+ if (null != componentInstancesProperties && componentInstancesProperties.containsKey(instanceUniqueId)) {
+ addPropertiesOfComponentInstance(componentInstancesProperties, dataTypes, instanceUniqueId,
+ props);
}
if (componentInstancesInputs != null && componentInstancesInputs.containsKey(instanceUniqueId)
&& !isComponentOfTypeServiceProxy(componentInstance)) {
+ //For service proxy the inputs are already handled under instance properties above
addComponentInstanceInputs(dataTypes, componentInstancesInputs, instanceUniqueId,
props);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java
index 20e0698276..9cce43ccd3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java
@@ -16,6 +16,8 @@
package org.openecomp.sdc.be.tosca.utils;
+import static org.openecomp.sdc.be.components.utils.PropertiesUtils.resolvePropertyValueFromInput;
+
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -29,7 +31,6 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
-import org.openecomp.sdc.be.model.tosca.ToscaFunctions;
import org.openecomp.sdc.be.tosca.PropertyConvertor;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
@@ -58,41 +59,16 @@ public class ToscaExportUtils {
addInputsToProperties(dataTypes, proxyComponent.getInputs(), proxyProperties);
if (CollectionUtils.isNotEmpty(proxyComponent.getProperties())) {
proxyProperties.putAll(proxyComponent.getProperties().stream()
+ .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition,
+ proxyComponent.getInputs()))
.collect(Collectors.toMap(PropertyDataDefinition::getName,
property -> PropertyConvertor.getInstance().convertProperty(dataTypes, property,
PropertyConvertor.PropertyType.PROPERTY))));
}
- resolvePropertyDefaultValueFromInput(proxyComponent.getInputs(), proxyProperties, dataTypes);
-
return MapUtils.isNotEmpty(proxyProperties) ? Optional.of(proxyProperties) : Optional.empty();
}
- public static void resolvePropertyDefaultValueFromInput(List<InputDefinition> componentInputs,
- Map<String, ToscaProperty> mergedProperties,
- Map<String, DataTypeDefinition> dataTypes) {
- if (MapUtils.isEmpty(mergedProperties) || CollectionUtils.isEmpty(componentInputs)) {
- return;
- }
- for (Map.Entry<String, ToscaProperty> mergedPropertyEntry : mergedProperties.entrySet()) {
- ToscaProperty value = mergedPropertyEntry.getValue();
- if (Objects.nonNull(value) && value.getDefaultp() instanceof Map) {
- Map<String, String> valueAsMap = (Map<String, String>) value.getDefaultp();
- String inputName = valueAsMap.get(ToscaFunctions.GET_INPUT.getFunctionName());
- Optional<InputDefinition> matchedInputDefinition = componentInputs.stream()
- .filter(componentInput -> componentInput.getName().equals(inputName))
- .findFirst();
- if (matchedInputDefinition.isPresent()) {
- InputDefinition matchedInput = matchedInputDefinition.get();
- Object resolvedDefaultValue = new PropertyConvertor().convertToToscaObject(matchedInput.getType(),
- matchedInput.getDefaultValue(), matchedInput.getSchemaType(), dataTypes, false);
- value.setDefaultp(resolvedDefaultValue);
- mergedProperties.put(mergedPropertyEntry.getKey(), value);
- }
- }
- }
- }
-
public static void addInputsToProperties(Map<String, DataTypeDefinition> dataTypes,
List<InputDefinition> componentInputs,
Map<String, ToscaProperty> mergedProperties) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/PropertiesUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/PropertiesUtilsTest.java
index 7e15eaa862..757e47a8f7 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/PropertiesUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/PropertiesUtilsTest.java
@@ -16,6 +16,7 @@
package org.openecomp.sdc.be.components.impl.utils;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
@@ -24,6 +25,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import org.junit.Assert;
import org.junit.Test;
@@ -42,6 +44,7 @@ import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
+
@RunWith(MockitoJUnitRunner.class)
public class PropertiesUtilsTest {
@Mock
@@ -51,7 +54,7 @@ public class PropertiesUtilsTest {
@Test
public void testProxyServiceProperties(){
when(service.getProperties()).thenReturn(Arrays.asList(buildPropertyDefinition("a"),buildPropertyDefinition("b")));
- when(service.getInputs()).thenReturn(Arrays.asList(buildInputDefiniton("a"),buildInputDefiniton("c")));
+ when(service.getInputs()).thenReturn(Arrays.asList(buildInputDefinition("a"), buildInputDefinition("c")));
final List<PropertyDefinition> properties = PropertiesUtils.getProperties(service);
assertEquals(3, properties.size());
@@ -69,7 +72,7 @@ public class PropertiesUtilsTest {
@Test
public void testProxyServiceNullProperties(){
when(service.getProperties()).thenReturn(null);
- when(service.getInputs()).thenReturn(Arrays.asList(buildInputDefiniton("a"),buildInputDefiniton("c")));
+ when(service.getInputs()).thenReturn(Arrays.asList(buildInputDefinition("a"), buildInputDefinition("c")));
final List<PropertyDefinition> properties = PropertiesUtils.getProperties(service);
assertEquals(2, properties.size());
@@ -149,18 +152,138 @@ public class PropertiesUtilsTest {
assertEquals(0, properties.size());
}
- private PropertyDefinition buildPropertyDefinition(String name){
+ @Test
+ public void testProxyInstanceGetPropertiesUndeclaredPropertyWithValue(){
+ String undeclaredPropertyValue = "testPropDefaultValue";
+ List<PropertyDefinition> propertyDefinitions =
+ Collections.singletonList(buildPropertyDefinition("undeclaredProperty", undeclaredPropertyValue));
+ when(service.getProperties()).thenReturn(propertyDefinitions);
+ when(service.getInputs()).thenReturn(null);
+ final List<PropertyDefinition> properties = PropertiesUtils.getProperties(service);
+ assertEquals(1, properties.size());
+ assertEquals(undeclaredPropertyValue, properties.get(0).getValue());
+ }
+
+ @Test
+ public void testProxyInstanceGetPropertiesUndeclaredPropertyWithoutValue(){
+ List<PropertyDefinition> propertyDefinitions =
+ Collections.singletonList(buildPropertyDefinition("undeclaredProperty"));
+ when(service.getProperties()).thenReturn(propertyDefinitions);
+ when(service.getInputs()).thenReturn(null);
+ final List<PropertyDefinition> properties = PropertiesUtils.getProperties(service);
+ assertEquals(1, properties.size());
+ assertNull(properties.get(0).getValue());
+ }
+
+ @Test
+ public void testProxyInstanceGetPropertiesResolvePropertyValueFromInput() {
+ String declaredPropertyName = "declaredProperty";
+ String mappedInputName = "mappedInput";
+ //Setting default value in input
+ String inputValue = "testDefaultValue";
+ List<PropertyDefinition> propertyDefinitions =
+ Collections.singletonList(buildPropertyDefinitionForDeclaredProperty(
+ declaredPropertyName, mappedInputName));
+ when(service.getProperties()).thenReturn(propertyDefinitions);
+ List<InputDefinition> inputDefinitions =
+ Collections.singletonList(buildInputDefinitionForMappedProperty(mappedInputName, inputValue,
+ "componentUUID." + declaredPropertyName));
+ when(service.getInputs()).thenReturn(inputDefinitions);
+ final List<PropertyDefinition> properties = PropertiesUtils.getProperties(service);
+ assertEquals(2, properties.size());
+
+ Optional<PropertyDefinition> declaredProperty = properties.stream()
+ .filter(propertyDefinition -> propertyDefinition.getName().equals(declaredPropertyName))
+ .findFirst();
+ Assert.assertTrue(declaredProperty.isPresent());
+ assertEquals(inputValue, declaredProperty.get().getValue());
+ }
+
+
+ @Test
+ public void testResolvePropertyValueFromInput() {
+ String mappedInputValue = "Default String Input Value";
+ PropertyDefinition mappedProperty =
+ buildPropertyDefinitionForDeclaredProperty("componentPropStr1", "componentInputStr1");
+ List<InputDefinition> componentInputs =
+ Collections.singletonList(buildInputDefinitionForMappedProperty("componentInputStr1", mappedInputValue,
+ "componentUUID.componentPropStr1"));
+ PropertyDefinition updatedPropertyDefinition =
+ PropertiesUtils.resolvePropertyValueFromInput(mappedProperty, componentInputs);
+ Assert.assertNotNull(updatedPropertyDefinition);
+ Assert.assertEquals(mappedInputValue, updatedPropertyDefinition.getValue());
+ }
+
+
+ @Test
+ public void testResolvePropertyValueFromInputNoInputs() {
+ PropertyDefinition mappedProperty =
+ buildPropertyDefinitionForDeclaredProperty("componentPropStr1", "componentInputStr1");
+ PropertyDefinition updatedPropertyDefinition =
+ PropertiesUtils.resolvePropertyValueFromInput(mappedProperty, null);
+ Assert.assertNotNull(updatedPropertyDefinition);
+ Assert.assertEquals(mappedProperty.getValue(), updatedPropertyDefinition.getValue());
+ }
+
+ @Test
+ public void testResolvePropertyValueFromInputPropertyDefinitionNull() {
+ List<InputDefinition> componentInputs =
+ Arrays.asList(buildInputDefinitionForMappedProperty("componentInputStr1", "Default Value",
+ "componentPropStr1"), buildInputDefinitionForMappedProperty("componentInputStr2",
+ "Default String Input2", "componentPropStr2"));
+ PropertyDefinition updatedPropertyDefinition =
+ PropertiesUtils.resolvePropertyValueFromInput(null, componentInputs);
+ Assert.assertNull(updatedPropertyDefinition);
+ }
+
+ @Test
+ public void testResolvePropertyValueFromInputUndeclaredProperty() {
+ String propertyValue = "Default String Property Value";
+ PropertyDefinition undeclaredProperty =
+ buildPropertyDefinition("componentPropStr1", propertyValue);
+ List<InputDefinition> componentInputs =
+ Arrays.asList(buildInputDefinition("componentInputStr1"), buildInputDefinition("componentInputStr2"));
+ PropertyDefinition updatedPropertyDefinition =
+ PropertiesUtils.resolvePropertyValueFromInput(undeclaredProperty, componentInputs);
+ Assert.assertNotNull(updatedPropertyDefinition);
+ Assert.assertEquals(undeclaredProperty.getValue(), updatedPropertyDefinition.getValue());
+ }
+
+ private PropertyDefinition buildPropertyDefinition(String name) {
PropertyDefinition retVal = new PropertyDefinition();
+ retVal.setUniqueId("componentUUID." + name);
retVal.setName(name);
return retVal;
}
- private InputDefinition buildInputDefiniton(String name){
+ private PropertyDefinition buildPropertyDefinition(String name, String value) {
+ PropertyDefinition retVal = buildPropertyDefinition(name);
+ retVal.setValue(value);
+ return retVal;
+ }
+
+ private InputDefinition buildInputDefinition(String name){
InputDefinition retVal = new InputDefinition();
retVal.setName(name);
return retVal;
}
+ private PropertyDefinition buildPropertyDefinitionForDeclaredProperty(String propertyName, String inputName){
+ String declaredPropertyValue = "{get_input : " + inputName + " }";
+ return buildPropertyDefinition(propertyName, declaredPropertyValue);
+ }
+
+ private InputDefinition buildInputDefinitionForMappedProperty(String inputName, String inputValue,
+ String mappedPropertyId){
+ InputDefinition inputDefinition = new InputDefinition();
+ inputDefinition.setName(inputName);
+ inputDefinition.setType("string");
+ inputDefinition.setPropertyId(mappedPropertyId);
+ inputDefinition.setDefaultValue(inputValue);
+ inputDefinition.setValue(inputValue);
+ return inputDefinition;
+ }
+
private ComponentInstanceProperty createProperties() {
ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
instanceProperty.setUniqueId("inputId");
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportUtilsTest.java
index 87cc6e8d20..1906b9eeb9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportUtilsTest.java
@@ -88,46 +88,6 @@ public class ToscaExportUtilsTest {
}
@Test
- public void testResolvePropertyDefaultValueFromInputNoInputs() {
- Component service = getTestComponent();
- service.setProperties(Collections.singletonList(createMockProperty("componentPropStr", null)));
- Optional<Map<String, ToscaProperty>> properties = ToscaExportUtils.getProxyNodeTypeProperties(service,
- dataTypes);
- Assert.assertTrue(properties.isPresent());
- Map<String, ToscaProperty> nodeTypeProperties = properties.get();
- ToscaExportUtils.resolvePropertyDefaultValueFromInput(null, nodeTypeProperties, dataTypes);
- nodeTypeProperties.values().forEach(val -> Assert.assertNull(val.getDefaultp()));
- }
-
- @Test
- public void testResolvePropertyDefaultValueFromInput() {
- Component service = getTestComponent();
- service.setProperties(Arrays.asList(createMockProperty("componentPropStr1", "{get_input: componentInputStr1}"),
- createMockProperty("componentPropStr2", "Default prop value"),
- createMockProperty("componentPropStr3", null)));
- Optional<Map<String, ToscaProperty>> properties = ToscaExportUtils.getProxyNodeTypeProperties(service,
- dataTypes);
- Assert.assertTrue(properties.isPresent());
- Map<String, ToscaProperty> nodeTypeProperties = properties.get();
- List<InputDefinition> componentInputs = Arrays.asList(createMockInput("componentInputStr1",
- "Default String Input1"), createMockInput("componentInputStr2", "Default String Input2"));
- ToscaExportUtils.resolvePropertyDefaultValueFromInput(componentInputs, nodeTypeProperties, dataTypes);
- nodeTypeProperties.entrySet().stream()
- .filter(entry -> entry.getKey().equals("componentPropStr1"))
- .forEach(entry -> Assert.assertEquals("Default String Input1",
- entry.getValue().getDefaultp().toString()));
-
- nodeTypeProperties.entrySet().stream()
- .filter(entry -> entry.getKey().equals("componentPropStr2"))
- .forEach(entry -> Assert.assertEquals("Default prop value",
- entry.getValue().getDefaultp().toString()));
-
- nodeTypeProperties.entrySet().stream()
- .filter(entry -> entry.getKey().equals("componentPropStr3"))
- .forEach(entry -> Assert.assertNull(entry.getValue().getDefaultp()));
- }
-
- @Test
public void testAddInputsToPropertiesNoInputs() {
Component service = getTestComponent();
service.setProperties(Arrays.asList(createMockProperty("componentPropStr", "Default String Prop"),