@@ -91,68 +91,44 @@ void testValidationMessage(PathType pathType, String schemaPath, String content,
91
91
}
92
92
}
93
93
94
- @ Test
95
- void testDoubleQuotes () throws JsonProcessingException {
96
- ObjectMapper mapper = new ObjectMapper ();
97
- SchemaValidatorsConfig schemaValidatorsConfig = new SchemaValidatorsConfig ();
98
- schemaValidatorsConfig .setPathType (PathType .JSON_PATH );
99
- /*
100
- {
101
- "$schema": "https://json-schema.org/draft/2019-09/schema",
102
- "type": "object",
103
- "properties": {
104
- "\"": {
105
- "type": "boolean"
106
- }
107
- }
108
- }
109
- */
110
- JsonSchema schema = JsonSchemaFactory .getInstance (SpecVersion .VersionFlag .V201909 )
111
- .getSchema (mapper .readTree ("{\n " +
112
- " \" $schema\" : \" https://json-schema.org/draft/2019-09/schema\" ,\n " +
113
- " \" type\" : \" object\" ,\n " +
114
- " \" properties\" : {\n " +
115
- " \" \\ \" \" : {\n " +
116
- " \" type\" : \" boolean\" \n " +
117
- " }\n " +
118
- " }\n " +
119
- "}" ), schemaValidatorsConfig );
120
- // {"\"": 1}
121
- Set <ValidationMessage > validationMessages = schema .validate (mapper .readTree ("{\" \\ \" \" : 1}" ));
122
- assertEquals (1 , validationMessages .size ());
123
- assertEquals ("$['\" ']" , validationMessages .iterator ().next ().getPath ());
94
+ public static Stream <Arguments > specialCharacterTests () {
95
+ return Stream .of (
96
+ Arguments .of (PathType .JSON_PATH , "'" , "$['\\ '']" ),
97
+ Arguments .of (PathType .JSON_PATH , "\\ \" " , "$['\" ']" ),
98
+ Arguments .of (PathType .JSON_PATH , "\\ n" , "$['\\ n']" ),
99
+ Arguments .of (PathType .JSON_PATH , "\\ r" , "$['\\ r']" ),
100
+ Arguments .of (PathType .JSON_PATH , "\\ t" , "$['\\ t']" ),
101
+ Arguments .of (PathType .JSON_PATH , "\\ f" , "$['\\ f']" ),
102
+ Arguments .of (PathType .JSON_PATH , "\\ b" , "$['\\ b']" ),
103
+ Arguments .of (PathType .JSON_POINTER , "~" , "/~0" ),
104
+ Arguments .of (PathType .JSON_POINTER , "/" , "/~1" ),
105
+ Arguments .of (PathType .JSON_POINTER , "\\ n" , "/\\ n" ),
106
+ Arguments .of (PathType .JSON_POINTER , "\\ r" , "/\\ r" ),
107
+ Arguments .of (PathType .JSON_POINTER , "\\ t" , "/\\ t" ),
108
+ Arguments .of (PathType .JSON_POINTER , "\\ f" , "/\\ f" ),
109
+ Arguments .of (PathType .JSON_POINTER , "\\ b" , "/\\ b" )
110
+ );
124
111
}
125
112
126
- @ Test
127
- void testSingleQuotes () throws JsonProcessingException {
113
+ @ ParameterizedTest
114
+ @ MethodSource ("specialCharacterTests" )
115
+ void testSpecialCharacters (PathType pathType , String propertyName , String expectedPath ) throws JsonProcessingException {
128
116
ObjectMapper mapper = new ObjectMapper ();
129
117
SchemaValidatorsConfig schemaValidatorsConfig = new SchemaValidatorsConfig ();
130
- schemaValidatorsConfig .setPathType (PathType .JSON_PATH );
131
- /*
132
- {
133
- "$schema": "https://json-schema.org/draft/2019-09/schema",
134
- "type": "object",
135
- "properties": {
136
- "'": {
137
- "type": "boolean"
138
- }
139
- }
140
- }
141
- */
118
+ schemaValidatorsConfig .setPathType (pathType );
142
119
JsonSchema schema = JsonSchemaFactory .getInstance (SpecVersion .VersionFlag .V201909 )
143
120
.getSchema (mapper .readTree ("{\n " +
144
121
" \" $schema\" : \" https://json-schema.org/draft/2019-09/schema\" ,\n " +
145
122
" \" type\" : \" object\" ,\n " +
146
123
" \" properties\" : {\n " +
147
- " \" ' \" : {\n " +
124
+ " \" " + propertyName + " \" : {\n " +
148
125
" \" type\" : \" boolean\" \n " +
149
126
" }\n " +
150
127
" }\n " +
151
128
"}" ), schemaValidatorsConfig );
152
- // {"\"": 1}
153
- Set <ValidationMessage > validationMessages = schema .validate (mapper .readTree ("{\" '\" : 1}" ));
129
+ Set <ValidationMessage > validationMessages = schema .validate (mapper .readTree ("{\" " +propertyName +"\" : 1}" ));
154
130
assertEquals (1 , validationMessages .size ());
155
- assertEquals ("$[' \\ '']" , validationMessages .iterator ().next ().getPath ());
131
+ assertEquals (expectedPath , validationMessages .iterator ().next ().getPath ());
156
132
}
157
133
158
134
}
0 commit comments