11package com .networknt .schema ;
22
3- import static org .junit .Assert .assertTrue ;
3+ import static org .junit .Assert .assertEquals ;
44
55import java .io .IOException ;
66import java .io .InputStream ;
77import java .util .LinkedHashSet ;
88import java .util .Set ;
99import java .util .TreeSet ;
1010
11- import com .networknt .schema .walk .WalkMethodInvocation ;
11+ import com .networknt .schema .walk .WalkFlow ;
1212import org .junit .Before ;
1313import org .junit .Test ;
1414
@@ -27,13 +27,12 @@ public class JsonWalkTest {
2727 private static final String CUSTOM_KEYWORD = "custom-keyword" ;
2828
2929 @ Before
30- public void setup () throws Exception {
30+ public void setup () {
3131 setupSchema ();
3232 }
3333
34- private void setupSchema () throws Exception {
35- final JsonMetaSchema metaSchema = getJsonMetaSchema (
36- "https://github.com/networknt/json-schema-validator/tests/schemas/example01" );
34+ private void setupSchema () {
35+ final JsonMetaSchema metaSchema = getJsonMetaSchema ();
3736 SchemaValidatorsConfig schemaValidatorsConfig = new SchemaValidatorsConfig ();
3837 schemaValidatorsConfig .addKeywordWalkListener (new AllKeywordListener ());
3938 schemaValidatorsConfig .addKeywordWalkListener (ValidatorTypeCode .REF .getValue (), new RefKeywordListener ());
@@ -45,10 +44,10 @@ private void setupSchema() throws Exception {
4544 this .jsonSchema = schemaFactory .getSchema (getSchema (), schemaValidatorsConfig );
4645 }
4746
48- private JsonMetaSchema getJsonMetaSchema (String uri ) throws Exception {
49- JsonMetaSchema jsonMetaSchema = JsonMetaSchema .builder (uri , JsonMetaSchema .getV201909 ())
47+ private JsonMetaSchema getJsonMetaSchema () {
48+ return JsonMetaSchema .builder (
49+ "https://github.com/networknt/json-schema-validator/tests/schemas/example01" , JsonMetaSchema .getV201909 ())
5050 .addKeyword (new CustomKeyword ()).build ();
51- return jsonMetaSchema ;
5251 }
5352
5453 @ Test
@@ -57,7 +56,7 @@ public void testWalk() throws IOException {
5756 ValidationResult result = jsonSchema .walk (
5857 objectMapper .readTree (getClass ().getClassLoader ().getResourceAsStream ("data/walk-data.json" )), false );
5958 JsonNode collectedNode = (JsonNode ) result .getCollectorContext ().get (SAMPLE_COLLECTOR );
60- assertTrue (collectedNode . equals (objectMapper .readTree ("{" +
59+ assertEquals (collectedNode , (objectMapper .readTree ("{" +
6160 " \" PROPERTY1\" : \" sample1\" ,"
6261 + " \" PROPERTY2\" : \" sample2\" ,"
6362 + " \" property3\" : {"
@@ -77,15 +76,15 @@ private InputStream getSchema() {
7776 /**
7877 * Our own custom keyword.
7978 */
80- private class CustomKeyword implements Keyword {
79+ private static class CustomKeyword implements Keyword {
8180 @ Override
8281 public String getValue () {
8382 return "custom-keyword" ;
8483 }
8584
8685 @ Override
8786 public JsonValidator newValidator (String schemaPath , JsonNode schemaNode , JsonSchema parentSchema ,
88- ValidationContext validationContext ) throws JsonSchemaException , Exception {
87+ ValidationContext validationContext ) throws JsonSchemaException {
8988 if (schemaNode != null && schemaNode .isArray ()) {
9089 return new CustomValidator ();
9190 }
@@ -98,7 +97,7 @@ public JsonValidator newValidator(String schemaPath, JsonNode schemaNode, JsonSc
9897 * This will be helpful in cases where we don't want to revisit the entire JSON
9998 * document again just for gathering this kind of information.
10099 */
101- private class CustomValidator implements JsonValidator {
100+ private static class CustomValidator implements JsonValidator {
102101
103102 @ Override
104103 public Set <ValidationMessage > validate (JsonNode node , JsonNode rootNode , String at ) {
@@ -118,9 +117,9 @@ public Set<ValidationMessage> walk(JsonNode node, JsonNode rootNode, String at,
118117 }
119118 }
120119
121- private class AllKeywordListener implements WalkListener {
120+ private static class AllKeywordListener implements WalkListener {
122121 @ Override
123- public WalkMethodInvocation onWalkStart (WalkEvent keywordWalkEvent ) {
122+ public WalkFlow onWalkStart (WalkEvent keywordWalkEvent ) {
124123 ObjectMapper mapper = new ObjectMapper ();
125124 String keyWordName = keywordWalkEvent .getKeyWordName ();
126125 JsonNode schemaNode = keywordWalkEvent .getSchemaNode ();
@@ -133,7 +132,7 @@ public WalkMethodInvocation onWalkStart(WalkEvent keywordWalkEvent) {
133132 objectNode .put (keywordWalkEvent .getSchemaNode ().get ("title" ).textValue ().toUpperCase (),
134133 keywordWalkEvent .getNode ().textValue ());
135134 }
136- return WalkMethodInvocation . CONTINUE_TO_WALK ;
135+ return WalkFlow . CONTINUE ;
137136 }
138137
139138 @ Override
@@ -142,10 +141,10 @@ public void onWalkEnd(WalkEvent keywordWalkEvent, Set<ValidationMessage> validat
142141 }
143142 }
144143
145- private class RefKeywordListener implements WalkListener {
144+ private static class RefKeywordListener implements WalkListener {
146145
147146 @ Override
148- public WalkMethodInvocation onWalkStart (WalkEvent keywordWalkEvent ) {
147+ public WalkFlow onWalkStart (WalkEvent keywordWalkEvent ) {
149148 ObjectMapper mapper = new ObjectMapper ();
150149 CollectorContext collectorContext = CollectorContext .getInstance ();
151150 if (collectorContext .get (SAMPLE_COLLECTOR ) == null ) {
@@ -154,7 +153,7 @@ public WalkMethodInvocation onWalkStart(WalkEvent keywordWalkEvent) {
154153 ObjectNode objectNode = (ObjectNode ) collectorContext .get (SAMPLE_COLLECTOR );
155154 objectNode .set (keywordWalkEvent .getSchemaNode ().get ("title" ).textValue ().toLowerCase (),
156155 keywordWalkEvent .getNode ());
157- return WalkMethodInvocation . SKIP_WALK ;
156+ return WalkFlow . SKIP ;
158157 }
159158
160159 @ Override
@@ -163,15 +162,15 @@ public void onWalkEnd(WalkEvent keywordWalkEvent, Set<ValidationMessage> validat
163162 }
164163 }
165164
166- private class PropertiesKeywordListener implements WalkListener {
165+ private static class PropertiesKeywordListener implements WalkListener {
167166
168167 @ Override
169- public WalkMethodInvocation onWalkStart (WalkEvent keywordWalkEvent ) {
168+ public WalkFlow onWalkStart (WalkEvent keywordWalkEvent ) {
170169 JsonNode schemaNode = keywordWalkEvent .getSchemaNode ();
171170 if (schemaNode .get ("title" ).textValue ().equals ("Property3" )) {
172- return WalkMethodInvocation . SKIP_WALK ;
171+ return WalkFlow . SKIP ;
173172 }
174- return WalkMethodInvocation . CONTINUE_TO_WALK ;
173+ return WalkFlow . CONTINUE ;
175174 }
176175
177176 @ Override
0 commit comments