From c4de5390c2a396e9ea88061454e40a92cea57ce1 Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Fri, 21 Apr 2023 14:41:52 +0100 Subject: Support service import with custom tosca functions Issue-ID: SDC-4479 Change-Id: I1a98c8a191fc255cb3b2b328b0ea1e72977252d2 Signed-off-by: JvD_Ericsson --- .../csar/ToscaFunctionYamlParsingHandlerTest.java | 49 ++++++++++++++++------ 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'catalog-be/src/test/java/org') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandlerTest.java index 5b0096bb3f..1dfb7a9113 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandlerTest.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Optional; import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.datatypes.elements.ToscaConcatFunction; +import org.openecomp.sdc.be.datatypes.elements.ToscaCustomFunction; import org.openecomp.sdc.be.datatypes.elements.ToscaFunction; import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition; @@ -43,6 +44,18 @@ class ToscaFunctionYamlParsingHandlerTest { final ToscaFunctionYamlParsingHandler toscaFunctionYamlParsingHandler = new ToscaFunctionYamlParsingHandler(); + private static void assertGetInput(final ToscaFunction actualGetInputFunction, final List expectedGetInputParameters) { + assertEquals(ToscaFunctionType.GET_INPUT, actualGetInputFunction.getType()); + assertTrue(actualGetInputFunction instanceof ToscaGetFunctionDataDefinition); + final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) actualGetInputFunction; + assertEquals(ToscaGetFunctionType.GET_INPUT, toscaGetFunction.getFunctionType()); + assertEquals(expectedGetInputParameters.get(expectedGetInputParameters.size() - 1), toscaGetFunction.getPropertyName()); + assertEquals(PropertySource.SELF, toscaGetFunction.getPropertySource()); + assertEquals(expectedGetInputParameters, toscaGetFunction.getPropertyPathFromSource()); + assertNull(toscaGetFunction.getPropertyUniqueId()); + assertNull(toscaGetFunction.getSourceName()); + } + @Test void buildToscaFunctionBasedOnPropertyValue_NotAToscaFunctionTest() { assertEquals(Optional.empty(), toscaFunctionYamlParsingHandler.buildToscaFunctionBasedOnPropertyValue(null)); @@ -119,6 +132,30 @@ class ToscaFunctionYamlParsingHandlerTest { assertGetInput(getFunction, List.of("inputName")); } + @Test + void buildToscaFunctionBasedOnPropertyValue_CustomTest() { + final List customValue = List.of("string1", "-", Map.of(ToscaFunctionType.GET_INPUT.getName(), "inputName")); + final Map customValueMap = Map.of("$customFuncName", customValue); + + final Optional actualToscaFunctionOpt = toscaFunctionYamlParsingHandler.buildToscaFunctionBasedOnPropertyValue(customValueMap); + assertTrue(actualToscaFunctionOpt.isPresent()); + final ToscaFunction actualToscaFunction = actualToscaFunctionOpt.get(); + assertEquals(ToscaFunctionType.CUSTOM, actualToscaFunction.getType()); + assertTrue(actualToscaFunction instanceof ToscaCustomFunction); + final ToscaCustomFunction toscaCustomFunction = (ToscaCustomFunction) actualToscaFunction; + final String functionName = toscaCustomFunction.getName(); + assertEquals("customFuncName", functionName); + assertEquals(3, toscaCustomFunction.getParameters().size()); + assertTrue(toscaCustomFunction.getParameters().get(0) instanceof ToscaStringParameter); + final ToscaStringParameter parameter1 = (ToscaStringParameter) toscaCustomFunction.getParameters().get(0); + assertEquals("string1", parameter1.getValue()); + assertTrue(toscaCustomFunction.getParameters().get(1) instanceof ToscaStringParameter); + final ToscaStringParameter parameter2 = (ToscaStringParameter) toscaCustomFunction.getParameters().get(1); + assertEquals("-", parameter2.getValue()); + assertTrue(toscaCustomFunction.getParameters().get(2) instanceof ToscaGetFunctionDataDefinition); + final ToscaGetFunctionDataDefinition getFunction = (ToscaGetFunctionDataDefinition) toscaCustomFunction.getParameters().get(2); + assertGetInput(getFunction, List.of("inputName")); + } @Test void isPropertyValueToscaFunctionTest() { @@ -135,16 +172,4 @@ class ToscaFunctionYamlParsingHandlerTest { assertFalse(toscaFunctionYamlParsingHandler.isPropertyValueToscaFunction(Map.of(ToscaFunctionType.YAML.getName(), ""))); assertFalse(toscaFunctionYamlParsingHandler.isPropertyValueToscaFunction(Map.of(ToscaFunctionType.STRING.getName(), ""))); } - - private static void assertGetInput(final ToscaFunction actualGetInputFunction, final List expectedGetInputParameters) { - assertEquals(ToscaFunctionType.GET_INPUT, actualGetInputFunction.getType()); - assertTrue(actualGetInputFunction instanceof ToscaGetFunctionDataDefinition); - final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) actualGetInputFunction; - assertEquals(ToscaGetFunctionType.GET_INPUT, toscaGetFunction.getFunctionType()); - assertEquals(expectedGetInputParameters.get(expectedGetInputParameters.size() - 1), toscaGetFunction.getPropertyName()); - assertEquals(PropertySource.SELF, toscaGetFunction.getPropertySource()); - assertEquals(expectedGetInputParameters, toscaGetFunction.getPropertyPathFromSource()); - assertNull(toscaGetFunction.getPropertyUniqueId()); - assertNull(toscaGetFunction.getSourceName()); - } } \ No newline at end of file -- cgit 1.2.3-korg