io.cucumber.core.runtime.FeaturePathFeatureSupplier Java Examples

The following examples show how to use io.cucumber.core.runtime.FeaturePathFeatureSupplier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllureCucumber5JvmTest.java    From allure-java with Apache License 2.0 7 votes vote down vote up
private byte runFeature(final AllureResultsWriterStub writer,
                        final String featureResource,
                        final String... moreOptions) {

    final AllureLifecycle lifecycle = new AllureLifecycle(writer);
    final AllureCucumber5Jvm cucumber5Jvm = new AllureCucumber5Jvm(lifecycle);
    Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
    final List<String> opts = new ArrayList<>(Arrays.asList(
            "--glue", "io.qameta.allure.cucumber5jvm.samples",
            "--plugin", "null_summary"
    ));
    opts.addAll(Arrays.asList(moreOptions));
    FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/"+featureResource);
    final RuntimeOptions options = new CommandlineOptionsParser().parse(opts).addFeature(featureWithLines).build();
    boolean mt = options.isMultiThreaded();

    EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    FeatureParser parser = new FeatureParser(bus::generateId);
    FeaturePathFeatureSupplier supplier = new FeaturePathFeatureSupplier(classLoader, options, parser);

    final Runtime runtime = Runtime.builder()
            .withClassLoader(classLoader)
            .withRuntimeOptions(options)
            .withAdditionalPlugins(cucumber5Jvm)
            .withFeatureSupplier(supplier)
            .build();

    runtime.run();
    return runtime.exitStatus();
}
 
Example #2
Source File: CucumberRunner.java    From cucumber-performance with MIT License 6 votes vote down vote up
/**
 * Builds local runtime instead of using cucumber runtime class.
 */
private void BuildRuntime() {
	Supplier<ClassLoader> classLoader = CucumberRunner.class::getClassLoader;
       ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(runtimeOptions);
       ObjectFactorySupplier objectFactory = new SingletonObjectFactorySupplier(objectFactoryServiceLoader);
       BackendServiceLoader backendSupplier = new BackendServiceLoader(classLoader, objectFactory);
       TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier = new ScanningTypeRegistryConfigurerSupplier(classLoader, runtimeOptions);
       runnerSupplier = new ThreadLocalRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactory, typeRegistryConfigurerSupplier);
	// can cull out pretty here
	// Plugins orgPlugins = new Plugins(this.classLoader, new PluginFactory(),
	// this.eventBus, this.runtimeOptions);
	// this.plugins = new Plugins(classLoader, new PluginFactory(), eventBus, new
	// RuntimeOptions(new ArrayList<String>()));
	// for (final Plugin plugin : orgPlugins) {
	// if(!(plugin instanceof PrettyFormatter))
	// {
	// plugins.addPlugin(plugin);
	// }
	// }
	this.plugins = new Plugins(new PluginFactory(), runtimeOptions);
	this.plugins.setEventBusOnEventListenerPlugins(eventBus);
	this.plugins.setSerialEventBusOnEventListenerPlugins(eventBus);
	this.featureSupplier = new FeaturePathFeatureSupplier(classLoader, this.runtimeOptions, null);
	this.filters = new Filters(this.runtimeOptions);
}
 
Example #3
Source File: CourgetteLoader.java    From courgette-jvm with MIT License 5 votes vote down vote up
public CourgetteLoader(CourgetteProperties courgetteProperties) {
    this.courgetteProperties = courgetteProperties;

    RuntimeOptions runtimeOptions = createRuntimeOptions();
    this.filters = new Filters(runtimeOptions);

    EventBus eventBus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    FeatureParser parser = new FeatureParser(eventBus::generateId);
    Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
    FeaturePathFeatureSupplier featureSupplier = new FeaturePathFeatureSupplier(classLoader, runtimeOptions, parser);

    this.features = featureSupplier.get();
}
 
Example #4
Source File: FeatureBuilder.java    From cucumber-performance with MIT License 4 votes vote down vote up
public static List<Feature> getFeatures(RuntimeOptions runtimeOptions) {
	Supplier<ClassLoader> classLoader = FeatureBuilder.class::getClassLoader;
	FeatureParser parser = new FeatureParser(UUID::randomUUID);
	return new FeaturePathFeatureSupplier(classLoader, runtimeOptions,parser).get();
}
 
Example #5
Source File: CucumberRuntime.java    From cucumber-performance with MIT License 4 votes vote down vote up
public CucumberRuntime build() {
         final ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(runtimeOptions);

         final ObjectFactorySupplier objectFactorySupplier = new ThreadLocalObjectFactorySupplier(objectFactoryServiceLoader);

         final BackendSupplier backendSupplier = this.backendSupplier != null
             ? this.backendSupplier
             : new BackendServiceLoader(this.classLoader, objectFactorySupplier);

         final Plugins plugins = new Plugins(new PluginFactory(), runtimeOptions);
         for (final Plugin plugin : additionalPlugins) {
             plugins.addPlugin(plugin);
         }
         final ExitStatus exitStatus = new ExitStatus(runtimeOptions);
         plugins.addPlugin(exitStatus);
         if (runtimeOptions.isMultiThreaded()) {
             plugins.setSerialEventBusOnEventListenerPlugins(eventBus);
         } else {
             plugins.setEventBusOnEventListenerPlugins(eventBus);
         }

         final TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier = new ScanningTypeRegistryConfigurerSupplier(classLoader, runtimeOptions);

         final RunnerSupplier runnerSupplier = new ThreadLocalRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactorySupplier, typeRegistryConfigurerSupplier);
            
         final ExecutorService executor = runtimeOptions.isMultiThreaded()
             ? Executors.newFixedThreadPool(runtimeOptions.getThreads(), new CucumberThreadFactory())
             : new SameThreadExecutorService();

