Search in sources :

Example 1 with Plugin

use of io.cucumber.plugin.Plugin 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 2 with Plugin

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

the class Plugins method createPlugins.

private List<Plugin> createPlugins() {
    List<Plugin> plugins = new ArrayList<>();
    if (!pluginNamesInstantiated) {
        for (Options.Plugin pluginOption : pluginOptions.plugins()) {
            Plugin plugin = pluginFactory.create(pluginOption);
            addPlugin(plugins, plugin);
        }
        pluginNamesInstantiated = true;
    }
    return plugins;
}
Also used : ArrayList(java.util.ArrayList) Plugin(io.cucumber.plugin.Plugin)

Example 3 with Plugin

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

the class CucumberOptionsAnnotationParserTest method inherit_plugin_from_baseclass.

@Test
void inherit_plugin_from_baseclass() {
    RuntimeOptions runtimeOptions = parser().parse(SubClassWithFormatter.class).build();
    Plugins plugins = new Plugins(new PluginFactory(), runtimeOptions);
    plugins.setEventBusOnEventListenerPlugins(new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID));
    List<Plugin> pluginList = plugins.getPlugins();
    assertAll(() -> assertPluginExists(pluginList, HtmlFormatter.class.getName()), () -> assertPluginExists(pluginList, PrettyFormatter.class.getName()));
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) PluginFactory(io.cucumber.core.plugin.PluginFactory) Plugins(io.cucumber.core.plugin.Plugins) Plugin(io.cucumber.plugin.Plugin) Test(org.junit.jupiter.api.Test)

Example 4 with Plugin

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

the class CucumberOptionsAnnotationParserTest method assertPluginExists.

private void assertPluginExists(List<Plugin> plugins, String pluginName) {
    boolean found = false;
    for (Plugin plugin : plugins) {
        if (plugin.getClass().getName().equals(pluginName)) {
            found = true;
            break;
        }
    }
    assertThat(pluginName + " not found among the plugins", found, is(equalTo(true)));
}
Also used : Plugin(io.cucumber.plugin.Plugin)

Aggregations

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