11package com .webfuzzing .overlayjvm ;
22
3- import org .junit .jupiter .api .Disabled ;
3+ import org .junit .jupiter .api .Test ;
44import org .junit .jupiter .params .ParameterizedTest ;
55import org .junit .jupiter .params .provider .MethodSource ;
6+ import org .noear .snack4 .ONode ;
67
78import java .util .stream .Stream ;
89
10+ import static org .junit .jupiter .api .Assertions .*;
11+
912public class OverlayJVM_V1_1_0_custom_Test extends ProcessorTestBase {
1013
1114 public static Stream <Data > overlayProvider () {
@@ -21,4 +24,83 @@ public static Stream<Data> overlayProvider() {
2124 public void testOverlay (ProcessorTestBase .Data data ) throws Exception {
2225 verifyOverlay (data , "src/test/resources/custom" );
2326 }
27+
28+ @ Test
29+ public void testLibrarySupport () throws Exception {
30+
31+ String json = readResource ("custom/array/array.json" );
32+ assertNotNull (json );
33+
34+ ONode schema = ONode .ofJson (json );
35+
36+ //----------------------------------------------------
37+ //this should return no results
38+ String q0 = "$.a[?@.y]" ;
39+ boolean e0 = schema .exists (q0 );
40+ ONode r0 = schema .select (q0 );
41+
42+ //assertFalse(e0); //this fails
43+ assertTrue (r0 .isArray ());
44+ assertEquals (0 , r0 .size ());
45+ assertNull (r0 .parent ());
46+
47+ //----------------------------------------------------
48+ //this should return the empty array in b
49+ String q1 = "$.b" ;
50+ boolean e1 = schema .exists (q1 );
51+ ONode r1 = schema .select (q1 );
52+
53+ assertTrue (e1 );
54+ assertTrue (r1 .isArray ());
55+ assertEquals (0 , r1 .size ());
56+ //is checking the parent the only way to see if the target is an array?
57+ assertNotNull (r1 .parent ());
58+
59+ //----------------------------------------------------
60+ //should get the elements in c and d
61+ String q2 = "$.*.y" ;
62+ boolean e2 = schema .exists (q2 );
63+ ONode r2 = schema .select (q2 );
64+
65+ assertTrue (e2 );
66+ assertTrue (r2 .isArray ());
67+ assertEquals (2 , r2 .size ());
68+ assertNull (r2 .parent ());
69+ // the returned nodes in the result arrays are not copies, but references to original tree, sharing same root
70+ assertEquals (r2 .get (0 ).parent ().parent (), r2 .get (1 ).parent ().parent ());
71+
72+ //----------------------------------------------------
73+ // although e is null, it exists
74+ String q3 = "$.e" ;
75+ boolean e3 = schema .exists (q3 );
76+ ONode r3 = schema .select (q3 );
77+
78+ assertTrue (e3 );
79+ assertFalse (r3 .isArray ());
80+ assertTrue (r3 .isNull ());
81+ assertNotNull (r3 .parent ());
82+
83+ //----------------------------------------------------
84+ // f is undefined in the document
85+ String q4 = "$.f" ;
86+ boolean e4 = schema .exists (q4 );
87+ ONode r4 = schema .select (q4 );
88+
89+ //if undefined, then it is treated as a "null" node, but with no parent, and with "exists" returning false
90+ assertFalse (e4 );
91+ assertFalse (r4 .isArray ());
92+ assertTrue (r4 .isNull ());
93+ assertNull (r4 .parent ());
94+
95+ //----------------------------------------------------
96+ // f is undefined
97+ String q5 = "$.f[?@.y]" ;
98+ boolean e5 = schema .exists (q5 );
99+ ONode r5 = schema .select (q5 );
100+
101+ //assertFalse(e5); // this fails???
102+ assertTrue (r5 .isArray ()); //this is now treated as an empty array?
103+ assertEquals (0 , r5 .size ());
104+ assertNull (r5 .parent ());
105+ }
24106}
0 commit comments