if (features == null) {
  final FeatureParser parser = new FeatureParser(eventBus::generateId);
  
  final FeatureSupplier featureSupplier = this.featureSupplier != null ?
  this.featureSupplier : new FeaturePathFeatureSupplier(classLoader,
  runtimeOptions, parser);
  features = featureSupplier.get();
}

         final Predicate<Pickle> filter = new Filters(runtimeOptions);
         final int limit = runtimeOptions.getLimitCount();
         final PickleOrder pickleOrder = runtimeOptions.getPickleOrder();

         return new CucumberRuntime(exitStatus, eventBus, filter, limit, runnerSupplier, features, executor, pickleOrder,failFast);
     }
 
Example #6
Source File: JustTestLahRunner.java    From justtestlah with Apache License 2.0 4 votes vote down vote up
/**
 * This is the code taken from {@link io.cucumber.junit.Cucumber}
 *
 * @param clazz {@link Class}
 * @throws InitializationError {@link InitializationError}
 */
private void initCucumber(Class<?> clazz) throws InitializationError {
  Assertions.assertNoCucumberAnnotatedMethods(clazz);

  // Parse the options early to provide fast feedback about invalid options
  RuntimeOptions propertiesFileOptions =
      new CucumberPropertiesParser().parse(CucumberProperties.fromPropertiesFile()).build();

  RuntimeOptions annotationOptions =
      new CucumberOptionsAnnotationParser()
          .withOptionsProvider(new JUnitCucumberOptionsProvider())
          .parse(clazz)
          .build(propertiesFileOptions);

  RuntimeOptions environmentOptions =
      new CucumberPropertiesParser()
          .parse(CucumberProperties.fromEnvironment())
          .build(annotationOptions);

  RuntimeOptions runtimeOptions =
      new CucumberPropertiesParser()
          .parse(CucumberProperties.fromSystemProperties())
          .addDefaultSummaryPrinterIfAbsent()
          .build(environmentOptions);

  if (!runtimeOptions.isStrict()) {
    LOG.warn(
        "By default Cucumber is running in --non-strict mode.\n"
            + "This default will change to --strict and --non-strict will be removed.\n"
            + "You can use --strict or @CucumberOptions(strict = true) to suppress this warning");
  }

  // Next parse the junit options
  JUnitOptions junitPropertiesFileOptions =
      new JUnitOptionsParser().parse(CucumberProperties.fromPropertiesFile()).build();

  JUnitOptions junitAnnotationOptions =
      new JUnitOptionsParser().parse(clazz).build(junitPropertiesFileOptions);

  JUnitOptions junitEnvironmentOptions =
      new JUnitOptionsParser()
          .parse(CucumberProperties.fromEnvironment())
          .build(junitAnnotationOptions);

  JUnitOptions junitOptions =
      new JUnitOptionsParser()
          .parse(CucumberProperties.fromSystemProperties())
          .setStrict(runtimeOptions.isStrict())
          .build(junitEnvironmentOptions);

  this.bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);

  // Parse the features early. Don't proceed when there are lexer errors
  FeatureParser parser = new FeatureParser(bus::generateId);
  Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
  FeaturePathFeatureSupplier featureSupplier =
      new FeaturePathFeatureSupplier(classLoader, runtimeOptions, parser);
  this.features = featureSupplier.get();

  // Create plugins after feature parsing to avoid the creation of empty files on
  // lexer errors.
  this.plugins = new Plugins(new PluginFactory(), runtimeOptions);

  ObjectFactoryServiceLoader objectFactoryServiceLoader =
      new ObjectFactoryServiceLoader(runtimeOptions);
  ObjectFactorySupplier objectFactorySupplier =
      new ThreadLocalObjectFactorySupplier(objectFactoryServiceLoader);
  BackendSupplier backendSupplier =
      new BackendServiceLoader(clazz::getClassLoader, objectFactorySupplier);
  TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier =
      new ScanningTypeRegistryConfigurerSupplier(classLoader, runtimeOptions);
  ThreadLocalRunnerSupplier runnerSupplier =
      new ThreadLocalRunnerSupplier(
          runtimeOptions,
          bus,
          backendSupplier,
          objectFactorySupplier,
          typeRegistryConfigurerSupplier);
  Predicate<Pickle> filters = new Filters(runtimeOptions);
  this.children =
      features.stream()
          .map(feature -> FeatureRunner.create(feature, filters, runnerSupplier, junitOptions))
          .filter(runner -> !runner.isEmpty())
          .collect(toList());

  LOG.info(
      "Found {} feature(s) in {}: {}",
      features.size(),
      System.getProperty("cucumber.features"),
      features);
}