Search in sources :

Example 11 with EventBus

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));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DataTableTypeDefinition(io.cucumber.core.backend.DataTableTypeDefinition) ParameterTypeDefinition(io.cucumber.core.backend.ParameterTypeDefinition) IsIterableContainingInOrder.contains(org.hamcrest.collection.IsIterableContainingInOrder.contains) SourceReference(io.cucumber.core.backend.SourceReference) Step(io.cucumber.core.gherkin.Step) DefaultDataTableCellTransformerDefinition(io.cucumber.core.backend.DefaultDataTableCellTransformerDefinition) DefaultDataTableEntryTransformerDefinition(io.cucumber.core.backend.DefaultDataTableEntryTransformerDefinition) DefaultParameterTransformerDefinition(io.cucumber.core.backend.DefaultParameterTransformerDefinition) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) DataTableType(io.cucumber.datatable.DataTableType) ScenarioScoped(io.cucumber.core.backend.ScenarioScoped) ArrayList(java.util.ArrayList) StepDefinition(io.cucumber.core.backend.StepDefinition) TestCaseState(io.cucumber.core.backend.TestCaseState) Is.is(org.hamcrest.core.Is.is) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ENGLISH(java.util.Locale.ENGLISH) DataTable(io.cucumber.datatable.DataTable) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) EventBus(io.cucumber.core.eventbus.EventBus) HookDefinition(io.cucumber.core.backend.HookDefinition) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StepTypeRegistry(io.cucumber.core.stepexpression.StepTypeRegistry) Envelope(io.cucumber.messages.types.Envelope) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) EventHandler(io.cucumber.plugin.event.EventHandler) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) Type(java.lang.reflect.Type) ParameterByTypeTransformer(io.cucumber.cucumberexpressions.ParameterByTypeTransformer) TableCellByTypeTransformer(io.cucumber.datatable.TableCellByTypeTransformer) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Feature(io.cucumber.core.gherkin.Feature) DocStringType(io.cucumber.docstring.DocStringType) Clock(java.time.Clock) Optional(java.util.Optional) TableEntryByTypeTransformer(io.cucumber.datatable.TableEntryByTypeTransformer) DocStringTypeDefinition(io.cucumber.core.backend.DocStringTypeDefinition) ParameterType(io.cucumber.cucumberexpressions.ParameterType) Mockito.mock(org.mockito.Mockito.mock) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ArrayList(java.util.ArrayList) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Envelope(io.cucumber.messages.types.Envelope) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 12 with EventBus

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"));
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TestRunStarted(io.cucumber.messages.types.TestRunStarted) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) Envelope(io.cucumber.messages.types.Envelope) TestRunFinished(io.cucumber.messages.types.TestRunFinished) Timestamp(io.cucumber.messages.types.Timestamp) Test(org.junit.jupiter.api.Test)

Example 13 with EventBus

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"));
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TestRunStarted(io.cucumber.messages.types.TestRunStarted) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) Envelope(io.cucumber.messages.types.Envelope) TestRunFinished(io.cucumber.messages.types.TestRunFinished) Timestamp(io.cucumber.messages.types.Timestamp) Test(org.junit.jupiter.api.Test)

Aggregations

EventBus (io.cucumber.core.eventbus.EventBus)13 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)11 UUID (java.util.UUID)11 Test (org.junit.jupiter.api.Test)10 Envelope (io.cucumber.messages.types.Envelope)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 RuntimeOptions (io.cucumber.core.options.RuntimeOptions)3 CucumberExecutionContext (io.cucumber.core.runtime.CucumberExecutionContext)3 ExitStatus (io.cucumber.core.runtime.ExitStatus)3 ThreadLocalRunnerSupplier (io.cucumber.core.runtime.ThreadLocalRunnerSupplier)3 TestRunFinished (io.cucumber.messages.types.TestRunFinished)3 TestRunStarted (io.cucumber.messages.types.TestRunStarted)3 Timestamp (io.cucumber.messages.types.Timestamp)3 Result (io.cucumber.plugin.event.Result)3 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Filters (io.cucumber.core.filter.Filters)2 Feature (io.cucumber.core.gherkin.Feature)2 BackendSupplier (io.cucumber.core.runtime.BackendSupplier)2 ObjectFactoryServiceLoader (io.cucumber.core.runtime.ObjectFactoryServiceLoader)2