io.cucumber.core.gherkin.Pickle Java Examples

The following examples show how to use io.cucumber.core.gherkin.Pickle. 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: CucumberRuntime.java    From cucumber-performance with MIT License 6 votes vote down vote up
private CucumberRuntime(final ExitStatus exitStatus,
                final EventBus bus,
                final Predicate<Pickle> filter,
                final int limit,
                final RunnerSupplier runnerSupplier,
                final List<Feature> features,
                final ExecutorService executor,
                final PickleOrder pickleOrder,
                final boolean failFast) {
    this.bus = bus;
    this.filter = filter;
    this.limit = limit;
    this.runnerSupplier = runnerSupplier;
    //this.featureSupplier = featureSupplier;
    this.features = features;
    this.executor = executor;
    this.exitStatus = exitStatus;
    this.pickleOrder = pickleOrder;
    this.failFast = failFast;
}
 
Example #2
Source File: FeatureFilter.java    From cucumber-performance with MIT License 6 votes vote down vote up
public static boolean isMatch(Feature feature, String text) {
	if (text.startsWith("@")) {
		List<String> tags = getGroupTags(text);
		TagPredicate tp = new TagPredicate(tags);
		for (Pickle pe : feature.getPickles()) {
			if (tp.test(pe)) {
				return true;
			}
		}
	} else {
		if (feature.getName().equalsIgnoreCase(text) || feature.getUri().toString()
				.substring(feature.getUri().toString().lastIndexOf("/") + 1).equalsIgnoreCase(text))
			return true;
	}
	return false;
}
 
Example #3
Source File: CourgettePickleMatcher.java    From courgette-jvm with MIT License 6 votes vote down vote up
public PickleLocation matchLocation(int pickleLocationLine) {
    final PickleLocation[] location = {null};

    List<Pickle> pickles = feature.getPickles();

    try {
        pickles.stream().filter(p -> p.getLocation().getLine() == pickleLocationLine)
                .findFirst()
                .ifPresent(pickleEvent -> {
                    if (filters.test(pickleEvent)) {
                        location[0] = new PickleLocation(pickleEvent.getLocation().getLine(), pickleEvent.getLocation().getColumn());
                        throw new ConditionSatisfiedException();
                    }
                });
    } catch (ConditionSatisfiedException ignored) {
    }
    return location[0];
}
 
Example #4
Source File: CucumberRunner.java    From cucumber-performance with MIT License 5 votes vote down vote up
public static List<Pickle> createPickles(Feature feature, Slice slice) {
    if (slice!= null) {
	    List<Pickle> pickles = new ArrayList<Pickle>();
	    for (Pickle pickle : feature.getPickles()) {
	    	pickles.add(new PerfPickle(pickle,slice));
	    }
	    return pickles;
    } else {
    	return feature.getPickles();
    }
}
 
Example #5
Source File: CucumberRunner.java    From cucumber-performance with MIT License 5 votes vote down vote up
private void runFeature(Feature cucumberFeature, Slice slice) throws Throwable {
	List<Pickle> pickles = createPickles(cucumberFeature, slice);
	for (Pickle pickle : pickles) {
		if (filters.test(pickle)) {
			runScenario(pickle);
		}
	}
}
 
Example #6
Source File: CucumberRunner.java    From cucumber-performance with MIT License 5 votes vote down vote up
private void runScenario(Pickle pickle) throws Throwable {
	runnerSupplier.get().runPickle(pickle);

	ScenarioResult sr = testCaseResultListener.getResult();
	sr.setChildResults(stepResultListener.getResults());
	scenarioResults.add(sr);
	stepResultListener.reset();

	if (failFast && !testCaseResultListener.getResult().isPassed()) {
		throw testCaseResultListener.getResult().getError();
	}
}
 
Example #7
Source File: TagPredicate.java    From cucumber-performance with MIT License 5 votes vote down vote up
public boolean test(Pickle pickle) {
    if (expressions.isEmpty()) {
        return true;
    }

    List<String> tags = pickle.getTags();
    return expressions.stream()
        .allMatch(expression -> expression.evaluate(tags));
}
 
Example #8
Source File: PerfPickle.java    From cucumber-performance with MIT License 4 votes vote down vote up
public PerfPickle(Pickle pickle, Slice slice) {
	this.pickle = pickle;
	this.steps = this.createSteps(slice);  
}
 
Example #9
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 #10
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 #11
Source File: ScenarioTestUnit.java    From pitest-cucumber-plugin with Apache License 2.0 4 votes vote down vote up
public ScenarioTestUnit(Description description, Pickle scenario, RunnerSupplier runnerSupplier, EventBus eventBus) {
    this.description = description;
    this.scenario = scenario;
    this.runnerSupplier = runnerSupplier;
    this.eventBus = eventBus;
}
 
Example #12
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();
    }