io.cucumber.core.filter.Filters Java Examples

The following examples show how to use io.cucumber.core.filter.Filters. 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: 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 #2
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 #3
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 #4
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);
}
 
Example #5
Source File: CourgettePickleMatcher.java    From courgette-jvm with MIT License 4 votes vote down vote up
public CourgettePickleMatcher(Feature feature, Filters filters) {
    this.feature = feature;
    this.filters = filters;
}
 
Example #6
Source File: CucumberTestUnitFinder.java    From pitest-cucumber-plugin with Apache License 2.0 4 votes vote down vote up
public List<TestUnit> findTestUnits(Class<?> junitTestClass) {

        if (hasACucumberAnnotation(junitTestClass)) {

            List<TestUnit> result = new ArrayList<>();

            RuntimeOptions runtimeOptions = new CucumberOptionsAnnotationParser()
                .withOptionsProvider(new CustomProvider())
                .parse(junitTestClass)
                .build();

            TimeServiceEventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
            FeatureParser parser = new FeatureParser(bus::generateId);

            FeatureSupplier featureSupplier = new FeaturePathFeatureSupplier(junitTestClass::getClassLoader, runtimeOptions, parser);
            final List<Feature> cucumberFeatures = featureSupplier.get();
            final Filters filters = new Filters(runtimeOptions);
            EventBus eventBus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
            ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(runtimeOptions);
            ObjectFactorySupplier objectFactorySupplier = new ThreadLocalObjectFactorySupplier(objectFactoryServiceLoader);
            BackendSupplier backendSupplier = new BackendServiceLoader(junitTestClass::getClassLoader, objectFactorySupplier);
            TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier = new ScanningTypeRegistryConfigurerSupplier(junitTestClass::getClassLoader, runtimeOptions);
            RunnerSupplier runnerSupplier = new SingletonRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactorySupplier, typeRegistryConfigurerSupplier);
            for (Feature feature : cucumberFeatures) {
                Log.getLogger().fine("Found feature \"" + feature.getName() + "\"");
                List<Pickle> pickles = feature.getPickles();
                for (Pickle pickle : pickles) {
                    if (!filters.test(pickle)) continue;
                    Description description = new Description(
                        feature.getName() + " : " + pickle.getName(),
                        junitTestClass);
                    Log.getLogger().fine("Found \"" + description.getName() + "\"");
                    result.add(new ScenarioTestUnit(description, pickle, runnerSupplier, eventBus));
                }
            }

            return result;

        }

        return Collections.emptyList();
    }