diff options
author | Satoshi Fujii <fujii-satoshi@jp.fujitsu.com> | 2019-04-26 20:00:07 +0900 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-05-08 14:52:59 +0000 |
commit | 0da3e7d52c83b54b126dd52f23da3bb94e152fba (patch) | |
tree | 109c0dfc595e979576fcab5ec3c38d852cc3a54d | |
parent | faaad99b7304d2d0901c282e7597acc453a77655 (diff) |
Fixed properties merge logic not to lose properties from inputs
Change-Id: I9dbc244c667272062bc4de90d616ea1c5458ed0a
Issue-ID: SDC-2255
Signed-off-by: Satoshi Fujii <fujii-satoshi@jp.fujitsu.com>
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java | 5 | ||||
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java | 51 |
2 files changed, 55 insertions, 1 deletions
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<PropertyDefinition> properties = component.getProperties(); - mergedProperties = properties.stream().collect(Collectors.toMap( + Map<String, ToscaProperty> 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; @@ -197,6 +209,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<ToscaTemplate, ToscaError> result = (Either<ToscaTemplate, ToscaError>) Deencapsulation + .invoke(testSubject, "convertInterfaceNodeType", new HashMap<String, Component>(), component, + new ToscaTemplate(TOSCA_VERSION), new HashMap<String, ToscaNodeType>(), false); + assertThat(result.isLeft(), is(true)); + Map<String, ToscaNodeType> nodeTypeMap = result.left().value().getNode_types(); + assertThat(nodeTypeMap.size(), is(1)); + ToscaNodeType toscaNodeType = nodeTypeMap.values().iterator().next(); + Map<String, ToscaProperty> 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(""); ToscaRepresentation result; |