From ddeb9a0906a314a4f990a54795dcf5860522b5d5 Mon Sep 17 00:00:00 2001 From: Sterchi Daniel Date: Thu, 7 Mar 2024 09:14:03 +0100 Subject: [PATCH] fix: add additional tests --- .../functions/FunctionParameterHelper.java | 6 +- .../FunctionParameterHelperTest.java | 4 +- .../functions/FunctionUtilsTest.java | 61 ++++++++++++++----- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionParameterHelper.java b/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionParameterHelper.java index 44f6cfdaa9..4bcbfc8174 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionParameterHelper.java +++ b/core/citrus-api/src/main/java/org/citrusframework/functions/FunctionParameterHelper.java @@ -21,16 +21,16 @@ /** * Helper class parsing a parameter string and converting the tokens to a parameter list. - * + * * @author Christoph Deppisch */ public final class FunctionParameterHelper { - + /** * Prevent class instantiation. */ private FunctionParameterHelper() {} - + /** * Convert a parameter string to a list of parameters. * diff --git a/core/citrus-api/src/test/java/org/citrusframework/functions/FunctionParameterHelperTest.java b/core/citrus-api/src/test/java/org/citrusframework/functions/FunctionParameterHelperTest.java index 5fd093b262..e421f41e5d 100644 --- a/core/citrus-api/src/test/java/org/citrusframework/functions/FunctionParameterHelperTest.java +++ b/core/citrus-api/src/test/java/org/citrusframework/functions/FunctionParameterHelperTest.java @@ -71,7 +71,7 @@ void shouldConvertSingleLineJson() { String json = """ {"myValues": ["O15o3a8","PhDjdSruZgG"]}"""; var result = getParameterList(wrappedInSingleQuotes(json)); - assertThat(result).contains(json); + assertThat(result).containsExactly(json); } @Test @@ -87,7 +87,7 @@ void shouldConvertMultiLineJson() { ] }"""; var result = getParameterList(wrappedInSingleQuotes(json)); - assertThat(result).contains(json); + assertThat(result).containsExactly(json); } @Test diff --git a/core/citrus-base/src/test/java/org/citrusframework/functions/FunctionUtilsTest.java b/core/citrus-base/src/test/java/org/citrusframework/functions/FunctionUtilsTest.java index 195414d867..2fb22ac4ec 100644 --- a/core/citrus-base/src/test/java/org/citrusframework/functions/FunctionUtilsTest.java +++ b/core/citrus-base/src/test/java/org/citrusframework/functions/FunctionUtilsTest.java @@ -21,10 +21,12 @@ import org.citrusframework.exceptions.NoSuchFunctionException; import org.citrusframework.exceptions.NoSuchFunctionLibraryException; import org.citrusframework.functions.core.CurrentDateFunction; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.util.Collections; import java.util.List; +import java.util.Objects; import static org.assertj.core.api.Assertions.assertThat; import static org.citrusframework.functions.FunctionUtils.resolveFunction; @@ -104,23 +106,54 @@ public void testUnknownFunctionLibrary() { resolveFunction("doesnotexist:concat('Hello', ' TestFramework!')", context); } - @Test - void shouldReplaceIfStringIsJson() { + @DataProvider + public static String[][] validParameterLists() { + return new String[][]{ + { + "citrus:concat('{\"lorem\": [\"ipsum\", \"other\"]}')", + "{\"lorem\": [\"ipsum\", \"other\"]}" + }, + { + // has two spaces here ----------------\/ + "citrus:concat('{\"lorem\": [\"ipsum\", \"other\"]}')", + "{\"lorem\": [\"ipsum\", \"other\"]}" + }, + { + // has no space here ----------------\/ + "citrus:concat('{\"lorem\": [\"ipsum\",\"other\"]}')", + "{\"lorem\": [\"ipsum\",\"other\"]}" + }, + { + // with linebreak after comma + """ + citrus:upperCase('{ + "myValues": [ + "O15o3a8", + "PhDjdSruZgG" + ] + }') + """, + """ + { + "MYVALUES": [ + "O15O3A8", + "PHDJDSRUZGG" + ] + } + """ + } + }; + } + + @Test(dataProvider = "validParameterLists") + void shouldReplaceWithCommasInValue(String given, String expected) { var contextSpy = spy(context); when(contextSpy.getFunctionRegistry()).thenReturn(spy(context.getFunctionRegistry())); List functionLibraries = List.of(new DefaultFunctionLibrary()); when(contextSpy.getFunctionRegistry().getFunctionLibraries()).thenReturn(functionLibraries); - var input = """ - { - "myValues": [ - "O15o3a8", - "PhDjdSruZgG" - ] - } - """; - - var result = FunctionUtils.replaceFunctionsInString(input, context, false); - - assertThat(result).isEqualTo(input); + + var result = FunctionUtils.replaceFunctionsInString(given, context, false); + + assertThat(result).isEqualTo(expected); } }