diff options
author | JvD_Ericsson <jeff.van.dam@est.tech> | 2023-05-04 13:27:26 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-05-18 10:41:07 +0000 |
commit | bc7dd3ad94acace55a2910abc22cc5cb64e0862d (patch) | |
tree | 43948e332fa27ea7cecc70ba19388bb63e1069d0 /common-be/src/test | |
parent | 38eaf2ddd678a837e2bfed25d5b4b45d72fce338 (diff) |
UI support for default custom function names with get_input structure
Issue-ID: SDC-4493
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: Iba3eda9bb5d57aabbe86045b6150564e17a0ff3e
Diffstat (limited to 'common-be/src/test')
2 files changed, 71 insertions, 0 deletions
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<String, Object> yamlMap = (Map<String, Object>) yamlObject; + assertEquals(1, yamlMap.size()); + final Object customFunctionGetInputValue = yamlMap.get("$" + ((ToscaCustomFunction) toscaFunction).getName()); + assertTrue(customFunctionGetInputValue instanceof ArrayList); + ArrayList<Object> customFunctionGetInputValueList = (ArrayList<Object>) customFunctionGetInputValue; + assertEquals(1, customFunctionGetInputValueList.size()); + assertEquals(1, customFunctionGetInputValueList.size()); + assertEquals("controller_actor", customFunctionGetInputValueList.get(0)); + + List<ToscaFunctionParameter> 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<Configuration.CustomToscaFunction> 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); } diff --git a/common-be/src/test/resources/toscaFunctionJsonDeserializer/customFunctionGetInputType.json b/common-be/src/test/resources/toscaFunctionJsonDeserializer/customFunctionGetInputType.json new file mode 100644 index 0000000000..81ae571c01 --- /dev/null +++ b/common-be/src/test/resources/toscaFunctionJsonDeserializer/customFunctionGetInputType.json @@ -0,0 +1,18 @@ +{ + "type": "CUSTOM", + "name": "custom_function_get_input_type", + "parameters": [ + { + "propertyUniqueId": "dd0ec4d2-7e74-4d92-af2f-89c7436baa63.controller_actor", + "propertyName": "controller_actor", + "propertySource": "SELF", + "sourceUniqueId": "dd0ec4d2-7e74-4d92-af2f-89c7436baa63", + "sourceName": "testService", + "functionType": "GET_INPUT", + "propertyPathFromSource": [ + "controller_actor" + ], + "type": "GET_INPUT" + } + ] +}
\ No newline at end of file |