Search in sources :

Example 1 with EventBus

use of io.cucumber.core.eventbus.EventBus in project cucumber-jvm by cucumber.

the class EventBusTest method handlers_do_not_receive_the_events_they_did_not_registered_for.

@Test
void handlers_do_not_receive_the_events_they_did_not_registered_for() {
    EventHandler handler = mock(EventHandler.class);
    PickleStepTestStep testStep = mock(PickleStepTestStep.class);
    TestCase testCase = mock(TestCase.class);
    TestStepStarted event = new TestStepStarted(EPOCH, testCase, testStep);
    EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
    bus.registerHandlerFor(TestStepFinished.class, handler);
    bus.send(event);
    verify(handler, never()).receive(event);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestCase(io.cucumber.plugin.event.TestCase) EventHandler(io.cucumber.plugin.event.EventHandler) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) Test(org.junit.jupiter.api.Test)

Example 2 with EventBus

use of io.cucumber.core.eventbus.EventBus in project cucumber-jvm by cucumber.

the class PluginFactoryTest method plugin_does_not_buffer_its_output.

@Test
void plugin_does_not_buffer_its_output() {
    PrintStream previousSystemOut = System.out;
    OutputStream mockSystemOut = new ByteArrayOutputStream();
    try {
        System.setOut(new PrintStream(mockSystemOut));
        // Need to create a new plugin factory here since we need it to pick
        // up the new value of System.out
        fc = new PluginFactory();
        PluginOption option = parse("progress");
        ProgressFormatter plugin = (ProgressFormatter) fc.create(option);
        EventBus bus = new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID);
        plugin.setEventPublisher(bus);
        Result result = new Result(Status.PASSED, ZERO, null);
        TestStepFinished event = new TestStepFinished(bus.getInstant(), mock(TestCase.class), mock(PickleStepTestStep.class), result);
        bus.send(event);
        assertThat(mockSystemOut.toString(), is(not(equalTo(""))));
    } finally {
        System.setOut(previousSystemOut);
    }
}
Also used : PrintStream(java.io.PrintStream) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ClockStub(io.cucumber.core.runner.ClockStub) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Result(io.cucumber.plugin.event.Result) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) PluginOption(io.cucumber.core.options.PluginOption) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 3 with EventBus

use of io.cucumber.core.eventbus.EventBus in project cucumber-jvm by cucumber.

the class SingletonRunnerSupplierTest method before.

@BeforeEach
void before() {
    Supplier<ClassLoader> classLoader = SingletonRunnerSupplier.class::getClassLoader;
    RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
    ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(classLoader, runtimeOptions);
    ObjectFactorySupplier objectFactory = new SingletonObjectFactorySupplier(objectFactoryServiceLoader);
    BackendServiceLoader backendSupplier = new BackendServiceLoader(getClass()::getClassLoader, objectFactory);
    EventBus eventBus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    runnerSupplier = new SingletonRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactory);
}
Also used : EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with EventBus

use of io.cucumber.core.eventbus.EventBus in project cucumber-jvm by cucumber.

the class HtmlFormatterTest method ignores_step_definitions.

@Test
void ignores_step_definitions() 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);
    StepDefinition stepDefinition = new StepDefinition();
    Envelope stepDefinitionEnvelope = new Envelope();
    stepDefinitionEnvelope.setStepDefinition(stepDefinition);
    bus.send(stepDefinitionEnvelope);
    Hook hook = new Hook();
    Envelope hookEnvelope = new Envelope();
    hookEnvelope.setHook(hook);
    bus.send(hookEnvelope);
    ParameterType parameterType = new ParameterType();
    Envelope parameterTypeEnvelope = new Envelope();
    parameterTypeEnvelope.setParameterType(parameterType);
    bus.send(parameterTypeEnvelope);
    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 : Hook(io.cucumber.messages.types.Hook) ParameterType(io.cucumber.messages.types.ParameterType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Envelope(io.cucumber.messages.types.Envelope) TestRunFinished(io.cucumber.messages.types.TestRunFinished) Timestamp(io.cucumber.messages.types.Timestamp) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TestRunStarted(io.cucumber.messages.types.TestRunStarted) StepDefinition(io.cucumber.messages.types.StepDefinition) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 5 with EventBus

use of io.cucumber.core.eventbus.EventBus in project cucumber-jvm by cucumber.

the class EventBusTest method handlers_receive_the_events_they_registered_for.

@Test
void handlers_receive_the_events_they_registered_for() {
    EventHandler<TestStepFinished> handler = mock(EventHandler.class);
    PickleStepTestStep testStep = mock(PickleStepTestStep.class);
    Result result = new Result(Status.PASSED, ZERO, null);
    TestCase testCase = mock(TestCase.class);
    TestStepFinished event = new TestStepFinished(EPOCH, testCase, testStep, result);
    EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
    bus.registerHandlerFor(TestStepFinished.class, handler);
    bus.send(event);
    verify(handler).receive(event);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Aggregations

EventBus (io.cucumber.core.eventbus.EventBus)13 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)11 UUID (java.util.UUID)11 Test (org.junit.jupiter.api.Test)10 Envelope (io.cucumber.messages.types.Envelope)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 RuntimeOptions (io.cucumber.core.options.RuntimeOptions)3 CucumberExecutionContext (io.cucumber.core.runtime.CucumberExecutionContext)3 ExitStatus (io.cucumber.core.runtime.ExitStatus)3 ThreadLocalRunnerSupplier (io.cucumber.core.runtime.ThreadLocalRunnerSupplier)3 TestRunFinished (io.cucumber.messages.types.TestRunFinished)3 TestRunStarted (io.cucumber.messages.types.TestRunStarted)3 Timestamp (io.cucumber.messages.types.Timestamp)3 Result (io.cucumber.plugin.event.Result)3 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Filters (io.cucumber.core.filter.Filters)2 Feature (io.cucumber.core.gherkin.Feature)2 BackendSupplier (io.cucumber.core.runtime.BackendSupplier)2 ObjectFactoryServiceLoader (io.cucumber.core.runtime.ObjectFactoryServiceLoader)2