-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add cucumber steps for checking JSON reports
Add the following Cucumber steps: - `Then the JSON report is valid` - `Then JSON at {string} contains {int} items` - `Then JSON at {string} has no null values` - `Then JSON at {string} is not null` - `Then JSON at {string} is {string}` JSON values or arrays are inspected using expressions based on a JSON path DSL, and asserted with the [json-path-assert](https://github.com/json-path/JsonPath) library.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/java/org/w3c/epubcheck/test/JSONReportAssertionSteps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()))); | ||
} | ||
} |