Search in sources :

Example 1 with EventListener

use of io.cucumber.plugin.EventListener in project cucumber-jvm by cucumber.

the class PluginsTest method shouldRegisterCanonicalOrderEventPublisherWithRootEventPublisher.

@Test
void shouldRegisterCanonicalOrderEventPublisherWithRootEventPublisher() {
    RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
    Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
    EventListener plugin = mock(EventListener.class);
    plugins.addPlugin(plugin);
    plugins.setSerialEventBusOnEventListenerPlugins(rootEventPublisher);
    verify(rootEventPublisher, times(1)).registerHandlerFor(eq(Event.class), ArgumentMatchers.any());
}
Also used : Event(io.cucumber.plugin.event.Event) ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) EventListener(io.cucumber.plugin.EventListener) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) Test(org.junit.jupiter.api.Test)

Example 2 with EventListener

use of io.cucumber.plugin.EventListener in project cucumber-jvm by cucumber.

the class RuntimeTest method generates_events_for_glue_and_scenario_scoped_glue.

@Test
void generates_events_for_glue_and_scenario_scoped_glue() {
    final Feature feature = TestFeatureParser.parse("test.feature", "" + "Feature: feature name\n" + "  Scenario: Run a scenario once\n" + "    Given global scoped\n" + "    And scenario scoped\n" + "  Scenario: Then do it again\n" + "    Given global scoped\n" + "    And scenario scoped\n" + "");
    final List<StepDefinition> stepDefinedEvents = new ArrayList<>();
    Plugin eventListener = (EventListener) publisher -> publisher.registerHandlerFor(StepDefinedEvent.class, (StepDefinedEvent event) -> {
        stepDefinedEvents.add(event.getStepDefinition());
    });
    final MockedStepDefinition mockedStepDefinition = new MockedStepDefinition();
    final MockedScenarioScopedStepDefinition mockedScenarioScopedStepDefinition = new MockedScenarioScopedStepDefinition();
    BackendSupplier backendSupplier = new TestBackendSupplier() {

        private Glue glue;

        @Override
        public void loadGlue(Glue glue, List<URI> gluePaths) {
            this.glue = glue;
            glue.addStepDefinition(mockedStepDefinition);
        }

        @Override
        public void buildWorld() {
            glue.addStepDefinition(mockedScenarioScopedStepDefinition);
        }
    };
    FeatureSupplier featureSupplier = new StubFeatureSupplier(feature);
    Runtime.builder().withBackendSupplier(backendSupplier).withAdditionalPlugins(eventListener).withEventBus(new TimeServiceEventBus(new StepDurationTimeService(ZERO), UUID::randomUUID)).withFeatureSupplier(featureSupplier).build().run();
    assertThat(stepDefinedEvents.get(0).getPattern(), is(mockedStepDefinition.getPattern()));
    assertThat(stepDefinedEvents.get(1).getPattern(), is(mockedScenarioScopedStepDefinition.getPattern()));
    // Twice, once for each scenario
    assertThat(stepDefinedEvents.get(2).getPattern(), is(mockedStepDefinition.getPattern()));
    assertThat(stepDefinedEvents.get(3).getPattern(), is(mockedScenarioScopedStepDefinition.getPattern()));
    assertThat(stepDefinedEvents.size(), is(4));
}
Also used : TestBackendSupplier(io.cucumber.core.runner.TestBackendSupplier) ArrayList(java.util.ArrayList) Feature(io.cucumber.core.gherkin.Feature) TestBackendSupplier(io.cucumber.core.runner.TestBackendSupplier) Glue(io.cucumber.core.backend.Glue) StepDefinedEvent(io.cucumber.plugin.event.StepDefinedEvent) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.plugin.event.StepDefinition) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) EventListener(io.cucumber.plugin.EventListener) UUID(java.util.UUID) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Plugin(io.cucumber.plugin.Plugin) Test(org.junit.jupiter.api.Test)

Example 3 with EventListener

