1212import java .util .Objects ;
1313import java .util .stream .Stream ;
1414
15- import static org .junit .jupiter .api .Assertions .*;
15+ import static org .junit .jupiter .api .Assertions .assertEquals ;
16+ import static org .junit .jupiter .api .Assertions .assertThrows ;
1617import static org .junit .jupiter .params .provider .Arguments .arguments ;
1718
1819class JsonbExpressionBuilderTest {
@@ -37,6 +38,27 @@ void testJsonbPathExpressionWithTemporal(ComparisonOperator operator, String key
3738 assertEquals (expectedJsonbPath , expression .jsonbPath ());
3839 }
3940
41+ @ ParameterizedTest
42+ @ MethodSource ("customized" )
43+ void testJsonbPathExpressionCustomized (ComparisonOperator operator , String keyPath , List <String > arguments , String expectedJsonbFunction , String expectedJsonbPath ) {
44+ String jsonbPathExists = JsonbSupport .JSONB_PATH_EXISTS ;
45+ String jsonbPathExistsTz = JsonbSupport .JSONB_PATH_EXISTS_TZ ;
46+ try {
47+ JsonbSupport .JSONB_PATH_EXISTS = "my_jsonb_path_exists" ;
48+ JsonbSupport .JSONB_PATH_EXISTS_TZ = "my_jsonb_path_exists_tz" ;
49+ JsonbSupport .DATE_TIME_SUPPORT = true ;
50+ JsonbExpressionBuilder builder = new JsonbExpressionBuilder (operator , keyPath , arguments );
51+ var expression = builder .getJsonPathExpression ();
52+ assertEquals (expectedJsonbFunction , expression .jsonbFunction ());
53+ assertEquals (expectedJsonbPath , expression .jsonbPath ());
54+ } catch (Exception e ) {
55+ throw e ;
56+ } finally {
57+ JsonbSupport .JSONB_PATH_EXISTS = jsonbPathExists ;
58+ JsonbSupport .JSONB_PATH_EXISTS_TZ = jsonbPathExistsTz ;
59+ }
60+ }
61+
4062 static Stream <Arguments > data () {
4163 return Stream .of (
4264 allOperators (),
@@ -78,6 +100,17 @@ static Stream<Arguments> conversion() {
78100 ).filter (Objects ::nonNull );
79101 }
80102
103+ static Stream <Arguments > customized () {
104+
105+ return Stream .of (
106+ arguments (RSQLOperators .EQUAL , "json.equal_key" , Collections .singletonList ("value" ), "my_jsonb_path_exists" , "$.equal_key ? (@ == \" value\" )" ),
107+ arguments (RSQLOperators .GREATER_THAN , "json.greater_than_key" , Collections .singletonList ("value" ), "my_jsonb_path_exists" , "$.greater_than_key ? (@ > \" value\" )" ),
108+ arguments (RSQLOperators .EQUAL , "json.equal_key" , Collections .singletonList ("1970-01-01T00:00:00.000" ), "my_jsonb_path_exists" , "$.equal_key ? (@.datetime() == \" 1970-01-01T00:00:00.000\" .datetime())" ),
109+ arguments (RSQLOperators .EQUAL , "json.equal_key" , Collections .singletonList ("1970-01-01T00:00:00.000Z" ), "my_jsonb_path_exists_tz" , "$.equal_key ? (@.datetime() == \" 1970-01-01T00:00:00.000Z\" .datetime())" ),
110+ null
111+ ).filter (Objects ::nonNull );
112+ }
113+
81114 static Stream <Arguments > temporal () {
82115
83116 return Stream .of (
0 commit comments