use of io.cucumber.plugin.event.EmbedEvent in project cucumber-jvm by cucumber.
the class TestCaseState method attach.
@Override
public void attach(String data, String mediaType, String name) {
requireNonNull(data);
requireNonNull(mediaType);
requireActiveTestStep();
bus.send(new EmbedEvent(bus.getInstant(), testCase, data.getBytes(UTF_8), mediaType, name));
Attachment attachment = createAttachment();
attachment.setBody(data);
attachment.setContentEncoding(ContentEncoding.IDENTITY);
attachment.setMediaType(mediaType);
if (name != null) {
attachment.setFileName(name);
}
bus.send(createEnvelope(attachment));
}
use of io.cucumber.plugin.event.EmbedEvent in project cucumber-jvm by cucumber.
the class TestCaseState method attach.
@Override
public void attach(byte[] data, String mediaType, String name) {
requireNonNull(data);
requireNonNull(mediaType);
requireActiveTestStep();
bus.send(new EmbedEvent(bus.getInstant(), testCase, data, mediaType, name));
Attachment attachment = createAttachment();
attachment.setBody(Base64.getEncoder().encodeToString(data));
attachment.setContentEncoding(ContentEncoding.BASE_64);
attachment.setMediaType(mediaType);
if (name != null) {
attachment.setFileName(name);
}
bus.send(createEnvelope(attachment));
}
use of io.cucumber.plugin.event.EmbedEvent 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.plugin.event.EmbedEvent 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