|
1 | 1 | package io.cucumber.jsonformatter; |
2 | 2 |
|
| 3 | +import com.networknt.schema.Error; |
3 | 4 | import com.networknt.schema.InputFormat; |
4 | | -import com.networknt.schema.JsonSchema; |
5 | | -import com.networknt.schema.JsonSchemaFactory; |
6 | | -import com.networknt.schema.ValidationMessage; |
| 5 | +import com.networknt.schema.Schema; |
| 6 | +import com.networknt.schema.SchemaRegistry; |
| 7 | +import com.networknt.schema.SpecificationVersion; |
7 | 8 | import io.cucumber.compatibilitykit.MessageOrderer; |
8 | 9 | import io.cucumber.messages.NdjsonToMessageIterable; |
9 | 10 | import io.cucumber.messages.types.Envelope; |
|
24 | 25 | import java.util.Comparator; |
25 | 26 | import java.util.List; |
26 | 27 | import java.util.Random; |
27 | | -import java.util.Set; |
28 | 28 | import java.util.function.Consumer; |
29 | 29 | import java.util.stream.Collectors; |
30 | 30 | import java.util.stream.Stream; |
31 | 31 |
|
32 | | -import static com.networknt.schema.SpecVersion.VersionFlag.V202012; |
33 | 32 | import static io.cucumber.jsonformatter.Jackson.OBJECT_MAPPER; |
34 | 33 | import static io.cucumber.jsonformatter.Jackson.PRETTY_PRINTER; |
35 | 34 | import static java.nio.charset.StandardCharsets.UTF_8; |
|
39 | 38 | class MessagesToJsonWriterAcceptanceTest { |
40 | 39 | private static final NdjsonToMessageIterable.Deserializer deserializer = (json) -> OBJECT_MAPPER.readValue(json, Envelope.class); |
41 | 40 | private static final MessagesToJsonWriter.Serializer serializer = OBJECT_MAPPER.writer(PRETTY_PRINTER)::writeValue; |
42 | | - private static final JsonSchema jsonSchema = readJsonSchema(); |
| 41 | + private static final Schema jsonSchema = readJsonSchema(); |
43 | 42 | private static final Random random = new Random(202509171757L); |
44 | 43 | private static final MessageOrderer messageOrderer = new MessageOrderer(random); |
45 | 44 |
|
@@ -85,10 +84,11 @@ private static void assertJsonEquals(String expected, String actual) throws JSON |
85 | 84 | JSONAssert.assertEquals(expected, actual, true); |
86 | 85 | } |
87 | 86 |
|
88 | | - private static JsonSchema readJsonSchema() { |
| 87 | + private static Schema readJsonSchema() { |
89 | 88 | Path path = Paths.get("../testdata/json-schema/src/cucumber-jvm.json"); |
90 | 89 | try (InputStream resource = Files.newInputStream(path)) { |
91 | | - return JsonSchemaFactory.getInstance(V202012).getSchema(resource); |
| 90 | + SchemaRegistry registry = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12); |
| 91 | + return registry.getSchema(resource); |
92 | 92 | } catch (IOException e) { |
93 | 93 | throw new RuntimeException(e); |
94 | 94 | } |
@@ -117,11 +117,11 @@ void validateAgainstJsonSchema(TestCase testCase) throws IOException { |
117 | 117 | // So for schema validation there is no need to run the formatter |
118 | 118 | // Makes the test faster |
119 | 119 | byte[] expected = Files.readAllBytes(testCase.expected); |
120 | | - Set<ValidationMessage> assertions = jsonSchema.validate( |
| 120 | + List<Error> assertions = jsonSchema.validate( |
121 | 121 | new String(expected, UTF_8), |
122 | 122 | InputFormat.JSON, |
123 | 123 | // By default, since Draft 2019-09 the format keyword only generates annotations and not assertions |
124 | | - executionContext -> executionContext.getExecutionConfig().setFormatAssertionsEnabled(true)); |
| 124 | + executionContext -> executionContext.executionConfig(config -> config.formatAssertionsEnabled(true))); |
125 | 125 | assertThat(assertions).isEmpty(); |
126 | 126 | } |
127 | 127 |
|
|
0 commit comments