io.cucumber.core.runtime.TimeServiceEventBus Java Examples

The following examples show how to use io.cucumber.core.runtime.TimeServiceEventBus. 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: 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: 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);
}