Search in sources :

Example 6 with EventBus

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

the class ThreadLocalRunnerSupplierTest method runner_should_wrap_event_bus_bus.

@Test
void runner_should_wrap_event_bus_bus() {
    // This avoids problems with JUnit which listens to individual runners
    EventBus runnerBus = runnerSupplier.get().getBus();
    assertAll(() -> assertThat(eventBus, is(not(equalTo(runnerBus)))), () -> assertThat(runnerBus, is(not(equalTo(eventBus)))));
}
Also used : EventBus(io.cucumber.core.eventbus.EventBus) Test(org.junit.jupiter.api.Test)

Example 7 with EventBus

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

the class JUnitReporterWithStepNotificationsTest method ignores_steps_when_step_notification_are_disabled.

@Test
void ignores_steps_when_step_notification_are_disabled() {
    EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    JUnitReporter jUnitReporter = new JUnitReporter(bus, new JUnitOptionsBuilder().setStepNotifications(false).build());
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    Result result = new Result(Status.PASSED, ZERO, null);
    bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier, never()).fireTestStarted(pickleRunner.describeChild(step));
    verify(runNotifier, never()).fireTestFinished(pickleRunner.describeChild(step));
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 8 with EventBus

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

the class CucumberEngineExecutionContext method createCucumberExecutionContext.

private CucumberExecutionContext createCucumberExecutionContext() {
    Supplier<ClassLoader> classLoader = CucumberEngineExecutionContext.class::getClassLoader;
    ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(classLoader, options);
    EventBus bus = synchronize(new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID));
    Plugins plugins = new Plugins(new PluginFactory(), options);
    ExitStatus exitStatus = new ExitStatus(options);
    plugins.addPlugin(exitStatus);
    RunnerSupplier runnerSupplier;
    if (options.isParallelExecutionEnabled()) {
        plugins.setSerialEventBusOnEventListenerPlugins(bus);
        ObjectFactorySupplier objectFactorySupplier = new ThreadLocalObjectFactorySupplier(objectFactoryServiceLoader);
        BackendSupplier backendSupplier = new BackendServiceLoader(classLoader, objectFactorySupplier);
        runnerSupplier = new ThreadLocalRunnerSupplier(options, bus, backendSupplier, objectFactorySupplier);
    } else {
        plugins.setEventBusOnEventListenerPlugins(bus);
        ObjectFactorySupplier objectFactorySupplier = new SingletonObjectFactorySupplier(objectFactoryServiceLoader);
        BackendSupplier backendSupplier = new BackendServiceLoader(classLoader, objectFactorySupplier);
        runnerSupplier = new SingletonRunnerSupplier(options, bus, backendSupplier, objectFactorySupplier);
    }
    return new CucumberExecutionContext(bus, exitStatus, runnerSupplier);
}
Also used : BackendSupplier(io.cucumber.core.runtime.BackendSupplier) ObjectFactoryServiceLoader(io.cucumber.core.runtime.ObjectFactoryServiceLoader) SingletonRunnerSupplier(io.cucumber.core.runtime.SingletonRunnerSupplier) SingletonObjectFactorySupplier(io.cucumber.core.runtime.SingletonObjectFactorySupplier) ThreadLocalObjectFactorySupplier(io.cucumber.core.runtime.ThreadLocalObjectFactorySupplier) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ExitStatus(io.cucumber.core.runtime.ExitStatus) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) CucumberExecutionContext(io.cucumber.core.runtime.CucumberExecutionContext) SingletonRunnerSupplier(io.cucumber.core.runtime.SingletonRunnerSupplier) RunnerSupplier(io.cucumber.core.runtime.RunnerSupplier) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) BackendServiceLoader(io.cucumber.core.runtime.BackendServiceLoader) PluginFactory(io.cucumber.core.plugin.PluginFactory) SingletonObjectFactorySupplier(io.cucumber.core.runtime.SingletonObjectFactorySupplier) ObjectFactorySupplier(io.cucumber.core.runtime.ObjectFactorySupplier) ThreadLocalObjectFactorySupplier(io.cucumber.core.runtime.ThreadLocalObjectFactorySupplier) Plugins(io.cucumber.core.plugin.Plugins)

Example 9 with EventBus

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

the class FeatureRunnerTest method should_filter_pickles.

@Test
void should_filter_pickles() {
    Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario_1 name\n" + "    Given step #1\n" + "  @tag\n" + "  Scenario: scenario_2 name\n" + "    Given step #1\n");
    RuntimeOptions options = new RuntimeOptionsBuilder().addTagFilter(TagExpressionParser.parse("@tag")).build();
    Filters filters = new Filters(options);
    IllegalStateException illegalStateException = new IllegalStateException();
    RunnerSupplier runnerSupplier = () -> {
        throw illegalStateException;
    };
    EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(options), runnerSupplier);
    FeatureRunner featureRunner = FeatureRunner.create(feature, null, filters, context, new JUnitOptions());
    assertThat(featureRunner.getChildren().size(), is(1));
    assertThat(featureRunner.getChildren().get(0).getDescription().getDisplayName(), is("scenario_2 name(feature name)"));
}
Also used : RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Feature(io.cucumber.core.gherkin.Feature) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ExitStatus(io.cucumber.core.runtime.ExitStatus) CucumberExecutionContext(io.cucumber.core.runtime.CucumberExecutionContext) Filters(io.cucumber.core.filter.Filters) RunnerSupplier(io.cucumber.core.runtime.RunnerSupplier) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) UUID(java.util.UUID) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) Test(org.junit.jupiter.api.Test)

Example 10 with EventBus

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

the class FeatureRunnerTest method createFeatureRunner.

private FeatureRunner createFeatureRunner(Feature feature, JUnitOptions junitOption) {
    ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(getClass()::getClassLoader, RuntimeOptions.defaultOptions());
    ObjectFactorySupplier objectFactory = new SingletonObjectFactorySupplier(objectFactoryServiceLoader);
    final RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
    final Clock clockStub = new Clock() {

        @Override
        public ZoneId getZone() {
            return null;
        }

        @Override
        public Clock withZone(ZoneId zone) {
            return null;
        }

        @Override
        public Instant instant() {
            return Instant.EPOCH;
        }
    };
    BackendSupplier backendSupplier = () -> singleton(new StubBackendProviderService.StubBackend());
    EventBus bus = new TimeServiceEventBus(clockStub, UUID::randomUUID);
    Filters filters = new Filters(runtimeOptions);
    ThreadLocalRunnerSupplier runnerSupplier = new ThreadLocalRunnerSupplier(runtimeOptions, bus, backendSupplier, objectFactory);
    CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(runtimeOptions), runnerSupplier);
    return FeatureRunner.create(feature, null, filters, context, junitOption);
}
Also used : BackendSupplier(io.cucumber.core.runtime.BackendSupplier) ObjectFactoryServiceLoader(io.cucumber.core.runtime.ObjectFactoryServiceLoader) ZoneId(java.time.ZoneId) SingletonObjectFactorySupplier(io.cucumber.core.runtime.SingletonObjectFactorySupplier) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Clock(java.time.Clock) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) ExitStatus(io.cucumber.core.runtime.ExitStatus) CucumberExecutionContext(io.cucumber.core.runtime.CucumberExecutionContext) Filters(io.cucumber.core.filter.Filters) SingletonObjectFactorySupplier(io.cucumber.core.runtime.SingletonObjectFactorySupplier) ObjectFactorySupplier(io.cucumber.core.runtime.ObjectFactorySupplier) UUID(java.util.UUID) RuntimeOptions(io.cucumber.core.options.RuntimeOptions)

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