Search in sources :

Example 11 with Envelope

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

the class CucumberExecutionContext method emitMeta.

private void emitMeta() {
    Envelope envelope = new Envelope();
    envelope.setMeta(createMeta());
    bus.send(envelope);
}
Also used : Envelope(io.cucumber.messages.types.Envelope)

Example 12 with Envelope

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

the class CucumberExecutionContext method emitTestRunFinished.

private void emitTestRunFinished(Throwable exception) {
    Instant instant = bus.getInstant();
    Result result = new Result(exception != null ? Status.FAILED : exitStatus.getStatus(), Duration.between(start, instant), exception);
    bus.send(new TestRunFinished(instant, result));
    io.cucumber.messages.types.TestRunFinished testRunFinished = new io.cucumber.messages.types.TestRunFinished(exception != null ? printStackTrace(exception) : null, exception == null && exitStatus.isSuccess(), javaInstantToTimestamp(instant));
    Envelope envelope = new Envelope();
    envelope.setTestRunFinished(testRunFinished);
    bus.send(envelope);
}
Also used : Instant(java.time.Instant) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) Envelope(io.cucumber.messages.types.Envelope) Result(io.cucumber.plugin.event.Result)

Example 13 with Envelope

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

the class RuntimeTest method emits_a_meta_message.

@Test
void emits_a_meta_message() {
    List<Envelope> messages = new ArrayList<>();
    EventListener listener = publisher -> publisher.registerHandlerFor(Envelope.class, messages::add);
    Runtime.builder().withAdditionalPlugins(listener).build().run();
    Meta meta = messages.get(0).getMeta();
    assertThat(meta.getProtocolVersion(), matchesPattern("\\d+\\.\\d+\\.\\d+(-RC\\d+)?(-SNAPSHOT)?"));
    assertThat(meta.getImplementation().getName(), is("cucumber-jvm"));
    assertThat(meta.getImplementation().getVersion(), matchesPattern("\\d+\\.\\d+\\.\\d+(-RC\\d+)?(-SNAPSHOT)?"));
    assertThat(meta.getOs().getName(), matchesPattern(".+"));
    assertThat(meta.getCpu().getName(), matchesPattern(".+"));
}
Also used : ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) Meta(io.cucumber.messages.types.Meta) Status(io.cucumber.plugin.event.Status) ScenarioScoped(io.cucumber.core.backend.ScenarioScoped) Collections.singletonList(java.util.Collections.singletonList) StepDefinedEvent(io.cucumber.plugin.event.StepDefinedEvent) Arrays.asList(java.util.Arrays.asList) CompositeCucumberException(io.cucumber.core.exception.CompositeCucumberException) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) TestBackendSupplier(io.cucumber.core.runner.TestBackendSupplier) HookDefinition(io.cucumber.core.backend.HookDefinition) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Envelope(io.cucumber.messages.types.Envelope) Result(io.cucumber.plugin.event.Result) Collections.emptyList(java.util.Collections.emptyList) Glue(io.cucumber.core.backend.Glue) UUID(java.util.UUID) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Matchers.matchesPattern(org.hamcrest.Matchers.matchesPattern) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) ZERO(java.time.Duration.ZERO) Mockito.mock(org.mockito.Mockito.mock) Plugin(io.cucumber.plugin.Plugin) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) StepDefinition(io.cucumber.plugin.event.StepDefinition) ZoneId.of(java.time.ZoneId.of) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) EventListener(io.cucumber.plugin.EventListener) ArrayList(java.util.ArrayList) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) ArgumentCaptor(org.mockito.ArgumentCaptor) ParameterInfo(io.cucumber.core.backend.ParameterInfo) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestCaseState(io.cucumber.core.backend.TestCaseState) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) EventPublisher(io.cucumber.plugin.event.EventPublisher) EventBus(io.cucumber.core.eventbus.EventBus) Clock.fixed(java.time.Clock.fixed) TestRunStarted(io.cucumber.plugin.event.TestRunStarted) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) Clock(java.time.Clock) HOURS(java.util.concurrent.TimeUnit.HOURS) EPOCH(java.time.Instant.EPOCH) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Meta(io.cucumber.messages.types.Meta) ArrayList(java.util.ArrayList) ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) EventListener(io.cucumber.plugin.EventListener) Envelope(io.cucumber.messages.types.Envelope) Test(org.junit.jupiter.api.Test)

