Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/dev harrel bump #82

Merged
merged 4 commits into from
Nov 19, 2023
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 build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dependencies {

implementation("org.leadpony.justify:justify:3.1.0")

implementation("dev.harrel:json-schema:1.4.1")
implementation("dev.harrel:json-schema:1.4.3")

implementation("org.apache.logging.log4j:log4j-core:$log4jVersion")
runtimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl:$log4jVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.awt.Color;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -89,12 +88,14 @@ public void validate(final String json) {
@Override
public byte[] serialize(final TestModel model, final boolean validate) {
try {
final String asString = mapper.writeValueAsString(model);
final Validator.Result result = validator.validate(schemaUri, asString);
final com.fasterxml.jackson.databind.JsonNode node =
mapper.convertValue(
model, com.fasterxml.jackson.databind.JsonNode.class);
final Validator.Result result = validator.validate(schemaUri, node);
if (validate && !result.isValid()) {
throw new RuntimeException(result.getErrors().get(0).getError());
}
return asString.getBytes(StandardCharsets.UTF_8);
return mapper.writeValueAsBytes(node);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
Expand All @@ -103,12 +104,12 @@ public byte[] serialize(final TestModel model, final boolean validate) {
@Override
public TestModel deserialize(final byte[] data) {
try {
final String json = new String(data, StandardCharsets.UTF_8);
final Validator.Result result = validator.validate(schemaUri, json);
final com.fasterxml.jackson.databind.JsonNode node = mapper.readTree(data);
final Validator.Result result = validator.validate(schemaUri, node);
if (!result.isValid()) {
throw new RuntimeException(result.getErrors().get(0).getError());
}
return mapper.readValue(data, TestModel.class);
return mapper.convertValue(node, TestModel.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -136,6 +137,7 @@ private Validator validator(final SchemaSpec spec, final AdditionalSchemas addit
case DRAFT_2020_12:
final Validator validator2020 =
new dev.harrel.jsonschema.ValidatorFactory()
.withDisabledSchemaValidation(true)
.withDialect(new Dialects.Draft2020Dialect())
.withJsonNodeFactory(nodeFactory)
.withSchemaResolver(resolver)
Expand All @@ -146,6 +148,7 @@ private Validator validator(final SchemaSpec spec, final AdditionalSchemas addit
case DRAFT_2019_09:
final Validator validator2019 =
new dev.harrel.jsonschema.ValidatorFactory()
.withDisabledSchemaValidation(true)
.withDialect(new Dialects.Draft2019Dialect())
.withJsonNodeFactory(nodeFactory)
.withSchemaResolver(resolver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
class JsonToMarkdownConvertorTest {

private static final String EXPECTED_HEADINGS =
"| Benchmark | Mode | Score | Score Error (99.9%) | Unit |\n"
+ "|-----------|------|-------|---------------------|------|\n";
"| Benchmark | Mode | Score | Score Error (99.9%) | Unit |"
+ System.lineSeparator()
+ "|-----------|------|-------|---------------------|------|"
+ System.lineSeparator();
big-andy-coates marked this conversation as resolved.
Show resolved Hide resolved

private static final Path SOME_PATH = Paths.get("some/path");

Expand Down Expand Up @@ -89,13 +91,16 @@ void shouldConvertJsonToMarkdown() {
"JsonValidateBenchmark",
EXPECTED_HEADINGS
+ "| measureDraft_4_Medeia | avgt | 0.34276 | 0.0038394 |"
+ " ms/op |\n"
+ " ms/op |"
+ System.lineSeparator()
+ "| measureDraft_7_Medeia | avgt | 0.89360 | 0.0035984 |"
+ " ms/op |\n",
+ " ms/op |"
+ System.lineSeparator(),
"JsonSerdeBenchmark",
EXPECTED_HEADINGS
+ "| measureEveritRoundTrip | diff | 2135454 | 0.0035367 |"
+ " us/op |\n")));
+ " us/op |"
+ System.lineSeparator())));
}

@Test
Expand All @@ -121,6 +126,7 @@ void shouldHandleNaN() {
"JsonValidateBenchmark",
EXPECTED_HEADINGS
+ "| measureDraft_7_Medeia | avgt | 0.89360 | | ms/op"
+ " |\n")));
+ " |"
+ System.lineSeparator())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ void shouldThrowIfBenchmarkMethodDoesNotMatchPattern() {
is(
"The JSON benchmark results contain a benchmark method with a name that"
+ " does not match the expected pattern. Expected pattern:"
+ " measure(?<draft>Draft[_0-9]+)_(?<impl>[A-Za-z0-9]+)\n"
+ " measure(?<draft>Draft[_0-9]+)_(?<impl>[A-Za-z0-9]+)"
+ System.lineSeparator()
+ "Method name: JsonTestBenchmark.invalidPattern"));
}

Expand All @@ -82,10 +83,13 @@ void shouldThrowOnUnknownDraftVersion() {
e.getMessage(),
is(
"The JSON benchmark results contain a benchmark method with a name that"
+ " does not contain a valid schema specification draft.\n"
+ " does not contain a valid schema specification draft."
+ System.lineSeparator()
+ "Available versions: [Draft_03, Draft_04, Draft_06, Draft_07,"
+ " Draft_2019_09, Draft_2020_12]\n"
+ "Detected version: Draft_11\n"
+ " Draft_2019_09, Draft_2020_12]"
+ System.lineSeparator()
+ "Detected version: Draft_11"
+ System.lineSeparator()
+ "Method name: JsonTestBenchmark.measureDraft_11_Snow"));
}

Expand All @@ -103,8 +107,10 @@ void shouldThrowOnUnknownImplementation() {
e.getMessage(),
is(
"The JSON benchmark results contain a benchmark method with a name that not"
+ " end with a known implementation's short name.\n"
+ "Detected short name: InvalidImpl\n"
+ " end with a known implementation's short name."
+ System.lineSeparator()
+ "Detected short name: InvalidImpl"
+ System.lineSeparator()
+ "Method name: JsonTestBenchmark.measureDraft_07_InvalidImpl"));
}

Expand Down