diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AllFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AllFunction.java index 1ae19f9cebf..fc640d5e5a0 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AllFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AllFunction.java @@ -58,10 +58,6 @@ public FEELFnResult invoke(@ParameterName( "list" ) List list) { } } - public FEELFnResult invoke(@ParameterName( "list" ) Boolean single) { - return FEELFnResult.ofResult( single ); - } - public FEELFnResult invoke(@ParameterName( "b" ) Object[] list) { if ( list == null ) { // Arrays.asList does not accept null as parameter diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AnyFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AnyFunction.java index 17e8d330634..9243758d730 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AnyFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/AnyFunction.java @@ -58,10 +58,6 @@ public FEELFnResult invoke(@ParameterName( "list" ) List list) { } } - public FEELFnResult invoke(@ParameterName( "list" ) Boolean single) { - return FEELFnResult.ofResult( single ); - } - public FEELFnResult invoke(@ParameterName( "b" ) Object[] list) { if ( list == null ) { // Arrays.asList does not accept null as parameter diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MeanFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MeanFunction.java index 0d940380ba7..cdb78dd9246 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MeanFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/MeanFunction.java @@ -47,9 +47,8 @@ public FEELFnResult invoke(@ParameterName( "list" ) List list) { FEELFnResult s = sum.invoke( list ); - Function> ifLeft = (event) -> { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "unable to sum the elements which is required to calculate the mean")); - }; + Function> ifLeft = event -> + FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "unable to sum the elements which is required to calculate the mean")); Function> ifRight = (sum) -> { try { @@ -62,22 +61,6 @@ public FEELFnResult invoke(@ParameterName( "list" ) List list) { return s.cata(ifLeft, ifRight); } - public FEELFnResult invoke(@ParameterName( "list" ) Number single) { - if ( single == null ) { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "single", "the single value list cannot be null")); - } - - if( single instanceof BigDecimal ) { - return FEELFnResult.ofResult((BigDecimal) single ); - } - BigDecimal result = NumberEvalHelper.getBigDecimalOrNull(single ); - if ( result != null ) { - return FEELFnResult.ofResult( result ); - } else { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "single element in list is not a number")); - } - } - public FEELFnResult invoke(@ParameterName( "n" ) Object[] list) { if ( list == null ) { // Arrays.asList does not accept null as parameter diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ProductFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ProductFunction.java index 11462667c87..42922bb82f6 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ProductFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/ProductFunction.java @@ -54,23 +54,6 @@ public FEELFnResult invoke(@ParameterName("list") List list) { return FEELFnResult.ofResult( product ); } - public FEELFnResult invoke(@ParameterName("list") Number single) { - if ( single == null ) { - // Arrays.asList does not accept null as parameter - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "the single value list cannot be null")); - } - - if( single instanceof BigDecimal ) { - return FEELFnResult.ofResult((BigDecimal) single ); - } - BigDecimal result = NumberEvalHelper.getBigDecimalOrNull( single ); - if ( result != null ) { - return FEELFnResult.ofResult( result ); - } else { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "single element in list not a number")); - } - } - public FEELFnResult invoke(@ParameterName("n") Object[] list) { if ( list == null ) { // Arrays.asList does not accept null as parameter diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StddevFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StddevFunction.java index de7451bb13f..8fae1477ceb 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StddevFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/StddevFunction.java @@ -69,18 +69,6 @@ public FEELFnResult invoke(@ParameterName("list") List list) { return FEELFnResult.ofResult( SqrtFunction.sqrt( mean ) ); } - public FEELFnResult invoke(@ParameterName("list") Object sole) { - if ( sole == null ) { - // Arrays.asList does not accept null as parameter - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "list", "the single value list cannot be null")); - } else if (NumberEvalHelper.getBigDecimalOrNull(sole) == null) { - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "list", - "the value can not be converted to a number")); - } - return FEELFnResult.ofError(new InvalidParametersEvent(FEELEvent.Severity.ERROR, "list", - "sample standard deviation of a single sample is undefined")); - } - public FEELFnResult invoke(@ParameterName("n") Object[] list) { if ( list == null ) { // Arrays.asList does not accept null as parameter diff --git a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SumFunction.java b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SumFunction.java index 86d3a0310c2..8cb0086c21d 100644 --- a/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SumFunction.java +++ b/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/runtime/functions/SumFunction.java @@ -60,23 +60,6 @@ public FEELFnResult invoke(@ParameterName("list") List list) { return FEELFnResult.ofResult( sum ); } - public FEELFnResult invoke(@ParameterName("list") Number single) { - if ( single == null ) { - // Arrays.asList does not accept null as parameter - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "the single value list cannot be null")); - } - - if( single instanceof BigDecimal ) { - return FEELFnResult.ofResult((BigDecimal) single ); - } - BigDecimal result = NumberEvalHelper.getBigDecimalOrNull( single ); - if ( result != null ) { - return FEELFnResult.ofResult( result ); - } else { - return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "single element in list not a number")); - } - } - public FEELFnResult invoke(@ParameterName("n") Object[] list) { if ( list == null ) { // Arrays.asList does not accept null as parameter diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEEL12ExtendedFunctionsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEEL12ExtendedFunctionsTest.java index 6eb25154891..7f2c9b67f16 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEEL12ExtendedFunctionsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEEL12ExtendedFunctionsTest.java @@ -59,9 +59,10 @@ private static Collection data() { { "stddev( [ 47 ] )", null, FEELEvent.Severity.ERROR }, { "stddev( 47 )", null, FEELEvent.Severity.ERROR }, { "stddev( [ ] )", null, FEELEvent.Severity.ERROR }, - {"mode( 6, 3, 9, 6, 6 )", List.of(BigDecimal.valueOf(6)), null }, + { "mode( 6 )", List.of(BigDecimal.valueOf(6)), null }, + { "mode( 6, 3, 9, 6, 6 )", List.of(BigDecimal.valueOf(6)), null }, { "mode( [6, 1, 9, 6, 1] )", Arrays.asList(BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 6 ) ), null }, - {"mode( [ ] )", List.of(), null }, + { "mode( [ ] )", List.of(), null }, }; return addAdditionalParameters(cases, false); } diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELFunctionsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELFunctionsTest.java index 4ec562e84f9..3707929e3bd 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELFunctionsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELFunctionsTest.java @@ -91,21 +91,37 @@ private static Collection data() { { "replace(\"0123456789\",\"(\\d{3})(\\d{3})(\\d{4})\",\"($1) $2-$3\")", "(012) 345-6789" , null}, { "list contains([1, 2, 3], 2)", Boolean.TRUE , null}, { "list contains([1, 2, 3], 5)", Boolean.FALSE , null}, + { "list contains(1, 1)", Boolean.TRUE , null}, + { "list contains(2, 1)", Boolean.FALSE , null}, + { "count( 1 )", BigDecimal.valueOf( 1 ) , null}, { "count([1, 2, 3])", BigDecimal.valueOf( 3 ) , null}, { "count( 1, 2, 3 )", BigDecimal.valueOf( 3 ) , null}, + { "min( \"a\" )", "a" , null}, { "min( \"a\", \"b\", \"c\" )", "a" , null}, { "min([ \"a\", \"b\", \"c\" ])", "a" , null}, + { "max( 1 )", BigDecimal.valueOf( 1 ) , null}, { "max( 1, 2, 3 )", BigDecimal.valueOf( 3 ) , null}, { "max([ 1, 2, 3 ])", BigDecimal.valueOf( 3 ) , null}, { "max(duration(\"PT1H6M\"), duration(\"PT1H5M\"))", Duration.parse("PT1H6M"), null}, { "max(duration(\"P6Y\"), duration(\"P5Y\"))", ComparablePeriod.parse("P6Y"), null}, + { "sum( 1 )", BigDecimal.valueOf( 1 ) , null}, + { "sum( [null] )", null , FEELEvent.Severity.ERROR}, + { "sum( null )", null , FEELEvent.Severity.ERROR}, { "sum( 1, 2, 3 )", BigDecimal.valueOf( 6 ) , null}, { "sum([ 1, 2, 3 ])", BigDecimal.valueOf( 6 ) , null}, { "sum([])", null, null}, + { "product( [2, 3, 4] )", BigDecimal.valueOf( 24 ) , null}, { "product( 2, 3, 4 )", BigDecimal.valueOf( 24 ) , null}, + { "product( 1 )", BigDecimal.valueOf( 1 ) , null}, + { "product( [null] )", null , FEELEvent.Severity.ERROR}, + { "product( null )", null , FEELEvent.Severity.ERROR}, { "product([ 2, 3, 4 ])", BigDecimal.valueOf( 24 ) , null}, { "product([])", null, FEELEvent.Severity.ERROR}, + { "mean( [1, 2, 3] )", BigDecimal.valueOf( 2 ) , null}, { "mean( 1, 2, 3 )", BigDecimal.valueOf( 2 ) , null}, + { "mean( 2 )", BigDecimal.valueOf( 2 ) , null}, + { "mean( [null] )", null , FEELEvent.Severity.ERROR}, + { "mean( null )", null , FEELEvent.Severity.ERROR}, { "mean([ 1, 2, 3 ])", BigDecimal.valueOf( 2 ) , null}, { "sublist( [1, 2, 3, 4, 5 ], 3, 2 )", Arrays.asList( BigDecimal.valueOf( 3 ), BigDecimal.valueOf( 4 ) ), null}, { "sublist( [1, 2, 3, 4, 5 ], -2, 1 )", Collections.singletonList(BigDecimal.valueOf(4)), null}, @@ -114,16 +130,21 @@ private static Collection data() { { "sublist( [1, 2, 3, 4, 5 ], -6, 3 )", null , FEELEvent.Severity.ERROR}, { "sublist( [1, 2, 3, 4, 5 ], -5, 3 )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ) ) , null}, { "sublist( [1, 2, 3, 4, 5 ], 1, 3 )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ) ) , null}, + { "sublist( 1, 1, 1 )", Arrays.asList( BigDecimal.valueOf( 1 ) ) , null}, + { "sublist( 1, 1 )", Arrays.asList( BigDecimal.valueOf( 1 ) ) , null}, { "append( [1, 2], 3, 4 )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ), BigDecimal.valueOf( 4 ) ) , null}, { "append( [], 3, 4 )", Arrays.asList( BigDecimal.valueOf( 3 ), BigDecimal.valueOf( 4 ) ) , null}, + { "append( 1, 3, 4 )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 3 ), BigDecimal.valueOf( 4 ) ) , null}, { "append( [1, 2] )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ) ) , null}, { "append( [1, 2], null, 4 )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), null, BigDecimal.valueOf( 4 ) ) , null}, { "append( null, 1, 2 )", null , FEELEvent.Severity.ERROR}, { "append( 0, 1, 2 )", Arrays.asList( BigDecimal.valueOf( 0 ), BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ) ), null}, { "concatenate( [1, 2], [3] )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ) ) , null}, + { "concatenate( 1, [3] )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 3 ) ) , null}, { "concatenate( [1, 2], 3, [4] )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ), BigDecimal.valueOf( 4 ) ) , null}, { "concatenate( [1, 2], null )", null , FEELEvent.Severity.ERROR}, { "insert before( [1, 2, 3], 1, 4 )", Arrays.asList( BigDecimal.valueOf( 4 ), BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ) ) , null}, + { "insert before( 1, 1, 4 )", Arrays.asList( BigDecimal.valueOf( 4 ), BigDecimal.valueOf( 1 ) ) , null}, { "insert before( [1, 2, 3], 3, 4 )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 4 ), BigDecimal.valueOf( 3 ) ) , null}, { "insert before( [1, 2, 3], 3, null )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), null, BigDecimal.valueOf( 3 ) ) , null}, { "insert before( null, 3, 4 )", null , FEELEvent.Severity.ERROR}, @@ -133,6 +154,7 @@ private static Collection data() { { "insert before( [1, 2, 3], 0, 4 )", null , FEELEvent.Severity.ERROR}, { "insert before( [1, 2, 3], -4, 4 )", null , FEELEvent.Severity.ERROR}, { "remove( [1, 2, 3], 1 )", Arrays.asList( BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ) ) , null}, + { "remove( 1, 1 )", Arrays.asList() , null}, { "remove( [1, 2, 3], 3 )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ) ) , null}, { "remove( [1, 2, 3], -1 )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ) ) , null}, { "remove( [1, 2, 3], -3 )", Arrays.asList( BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ) ) , null}, @@ -140,14 +162,20 @@ private static Collection data() { { "remove( [1, 2, 3], -4 )", null , FEELEvent.Severity.ERROR}, { "remove( [1, 2, 3], 0 )", null , FEELEvent.Severity.ERROR}, { "reverse( [1, 2, 3] )", Arrays.asList( BigDecimal.valueOf( 3 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 1 ) ) , null}, + { "reverse( 1 )", Arrays.asList( BigDecimal.valueOf( 1 ) ) , null}, { "reverse( null )", null , FEELEvent.Severity.ERROR}, + { "index of( 1, 1 )", Arrays.asList( BigDecimal.valueOf( 1 ) ) , null}, { "index of( [1, 2, 3, 2], 2 )", Arrays.asList( BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 4 ) ) , null}, { "index of( [1, 2, null, null], null )", Arrays.asList( BigDecimal.valueOf( 3 ), BigDecimal.valueOf( 4 ) ) , null}, { "index of( [1, 2, null, null], 1 )", Collections.singletonList(BigDecimal.valueOf(1)), null}, { "index of( null, 1 )", null , FEELEvent.Severity.ERROR}, + { "union( 1, [2, 3], 2, 4 )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ), BigDecimal.valueOf( 4 ) ) , null}, + { "union( 1 )", Arrays.asList( BigDecimal.valueOf( 1 ) ) , null}, { "union( [1, 2, 1], [2, 3], 2, 4 )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ), BigDecimal.valueOf( 4 ) ) , null}, { "union( [1, 2, null], 4 )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), null, BigDecimal.valueOf( 4 ) ) , null}, { "union( null, 4 )", Arrays.asList( null, BigDecimal.valueOf(4) ), null}, + { "flatten( [[1,2],[[3]], 4] )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ), BigDecimal.valueOf( 4 ) ), null}, + { "flatten( 1 )", Arrays.asList( BigDecimal.valueOf( 1 ) ), null}, { "distinct values( [1, 2, 3, 2, 4] )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), BigDecimal.valueOf( 3 ), BigDecimal.valueOf( 4 ) ) , null}, { "distinct values( [1, 2, null, 2, 4] )", Arrays.asList( BigDecimal.valueOf( 1 ), BigDecimal.valueOf( 2 ), null, BigDecimal.valueOf( 4 ) ) , null}, { "distinct values( 1 )", Collections.singletonList(BigDecimal.valueOf(1)), null}, @@ -240,6 +268,7 @@ private static Collection data() { { "week of year( date(2005, 1, 1) )", BigDecimal.valueOf( 53 ), null}, { "median( 8, 2, 5, 3, 4 )", new BigDecimal("4") , null}, { "median( [6, 1, 2, 3] )", new BigDecimal("2.5") , null}, + { "median( 1 )", new BigDecimal("1") , null}, { "median( [ ] ) ", null, null}, // DMN spec, Table 69: Semantics of list functions { "0-max( 1, 2, 3 )", BigDecimal.valueOf( -3 ) , null}, @@ -264,6 +293,8 @@ private static Collection data() { { "if list contains ([2.2, 3, 4], 3.000) then \"OK\" else \"NOT_OK\"", "OK" , null}, {"list replace ( null, 3, 6)", null , FEELEvent.Severity.ERROR}, {"list replace ( [2, 4, 7, 8], null, 6)", null , FEELEvent.Severity.ERROR}, + {"list replace ( [1], 1, 7)", Arrays.asList(BigDecimal.valueOf(7)), null}, + {"list replace ( 1, 1, 7)", Arrays.asList(BigDecimal.valueOf(7)), null}, {"list replace ( [2, 4, 7, 8], 3, 6)", Arrays.asList(BigDecimal.valueOf(2), BigDecimal.valueOf(4), BigDecimal.valueOf(6), BigDecimal.valueOf(8)), null}, {"list replace ( [2, 4, 7, 8], -3, 6)", Arrays.asList(BigDecimal.valueOf(2), BigDecimal.valueOf(6), BigDecimal.valueOf(7), BigDecimal.valueOf(8)), null}, {"list replace ( [2, 4, 7, 8], function(item, newItem) item + newItem, 6)", null , FEELEvent.Severity.ERROR}, diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/KieFEELExtendedFunctionsTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/KieFEELExtendedFunctionsTest.java index 8e5b0ed40bd..e3d508d1652 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/KieFEELExtendedFunctionsTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/KieFEELExtendedFunctionsTest.java @@ -50,10 +50,12 @@ private static Collection data() { { "string join([\"a\",\"b\",\"c\"], \"\")", "abc", null}, { "string join([\"a\",\"b\",\"c\"], null)", "abc", null}, { "string join([\"a\"], \"X\")", "a", null}, + { "string join(\"a\", \"X\")", "a", null}, { "string join([\"a\",null,\"c\"], \"X\")", "aXc", null}, { "string join([], \"X\")", "", null}, { "string join([\"a\",\"b\",\"c\"])", "abc", null}, { "string join([\"a\",null,\"c\"])", "ac", null}, + { "string join(\"a\")", "a", null}, { "string join([])", "", null}, { "string join([\"a\",123,\"c\"], null)", null, FEELEvent.Severity.ERROR}, { "string join(null, null)", null, FEELEvent.Severity.ERROR}, @@ -123,11 +125,16 @@ private static Collection data() { { "context put({name: \"John Doe\", address: { street: \"St.\", country:\"US\"}}, [\"address\", \"country\"], \"IT\")", mapOf(entry("name", "John Doe"),entry("address",mapOf(entry("street","St."), entry("country","IT")))), null }, { "context put({name: \"John Doe\", age: 0}, \"age\", 47)", mapOf(entry("name", "John Doe"),entry("age", new BigDecimal(47))), null }, { "context put({name: \"John Doe\", age: 0, z:999}, \"age\", 47)", mapOf(entry("name", "John Doe"),entry("age", new BigDecimal(47)),entry("z", new BigDecimal(999))), null }, - { "context merge([{name: \"John Doe\"}, {age: 47}])", mapOf(entry("name", "John Doe"),entry("age", new BigDecimal(47))), null }, + { "context merge([{name: \"John Doe\"}, {age: 47}])", mapOf(entry("name", "John Doe") ,entry("age", new BigDecimal(47))), null }, + { "context merge({name: \"John Doe\"})", mapOf(entry("name", "John Doe")), null }, { "context merge([{name: \"John Doe\", age: 0}, {age: 47}])", mapOf(entry("name", "John Doe"),entry("age", new BigDecimal(47))), null }, - { "context([{key: \"name\", value: \"John Doe\"},{\"key\":\"age\", \"value\":47}])", mapOf(entry("name", "John Doe"),entry("age", new BigDecimal(47))), null }, - { "context([{key: \"name\", value: \"John Doe\"},{\"key\":\"age\", \"value\":47, \"something\":\"else\"}])", mapOf(entry("name", "John Doe"),entry("age", new BigDecimal(47))), null }, - { "context([{key: \"name\", value: \"John Doe\"},{\"key\":\"age\"}])", null, FEELEvent.Severity.ERROR }, + { "context([{key: null, value: \"John Doe\"},{\"key\": \"age\", \"value\": 47}])", null, FEELEvent.Severity.ERROR }, + { "context([{key: \"name\", value: \"John Doe\"},{\"value\": 47}])", null, FEELEvent.Severity.ERROR }, + { "context([{key: \"name\", value: \"John Doe\"},{\"key\": \"age\"}])", null, FEELEvent.Severity.ERROR }, + { "context([{key: \"name\", value: \"John Doe\"},{\"key\": \"age\", \"value\": 47}])", mapOf(entry("name", "John Doe"), entry("age", new BigDecimal(47))), null }, + { "context([{key: \"name\", value: \"John Doe\"},{\"key\": \"age\", \"value\": 47, \"something\": \"else\"}])", mapOf(entry("name", "John Doe"), entry("age", new BigDecimal(47))), null }, + { "context([{key: \"name\", value: \"John Doe\"},{\"key\": \"age\", \"value\": 47, \"something\": \"else\"}])", mapOf(entry("name", "John Doe"), entry("age", new BigDecimal(47))), null }, + { "context({key: \"name\", value: \"John Doe\"})", mapOf(entry("name", "John Doe")), null }, { "context([{key: \"name\", value: \"John Doe\"},{key: \"name\", value: \"Doe John\"}])", null, FEELEvent.Severity.ERROR }, { "time(10, 20, 30)", LocalTime.of(10, 20, 30), null }, { "date( 2020, 2, 31 )", null, FEELEvent.Severity.ERROR}, diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java index b4d9eaa8d7c..5438fc32d9f 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AllFunctionTest.java @@ -29,21 +29,6 @@ class AllFunctionTest { private static final AllFunction allFunction = AllFunction.INSTANCE; - @Test - void invokeBooleanParamNull() { - FunctionTestUtil.assertResultNull(allFunction.invoke((Boolean) null)); - } - - @Test - void invokeBooleanParamTrue() { - FunctionTestUtil.assertResult(allFunction.invoke(true), true); - } - - @Test - void invokeBooleanParamFalse() { - FunctionTestUtil.assertResult(allFunction.invoke(false), false); - } - @Test void invokeArrayParamNull() { FunctionTestUtil.assertResultError(allFunction.invoke((Object[]) null), InvalidParametersEvent.class); diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java index 45aa9d6061a..3dfd4006514 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/AnyFunctionTest.java @@ -29,21 +29,6 @@ class AnyFunctionTest { private static final AnyFunction anyFunction = AnyFunction.INSTANCE; - @Test - void invokeBooleanParamNull() { - FunctionTestUtil.assertResultNull(anyFunction.invoke((Boolean) null)); - } - - @Test - void invokeBooleanParamTrue() { - FunctionTestUtil.assertResult(anyFunction.invoke(true), true); - } - - @Test - void invokeBooleanParamFalse() { - FunctionTestUtil.assertResult(anyFunction.invoke(false), false); - } - @Test void invokeArrayParamNull() { FunctionTestUtil.assertResultError(anyFunction.invoke((Object[]) null), InvalidParametersEvent.class); diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java index 598e0371607..6513c445af4 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MeanFunctionTest.java @@ -32,44 +32,29 @@ class MeanFunctionTest { @Test void invokeNumberNull() { - FunctionTestUtil.assertResultError(meanFunction.invoke((Number) null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(meanFunction.invoke(Arrays.asList(10, null, 30)), InvalidParametersEvent.class); } @Test void invokeNumberBigDecimal() { - FunctionTestUtil.assertResult(meanFunction.invoke(BigDecimal.TEN), BigDecimal.TEN); - } - - @Test - void invokeNumberInteger() { - FunctionTestUtil.assertResult(meanFunction.invoke(10), BigDecimal.TEN); - } - - @Test - void invokeNumberDoubleWithoutDecimalPart() { - FunctionTestUtil.assertResult(meanFunction.invoke(10d), BigDecimal.valueOf(10)); - } - - @Test - void invokeNumberDoubleWithDecimalPart() { - FunctionTestUtil.assertResult(meanFunction.invoke(10.1d), BigDecimal.valueOf(10.1)); + FunctionTestUtil.assertResult(meanFunction.invoke(Arrays.asList(BigDecimal.TEN)), BigDecimal.TEN); } @Test void invokeNumberFloat() { - FunctionTestUtil.assertResult(meanFunction.invoke(10.1f), BigDecimal.valueOf(10.1)); + FunctionTestUtil.assertResult(meanFunction.invoke(Arrays.asList(10.1f)), BigDecimal.valueOf(10.1)); } @Test void invokeUnconvertableNumber() { - FunctionTestUtil.assertResultError(meanFunction.invoke(Double.POSITIVE_INFINITY), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(meanFunction.invoke(Double.NEGATIVE_INFINITY), InvalidParametersEvent.class); - FunctionTestUtil.assertResultError(meanFunction.invoke(Double.NaN), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(meanFunction.invoke(Arrays.asList(Double.POSITIVE_INFINITY)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(meanFunction.invoke(Arrays.asList(Double.NEGATIVE_INFINITY)), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(meanFunction.invoke(Arrays.asList(Double.NaN)), InvalidParametersEvent.class); } @Test void invokeListNull() { - FunctionTestUtil.assertResultError(meanFunction.invoke((List) null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(meanFunction.invoke((List) null), InvalidParametersEvent.class); } @Test diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringJoinFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringJoinFunctionTest.java new file mode 100644 index 00000000000..37243c8405f --- /dev/null +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/StringJoinFunctionTest.java @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.dmn.feel.runtime.functions; + +import org.junit.jupiter.api.Test; +import org.kie.dmn.feel.runtime.events.InvalidParametersEvent; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +class StringJoinFunctionTest { + + private static final StringJoinFunction stringJoinFunction = StringJoinFunction.INSTANCE; + + @Test + void setStringJoinFunctionNullValues() { + FunctionTestUtil.assertResultError(stringJoinFunction.invoke( null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(stringJoinFunction.invoke((List) null , null), InvalidParametersEvent.class); + } + + @Test + void stringJoinFunctionEmptyList() { + FunctionTestUtil.assertResult(stringJoinFunction.invoke(Collections.emptyList()), ""); + FunctionTestUtil.assertResult(stringJoinFunction.invoke(Collections.emptyList(), "X"), ""); + } + + @Test + void stringJoinFunction() { + FunctionTestUtil.assertResult(stringJoinFunction.invoke(Arrays.asList("a", "b", "c"), "_and_"), "a_and_b_and_c"); + FunctionTestUtil.assertResult(stringJoinFunction.invoke(Arrays.asList("a", "b", "c"), ""), "abc"); + FunctionTestUtil.assertResult(stringJoinFunction.invoke(Arrays.asList("a", "b", "c"), null), "abc"); + FunctionTestUtil.assertResult(stringJoinFunction.invoke(Arrays.asList("a"), "X"), "a"); + FunctionTestUtil.assertResult(stringJoinFunction.invoke(Arrays.asList("a", null, "c"), "X"), "aXc"); + FunctionTestUtil.assertResult(stringJoinFunction.invoke(Arrays.asList("a", "b", "c")), "abc"); + FunctionTestUtil.assertResult(stringJoinFunction.invoke(Arrays.asList("a", null, "c")), "ac"); + } + +} diff --git a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java index 50d15bf8e64..84895deb7f4 100644 --- a/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java +++ b/kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/SumFunctionTest.java @@ -29,27 +29,9 @@ class SumFunctionTest { private static final SumFunction sumFunction = SumFunction.INSTANCE; - @Test - void invokeNumberParamNull() { - FunctionTestUtil.assertResultError(sumFunction.invoke((Number) null), InvalidParametersEvent.class); - } - - @Test - void invokeNumberParamUnsupportedNumber() { - FunctionTestUtil.assertResultError(sumFunction.invoke(Double.NaN), InvalidParametersEvent.class); - } - - @Test - void invokeNumberParamSupportedNumber() { - FunctionTestUtil.assertResult(sumFunction.invoke(BigDecimal.TEN), BigDecimal.TEN); - FunctionTestUtil.assertResult(sumFunction.invoke(10), BigDecimal.TEN); - FunctionTestUtil.assertResult(sumFunction.invoke(-10), BigDecimal.valueOf(-10)); - FunctionTestUtil.assertResult(sumFunction.invoke(10.12), BigDecimal.valueOf(10.12)); - } - @Test void invokeListParam() { - FunctionTestUtil.assertResultError(sumFunction.invoke((List) null), InvalidParametersEvent.class); + FunctionTestUtil.assertResultError(sumFunction.invoke((List) null), InvalidParametersEvent.class); } @Test