Example 14 with Envelope

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

the class TestCaseStateTest method attach_string_emits_event_on_bus.

@Test
void attach_string_emits_event_on_bus() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have 4 cukes in my belly\n");
    TestCaseState state = createTestCaseState(feature);
    List<EmbedEvent> embedEvents = new ArrayList<>();
    List<Envelope> envelopes = new ArrayList<>();
    bus.registerHandlerFor(EmbedEvent.class, embedEvents::add);
    bus.registerHandlerFor(Envelope.class, envelopes::add);
    UUID activeTestStep = UUID.randomUUID();
    state.setCurrentTestStepId(activeTestStep);
    state.attach("Hello World", "text/plain", "hello.txt");
    EmbedEvent embedEvent = embedEvents.get(0);
    assertThat(embedEvent.getData(), is("Hello World".getBytes(UTF_8)));
    assertThat(embedEvent.getMediaType(), is("text/plain"));
    assertThat(embedEvent.getName(), is("hello.txt"));
    Envelope envelope = envelopes.get(0);
    assertThat(envelope.getAttachment().getBody(), is("Hello World"));
    assertThat(envelope.getAttachment().getContentEncoding(), is(ContentEncoding.IDENTITY));
    assertThat(envelope.getAttachment().getMediaType(), is("text/plain"));
    assertThat(envelope.getAttachment().getFileName(), is("hello.txt"));
    assertThat(envelope.getAttachment().getTestStepId(), is(activeTestStep.toString()));
    assertThat(envelope.getAttachment().getTestCaseStartedId(), is(state.getTestExecutionId().toString()));
}
Also used : ArrayList(java.util.ArrayList) Envelope(io.cucumber.messages.types.Envelope) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) EmbedEvent(io.cucumber.plugin.event.EmbedEvent) Test(org.junit.jupiter.api.Test)

Example 15 with Envelope

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

the class TestCaseStateTest method attach_bytes_emits_event_on_bus.

@Test
void attach_bytes_emits_event_on_bus() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have 4 cukes in my belly\n");
    TestCaseState state = createTestCaseState(feature);
    List<EmbedEvent> embedEvents = new ArrayList<>();
    List<Envelope> envelopes = new ArrayList<>();
    bus.registerHandlerFor(EmbedEvent.class, embedEvents::add);
    bus.registerHandlerFor(Envelope.class, envelopes::add);
    UUID activeTestStep = UUID.randomUUID();
    state.setCurrentTestStepId(activeTestStep);
    state.attach("Hello World".getBytes(UTF_8), "text/plain", "hello.txt");
    EmbedEvent embedEvent = embedEvents.get(0);
    assertThat(embedEvent.getData(), is("Hello World".getBytes(UTF_8)));
    assertThat(embedEvent.getMediaType(), is("text/plain"));
    assertThat(embedEvent.getName(), is("hello.txt"));
    Envelope envelope = envelopes.get(0);
    assertThat(envelope.getAttachment().getBody(), is(Base64.getEncoder().encodeToString("Hello World".getBytes(UTF_8))));
    assertThat(envelope.getAttachment().getContentEncoding(), is(ContentEncoding.BASE_64));
    assertThat(envelope.getAttachment().getMediaType(), is("text/plain"));
    assertThat(envelope.getAttachment().getFileName(), is("hello.txt"));
    assertThat(envelope.getAttachment().getTestStepId(), is(activeTestStep.toString()));
    assertThat(envelope.getAttachment().getTestCaseStartedId(), is(state.getTestExecutionId().toString()));
}
Also used : ArrayList(java.util.ArrayList) Envelope(io.cucumber.messages.types.Envelope) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) EmbedEvent(io.cucumber.plugin.event.EmbedEvent) 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