use of io.cucumber.core.plugin.JsonFormatter in project cucumber-jvm by cucumber.
the class CompatibilityTest method produces_expected_output_for.
@ParameterizedTest
@MethodSource("io.cucumber.compatibility.TestCase#testCases")
void produces_expected_output_for(TestCase testCase) throws IOException {
Path parentDir = Files.createDirectories(Paths.get("target", "messages", testCase.getId()));
Path outputNdjson = parentDir.resolve("out.ndjson");
Path outputHtml = parentDir.resolve("out.html");
Path outputJson = parentDir.resolve("out.json");
try {
Runtime.builder().withRuntimeOptions(new RuntimeOptionsBuilder().addGlue(testCase.getGlue()).addFeature(testCase.getFeature()).build()).withAdditionalPlugins(new MessageFormatter(newOutputStream(outputNdjson)), new HtmlFormatter(newOutputStream(outputHtml)), new JsonFormatter(newOutputStream(outputJson))).build().run();
} catch (Exception ignored) {
}
List<JsonNode> expected = readAllMessages(testCase.getExpectedFile());
List<JsonNode> actual = readAllMessages(outputNdjson);
Map<String, List<JsonNode>> expectedEnvelopes = openEnvelopes(expected);
Map<String, List<JsonNode>> actualEnvelopes = openEnvelopes(actual);
// exception: Java step definitions are not in a predictable order
// because Class#getMethods() does not return a predictable order.
sortStepDefinitions(expectedEnvelopes);
sortStepDefinitions(actualEnvelopes);
// unknown-parameter-types
if ("unknown-parameter-type".equals(testCase.getId())) {
expectedEnvelopes.remove("testCase");
expectedEnvelopes.remove("testCaseStarted");
expectedEnvelopes.remove("testStepStarted");
expectedEnvelopes.remove("testStepFinished");
expectedEnvelopes.remove("testCaseFinished");
}
expectedEnvelopes.forEach((messageType, expectedMessages) -> assertThat(actualEnvelopes, hasEntry(is(messageType), containsInRelativeOrder(aComparableMessage(expectedMessages)))));
}
Aggregations