Skip to content

Commit 6b98cd4

Browse files
committed
Update test cases for changes
1 parent 0553bb1 commit 6b98cd4

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/test/java/com/relogiclabs/json/schema/negative/DataTypeTests.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void When_MultipleNestedDataTypeWithWrongValueInObject_ExceptionThrown()
153153
{
154154
"key1": ["2021-08-01", "2021-08-01T15:50:30.300Z", "test"],
155155
"key2": ["test", null, "text", 10],
156-
"key3": [10, 100, 200.5, "text"]
156+
"key3": [false, true, null, "text"]
157157
}
158158
""";
159159
JsonSchema.isValid(schema, json);
@@ -163,6 +163,33 @@ public void When_MultipleNestedDataTypeWithWrongValueInObject_ExceptionThrown()
163163
exception.printStackTrace();
164164
}
165165

166+
@Test
167+
public void When_DataTypeExceptionCountInObject_ExceptionThrown() {
168+
var schema =
169+
"""
170+
{
171+
"key1": #boolean* #integer #string #array,
172+
"key2": #boolean* #integer #string,
173+
"key3": #boolean* #integer #string #array
174+
}
175+
""";
176+
var json =
177+
"""
178+
{
179+
"key1": [10, "test", "2021-08-01"],
180+
"key2": [10, "test", "2021-08-01"],
181+
"key3": []
182+
}
183+
""";
184+
var jsonSchema = new JsonSchema(schema);
185+
if(!jsonSchema.isValid(json)) jsonSchema.writeError();
186+
assertEquals(8, jsonSchema.getExceptions().getCount());
187+
var exception = assertThrows(JsonSchemaException.class,
188+
() -> JsonAssert.isValid(schema, json));
189+
assertEquals(DTYP06, exception.getCode());
190+
exception.printStackTrace();
191+
}
192+
166193
@Test
167194
public void When_MultipleDataTypeWithWrongValueInObject_ExceptionThrown() {
168195
var schema =

src/test/java/com/relogiclabs/json/schema/negative/OtherTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void When_MandatoryValueMissingInArray_ExceptionThrown() {
133133
}
134134

135135
@Test
136-
public void When_OptionalValueMisplacedInArray_ExceptionThrown() {
136+
public void When_OptionalValidatorMisplacedInArray_ExceptionThrown() {
137137
var schema = "[#number, #number?, #number]";
138138
var json = "[10, 20]";
139139
JsonSchema.isValid(schema, json);

src/test/java/com/relogiclabs/json/schema/positive/AggregatedTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,14 @@ public void When_JsonAggregatedFormatTest_ValidTrue() {
111111
"key13" : [ "Microsoft", "https://www.microsoft.com/en-us/" ],
112112
"key14" : [ 10, 20, 30, 40 ]
113113
},
114-
"key8" : [ "ABC", "EFG", "XYZ" ],
115114
"key7" : true,
115+
"key8" : [ "ABC", "EFG", "XYZ" ],
116116
"key9" : null
117117
}
118118
""";
119119
var actual = """
120120
{
121+
"key7": true,
121122
"key3": [5, 10, 15, 20],
122123
"key1": 10, "key2": "val2",
123124
"key4": 0.5, "key5": 10E-10,
@@ -126,7 +127,7 @@ public void When_JsonAggregatedFormatTest_ValidTrue() {
126127
"key13": ["Microsoft", "https://www.microsoft.com/en-us/"],
127128
"key11": "test", "key14": [10, 20, 30, 40]
128129
},
129-
"key8": ["ABC", "EFG", "XYZ"], "key7": true, "key9": null
130+
"key8": ["ABC", "EFG", "XYZ"], "key9": null
130131
}
131132
""";
132133
JsonAssert.areEqual(expected, actual);

0 commit comments

Comments
 (0)