diff --git a/src/main/java/com/api/jsonata4java/expressions/functions/EachFunction.java b/src/main/java/com/api/jsonata4java/expressions/functions/EachFunction.java index d33c43d..b118e6e 100644 --- a/src/main/java/com/api/jsonata4java/expressions/functions/EachFunction.java +++ b/src/main/java/com/api/jsonata4java/expressions/functions/EachFunction.java @@ -64,6 +64,7 @@ public class EachFunction extends FunctionBase { public static String ERR_ARG3BADTYPE = String.format(Constants.ERR_MSG_ARG3_BAD_TYPE, Constants.FUNCTION_EACH); public static String ERR_ARG1_MUST_BE_ARRAY_OF_OBJECTS = String .format(Constants.ERR_MSG_ARG1_MUST_BE_ARRAY_OF_OBJECTS, Constants.FUNCTION_EACH); + public static String ERR_ARG2_FUNCTION_RESOLVE = "Could not resolve function variable reference \"%s\"."; public JsonNode invoke(ExpressionsVisitor expressionVisitor, Function_callContext ctx) { SelectorArrayNode result = null; diff --git a/src/main/java/com/api/jsonata4java/expressions/functions/FilterFunction.java b/src/main/java/com/api/jsonata4java/expressions/functions/FilterFunction.java index c7e0959..6cd375d 100644 --- a/src/main/java/com/api/jsonata4java/expressions/functions/FilterFunction.java +++ b/src/main/java/com/api/jsonata4java/expressions/functions/FilterFunction.java @@ -22,7 +22,6 @@ package com.api.jsonata4java.expressions.functions; -import java.util.Iterator; import org.antlr.v4.runtime.tree.TerminalNode; import com.api.jsonata4java.expressions.EvaluateRuntimeException; import com.api.jsonata4java.expressions.ExpressionsVisitor; @@ -39,7 +38,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; /** * From http://docs.jsonata.org/higher-order-functions#filter @@ -74,6 +72,7 @@ public class FilterFunction extends FunctionBase { public static String ERR_ARG3BADTYPE = String.format(Constants.ERR_MSG_ARG3_BAD_TYPE, Constants.FUNCTION_FILTER); public static String ERR_ARG1_MUST_BE_ARRAY_OF_OBJECTS = String .format(Constants.ERR_MSG_ARG1_MUST_BE_ARRAY_OF_OBJECTS, Constants.FUNCTION_SPREAD); + public static String ERR_ARG2_FUNCTION_RESOLVE = "Could not resolve function variable reference \"%s\"."; public JsonNode invoke(ExpressionsVisitor expressionVisitor, Function_callContext ctx) { SelectorArrayNode result = new SelectorArrayNode(JsonNodeFactory.instance); @@ -250,13 +249,4 @@ public String getSignature() { // accepts anything, returns an array of objects return ""; } - - public void addObject(SelectorArrayNode result, ObjectNode obj) { - for (Iterator it = obj.fieldNames(); it.hasNext();) { - String key = it.next(); - ObjectNode cell = JsonNodeFactory.instance.objectNode(); - cell.set(key, obj.get(key)); - result.add(cell); - } - } } diff --git a/src/test/java/com/api/jsonata4java/AgnosticTestSuite.java b/src/test/java/com/api/jsonata4java/AgnosticTestSuite.java index 29629a3..e171143 100644 --- a/src/test/java/com/api/jsonata4java/AgnosticTestSuite.java +++ b/src/test/java/com/api/jsonata4java/AgnosticTestSuite.java @@ -395,11 +395,11 @@ private void init() throws Exception { runJsonataTest(JsonataDotOrgTests.data()); runJunitTests(new BasicExpressionsTests()); - + runJunitTests(new FunctionChainingTests()); - + runJunitTests(new PathExpressionParentTests()); - + runJunitTests(new JsonataTimeoutTest()); } diff --git a/src/test/java/com/api/jsonata4java/expressions/BasicExpressionsTests.java b/src/test/java/com/api/jsonata4java/expressions/BasicExpressionsTests.java index 11d9494..5606b7c 100644 --- a/src/test/java/com/api/jsonata4java/expressions/BasicExpressionsTests.java +++ b/src/test/java/com/api/jsonata4java/expressions/BasicExpressionsTests.java @@ -204,7 +204,7 @@ public class BasicExpressionsTests implements Serializable { + " \"Account Name\": \"'\" \n" + " }\n" + "}"; - + static JsonNodeFactory factory = JsonNodeFactory.instance; static ObjectMapper mapper = new ObjectMapper(); static JsonNode jsonObj = null; @@ -333,10 +333,10 @@ public void testNewStuff() throws Exception { expectArray.removeAll(); expectArray.add("one"); simpleTest("{ \"books\": [\"one\"] }.books", expectArray, jsonObj3); - + // issue #247 - simpleTest("Account.`Account Name`","'",jsonObj4); - + simpleTest("Account.`Account Name`", "'", jsonObj4); + // issue #29 and #30 expectArray.removeAll(); expectArray.add("one"); diff --git a/src/test/java/com/api/jsonata4java/expressions/functions/EachFunctionTest.java b/src/test/java/com/api/jsonata4java/expressions/functions/EachFunctionTest.java index 2f9136f..bc15949 100644 --- a/src/test/java/com/api/jsonata4java/expressions/functions/EachFunctionTest.java +++ b/src/test/java/com/api/jsonata4java/expressions/functions/EachFunctionTest.java @@ -28,13 +28,46 @@ public class EachFunctionTest { @Test - public void nullInput() throws Exception { - test("$each()", null, null, (String) null); + public void eachWithFunctionInlinedWith1Arg() throws Exception { + test("$each(Address, function($val) {$val})", + "[\n" + + " \"Hursley Park\",\n" + + " \"Winchester\",\n" + + " \"SO21 2JN\"\n" + + "]", + null, + "{\n" + + " \"FirstName\": \"Fred\",\n" + + " \"Address\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + "}"); } @Test - public void eachKeyValuePairIntoArray() throws Exception { - test("$each(Address, function($v, $k) {$k & \": \" & $v})", + public void eachWithFunctionInlinedWith1ArgReturnNull() throws Exception { + test("$each(Address, function($val) {null})", + "[\n" + + " null,\n" + + " null,\n" + + " null\n" + + "]", + null, + "{\n" + + " \"FirstName\": \"Fred\",\n" + + " \"Address\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + "}"); + } + + @Test + public void eachWithFunctionInlinedWith2Args() throws Exception { + test("$each(Address, function($val, $key) {$key & \": \" & $val})", "[\n" + " \"Street: Hursley Park\",\n" + " \"City: Winchester\",\n" @@ -51,9 +84,288 @@ public void eachKeyValuePairIntoArray() throws Exception { + "}"); } + @Test + public void eachWithFunctionInlinedWith3Args() throws Exception { + test("$each(Address, function($val, $key, $obj) {{ $key & \"|\" & $val : $obj }})", + "[\n" + + " {\n" + + " \"Street|Hursley Park\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + " },\n" + + " {\n" + + " \"City|Winchester\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + " },\n" + + " {\n" + + " \"Postcode|SO21 2JN\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + " }\n" + + "]", + null, + "{\n" + + " \"FirstName\": \"Fred\",\n" + + " \"Address\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + "}"); + } + + @Test + public void eachWithFunctionInlinedWith4Args() throws Exception { + test("$each(Address, function($val, $key, $obj, $x) {{ $key & \"|\" & $val : $obj & $x}})", + "[\n" + + " {\n" + + " \"Street|Hursley Park\": \"{\\\"Street\\\":\\\"Hursley Park\\\",\\\"City\\\":\\\"Winchester\\\",\\\"Postcode\\\":\\\"SO21 2JN\\\"}\"\n" + + " },\n" + + " {\n" + + " \"City|Winchester\": \"{\\\"Street\\\":\\\"Hursley Park\\\",\\\"City\\\":\\\"Winchester\\\",\\\"Postcode\\\":\\\"SO21 2JN\\\"}\"\n" + + " },\n" + + " {\n" + + " \"Postcode|SO21 2JN\": \"{\\\"Street\\\":\\\"Hursley Park\\\",\\\"City\\\":\\\"Winchester\\\",\\\"Postcode\\\":\\\"SO21 2JN\\\"}\"\n" + + " }\n" + + "]", + null, + "{\n" + + " \"FirstName\": \"Fred\",\n" + + " \"Address\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + "}"); + } + + @Test + public void eachWithFunctionWith1Arg() throws Exception { + test("($func := function($val) {$val};\n" + + "$each(Address, $func))", + "[\n" + + " \"Hursley Park\",\n" + + " \"Winchester\",\n" + + " \"SO21 2JN\"\n" + + "]", + null, + "{\n" + + " \"FirstName\": \"Fred\",\n" + + " \"Address\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + "}"); + } + + @Test + public void eachWithFunctionWith2Args() throws Exception { + test("($mapKeyValue := function($v, $k) {$k & \": \" & $v};\n" + + "$each(Address, $mapKeyValue))", + "[\n" + + " \"Street: Hursley Park\",\n" + + " \"City: Winchester\",\n" + + " \"Postcode: SO21 2JN\"\n" + + "]", + null, + "{\n" + + " \"FirstName\": \"Fred\",\n" + + " \"Address\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + "})"); + } + + @Test + public void eachWithFunctionWith3Args() throws Exception { + test("($myfunc := function($val, $key, $obj) {{ $key & \"|\" & $val : $obj }};\n" + + "$each(Address, $myfunc))", + "[\n" + + " {\n" + + " \"Street|Hursley Park\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + " },\n" + + " {\n" + + " \"City|Winchester\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + " },\n" + + " {\n" + + " \"Postcode|SO21 2JN\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + " }\n" + + "]", + null, + "{\n" + + " \"FirstName\": \"Fred\",\n" + + " \"Address\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + "}"); + } + + @Test + public void eachWithFunctionWith4Args() throws Exception { + test("($func := function($val, $key, $obj, $x) {{ $key & \"|\" & $val : $obj & $x}};" + + "$each(Address, $func))", + "[\n" + + " {\n" + + " \"Street|Hursley Park\": \"{\\\"Street\\\":\\\"Hursley Park\\\",\\\"City\\\":\\\"Winchester\\\",\\\"Postcode\\\":\\\"SO21 2JN\\\"}\"\n" + + " },\n" + + " {\n" + + " \"City|Winchester\": \"{\\\"Street\\\":\\\"Hursley Park\\\",\\\"City\\\":\\\"Winchester\\\",\\\"Postcode\\\":\\\"SO21 2JN\\\"}\"\n" + + " },\n" + + " {\n" + + " \"Postcode|SO21 2JN\": \"{\\\"Street\\\":\\\"Hursley Park\\\",\\\"City\\\":\\\"Winchester\\\",\\\"Postcode\\\":\\\"SO21 2JN\\\"}\"\n" + + " }\n" + + "]", + null, + "{\n" + + " \"FirstName\": \"Fred\",\n" + + " \"Address\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + "}"); + } + + @Test + public void eachKeyValuePairIntoArrayWithJsonataFunction() throws Exception { + test("$each(Address, $uppercase))", + "[\n" + + " \"HURSLEY PARK\",\n" + + " \"WINCHESTER\",\n" + + " \"SO21 2JN\"\n" + + "]", + null, + "{\n" + + " \"Address\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + "})"); + } + @Test public void combineWithMap() throws Exception { test("$map([{\"a\":1,\"value\":2},{\"b\":3,\"value\":4}],function($obj1){$each($obj1,function($v,$k){$k&\"=\"&$v})})", "[[\"a=1\", \"value=2\"], [\"b=3\", \"value=4\"]]", null, (String) null); } + + @Test + public void agnosticTestSuiteCase002() throws Exception { + test("$each(function($v, $k) {$k[$v>2]})", + "[\"c\", \"d\"]", + null, + "{ \"a\": 1, \"b\": 2, \"c\": 3, \"d\": 4 }"); + } + + @Test + public void undefindedFunction() throws Exception { + test("$each(Address, $xyz))", + null, + String.format(EachFunction.ERR_ARG2_FUNCTION_RESOLVE, "$xyz"), + "{\n" + + " \"Address\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + "})"); + } + + @Test + public void nullInput() throws Exception { + test("$each()", null, EachFunction.ERR_ARG1BADTYPE, (String) null); + } + + public void nullInput2() throws Exception { + test("$each()", null, null, (String) null); + } + + @Test + public void nullInputFromChain() throws Exception { + test("null ~> $each()", null, EachFunction.ERR_ARG1BADTYPE, (String) null); + } + + @Test + public void oneArgNoFunctionArg() throws Exception { + test("$each(object)", null, EachFunction.ERR_ARG2BADTYPE, (String) null); + } + + @Test + public void oneArgNoObjectArg() throws Exception { + test("$each(function($v, $k){{$k: $v}})", null, null, (String) null); + } + + @Test + public void twoArgsObjectNoMatch() throws Exception { + test("$each(obj, function($v, $k){{$k: $v}})", null, null, (String) null); + } + + @Test + public void twoArgs1stWrongType() throws Exception { + test("$each(2, function($v, $k){{$k: $v}})", null, EachFunction.ERR_ARG1BADTYPE, (String) null); + } + + @Test + public void twoArgs2ndWrongType() throws Exception { + test("$each({\"key\":\"value\"}, 2)", "[]", EachFunction.ERR_ARG2BADTYPE, (String) null); + } + + @Test + public void twoArgs1stNoMatch2ndWrongType() throws Exception { + test("$each(obj, 2)", null, EachFunction.ERR_ARG2BADTYPE, (String) null); + } + + @Test + public void threeArgs() throws Exception { + test("$each({\"key\":\"value\"}, function($v, $k){{$k: $v}}, 2)", null, EachFunction.ERR_ARG3BADTYPE, (String) null); + } + + @Test + public void threeArgs1stNoMatch() throws Exception { + test("$each(object, function($v, $k){{$k: $v}}, 2)", null, EachFunction.ERR_ARG3BADTYPE, (String) null); + } + + @Test + public void eachKeyValuePairIntoArray() throws Exception { + test("$each(Address, function($v, $k) {$k & \": \" & $v})", + "[\n" + + " \"Street: Hursley Park\",\n" + + " \"City: Winchester\",\n" + + " \"Postcode: SO21 2JN\"\n" + + "]", + null, + "{\n" + + " \"FirstName\": \"Fred\",\n" + + " \"Address\": {\n" + + " \"Street\": \"Hursley Park\",\n" + + " \"City\": \"Winchester\",\n" + + " \"Postcode\": \"SO21 2JN\"\n" + + " }\n" + + "}"); + } } diff --git a/src/test/java/com/api/jsonata4java/expressions/functions/FilterFunctionTest.java b/src/test/java/com/api/jsonata4java/expressions/functions/FilterFunctionTest.java index bc291b6..af3ba9a 100644 --- a/src/test/java/com/api/jsonata4java/expressions/functions/FilterFunctionTest.java +++ b/src/test/java/com/api/jsonata4java/expressions/functions/FilterFunctionTest.java @@ -27,11 +27,6 @@ public class FilterFunctionTest { - @Test - public void nullInput() throws Exception { - test("$filter()", null, null, (String) null); - } - @Test public void filterObjects() throws Exception { test(/* expression */ "{\n" @@ -53,13 +48,53 @@ public void filterObjects() throws Exception { } @Test - public void filterNumbers() throws Exception { - test("($x:=function($l){$l>2};$filter([1,5,3,4,2],$x))", "[5, 3, 4]", null, null); + public void filterNumbersFuncInlined() throws Exception { + test("$filter([1,5,3,4,2], function($n){$n>2})", "[5,3,4]", null, null); } @Test - public void filterNumbersOdd() throws Exception { - test("($x:=function($l){$l%2=1};$filter([1,5,3,4,2],$x))", "[1, 5, 3]", null, null); + public void filterNumbersFuncDeclared() throws Exception { + test("($x:=function($n){$n>2};$filter([1,5,3,4,2], $x))", "[5,3,4]", null, null); + } + + @Test + public void filterNumbersFuncJsonata1() throws Exception { + test("$filter([-2,-1,0,1,2], $abs)", "[-2,-1,1,2]", null, null); + } + + @Test + public void filterNumbersFuncJsonataIncompatible() throws Exception { + test("$filter([1,5,3,4,2], $substring)", null, "Context value is not a compatible type with argument 1 of function \"$substring\"", (String) null); + } + + @Test + public void filterNumbersFuncJsonataArgNotMatch1() throws Exception { + test("$filter([1,5,3,4,2], $pad)", null, "Argument 1 of function $pad does not match function signature", (String) null); + } + + @Test + public void filterNumbersFuncJsonataArgNotMatch2() throws Exception { + test("$filter([1,5,3,4,2], $split)", null, "Argument 2 of function $split does not match function signature", (String) null); + } + + @Test + public void filterNumbersFuncJsonata2() throws Exception { + test("$filter([1,5,3,4,2], $reduce)", "[1,5,3,4,2]", null, (String) null); + } + + @Test + public void filterNumbersByIndex() throws Exception { + test("$filter([10,4,45,2,13,7], function($n, $i){$i < 3})", "[10,4,45]", null, null); + } + + @Test + public void filterNumbersByIndexAndCompleteArray() throws Exception { + test("$filter([10,4,45,2,13,7], function($n, $i, $a){$i > 0 and $a[$i - 1] >= 10})", "[4,2,7]", null, null); + } + + @Test + public void filterNumbersByIndexAndCompleteArrayPlusArg() throws Exception { + test("$filter([10,4,45,2,13,7], function($n, $i, $a, $s){$i > 0 and $a[$i - 1] >= 10 and $s})", null, null, (String) null); } @Test @@ -77,13 +112,66 @@ public void filterAll() throws Exception { } @Test - public void filterMissingFunctionArg() throws Exception { + public void noInput() throws Exception { + test("$filter()", null, FilterFunction.ERR_ARG1BADTYPE, (String) null); + } + + @Test + public void nullInput() throws Exception { + test("$filter(null)", null, FilterFunction.ERR_ARG2BADTYPE, (String) null); + } + + public void nullInput2() throws Exception { + test("$filter()", null, null, (String) null); + } + + @Test + public void nullInputChain() throws Exception { + test("null ~> $filter()", null, FilterFunction.ERR_ARG1BADTYPE, (String) null); + } + + @Test + public void missingFunctionArg() throws Exception { test("$filter([1,5,3,4,2])", null, FilterFunction.ERR_ARG2BADTYPE, (String) null); } + // Original JSONata FilterFunction.ERR_ARG2BADTYPE + // FIXME how to differ this case from chainedArrayArgNullFuncInlined() @Test - public void filterMissingArrayArg() throws Exception { - test("($x:=function($l){$l>2};$filter($x))", null, null, (String) null); + public void missingArrayArgFuncInlined() throws Exception { + test("$filter(function($n){$n>2})", null, null, (String) null); + } + + // Original JSONata FilterFunction.ERR_ARG2BADTYPE + // FIXME how to differ this case from chainedArrayArgNullFuncInlined() + @Test + public void missingArrayArgFuncDeclared() throws Exception { + test("($func:=function($n){$n>2};$filter($func))", null, null, (String) null); + } + + @Test + public void filterNumbersFuncNotDeclared() throws Exception { + test("$filter([1,5,3,4,2], $func)", "[5,3,4]", String.format(FilterFunction.ERR_ARG2_FUNCTION_RESOLVE, "$func"), null); + } + + @Test + public void filterNumbersFuncReturnsNothing() throws Exception { + test("$filter([1,5,3,4,2], function($n){null})", null, null, (String) null); + } + + @Test + public void filterNumbersFuncReturnsNoBoolean() throws Exception { + test("$filter([1,5,3,4,2], function($n){\"foo\"})", null, null, (String) null); + } + + @Test + public void chainedArrayArgNullFuncInlined() throws Exception { + test("null ~> $filter(function($n){$n>2})", null, null, (String) null); + } + + @Test + public void chainedArgEmptyFuncInlined() throws Exception { + test("[] ~> $filter(function($n){$n>2})", null, null, (String) null); } @Test @@ -101,4 +189,41 @@ public void filterNumbersEmpty() throws Exception { + " ]\n" + "}"); } + + @Test + public void nullArrayArg() throws Exception { + test("$filter(null, function($n){$n>2})", null, + "The expressions either side of operator \">\" must evaluate to numeric or string values", + (String) null); + } + + @Test + public void noMatchArrayArg() throws Exception { + test("$filter(n, function($n){$n>2})", null, null, (String) null); + } + + @Test + public void tooMuchArgs() throws Exception { + test("$filter([1,5,3], function($n){$n>2}, \"test\")", null, FilterFunction.ERR_ARG3BADTYPE, (String) null); + } + + @Test + public void filterNumbers() throws Exception { + test("($x:=function($l){$l>2};$filter([1,5,3,4,2],$x))", "[5, 3, 4]", null, null); + } + + @Test + public void filterNumbersOdd() throws Exception { + test("($x:=function($l){$l%2=1};$filter([1,5,3,4,2],$x))", "[1, 5, 3]", null, null); + } + + @Test + public void filterMissingFunctionArg() throws Exception { + test("$filter([1,5,3,4,2])", null, FilterFunction.ERR_ARG2BADTYPE, (String) null); + } + + @Test + public void filterMissingArrayArg() throws Exception { + test("($x:=function($l){$l>2};$filter($x))", null, null, (String) null); + } } diff --git a/src/test/java/com/api/jsonata4java/test/expressions/BasicExpressionsTests.java b/src/test/java/com/api/jsonata4java/test/expressions/BasicExpressionsTest.java similarity index 98% rename from src/test/java/com/api/jsonata4java/test/expressions/BasicExpressionsTests.java rename to src/test/java/com/api/jsonata4java/test/expressions/BasicExpressionsTest.java index 56736c5..44b5db9 100644 --- a/src/test/java/com/api/jsonata4java/test/expressions/BasicExpressionsTests.java +++ b/src/test/java/com/api/jsonata4java/test/expressions/BasicExpressionsTest.java @@ -44,7 +44,6 @@ import com.api.jsonata4java.expressions.functions.CountFunction; import com.api.jsonata4java.expressions.functions.ExistsFunction; import com.api.jsonata4java.expressions.functions.LookupFunction; -import com.api.jsonata4java.expressions.functions.MergeFunction; import com.api.jsonata4java.expressions.functions.ShuffleFunction; import com.api.jsonata4java.expressions.functions.SubstringFunction; import com.api.jsonata4java.expressions.functions.SumFunction; @@ -67,7 +66,7 @@ * class. Retained because we might as well keep them (they execute in seconds). */ @SuppressWarnings("deprecation") -public class BasicExpressionsTests implements Serializable { +public class BasicExpressionsTest implements Serializable { private static final long serialVersionUID = -2403728781442037506L; @@ -1037,41 +1036,6 @@ public void testObjectFunctions() throws Exception { simpleTest("$spread([1])", "[1]"); - // jsonata.js 1.8 docs only talk about objects and arrays of objects - // but changed code to behave like jsonata.js - // { - // try { - // Expressions.parse("$spread([1])").evaluate(null); - // Assert.fail("Did not throw an expected exception"); - // } catch (EvaluateException ex) { - // Assert.assertEquals(SpreadFunction.ERR_ARG1_MUST_BE_ARRAY_OF_OBJECTS, - // ex.getMessage()); - // } - // } - - simpleTest("$merge([{\"a\":1,\"value\":2},{\"b\":{\"value\":{\"d\":5},\"c\":5}},{\"a\":2}])", - "{\"a\":2, \"value\":2, \"b\":{\"value\":{\"d\":5},\"c\":5}}"); - simpleTest("$merge(a.b)", null); - - { - Expressions expression = Expressions.parse("$merge()"); - try { - expression.evaluate(null); - Assert.fail("Did not throw an expected exception"); - } catch (EvaluateException ex) { - Assert.assertEquals(MergeFunction.ERR_ARG1BADTYPE, ex.getMessage()); - } - } - { - Expressions expression = Expressions.parse("$merge({\"hello\":1},2)"); - try { - expression.evaluate(null); - Assert.fail("Did not throw an expected exception"); - } catch (EvaluateException ex) { - Assert.assertEquals(MergeFunction.ERR_ARG2BADTYPE, ex.getMessage()); - } - } - // issue #237 JsonNode payload = mapper.readTree("{ \"key1\": \"\\\"v1\\\"\" }"); JsonNode result1 = Expressions.parse("$each($, function($v, $k) {({ $k: $v})}) ~> $merge()").evaluate(payload); @@ -2131,7 +2095,6 @@ public void testBasicSelection() throws Exception { // selecting empty member names simpleTest("[{\"\":1}, {\"\":2}].``", "[1,2]"); - } @Test diff --git a/src/test/java/testmanually/ComponentTestSuite.java b/src/test/java/testmanually/ComponentTestSuite.java index d11db62..726c41d 100644 --- a/src/test/java/testmanually/ComponentTestSuite.java +++ b/src/test/java/testmanually/ComponentTestSuite.java @@ -23,6 +23,7 @@ package testmanually; import java.io.Serializable; +import org.junit.Ignore; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @@ -123,6 +124,7 @@ UppercaseFunctionTests.class, // TestBindingReference.class // }) +@Ignore public class ComponentTestSuite implements Serializable { diff --git a/src/test/java/testmanually/ExpressionTestPerfomance.java b/src/test/java/testmanually/ExpressionTestPerfomance.java index 9b07ef2..54551ff 100644 --- a/src/test/java/testmanually/ExpressionTestPerfomance.java +++ b/src/test/java/testmanually/ExpressionTestPerfomance.java @@ -22,6 +22,7 @@ package testmanually; +import org.junit.Ignore; import org.junit.Test; import com.api.jsonata4java.expressions.Jsonata4JavaTestMapper; import com.fasterxml.jackson.core.JsonProcessingException; @@ -34,6 +35,7 @@ * * @author Martin Bluemel */ +@Ignore public class ExpressionTestPerfomance { private final ObjectMapper jsonMapper = new ObjectMapper(); diff --git a/src/test/java/testmanually/JsonataUnitTests.java b/src/test/java/testmanually/JsonataUnitTests.java index 3d11cef..7184b88 100644 --- a/src/test/java/testmanually/JsonataUnitTests.java +++ b/src/test/java/testmanually/JsonataUnitTests.java @@ -26,6 +26,7 @@ import java.io.Serializable; import java.util.Arrays; import java.util.Collection; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -37,6 +38,7 @@ * Verify behavior when access special $state, $event and $instance variables. */ @RunWith(Parameterized.class) +@Ignore public class JsonataUnitTests implements Serializable { private static final long serialVersionUID = -862598258330086928L; diff --git a/src/test/java/testmanually/MapFunctionNonParTests.java b/src/test/java/testmanually/MapFunctionNonParTests.java index a454975..42df1db 100644 --- a/src/test/java/testmanually/MapFunctionNonParTests.java +++ b/src/test/java/testmanually/MapFunctionNonParTests.java @@ -23,6 +23,7 @@ package testmanually; import static com.api.jsonata4java.expressions.utils.Utils.test; +import org.junit.Ignore; import org.junit.Test; /** @@ -30,6 +31,7 @@ * * @author Martin Bluemel */ +@Ignore public class MapFunctionNonParTests { // @Test diff --git a/src/test/java/testmanually/TestBindingReference.java b/src/test/java/testmanually/TestBindingReference.java index 07806c6..028670c 100644 --- a/src/test/java/testmanually/TestBindingReference.java +++ b/src/test/java/testmanually/TestBindingReference.java @@ -2,6 +2,7 @@ import java.io.Serializable; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import com.api.jsonata4java.Expression; import com.api.jsonata4java.expressions.utils.Utils; @@ -9,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; +@Ignore public class TestBindingReference implements Serializable { private static final long serialVersionUID = -7721819254928734600L; diff --git a/src/test/java/testmanually/ThreadTester.java b/src/test/java/testmanually/ThreadTester.java index 1b88eba..4a21fbc 100644 --- a/src/test/java/testmanually/ThreadTester.java +++ b/src/test/java/testmanually/ThreadTester.java @@ -1,4 +1,6 @@ package testmanually; + +import org.junit.Ignore; import org.junit.Test; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; @@ -6,6 +8,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +@Ignore public class ThreadTester { static boolean showError = false;