diff --git a/pom.xml b/pom.xml index 129298fdd..f4aa923b0 100644 --- a/pom.xml +++ b/pom.xml @@ -160,6 +160,11 @@ 1.1.1 test + + com.jayway.jsonpath + json-path-assert + 2.8.0 + xmlunit xmlunit @@ -190,6 +195,11 @@ 2.1 test + + org.slf4j + slf4j-nop + 1.7.36 + diff --git a/src/test/java/org/w3c/epubcheck/test/JSONReportAssertionSteps.java b/src/test/java/org/w3c/epubcheck/test/JSONReportAssertionSteps.java new file mode 100644 index 000000000..6064d48ff --- /dev/null +++ b/src/test/java/org/w3c/epubcheck/test/JSONReportAssertionSteps.java @@ -0,0 +1,54 @@ +package org.w3c.epubcheck.test; + +import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath; +import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJson; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.everyItem; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; + +import io.cucumber.java.en.Then; + +public class JSONReportAssertionSteps +{ + + private TestReport report; + + public JSONReportAssertionSteps(TestConfiguration configuration) + { + this.report = configuration.getReport(); + } + + @Then("the JSON report is valid") + public void jsonIsValid() + { + assertThat(report.getOutput(), isJson()); + } + + @Then("JSON at {string} contains {int} items") + public void jsonArrayHasSize(String path, int size) + { + assertThat(report.getOutput(), hasJsonPath(path, hasSize(size))); + } + + @Then("JSON at {string} is {string}") + public void jsonValueIs(String path, String value) + { + assertThat(report.getOutput(), hasJsonPath(path, equalTo(value))); + } + + @Then("JSON at {string} is not null") + public void jsonValueIsNotNull(String path) + { + assertThat(report.getOutput(), hasJsonPath(path, not(nullValue()))); + } + + @Then("JSON at {string} has no null values") + public void jsonValuesAreNotNull(String path) + { + assertThat(report.getOutput(), hasJsonPath(path, everyItem(notNullValue()))); + } +}