|
| 1 | +package com.networknt.schema; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 5 | + |
| 6 | +import java.io.IOException; |
| 7 | + |
| 8 | +import org.junit.jupiter.api.BeforeAll; |
| 9 | +import org.junit.jupiter.params.ParameterizedTest; |
| 10 | +import org.junit.jupiter.params.provider.ValueSource; |
| 11 | + |
| 12 | +class Issue1260Test extends BaseJsonSchemaValidatorTest { |
| 13 | + |
| 14 | + private static final String RESOURCE_PREFIX = "issues/1260/"; |
| 15 | + private static Schema schema; |
| 16 | + |
| 17 | + @BeforeAll |
| 18 | + static void setup() { |
| 19 | + schema = getJsonSchemaFromClasspath(resource("schema.json"), SpecificationVersion.DRAFT_2020_12); |
| 20 | + } |
| 21 | + |
| 22 | + @ParameterizedTest |
| 23 | + @ValueSource(strings = {"valid1.json", "valid2.json", "valid3.json"}) |
| 24 | + void testNoErrorsForValidInput(String validJson) throws IOException { |
| 25 | + final var node = getJsonNodeFromClasspath(resource(validJson)); |
| 26 | + final var errors = schema.validate(node); |
| 27 | + assertTrue(errors.isEmpty(), "No validation errors for valid input"); |
| 28 | + } |
| 29 | + |
| 30 | + @ParameterizedTest |
| 31 | + @ValueSource(strings = {"invalid1.json", "invalid2.json", "invalid3.json"}) |
| 32 | + void testErrorsForInvalidInput(String invalidJson) throws IOException { |
| 33 | + final var node = getJsonNodeFromClasspath(resource(invalidJson)); |
| 34 | + final var errors = schema.validate(node); |
| 35 | + assertFalse(errors.isEmpty(), "Validation errors for invalid input"); |
| 36 | + } |
| 37 | + |
| 38 | + private static String resource(String name) { |
| 39 | + return RESOURCE_PREFIX + name; |
| 40 | + } |
| 41 | +} |
0 commit comments