Fix 'Tosca Function get_input in Properties Assignment error'-bug 61/135761/6
authorvasraz <vasyl.razinkov@est.tech>
Thu, 17 Aug 2023 10:31:31 +0000 (11:31 +0100)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Thu, 17 Aug 2023 16:59:00 +0000 (16:59 +0000)
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: If404b777b7be312d7f51c3d27905af898eb74eb6
Issue-ID: SDC-4598

common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java
common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java
common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializerTest.java
common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java
common-be/src/test/resources/toscaFunctionJsonDeserializer/customFunctionGetInputType.json

index 5a7acf4..ee5cd0e 100644 (file)
@@ -332,7 +332,6 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
         return this.toscaGetFunctionType != null || this.toscaFunction != null;
     }
 
-
     @JsonIgnoreProperties
     public boolean isToscaGetFunction() {
         return this.toscaFunction != null
index 82958a7..6f78c68 100644 (file)
@@ -126,17 +126,18 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct
     }
 
     private Map<String, Object> buildGetInputFunctionValue() {
-        List<Object> propertySourceCopy = new ArrayList<Object>(this.propertyPathFromSource);
-        List<Object> propertySourceOneCopy = new ArrayList<>();
+        final List<Object> propertySourceCopy = new ArrayList<>(this.propertyPathFromSource);
+        final List<Object> 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
index 5128c63..d0bc953 100644 (file)
@@ -209,10 +209,12 @@ class ToscaFunctionJsonDeserializerTest {
         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<Object> customFunctionGetInputValueList = (ArrayList<Object>) 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<ToscaFunctionParameter> 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
+}
index 3add149..fbbaff5 100644 (file)
@@ -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<String>)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
+}
index 81ae571..611b3e9 100644 (file)
@@ -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
+}