use of io.cucumber.core.eventbus.EventBus in project cucumber-jvm by cucumber.
the class CachingGlueTest method emits_hook_messages_to_bus.
@Test
public void emits_hook_messages_to_bus() {
List<Envelope> events = new ArrayList<>();
EventHandler<Envelope> messageEventHandler = e -> events.add(e);
EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
bus.registerHandlerFor(Envelope.class, messageEventHandler);
CachingGlue glue = new CachingGlue(bus);
glue.addBeforeHook(new MockedScenarioScopedHookDefinition());
glue.addAfterHook(new MockedScenarioScopedHookDefinition());
glue.addBeforeStepHook(new MockedScenarioScopedHookDefinition());
glue.addAfterStepHook(new MockedScenarioScopedHookDefinition());
glue.prepareGlue(stepTypeRegistry);
assertThat(events.size(), is(4));
}
use of io.cucumber.core.eventbus.EventBus in project cucumber-jvm by cucumber.
the class HtmlFormatterTest method writes_index_html.
@Test
void writes_index_html() throws Throwable {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
HtmlFormatter formatter = new HtmlFormatter(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 html = new String(bytes.toByteArray(), UTF_8);
assertThat(html, containsString("" + "window.CUCUMBER_MESSAGES = [" + "{\"testRunStarted\":{\"timestamp\":{\"seconds\":10,\"nanos\":0}}}," + "{\"testRunFinished\":{\"timestamp\":{\"seconds\":15,\"nanos\":0}}}" + "];\n"));
}
use of io.cucumber.core.eventbus.EventBus 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"));
}
Aggregations