Skip to content

Commit 2404173

Browse files
committed
adding one more test checking readOnly when the input is null
1 parent 6f3bc32 commit 2404173

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

core/src/test/java/org/everit/json/schema/ValidatorTest.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
public class ValidatorTest {
1212

13+
private static final ObjectSchema RW_SCHEMA = (ObjectSchema) SchemaLoader
14+
.load(ResourceLoader.DEFAULT.readObj("read-write-context.json"));
15+
1316
@Test
1417
public void testCollectAllMode() {
1518
Validator actual = Validator.builder().build();
@@ -41,13 +44,12 @@ public void readOnlyContext() {
4144
Validator subject = Validator.builder()
4245
.readWriteContext(ReadWriteContext.READ)
4346
.build();
44-
ObjectSchema schema = (ObjectSchema) SchemaLoader.load(ResourceLoader.DEFAULT.readObj("read-write-context.json"));
4547
JSONObject input = new JSONObject("{\"writeOnlyProp\":3}");
46-
TestSupport.failureOf(schema)
48+
TestSupport.failureOf(RW_SCHEMA)
4749
.expectedPointer("#/writeOnlyProp")
4850
.expectedSchemaLocation("#/properties/writeOnlyProp")
4951
.expectedKeyword("writeOnly")
50-
.expectedViolatedSchema(schema.getPropertySchemas().get("writeOnlyProp"))
52+
.expectedViolatedSchema(RW_SCHEMA.getPropertySchemas().get("writeOnlyProp"))
5153
.input(input)
5254
.validator(subject)
5355
.expect();
@@ -58,13 +60,29 @@ public void writeOnlyContext() {
5860
Validator subject = Validator.builder()
5961
.readWriteContext(ReadWriteContext.WRITE)
6062
.build();
61-
ObjectSchema schema = (ObjectSchema) SchemaLoader.load(ResourceLoader.DEFAULT.readObj("read-write-context.json"));
6263
JSONObject input = new JSONObject("{\"readOnlyProp\":\"foo\"}");
63-
TestSupport.failureOf(schema)
64+
TestSupport.failureOf(RW_SCHEMA)
6465
.expectedPointer("#/readOnlyProp")
6566
.expectedSchemaLocation("#/properties/readOnlyProp")
6667
.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"))
6886
.input(input)
6987
.validator(subject)
7088
.expect();

0 commit comments

Comments
 (0)