use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.
the class JsonFormatterTest method should_format_scenario_with_an_undefined_step.
@Test
void should_format_scenario_with_an_undefined_step() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + " Scenario: Monkey eats bananas\n" + " Given there are bananas\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier()).build().run();
String expected = "" + "[\n" + " {\n" + " \"id\": \"banana-party\",\n" + " \"uri\": \"file:path/test.feature\",\n" + " \"keyword\": \"Feature\",\n" + " \"name\": \"Banana party\",\n" + " \"line\": 1,\n" + " \"description\": \"\",\n" + " \"elements\": [\n" + " {\n" + " \"id\": \"banana-party;monkey-eats-bananas\",\n" + " \"keyword\": \"Scenario\",\n" + " \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + " \"name\": \"Monkey eats bananas\",\n" + " \"line\": 3,\n" + " \"description\": \"\",\n" + " \"type\": \"scenario\",\n" + " \"steps\": [\n" + " {\n" + " \"keyword\": \"Given \",\n" + " \"name\": \"there are bananas\",\n" + " \"line\": 4,\n" + " \"match\": {},\n" + " \"result\": {\n" + " \"status\": \"undefined\"\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + " \"tags\": []\n" + " }\n" + "]";
assertJsonEquals(expected, out);
}
use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.
the class JsonFormatterTest method should_format_scenario_with_a_passed_step.
@Test
void should_format_scenario_with_a_passed_step() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + " Scenario: Monkey eats bananas\n" + " Given there are bananas\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()"))).build().run();
String expected = "" + "[\n" + " {\n" + " \"id\": \"banana-party\",\n" + " \"uri\": \"file:path/test.feature\",\n" + " \"keyword\": \"Feature\",\n" + " \"name\": \"Banana party\",\n" + " \"line\": 1,\n" + " \"description\": \"\",\n" + " \"elements\": [\n" + " {\n" + " \"id\": \"banana-party;monkey-eats-bananas\",\n" + " \"keyword\": \"Scenario\",\n" + " \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + " \"name\": \"Monkey eats bananas\",\n" + " \"line\": 3,\n" + " \"description\": \"\",\n" + " \"type\": \"scenario\",\n" + " \"steps\": [\n" + " {\n" + " \"keyword\": \"Given \",\n" + " \"name\": \"there are bananas\",\n" + " \"line\": 4,\n" + " \"match\": {\n" + " \"location\": \"StepDefs.there_are_bananas()\"\n" + " },\n" + " \"result\": {\n" + " \"status\": \"passed\",\n" + " \"duration\": 1000000\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + " \"tags\": []\n" + " }\n" + "]";
assertJsonEquals(expected, out);
}
use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.
the class JsonFormatterTest method should_format_scenario_with_hooks.
@Test
void should_format_scenario_with_hooks() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + " Scenario: Monkey eats bananas\n" + " Given there are bananas\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition("Hooks.before_hook_1()")), singletonList(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()")), singletonList(new StubHookDefinition("Hooks.after_hook_1()")))).build().run();
String expected = "" + "[\n" + " {\n" + " \"id\": \"banana-party\",\n" + " \"uri\": \"file:path/test.feature\",\n" + " \"keyword\": \"Feature\",\n" + " \"name\": \"Banana party\",\n" + " \"line\": 1,\n" + " \"description\": \"\",\n" + " \"elements\": [\n" + " {\n" + " \"id\": \"banana-party;monkey-eats-bananas\",\n" + " \"keyword\": \"Scenario\",\n" + " \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + " \"name\": \"Monkey eats bananas\",\n" + " \"line\": 3,\n" + " \"description\": \"\",\n" + " \"type\": \"scenario\",\n" + " \"before\": [\n" + " {\n" + " \"match\": {\n" + " \"location\": \"Hooks.before_hook_1()\"\n" + " },\n" + " \"result\": {\n" + " \"status\": \"passed\",\n" + " \"duration\": 1000000\n" + " }\n" + " }\n" + " ],\n" + " \"steps\": [\n" + " {\n" + " \"keyword\": \"Given \",\n" + " \"name\": \"there are bananas\",\n" + " \"line\": 4,\n" + " \"match\": {\n" + " \"location\": \"StepDefs.there_are_bananas()\"\n" + " },\n" + " \"result\": {\n" + " \"status\": \"passed\",\n" + " \"duration\": 1000000\n" + " }\n" + " }\n" + " ],\n" + " \"after\": [\n" + " {\n" + " \"match\": {\n" + " \"location\": \"Hooks.after_hook_1()\"\n" + " },\n" + " \"result\": {\n" + " \"status\": \"passed\",\n" + " \"duration\": 1000000\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + " \"tags\": []\n" + " }\n" + "]";
assertJsonEquals(expected, out);
}
use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.
the class MessageFormatterTest method test.
@Test
void test() {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
MessageFormatter formatter = new MessageFormatter(bytes);
EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
formatter.setEventPublisher(bus);
TestRunStarted testRunStarted = new TestRunStarted();
testRunStarted.setTimestamp(new Timestamp(10L, 0L));
Envelope testRunStartedEnvelope = new Envelope();
testRunStartedEnvelope.setTestRunStarted(testRunStarted);
bus.send(testRunStartedEnvelope);
TestRunFinished testRunFinished = new TestRunFinished();
testRunFinished.setTimestamp(new Timestamp(15L, 0L));
Envelope testRunFinishedEnvelope = new Envelope();
testRunFinishedEnvelope.setTestRunFinished(testRunFinished);
bus.send(testRunFinishedEnvelope);
String ndjson = new String(bytes.toByteArray(), UTF_8);
assertThat(ndjson, containsString("" + "{\"testRunStarted\":{\"timestamp\":{\"seconds\":10,\"nanos\":0}}}\n" + "{\"testRunFinished\":{\"timestamp\":{\"seconds\":15,\"nanos\":0}}}\n"));
}
use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.
the class CucumberOptionsAnnotationParserTest method inherit_plugin_from_baseclass.
@Test
void inherit_plugin_from_baseclass() {
RuntimeOptions runtimeOptions = parser().parse(SubClassWithFormatter.class).build();
Plugins plugins = new Plugins(new PluginFactory(), runtimeOptions);
plugins.setEventBusOnEventListenerPlugins(new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID));
List<Plugin> pluginList = plugins.getPlugins();
assertAll(() -> assertPluginExists(pluginList, HtmlFormatter.class.getName()), () -> assertPluginExists(pluginList, PrettyFormatter.class.getName()));
}
Aggregations