use of io.cucumber.messages.internal.com.fasterxml.jackson.databind.JsonNode in project cucumber-jvm by cucumber.
the class AComparableMessage method aComparableValue.
@SuppressWarnings("unchecked")
private static Matcher<?> aComparableValue(Object value, int depth) {
if (value instanceof ObjectNode) {
JsonNode message = (JsonNode) value;
return new AComparableMessage(message, depth);
}
if (value instanceof ArrayNode) {
ArrayNode values = (ArrayNode) value;
Spliterator<JsonNode> spliterator = spliteratorUnknownSize(values.iterator(), 0);
List<Matcher<? super Object>> allComparableValues = stream(spliterator, false).map(o -> aComparableValue(o, depth)).map(o -> (Matcher<? super Object>) o).collect(Collectors.toList());
return contains(allComparableValues);
}
if (value instanceof TextNode || value instanceof NumericNode || value instanceof BooleanNode) {
return CoreMatchers.is(value);
}
throw new IllegalArgumentException("Unsupported type " + value.getClass() + ": " + value);
}
use of io.cucumber.messages.internal.com.fasterxml.jackson.databind.JsonNode in project cucumber-jvm by cucumber.
the class CompatibilityTest method readAllMessages.
private static List<JsonNode> readAllMessages(Path output) throws IOException {
List<JsonNode> expectedEnvelopes = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper().enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Files.readAllLines(output).forEach(s -> {
try {
expectedEnvelopes.add(mapper.readTree(s));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
});
return expectedEnvelopes;
}
use of io.cucumber.messages.internal.com.fasterxml.jackson.databind.JsonNode in project cucumber-jvm by cucumber.
the class AComparableMessage method asMapOfJsonNameToField.
private static Map<String, Object> asMapOfJsonNameToField(JsonNode envelope) {
Map<String, Object> map = new LinkedHashMap<>();
envelope.fieldNames().forEachRemaining(jsonField -> {
JsonNode value = envelope.get(jsonField);
map.put(jsonField, value);
});
return map;
}
use of io.cucumber.messages.internal.com.fasterxml.jackson.databind.JsonNode 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