diff options
author | andre.schmid <andre.schmid@est.tech> | 2022-06-15 15:30:40 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-06-22 20:36:22 +0000 |
commit | 7a7b13726c195e2944ccc59e4d5c5ade57318763 (patch) | |
tree | c22384a2abfc24adeb1c69a3696cda15c8e37548 /common-be | |
parent | fbab79aeaccf74385c9a55b697a1055a86bdf171 (diff) |
Support TOSCA get_attribute function
Adds support to TOSCA get_attribute function in the Property Assignment
TOSCA Function modal.
Change-Id: I73dda215a7c9d7fecf0803cc259634279c3bdfb6
Issue-ID: SDC-4053
Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'common-be')
2 files changed, 21 insertions, 12 deletions
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 adc2ad6b44..0741d6849e 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 @@ -63,8 +63,8 @@ public class ToscaGetFunctionDataDefinition { } final var gson = new Gson(); - if (functionType == ToscaGetFunctionType.GET_PROPERTY) { - return gson.toJson(buildGetPropertyFunctionValue()); + if (functionType == ToscaGetFunctionType.GET_PROPERTY || functionType == ToscaGetFunctionType.GET_ATTRIBUTE) { + return gson.toJson(buildFunctionValueWithPropertySource()); } if (functionType == ToscaGetFunctionType.GET_INPUT) { return gson.toJson(buildGetInputFunctionValue()); @@ -73,9 +73,11 @@ public class ToscaGetFunctionDataDefinition { throw new UnsupportedOperationException(String.format("ToscaGetFunctionType '%s' is not supported yet", functionType)); } - private Map<String, Object> buildGetPropertyFunctionValue() { + private Map<String, Object> buildFunctionValueWithPropertySource() { if (propertySource == null) { - throw new IllegalStateException("propertySource is required in order to generate the get_property value"); + throw new IllegalStateException( + String.format("propertySource is required in order to generate the %s value", functionType.getFunctionName()) + ); } if (propertySource == PropertySource.SELF) { return Map.of(functionType.getFunctionName(), @@ -84,7 +86,9 @@ public class ToscaGetFunctionDataDefinition { } if (propertySource == PropertySource.INSTANCE) { if (sourceName == null) { - throw new IllegalStateException("sourceName is required in order to generate the get_property from INSTANCE value"); + throw new IllegalStateException( + String.format("sourceName is required in order to generate the %s from INSTANCE value", functionType.getFunctionName()) + ); } return Map.of(functionType.getFunctionName(), Stream.concat(Stream.of(sourceName), propertyPathFromSource.stream()).collect(Collectors.toList()) 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 1c4a678010..a199f5ec97 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 @@ -21,7 +21,10 @@ package org.openecomp.sdc.be.datatypes.elements; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.gson.Gson; import java.util.List; @@ -29,6 +32,8 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import org.openecomp.sdc.be.datatypes.enums.PropertySource; import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; @@ -78,10 +83,10 @@ class ToscaGetFunctionDataDefinitionTest { assertEquals(value, toscaGetFunction.getPropertyPathFromSource()); } - @Test - void generateValueForGetPropertyFromSelfTest() { + @ParameterizedTest + @EnumSource(value = ToscaGetFunctionType.class, names = {"GET_ATTRIBUTE", "GET_PROPERTY"}) + void generateValueForGetFunctionWithSelfAsSourceTest(final ToscaGetFunctionType toscaFunction) { //given - final ToscaGetFunctionType toscaFunction = ToscaGetFunctionType.GET_PROPERTY; final var toscaGetFunction = createGetFunction(toscaFunction, PropertySource.SELF, List.of("property"), null); //when String actualValue = toscaGetFunction.generatePropertyValue(); @@ -110,10 +115,10 @@ class ToscaGetFunctionDataDefinitionTest { assertEquals(expectedGetPropertyValue, actualGetPropertyValue); } - @Test - void generateValueForGetPropertyFromInstanceTest() { + @ParameterizedTest + @EnumSource(value = ToscaGetFunctionType.class, names = {"GET_ATTRIBUTE", "GET_PROPERTY"}) + void generateValueForGetFunctionWithInstanceAsSourceTest(final ToscaGetFunctionType toscaFunction) { //given - final ToscaGetFunctionType toscaFunction = ToscaGetFunctionType.GET_PROPERTY; final var toscaGetFunction = createGetFunction(toscaFunction, PropertySource.INSTANCE, List.of("property"), "sourceName"); //when String actualValue = toscaGetFunction.generatePropertyValue(); |