Search in sources :

Example 16 with Envelope

use of io.cucumber.messages.types.Envelope in project cucumber-jvm by cucumber.

the class TestCase method emitTestCaseFinished.

private void emitTestCaseFinished(EventBus bus, UUID executionId, Instant stop, Duration duration, Status status, Result result) {
    bus.send(new TestCaseFinished(stop, this, result));
    TestStepResult testStepResult = new TestStepResult();
    testStepResult.setStatus(from(status));
    testStepResult.setDuration(javaDurationToDuration(duration));
    if (result.getError() != null) {
        testStepResult.setMessage(toString(result.getError()));
    }
    Envelope envelope = new Envelope();
    envelope.setTestCaseFinished(new io.cucumber.messages.types.TestCaseFinished(executionId.toString(), javaInstantToTimestamp(stop), false));
    bus.send(envelope);
}
Also used : TestStepResult(io.cucumber.messages.types.TestStepResult) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) Envelope(io.cucumber.messages.types.Envelope)

Example 17 with Envelope

use of io.cucumber.messages.types.Envelope in project cucumber-jvm by cucumber.

the class CucumberExecutionContext method emitTestRunStarted.

private void emitTestRunStarted() {
    log.debug(() -> "Sending run test started event");
    start = bus.getInstant();
    bus.send(new TestRunStarted(start));
    Envelope envelope = new Envelope();
    envelope.setTestRunStarted(new io.cucumber.messages.types.TestRunStarted(javaInstantToTimestamp(start)));
    bus.send(envelope);
}
Also used : TestRunStarted(io.cucumber.plugin.event.TestRunStarted) Envelope(io.cucumber.messages.types.Envelope)

Example 18 with Envelope

use of io.cucumber.messages.types.Envelope in project cucumber-jvm by cucumber.

the class CachingGlue method emitHook.

private void emitHook(CoreHookDefinition coreHook) {
    Hook messagesHook = new Hook();
    messagesHook.setId(coreHook.getId().toString());
    messagesHook.setTagExpression(coreHook.getTagExpression());
    coreHook.getDefinitionLocation().ifPresent(reference -> messagesHook.setSourceReference(createSourceReference(reference)));
    Envelope envelope = new Envelope();
    envelope.setHook(messagesHook);
    bus.send(envelope);
}
Also used : Hook(io.cucumber.messages.types.Hook) Envelope(io.cucumber.messages.types.Envelope)

Example 19 with Envelope

use of io.cucumber.messages.types.Envelope 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 20 with Envelope

use of io.cucumber.messages.types.Envelope 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)

Aggregations

Envelope (io.cucumber.messages.types.Envelope)22 UUID (java.util.UUID)8 Test (org.junit.jupiter.api.Test)8 EventBus (io.cucumber.core.eventbus.EventBus)5 Feature (io.cucumber.core.gherkin.Feature)5 ArrayList (java.util.ArrayList)5 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)4 StepDefinition (io.cucumber.core.backend.StepDefinition)3 TestRunFinished (io.cucumber.messages.types.TestRunFinished)3 TestRunStarted (io.cucumber.messages.types.TestRunStarted)3 Timestamp (io.cucumber.messages.types.Timestamp)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 URI (java.net.URI)3 List (java.util.List)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 HookDefinition (io.cucumber.core.backend.HookDefinition)2 ScenarioScoped (io.cucumber.core.backend.ScenarioScoped)2 TestCaseState (io.cucumber.core.backend.TestCaseState)2 TestFeatureParser (io.cucumber.core.feature.TestFeatureParser)2 EmbedEvent (io.cucumber.plugin.event.EmbedEvent)2