use of io.cucumber.plugin.EventListener 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(".+"));
}
Also used : ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) Meta(io.cucumber.messages.types.Meta) Status(io.cucumber.plugin.event.Status) ScenarioScoped(io.cucumber.core.backend.ScenarioScoped) Collections.singletonList(java.util.Collections.singletonList) StepDefinedEvent(io.cucumber.plugin.event.StepDefinedEvent) Arrays.asList(java.util.Arrays.asList) CompositeCucumberException(io.cucumber.core.exception.CompositeCucumberException) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) TestBackendSupplier(io.cucumber.core.runner.TestBackendSupplier) HookDefinition(io.cucumber.core.backend.HookDefinition) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Envelope(io.cucumber.messages.types.Envelope) Result(io.cucumber.plugin.event.Result) Collections.emptyList(java.util.Collections.emptyList) Glue(io.cucumber.core.backend.Glue) UUID(java.util.UUID) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Matchers.matchesPattern(org.hamcrest.Matchers.matchesPattern) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) ZERO(java.time.Duration.ZERO) Mockito.mock(org.mockito.Mockito.mock) Plugin(io.cucumber.plugin.Plugin) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) StepDefinition(io.cucumber.plugin.event.StepDefinition) ZoneId.of(java.time.ZoneId.of) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) EventListener(io.cucumber.plugin.EventListener) ArrayList(java.util.ArrayList) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) ArgumentCaptor(org.mockito.ArgumentCaptor) ParameterInfo(io.cucumber.core.backend.ParameterInfo) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestCaseState(io.cucumber.core.backend.TestCaseState) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) EventPublisher(io.cucumber.plugin.event.EventPublisher) EventBus(io.cucumber.core.eventbus.EventBus) Clock.fixed(java.time.Clock.fixed) TestRunStarted(io.cucumber.plugin.event.TestRunStarted) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) Clock(java.time.Clock) HOURS(java.util.concurrent.TimeUnit.HOURS) EPOCH(java.time.Instant.EPOCH) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Meta(io.cucumber.messages.types.Meta) ArrayList(java.util.ArrayList) ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) EventListener(io.cucumber.plugin.EventListener) Envelope(io.cucumber.messages.types.Envelope) Test(org.junit.jupiter.api.Test)

Example 4 with EventListener

use of io.cucumber.plugin.EventListener in project cucumber-jvm by cucumber.

the class PluginsTest method shouldSetNonConcurrentEventListener.

@Test
void shouldSetNonConcurrentEventListener() {
    RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
    Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
    EventListener plugin = mock(EventListener.class);
    plugins.addPlugin(plugin);
    plugins.setSerialEventBusOnEventListenerPlugins(rootEventPublisher);
    verify(plugin, times(1)).setEventPublisher(eventPublisher.capture());
    assertThat(eventPublisher.getValue().getClass(), is(equalTo(CanonicalOrderEventPublisher.class)));
}
Also used : ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) EventListener(io.cucumber.plugin.EventListener) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) Test(org.junit.jupiter.api.Test)

Aggregations

ConcurrentEventListener (io.cucumber.plugin.ConcurrentEventListener)4 EventListener (io.cucumber.plugin.EventListener)4 Test (org.junit.jupiter.api.Test)4 Glue (io.cucumber.core.backend.Glue)2 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)2 Feature (io.cucumber.core.gherkin.Feature)2 RuntimeOptions (io.cucumber.core.options.RuntimeOptions)2 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)2 TestBackendSupplier (io.cucumber.core.runner.TestBackendSupplier)2 Plugin (io.cucumber.plugin.Plugin)2 StepDefinedEvent (io.cucumber.plugin.event.StepDefinedEvent)2 StepDefinition (io.cucumber.plugin.event.StepDefinition)2 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 UUID (java.util.UUID)2 HookDefinition (io.cucumber.core.backend.HookDefinition)1 ParameterInfo (io.cucumber.core.backend.ParameterInfo)1