Search in sources :

Example 1 with EmbedEvent

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));
}
Also used : Attachment(io.cucumber.messages.types.Attachment) EmbedEvent(io.cucumber.plugin.event.EmbedEvent)

Example 2 with EmbedEvent

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));
}
Also used : Attachment(io.cucumber.messages.types.Attachment) EmbedEvent(io.cucumber.plugin.event.EmbedEvent)

Example 3 with EmbedEvent

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()));
}
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 4 with EmbedEvent

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()));
}
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

EmbedEvent (io.cucumber.plugin.event.EmbedEvent)4 Feature (io.cucumber.core.gherkin.Feature)2 Attachment (io.cucumber.messages.types.Attachment)2 Envelope (io.cucumber.messages.types.Envelope)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 Test (org.junit.jupiter.api.Test)2