aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-08-17 11:31:31 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2023-08-17 16:59:00 +0000
commit1f7c6cccdd3a9544a7760db9a305403def4e5365 (patch)
treeb45870b71388d38e1c59084c1f93308ce10e9201
parent7c61c7bb0369bc27d05c8801c8cb0cca41e494bf (diff)
Fix 'Tosca Function get_input in Properties Assignment error'-bug
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: If404b777b7be312d7f51c3d27905af898eb74eb6 Issue-ID: SDC-4598
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java1
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java9
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializerTest.java18
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java10
-rw-r--r--common-be/src/test/resources/toscaFunctionJsonDeserializer/customFunctionGetInputType.json15
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<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
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<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
+}
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<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
+}
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
+}