Skip to content

Commit d60d0b6

Browse files
committed
test to check library behavior
1 parent a5f4aef commit d60d0b6

4 files changed

Lines changed: 99 additions & 2 deletions

File tree

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
<properties>
5151
<java.version>1.8</java.version>
52+
<snackjson.version>4.0.37</snackjson.version>
5253
<jackson.version>2.14.3</jackson.version>
5354
<junit.jupiter.version>5.14.3</junit.jupiter.version>
5455
<junit.platform.version>1.14.3</junit.platform.version>
@@ -88,7 +89,7 @@
8889
<dependency>
8990
<groupId>org.noear</groupId>
9091
<artifactId>snack4-jsonpath</artifactId>
91-
<version>4.0.36</version>
92+
<version>${snackjson.version}</version>
9293
</dependency>
9394

9495
<!--

src/test/java/com/webfuzzing/overlayjvm/OverlayJVM_V1_1_0_custom_Test.java

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.webfuzzing.overlayjvm;
22

3-
import org.junit.jupiter.api.Disabled;
3+
import org.junit.jupiter.api.Test;
44
import org.junit.jupiter.params.ParameterizedTest;
55
import org.junit.jupiter.params.provider.MethodSource;
6+
import org.noear.snack4.ONode;
67

78
import java.util.stream.Stream;
89

10+
import static org.junit.jupiter.api.Assertions.*;
11+
912
public 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
}

src/test/java/com/webfuzzing/overlayjvm/ProcessorTestBase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
import org.skyscreamer.jsonassert.JSONAssert;
44
import org.skyscreamer.jsonassert.JSONCompareMode;
55

6+
import java.io.IOException;
67
import java.nio.file.Files;
8+
import java.nio.file.Path;
79
import java.nio.file.Paths;
810

911
import static org.junit.jupiter.api.Assertions.*;
1012

1113
public class ProcessorTestBase {
1214

15+
protected String readResource(String resource) throws Exception {
16+
Path path = Paths.get(this.getClass().getClassLoader().getResource(resource).toURI());
17+
return new String(Files.readAllBytes(path));
18+
}
19+
1320
protected void verifyOverlay(Data data, String base) throws Exception {
1421

1522
String openApi = new String(Files.readAllBytes(Paths.get(base, data.openApi)));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"a": [{"x": 42}, {"x": 777}],
3+
"b": [],
4+
"c": {"y": 1},
5+
"d": {"y": 2},
6+
"e": null
7+
}

0 commit comments

Comments
 (0)