Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.5.9</version>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.cucumber.jsonformatter;

import com.networknt.schema.Error;
import com.networknt.schema.InputFormat;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.ValidationMessage;
import com.networknt.schema.Schema;
import com.networknt.schema.SchemaRegistry;
import com.networknt.schema.SpecificationVersion;
import io.cucumber.compatibilitykit.MessageOrderer;
import io.cucumber.messages.NdjsonToMessageIterable;
import io.cucumber.messages.types.Envelope;
Expand All @@ -24,12 +25,10 @@
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.networknt.schema.SpecVersion.VersionFlag.V202012;
import static io.cucumber.jsonformatter.Jackson.OBJECT_MAPPER;
import static io.cucumber.jsonformatter.Jackson.PRETTY_PRINTER;
import static java.nio.charset.StandardCharsets.UTF_8;
Expand All @@ -39,7 +38,7 @@
class MessagesToJsonWriterAcceptanceTest {
private static final NdjsonToMessageIterable.Deserializer deserializer = (json) -> OBJECT_MAPPER.readValue(json, Envelope.class);
private static final MessagesToJsonWriter.Serializer serializer = OBJECT_MAPPER.writer(PRETTY_PRINTER)::writeValue;
private static final JsonSchema jsonSchema = readJsonSchema();
private static final Schema jsonSchema = readJsonSchema();
private static final Random random = new Random(202509171757L);
private static final MessageOrderer messageOrderer = new MessageOrderer(random);

Expand Down Expand Up @@ -85,10 +84,11 @@ private static void assertJsonEquals(String expected, String actual) throws JSON
JSONAssert.assertEquals(expected, actual, true);
}

private static JsonSchema readJsonSchema() {
private static Schema readJsonSchema() {
Path path = Paths.get("../testdata/json-schema/src/cucumber-jvm.json");
try (InputStream resource = Files.newInputStream(path)) {
return JsonSchemaFactory.getInstance(V202012).getSchema(resource);
SchemaRegistry registry = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12);
return registry.getSchema(resource);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -117,11 +117,11 @@ void validateAgainstJsonSchema(TestCase testCase) throws IOException {
// So for schema validation there is no need to run the formatter
// Makes the test faster
byte[] expected = Files.readAllBytes(testCase.expected);
Set<ValidationMessage> assertions = jsonSchema.validate(
List<Error> assertions = jsonSchema.validate(
new String(expected, UTF_8),
InputFormat.JSON,
// By default, since Draft 2019-09 the format keyword only generates annotations and not assertions
executionContext -> executionContext.getExecutionConfig().setFormatAssertionsEnabled(true));
executionContext -> executionContext.executionConfig(config -> config.formatAssertionsEnabled(true)));
assertThat(assertions).isEmpty();
}

Expand Down