10
10
11
11
public class ValidatorTest {
12
12
13
+ private static final ObjectSchema RW_SCHEMA = (ObjectSchema ) SchemaLoader
14
+ .load (ResourceLoader .DEFAULT .readObj ("read-write-context.json" ));
15
+
13
16
@ Test
14
17
public void testCollectAllMode () {
15
18
Validator actual = Validator .builder ().build ();
@@ -41,13 +44,12 @@ public void readOnlyContext() {
41
44
Validator subject = Validator .builder ()
42
45
.readWriteContext (ReadWriteContext .READ )
43
46
.build ();
44
- ObjectSchema schema = (ObjectSchema ) SchemaLoader .load (ResourceLoader .DEFAULT .readObj ("read-write-context.json" ));
45
47
JSONObject input = new JSONObject ("{\" writeOnlyProp\" :3}" );
46
- TestSupport .failureOf (schema )
48
+ TestSupport .failureOf (RW_SCHEMA )
47
49
.expectedPointer ("#/writeOnlyProp" )
48
50
.expectedSchemaLocation ("#/properties/writeOnlyProp" )
49
51
.expectedKeyword ("writeOnly" )
50
- .expectedViolatedSchema (schema .getPropertySchemas ().get ("writeOnlyProp" ))
52
+ .expectedViolatedSchema (RW_SCHEMA .getPropertySchemas ().get ("writeOnlyProp" ))
51
53
.input (input )
52
54
.validator (subject )
53
55
.expect ();
@@ -58,13 +60,29 @@ public void writeOnlyContext() {
58
60
Validator subject = Validator .builder ()
59
61
.readWriteContext (ReadWriteContext .WRITE )
60
62
.build ();
61
- ObjectSchema schema = (ObjectSchema ) SchemaLoader .load (ResourceLoader .DEFAULT .readObj ("read-write-context.json" ));
62
63
JSONObject input = new JSONObject ("{\" readOnlyProp\" :\" foo\" }" );
63
- TestSupport .failureOf (schema )
64
+ TestSupport .failureOf (RW_SCHEMA )
64
65
.expectedPointer ("#/readOnlyProp" )
65
66
.expectedSchemaLocation ("#/properties/readOnlyProp" )
66
67
.expectedKeyword ("readOnly" )
67
- .expectedViolatedSchema (schema .getPropertySchemas ().get ("readOnlyProp" ))
68
+ .expectedViolatedSchema (RW_SCHEMA .getPropertySchemas ().get ("readOnlyProp" ))
69
+ .input (input )
70
+ .validator (subject )
71
+ .expect ();
72
+ }
73
+
74
+ @ Test
75
+ public void readOnlyNullValue () {
76
+ Validator subject = Validator .builder ()
77
+ .failEarly ()
78
+ .readWriteContext (ReadWriteContext .READ )
79
+ .build ();
80
+ JSONObject input = new JSONObject ("{\" writeOnlyProp\" :null}" );
81
+ TestSupport .failureOf (RW_SCHEMA )
82
+ .expectedPointer ("#/writeOnlyProp" )
83
+ .expectedSchemaLocation ("#/properties/writeOnlyProp" )
84
+ .expectedKeyword ("writeOnly" )
85
+ .expectedViolatedSchema (RW_SCHEMA .getPropertySchemas ().get ("writeOnlyProp" ))
68
86
.input (input )
69
87
.validator (subject )
70
88
.expect ();
0 commit comments