From 0da3e7d52c83b54b126dd52f23da3bb94e152fba Mon Sep 17 00:00:00 2001 From: Satoshi Fujii Date: Fri, 26 Apr 2019 20:00:07 +0900 Subject: Fixed properties merge logic not to lose properties from inputs Change-Id: I9dbc244c667272062bc4de90d616ea1c5458ed0a Issue-ID: SDC-2255 Signed-off-by: Satoshi Fujii --- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 5 ++- .../sdc/be/tosca/ToscaExportHandlerTest.java | 51 ++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) (limited to 'catalog-be') 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 65451e9dc5..127d6f67af 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 @@ -551,10 +551,13 @@ public class ToscaExportHandler { if(CollectionUtils.isNotEmpty(component.getProperties())) { List properties = component.getProperties(); - mergedProperties = properties.stream().collect(Collectors.toMap( + Map convertedProperties; + convertedProperties = properties.stream().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) && Objects.nonNull(inputDef)) { resolveDefaultPropertyValue(inputDef, mergedProperties, dataTypes); 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 78ed40a9e6..65298ea81d 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 @@ -35,6 +35,7 @@ import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.ComponentInstanceInput; import org.openecomp.sdc.be.model.ComponentInstanceProperty; +import org.openecomp.sdc.be.model.ComponentMetadataDefinition; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.GroupDefinition; @@ -57,12 +58,23 @@ import org.openecomp.sdc.be.tosca.model.ToscaCapability; import org.openecomp.sdc.be.tosca.model.ToscaMetadata; import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate; import org.openecomp.sdc.be.tosca.model.ToscaNodeType; +import org.openecomp.sdc.be.tosca.model.ToscaProperty; 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 org.openecomp.sdc.be.tosca.utils.InputConverter; +import org.yaml.snakeyaml.Yaml; + +import static org.junit.Assert.assertThat; +import static org.hamcrest.CoreMatchers.is; public class ToscaExportHandlerTest extends BeConfDependentTest { + private static final String COMPONENT_PROPERTY_NAME = "prop1"; + private static final String COMPONENT_PROPERTY_TYPE = "string"; + private static final String COMPONENT_INPUT_NAME = "input1"; + private static final String COMPONENT_INPUT_TYPE = "integer"; + private static final String RESOURCE_NAME = "resource"; + private static final String TOSCA_VERSION = "tosca_simple_yaml_1_1"; @InjectMocks ToscaExportHandler testSubject; @@ -196,6 +208,45 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { } + @Test + public void testConvertInterfaceNodeTypeProperties() throws Exception { + + Resource component = getNewResource(); + + component.setInterfaces(new HashMap<>()); + InputDefinition input = new InputDefinition(); + input.setName(COMPONENT_INPUT_NAME); + input.setType(COMPONENT_INPUT_TYPE); + component.setInputs(Collections.singletonList(input)); + PropertyDefinition property = new PropertyDefinition(); + property.setName(COMPONENT_PROPERTY_NAME); + property.setType(COMPONENT_PROPERTY_TYPE); + component.setProperties(Collections.singletonList(property)); + component.setName(RESOURCE_NAME); + component.setToscaResourceName(RESOURCE_NAME); + + Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + .thenReturn(Either.left(Collections.emptyMap())); + Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); + // when convertRequirements is called, make it return the same value as 3rd (index=2) argument. + Mockito + .when(capabiltyRequirementConvertor.convertRequirements(Mockito.any(Map.class), Mockito.any(Resource.class), + Mockito.any(ToscaNodeType.class))).thenAnswer(i -> Either.left(i.getArgument(2))); + + Either result = (Either) Deencapsulation + .invoke(testSubject, "convertInterfaceNodeType", new HashMap(), component, + new ToscaTemplate(TOSCA_VERSION), new HashMap(), false); + assertThat(result.isLeft(), is(true)); + Map nodeTypeMap = result.left().value().getNode_types(); + assertThat(nodeTypeMap.size(), is(1)); + ToscaNodeType toscaNodeType = nodeTypeMap.values().iterator().next(); + Map propertyMap = toscaNodeType.getProperties(); + // Check if inputs and properties in component are merged properly + assertThat(propertyMap.size(), is(2)); + assertThat(propertyMap.containsKey(COMPONENT_INPUT_NAME), is(true)); + assertThat(propertyMap.containsKey(COMPONENT_PROPERTY_NAME), is(true)); + } + @Test public void testCreateToscaRepresentation() throws Exception { ToscaTemplate toscaTemplate = new ToscaTemplate(""); -- cgit 1.2.3-korg