From 1f7c6cccdd3a9544a7760db9a305403def4e5365 Mon Sep 17 00:00:00 2001 From: vasraz Date: Thu, 17 Aug 2023 11:31:31 +0100 Subject: Fix 'Tosca Function get_input in Properties Assignment error'-bug Signed-off-by: Vasyl Razinkov Change-Id: If404b777b7be312d7f51c3d27905af898eb74eb6 Issue-ID: SDC-4598 --- .../be/datatypes/elements/PropertyDataDefinition.java | 1 - .../elements/ToscaGetFunctionDataDefinition.java | 9 +++++---- .../elements/ToscaFunctionJsonDeserializerTest.java | 18 ++++++++++-------- .../elements/ToscaGetFunctionDataDefinitionTest.java | 10 +++++----- .../customFunctionGetInputType.json | 15 ++++++++++----- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java index 5a7acf4919..ee5cd0ec96 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java @@ -332,7 +332,6 @@ public class PropertyDataDefinition extends ToscaDataDefinition { return this.toscaGetFunctionType != null || this.toscaFunction != null; } - @JsonIgnoreProperties public boolean isToscaGetFunction() { return this.toscaFunction != null diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java index 82958a7532..6f78c6828a 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java @@ -126,17 +126,18 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct } private Map buildGetInputFunctionValue() { - List propertySourceCopy = new ArrayList(this.propertyPathFromSource); - List propertySourceOneCopy = new ArrayList<>(); + final List propertySourceCopy = new ArrayList<>(this.propertyPathFromSource); + final List propertySourceOneCopy = new ArrayList<>(); propertySourceOneCopy.add(this.propertyPathFromSource.get(0)); if (CollectionUtils.isNotEmpty(toscaIndexList)) { propertySourceCopy.addAll(toscaIndexList); propertySourceOneCopy.addAll(toscaIndexList); } if (this.propertyPathFromSource.size() == 1) { - return Map.of(this.functionType.getFunctionName(), propertySourceOneCopy); + return Map.of(functionType.getFunctionName(), propertySourceOneCopy.size() == 1 ? propertySourceOneCopy.get(0) : propertySourceOneCopy); + } else { + return Map.of(functionType.getFunctionName(), propertySourceCopy.size() == 1 ? propertySourceCopy.get(0) : propertySourceCopy); } - return Map.of(this.functionType.getFunctionName(), propertySourceCopy); } @Override 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 5128c63668..d0bc953df1 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 @@ -209,10 +209,12 @@ class ToscaFunctionJsonDeserializerTest { 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 customFunctionGetInputValueList = (ArrayList) customFunctionGetInputValue; + assertEquals(4, customFunctionGetInputValueList.size()); + assertEquals("pLMNInfoList", customFunctionGetInputValueList.get(0)); + assertEquals(1, customFunctionGetInputValueList.get(1)); + assertEquals("snssai", customFunctionGetInputValueList.get(2)); + assertEquals("sd", customFunctionGetInputValueList.get(3)); List parameters = toscaCustomFunction.getParameters(); assertEquals(1, parameters.size()); @@ -222,12 +224,12 @@ class ToscaFunctionJsonDeserializerTest { 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("dd0ec4d2-7e74-4d92-af2f-89c7436baa63.pLMNInfoList", toscaGetFunction.getPropertyUniqueId()); assertEquals(PropertySource.SELF, toscaGetFunction.getPropertySource()); - assertEquals("controller_actor", toscaGetFunction.getPropertyName()); + assertEquals("pLMNInfoList", toscaGetFunction.getPropertyName()); assertEquals("testService", toscaGetFunction.getSourceName()); assertEquals("dd0ec4d2-7e74-4d92-af2f-89c7436baa63", toscaGetFunction.getSourceUniqueId()); - assertEquals(List.of("controller_actor"), toscaGetFunction.getPropertyPathFromSource()); + assertEquals(List.of("pLMNInfoList"), toscaGetFunction.getPropertyPathFromSource()); } private void setDefaultCustomToscaFunctionOnConfiguration() { @@ -245,4 +247,4 @@ class ToscaFunctionJsonDeserializerTest { private ToscaFunction parseToscaFunction(final String toscaFunctionJson) throws JsonProcessingException { return new ObjectMapper().readValue(toscaFunctionJson, ToscaFunction.class); } -} \ No newline at end of file +} diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java index 3add149e23..fbbaff56d1 100644 --- a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java +++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java @@ -62,8 +62,8 @@ class ToscaGetFunctionDataDefinitionTest { final Map getInputJsonAsMap = convertJsonStringToMap(actualValue); assertTrue(getInputJsonAsMap.containsKey(ToscaGetFunctionType.GET_INPUT.getFunctionName())); final Object value = getInputJsonAsMap.get(ToscaGetFunctionType.GET_INPUT.getFunctionName()); - assertTrue(value instanceof List); - assertEquals(((List)value).get(0), propertyName); + assertTrue(value instanceof String); + assertEquals(value, propertyName); } @Test @@ -86,7 +86,7 @@ class ToscaGetFunctionDataDefinitionTest { } @ParameterizedTest - @EnumSource(value = ToscaGetFunctionType.class, names = {"GET_ATTRIBUTE", "GET_PROPERTY"}) + @EnumSource(value = ToscaGetFunctionType.class, names = {"GET_ATTRIBUTE", "GET_PROPERTY"}) void generateValueForGetFunctionWithSelfAsSourceTest(final ToscaGetFunctionType toscaFunction) { //given final var toscaGetFunction = createGetFunction(toscaFunction, PropertySource.SELF, List.of("property"), null); @@ -118,7 +118,7 @@ class ToscaGetFunctionDataDefinitionTest { } @ParameterizedTest - @EnumSource(value = ToscaGetFunctionType.class, names = {"GET_ATTRIBUTE", "GET_PROPERTY"}) + @EnumSource(value = ToscaGetFunctionType.class, names = {"GET_ATTRIBUTE", "GET_PROPERTY"}) void generateValueForGetFunctionWithInstanceAsSourceTest(final ToscaGetFunctionType toscaFunction) { //given final var toscaGetFunction = createGetFunction(toscaFunction, PropertySource.INSTANCE, List.of("property"), "sourceName"); @@ -215,4 +215,4 @@ class ToscaGetFunctionDataDefinitionTest { final Gson gson = new Gson(); return gson.fromJson(actualValue, Map.class); } -} \ No newline at end of file +} diff --git a/common-be/src/test/resources/toscaFunctionJsonDeserializer/customFunctionGetInputType.json b/common-be/src/test/resources/toscaFunctionJsonDeserializer/customFunctionGetInputType.json index 81ae571c01..611b3e9c3c 100644 --- a/common-be/src/test/resources/toscaFunctionJsonDeserializer/customFunctionGetInputType.json +++ b/common-be/src/test/resources/toscaFunctionJsonDeserializer/customFunctionGetInputType.json @@ -3,16 +3,21 @@ "name": "custom_function_get_input_type", "parameters": [ { - "propertyUniqueId": "dd0ec4d2-7e74-4d92-af2f-89c7436baa63.controller_actor", - "propertyName": "controller_actor", + "propertyUniqueId": "dd0ec4d2-7e74-4d92-af2f-89c7436baa63.pLMNInfoList", + "propertyName": "pLMNInfoList", "propertySource": "SELF", "sourceUniqueId": "dd0ec4d2-7e74-4d92-af2f-89c7436baa63", "sourceName": "testService", "functionType": "GET_INPUT", "propertyPathFromSource": [ - "controller_actor" + "pLMNInfoList" ], - "type": "GET_INPUT" + "type": "GET_INPUT", + "toscaIndexList": [ + "1", + "snssai", + "sd" + ] } ] -} \ No newline at end of file +} -- cgit 1.2.3-korg