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);
}
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);
}
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(".+"));
}
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()));
}
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()));
}
Aggregations