Search in sources :

Example 1 with InstanceStepsFactory

use of org.jbehave.core.steps.InstanceStepsFactory in project jbehave-core by jbehave.

the class ReportTransformBehaviour method runStories.

private void runStories(String... storyPaths) {
    StoryReporterBuilder storyReporterBuilder = new StoryReporterBuilder().withDefaultFormats().withCodeLocation(CodeLocations.codeLocationFromClass(ReportTransformBehaviour.class)).withFormats(Format.XML);
    Configuration configuration = new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass())).useStoryReporterBuilder(storyReporterBuilder).useFailureStrategy(new SilentlyAbsorbingFailure()).useStepCollector(new MarkUnmatchedStepsAsPending(new StepFinder(new ByLevenshteinDistance())));
    Embedder embedder = new Embedder();
    embedder.useEmbedderControls(new EmbedderControls().doGenerateViewAfterStories(false));
    embedder.useConfiguration(configuration);
    embedder.useCandidateSteps(new InstanceStepsFactory(configuration, new MySteps()).createCandidateSteps());
    embedder.useMetaFilters(asList("-skip true"));
    try {
        embedder.runStoriesAsPaths(asList(storyPaths));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) StepFinder(org.jbehave.core.steps.StepFinder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) FileNotFoundException(java.io.FileNotFoundException) SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) ByLevenshteinDistance(org.jbehave.core.steps.StepFinder.ByLevenshteinDistance) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) InstanceStepsFactory(org.jbehave.core.steps.InstanceStepsFactory) EmbedderControls(org.jbehave.core.embedder.EmbedderControls) MarkUnmatchedStepsAsPending(org.jbehave.core.steps.MarkUnmatchedStepsAsPending)

Example 2 with InstanceStepsFactory

use of org.jbehave.core.steps.InstanceStepsFactory in project jbehave-core by jbehave.

the class ReportTransformBehaviour method runStories.

private void runStories(String... storyPaths) {
    StoryReporterBuilder storyReporterBuilder = new StoryReporterBuilder().withDefaultFormats().withCodeLocation(CodeLocations.codeLocationFromClass(ReportTransformBehaviour.class)).withFormats(Format.XML);
    Configuration configuration = new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass())).useStoryReporterBuilder(storyReporterBuilder).useFailureStrategy(new SilentlyAbsorbingFailure()).useStepCollector(new MarkUnmatchedStepsAsPending(new StepFinder(new ByLevenshteinDistance())));
    Embedder embedder = new Embedder();
    embedder.useEmbedderControls(new EmbedderControls().doGenerateViewAfterStories(false));
    embedder.useConfiguration(configuration);
    embedder.useCandidateSteps(new InstanceStepsFactory(configuration, new MySteps()).createCandidateSteps());
    embedder.useMetaFilters(asList("-skip true"));
    try {
        embedder.runStoriesAsPaths(asList(storyPaths));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) StepFinder(org.jbehave.core.steps.StepFinder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) ByLevenshteinDistance(org.jbehave.core.steps.StepFinder.ByLevenshteinDistance) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) InstanceStepsFactory(org.jbehave.core.steps.InstanceStepsFactory) EmbedderControls(org.jbehave.core.embedder.EmbedderControls) MarkUnmatchedStepsAsPending(org.jbehave.core.steps.MarkUnmatchedStepsAsPending)

Example 3 with InstanceStepsFactory

use of org.jbehave.core.steps.InstanceStepsFactory in project jbehave-core by jbehave.

the class AnnotationBuilder method buildStepsFactory.

/**
 * Builds the {@link InjectableStepsFactory} using annotation
 * {@link UsingSteps} found in the annotated object instance and the
 * configuration provided
 *
 * @param configuration the Configuration
 * @return A {@link InjectableStepsFactory}
 */
public InjectableStepsFactory buildStepsFactory(Configuration configuration) {
    List<Object> stepsInstances = new ArrayList<>();
    InjectableStepsFactory factory = null;
    if (finder.isAnnotationPresent(UsingSteps.class)) {
        List<Class<Object>> stepsClasses = finder.getAnnotatedClasses(UsingSteps.class, Object.class, "instances");
        if (!stepsClasses.isEmpty()) {
            for (Class<Object> stepsClass : stepsClasses) {
                stepsInstances.add(instanceOf(Object.class, stepsClass));
            }
            factory = new InstanceStepsFactory(configuration, stepsInstances);
        }
        List<String> packages = finder.getAnnotatedValues(UsingSteps.class, String.class, "packages");
        if (!packages.isEmpty()) {
            String matchingNames = finder.getAnnotatedValue(UsingSteps.class, String.class, "matchingNames");
            String notMatchingNames = finder.getAnnotatedValue(UsingSteps.class, String.class, "notMatchingNames");
            factory = new ScanningStepsFactory(configuration, packages.toArray(new String[packages.size()])).matchingNames(matchingNames).notMatchingNames(notMatchingNames);
        }
    } else {
        annotationMonitor.annotationNotFound(UsingSteps.class, annotatedClass);
    }
    if (factory == null) {
        factory = new InstanceStepsFactory(configuration);
    }
    return factory;
}
Also used : InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) InstanceStepsFactory(org.jbehave.core.steps.InstanceStepsFactory) ArrayList(java.util.ArrayList) ScanningStepsFactory(org.jbehave.core.steps.ScanningStepsFactory)

Aggregations

InstanceStepsFactory (org.jbehave.core.steps.InstanceStepsFactory)3 FileNotFoundException (java.io.FileNotFoundException)2 Configuration (org.jbehave.core.configuration.Configuration)2 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)2 Embedder (org.jbehave.core.embedder.Embedder)2 EmbedderControls (org.jbehave.core.embedder.EmbedderControls)2 SilentlyAbsorbingFailure (org.jbehave.core.failures.SilentlyAbsorbingFailure)2 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)2 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)2 MarkUnmatchedStepsAsPending (org.jbehave.core.steps.MarkUnmatchedStepsAsPending)2 StepFinder (org.jbehave.core.steps.StepFinder)2 ByLevenshteinDistance (org.jbehave.core.steps.StepFinder.ByLevenshteinDistance)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 InjectableStepsFactory (org.jbehave.core.steps.InjectableStepsFactory)1 ScanningStepsFactory (org.jbehave.core.steps.ScanningStepsFactory)1