From bc7dd3ad94acace55a2910abc22cc5cb64e0862d Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Thu, 4 May 2023 13:27:26 +0100 Subject: UI support for default custom function names with get_input structure Issue-ID: SDC-4493 Signed-off-by: JvD_Ericsson Change-Id: Iba3eda9bb5d57aabbe86045b6150564e17a0ff3e --- .../ToscaFunctionJsonDeserializerTest.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'common-be/src/test/java/org/openecomp') diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializerTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializerTest.java index d7c2e7c65e..5128c63668 100644 --- a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializerTest.java +++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializerTest.java @@ -33,9 +33,12 @@ import com.fasterxml.jackson.databind.exc.ValueInstantiationException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.config.Configuration; +import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.datatypes.enums.PropertySource; import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; import org.yaml.snakeyaml.Yaml; @@ -142,6 +145,7 @@ class ToscaFunctionJsonDeserializerTest { @Test void testCustomToscaFunction() throws IOException { //given + setDefaultCustomToscaFunctionOnConfiguration(); final String toscaCustomFunction = Files.readString(TEST_RESOURCES_PATH.resolve("customFunction.json")); //when final ToscaFunction toscaFunction = parseToscaFunction(toscaCustomFunction); @@ -189,6 +193,55 @@ class ToscaFunctionJsonDeserializerTest { assertEquals("string3", customParameters.get(1)); } + @Test + void testCustomToscaFunctionGetInputType() throws IOException { + //given + setDefaultCustomToscaFunctionOnConfiguration(); + final String toscaCustomFunctionFile = Files.readString(TEST_RESOURCES_PATH.resolve("customFunctionGetInputType.json")); + //when + final ToscaFunction toscaFunction = parseToscaFunction(toscaCustomFunctionFile); + //then + assertTrue(toscaFunction instanceof ToscaCustomFunction); + ToscaCustomFunction toscaCustomFunction = (ToscaCustomFunction) toscaFunction; + final Object yamlObject = new Yaml().load(toscaFunction.getValue()); + assertTrue(yamlObject instanceof Map); + final Map yamlMap = (Map) yamlObject; + assertEquals(1, yamlMap.size()); + final Object customFunctionGetInputValue = yamlMap.get("$" + ((ToscaCustomFunction) toscaFunction).getName()); + assertTrue(customFunctionGetInputValue instanceof ArrayList); + ArrayList customFunctionGetInputValueList = (ArrayList) customFunctionGetInputValue; + assertEquals(1, customFunctionGetInputValueList.size()); + assertEquals(1, customFunctionGetInputValueList.size()); + assertEquals("controller_actor", customFunctionGetInputValueList.get(0)); + + List parameters = toscaCustomFunction.getParameters(); + assertEquals(1, parameters.size()); + ToscaFunctionParameter paramFunction = toscaCustomFunction.getParameters().get(0); + assertTrue(paramFunction instanceof ToscaGetFunctionDataDefinition); + + final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) paramFunction; + assertEquals(ToscaFunctionType.GET_INPUT, toscaGetFunction.getType()); + assertEquals(ToscaGetFunctionType.GET_INPUT, toscaGetFunction.getFunctionType()); + assertEquals("dd0ec4d2-7e74-4d92-af2f-89c7436baa63.controller_actor", toscaGetFunction.getPropertyUniqueId()); + assertEquals(PropertySource.SELF, toscaGetFunction.getPropertySource()); + assertEquals("controller_actor", toscaGetFunction.getPropertyName()); + assertEquals("testService", toscaGetFunction.getSourceName()); + assertEquals("dd0ec4d2-7e74-4d92-af2f-89c7436baa63", toscaGetFunction.getSourceUniqueId()); + assertEquals(List.of("controller_actor"), toscaGetFunction.getPropertyPathFromSource()); + } + + private void setDefaultCustomToscaFunctionOnConfiguration() { + final var configurationManager = new ConfigurationManager(); + final var configuration = new Configuration(); + List defaultCustomToscaFunctions = new ArrayList<>(); + Configuration.CustomToscaFunction defaultCustomType = new Configuration.CustomToscaFunction(); + defaultCustomType.setName("custom_function_get_input_type"); + defaultCustomType.setType("get_input"); + defaultCustomToscaFunctions.add(defaultCustomType); + configuration.setDefaultCustomToscaFunctions(defaultCustomToscaFunctions); + configurationManager.setConfiguration(configuration); + } + private ToscaFunction parseToscaFunction(final String toscaFunctionJson) throws JsonProcessingException { return new ObjectMapper().readValue(toscaFunctionJson, ToscaFunction.class); } -- cgit 1.2.3-korg