Skip to content

Commit d6d0079

Browse files
committed
Add and update test cases
1 parent 7904a26 commit d6d0079

File tree

6 files changed

+44
-14
lines changed

6 files changed

+44
-14
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
import com.relogiclabs.json.schema.exception.JsonSchemaException;
77
import org.junit.jupiter.api.Test;
88

9-
import static com.relogiclabs.json.schema.message.ErrorCode.*;
9+
import static com.relogiclabs.json.schema.message.ErrorCode.DEFI03;
10+
import static com.relogiclabs.json.schema.message.ErrorCode.DEFI04;
11+
import static com.relogiclabs.json.schema.message.ErrorCode.DTYP03;
12+
import static com.relogiclabs.json.schema.message.ErrorCode.DTYP04;
13+
import static com.relogiclabs.json.schema.message.ErrorCode.DTYP06;
1014
import static org.junit.jupiter.api.Assertions.assertEquals;
1115
import static org.junit.jupiter.api.Assertions.assertThrows;
1216

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,19 @@ public class DateTimeTests {
4242
@Test
4343
public void When_JsonNotDate_ExceptionThrown() {
4444
var schema = "#date";
45-
var json = "\"This is not a valid date\"";
45+
var json = "\"This is not a date\"";
46+
47+
JsonSchema.isValid(schema, json);
48+
var exception = assertThrows(JsonSchemaException.class,
49+
() -> JsonAssert.isValid(schema, json));
50+
assertEquals(DTYP04, exception.getCode());
51+
exception.printStackTrace();
52+
}
53+
54+
@Test
55+
public void When_JsonNotValidDate_ExceptionThrown() {
56+
var schema = "#date";
57+
var json = "\"1939-02-29\"";
4658

4759
JsonSchema.isValid(schema, json);
4860
var exception = assertThrows(JsonSchemaException.class,
@@ -54,7 +66,19 @@ public void When_JsonNotDate_ExceptionThrown() {
5466
@Test
5567
public void When_JsonNotTime_ExceptionThrown() {
5668
var schema = "#time";
57-
var json = "\"This is not a valid time\"";
69+
var json = "\"This is not a time\"";
70+
71+
JsonSchema.isValid(schema, json);
72+
var exception = assertThrows(JsonSchemaException.class,
73+
() -> JsonAssert.isValid(schema, json));
74+
assertEquals(DTYP04, exception.getCode());
75+
exception.printStackTrace();
76+
}
77+
78+
@Test
79+
public void When_JsonNotValidTime_ExceptionThrown() {
80+
var schema = "#time";
81+
var json = "\"1939-09-02T2:12:12.000Z\"";
5882

5983
JsonSchema.isValid(schema, json);
6084
var exception = assertThrows(JsonSchemaException.class,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.relogiclabs.json.schema.negative;
22

33
import com.relogiclabs.json.schema.JsonAssert;
4+
import com.relogiclabs.json.schema.JsonSchema;
45
import com.relogiclabs.json.schema.exception.ClassInstantiationException;
56
import com.relogiclabs.json.schema.exception.DuplicateIncludeException;
6-
import com.relogiclabs.json.schema.exception.FunctionMismatchException;
77
import com.relogiclabs.json.schema.exception.FunctionNotFoundException;
88
import com.relogiclabs.json.schema.exception.InvalidFunctionException;
99
import com.relogiclabs.json.schema.exception.InvalidIncludeException;
10+
import com.relogiclabs.json.schema.exception.JsonSchemaException;
1011
import com.relogiclabs.json.schema.exception.NotFoundClassException;
1112
import org.junit.jupiter.api.Test;
1213

@@ -34,8 +35,8 @@ public void When_FunctionAppliedOnWrongType_ExceptionThrown() {
3435
"test"
3536
""";
3637

37-
//JsonSchema.IsValid(schema, json);
38-
var exception = assertThrows(FunctionMismatchException.class,
38+
JsonSchema.isValid(schema, json);
39+
var exception = assertThrows(JsonSchemaException.class,
3940
() -> JsonAssert.isValid(schema, json));
4041
assertEquals(FUNC03, exception.getCode());
4142
exception.printStackTrace();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import static com.relogiclabs.json.schema.message.ErrorCode.OLEN04;
1717
import static com.relogiclabs.json.schema.message.ErrorCode.OLEN05;
1818
import static com.relogiclabs.json.schema.message.ErrorCode.PROP03;
19+
import static com.relogiclabs.json.schema.message.ErrorCode.PROP04;
1920
import static com.relogiclabs.json.schema.message.ErrorCode.VALU01;
2021
import static org.junit.jupiter.api.Assertions.assertEquals;
2122
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -264,7 +265,7 @@ public void When_DuplicateSchemaPropertyInObject_ExceptionThrown() {
264265
//JsonSchema.IsValid(schema, json);
265266
var exception = assertThrows(DuplicatePropertyKeyException.class,
266267
() -> JsonAssert.isValid(schema, json));
267-
assertEquals(PROP03, exception.getCode());
268+
assertEquals(PROP04, exception.getCode());
268269
exception.printStackTrace();
269270
}
270271

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import static com.relogiclabs.json.schema.message.ErrorCode.PRAG01;
1414
import static com.relogiclabs.json.schema.message.ErrorCode.PRAG02;
1515
import static com.relogiclabs.json.schema.message.ErrorCode.PRAG03;
16-
import static com.relogiclabs.json.schema.message.ErrorCode.PROP05;
1716
import static com.relogiclabs.json.schema.message.ErrorCode.PROP06;
17+
import static com.relogiclabs.json.schema.message.ErrorCode.PROP07;
1818
import static com.relogiclabs.json.schema.message.ErrorCode.SPRS01;
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -40,7 +40,7 @@ public void When_UndefinedPropertyOfObject_ExceptionThrown() {
4040
JsonSchema.isValid(schema, json);
4141
var exception = assertThrows(JsonSchemaException.class,
4242
() -> JsonAssert.isValid(schema, json));
43-
assertEquals(PROP05, exception.getCode());
43+
assertEquals(PROP06, exception.getCode());
4444
exception.printStackTrace();
4545
}
4646

@@ -139,7 +139,7 @@ public void When_IgnorePropertyOrderOfObject_ExceptionThrown() {
139139
JsonSchema.isValid(schema, json);
140140
var exception = assertThrows(JsonSchemaException.class,
141141
() -> JsonAssert.isValid(schema, json));
142-
assertEquals(PROP06, exception.getCode());
142+
assertEquals(PROP07, exception.getCode());
143143
exception.printStackTrace();
144144
}
145145

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public void When_DataTypeTimeInObject_ValidTrue() {
5252
var json =
5353
"""
5454
{
55-
"key1": "1950-12-31T11:40:10.000+06:30",
56-
"key2": "0001-01-01T00:00:00.000+00:00",
57-
"key3": "1600-02-29T23:59:59.999Z"
55+
"key1": "1950-12-31T11:40:10.333+06:30",
56+
"key2": "0001-01-01T00:00:00.0+00:00",
57+
"key3": "1600-02-29T23:59:59.99999Z"
5858
}
5959
""";
6060
JsonAssert.isValid(schema, json);
@@ -81,7 +81,7 @@ public void When_DataTypeTimeInArray_ValidTrue() {
8181
""";
8282
var json =
8383
"""
84-
["0001-01-01T00:00:00.000Z", "9999-12-31T23:59:59.999+12:59"]
84+
["0001-01-01T00:00:00.0Z", "9999-12-31T23:59:59.999999+12:59"]
8585
""";
8686
JsonAssert.isValid(schema, json);
8787
}

0 commit comments

Comments
 (0)