From 1a6dc06b35e3d49953325a3d6c1eefee76ac8601 Mon Sep 17 00:00:00 2001 From: ojasdubey Date: Fri, 7 Jun 2019 16:36:39 +0530 Subject: Fix Service proxy node template Fixes for issues: 1. Declared properties of VFCs not appearing in proxy node template 2. Proper value resolution of proxy properties Change-Id: I4b5bedc7e2a4b4071f3adb4dfe909db80575c25a Issue-ID: SDC-2359 Signed-off-by: ojasdubey --- .../components/impl/utils/PropertiesUtilsTest.java | 131 ++++++++++++++++++++- .../sdc/be/tosca/ToscaExportUtilsTest.java | 40 ------- 2 files changed, 127 insertions(+), 44 deletions(-) (limited to 'catalog-be/src/test/java/org') 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 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 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 propertyDefinitions = + Collections.singletonList(buildPropertyDefinition("undeclaredProperty", undeclaredPropertyValue)); + when(service.getProperties()).thenReturn(propertyDefinitions); + when(service.getInputs()).thenReturn(null); + final List properties = PropertiesUtils.getProperties(service); + assertEquals(1, properties.size()); + assertEquals(undeclaredPropertyValue, properties.get(0).getValue()); + } + + @Test + public void testProxyInstanceGetPropertiesUndeclaredPropertyWithoutValue(){ + List propertyDefinitions = + Collections.singletonList(buildPropertyDefinition("undeclaredProperty")); + when(service.getProperties()).thenReturn(propertyDefinitions); + when(service.getInputs()).thenReturn(null); + final List 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 propertyDefinitions = + Collections.singletonList(buildPropertyDefinitionForDeclaredProperty( + declaredPropertyName, mappedInputName)); + when(service.getProperties()).thenReturn(propertyDefinitions); + List inputDefinitions = + Collections.singletonList(buildInputDefinitionForMappedProperty(mappedInputName, inputValue, + "componentUUID." + declaredPropertyName)); + when(service.getInputs()).thenReturn(inputDefinitions); + final List properties = PropertiesUtils.getProperties(service); + assertEquals(2, properties.size()); + + Optional 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 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 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 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 @@ -87,46 +87,6 @@ public class ToscaExportUtilsTest { Assert.assertEquals(2, componentProperties.size()); } - @Test - public void testResolvePropertyDefaultValueFromInputNoInputs() { - Component service = getTestComponent(); - service.setProperties(Collections.singletonList(createMockProperty("componentPropStr", null))); - Optional> properties = ToscaExportUtils.getProxyNodeTypeProperties(service, - dataTypes); - Assert.assertTrue(properties.isPresent()); - Map 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> properties = ToscaExportUtils.getProxyNodeTypeProperties(service, - dataTypes); - Assert.assertTrue(properties.isPresent()); - Map nodeTypeProperties = properties.get(); - List 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(); -- cgit 1.2.3-korg