Search in sources :

Example 31 with Story

use of org.jbehave.core.model.Story in project jbehave-core by jbehave.

the class PerformableTree method performableGivenStories.

private List<PerformableStory> performableGivenStories(RunContext context, GivenStories givenStories, Map<String, String> parameters) {
    List<PerformableStory> stories = new ArrayList<>();
    if (givenStories.getPaths().size() > 0) {
        for (GivenStory givenStory : givenStories.getStories()) {
            RunContext childContext = context.childContextFor(givenStory);
            // run given story, using any parameters provided
            Story story = storyOfPath(context.configuration(), childContext.path());
            if (givenStory.hasAnchorParameters()) {
                story = storyWithMatchingScenarios(story, givenStory.getAnchorParameters());
            }
            parameters.putAll(givenStory.getParameters());
            stories.add(performableStory(childContext, story, parameters));
        }
    }
    return stories;
}
Also used : GivenStory(org.jbehave.core.model.GivenStory) ArrayList(java.util.ArrayList) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story)

Example 32 with Story

use of org.jbehave.core.model.Story in project jbehave-core by jbehave.

the class PrintStreamEmbedderMonitor method storiesNotAllowed.

public void storiesNotAllowed(List<Story> stories, MetaFilter filter, boolean verbose) {
    StringBuffer sb = new StringBuffer();
    sb.append(stories.size() + " stories excluded by filter: " + filter.asString() + "\n");
    if (verbose) {
        for (Story story : stories) {
            sb.append(story.getPath()).append("\n");
        }
    }
    print(sb.toString());
}
Also used : Story(org.jbehave.core.model.Story)

Example 33 with Story

use of org.jbehave.core.model.Story in project jbehave-core by jbehave.

the class StoryRunner method runBeforeOrAfterStories.

/**
 * Run steps before or after a collection of stories. Steps are execute only
 * <b>once</b> per collection of stories.
 *
 * @param configuration the Configuration used to find the steps to run
 * @param candidateSteps the List of CandidateSteps containing the candidate
 *            steps methods
 * @param stage the Stage
 * @return The State after running the steps
 */
public State runBeforeOrAfterStories(Configuration configuration, List<CandidateSteps> candidateSteps, Stage stage) {
    String storyPath = capitalizeFirstLetter(stage.name().toLowerCase()) + "Stories";
    reporter.set(configuration.storyReporter(storyPath));
    reporter.get().beforeStory(new Story(storyPath), false);
    RunContext context = new RunContext(configuration, candidateSteps, storyPath, MetaFilter.EMPTY);
    if (stage == Stage.BEFORE) {
        resetStoryFailure(context);
    }
    if (stage == Stage.AFTER && storiesState.get() != null) {
        context.stateIs(storiesState.get());
    }
    try {
        runStepsWhileKeepingState(context, configuration.stepCollector().collectBeforeOrAfterStoriesSteps(context.candidateSteps(), stage));
    } catch (InterruptedException e) {
        throw new UUIDExceptionWrapper(e);
    }
    reporter.get().afterStory(false);
    storiesState.set(context.state());
    // methods, otherwise we will forget to close files on BeforeStories
    if (stage == Stage.BEFORE) {
        if (reporter.get() instanceof ConcurrentStoryReporter) {
            ((ConcurrentStoryReporter) reporter.get()).invokeDelayed();
        }
    }
    // handle any after stories failure according to strategy
    if (stage == Stage.AFTER) {
        try {
            handleStoryFailureByStrategy();
        } catch (Throwable e) {
            return new SomethingHappened(storyFailure.get());
        } finally {
            if (reporter.get() instanceof ConcurrentStoryReporter) {
                ((ConcurrentStoryReporter) reporter.get()).invokeDelayed();
            }
        }
    }
    return context.state();
}
Also used : ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper)

Example 34 with Story

use of org.jbehave.core.model.Story in project serenity-jbehave by serenity-bdd.

the class SerenityReporter method processExcludedByFilter.

public List<String> processExcludedByFilter(final Story story, final Set<String> exclude) {
    final Meta storyMeta = story.getMeta();
    final List<Scenario> processing = new LinkedList<>();
    final List<String> processed = new LinkedList<>();
    if (isSkipped(storyMeta) || isIgnored(storyMeta)) {
        // this story should be excluded by filter
        processing.addAll(story.getScenarios());
    } else {
        for (Scenario scenario : story.getScenarios()) {
            final Meta scenarioMeta = scenario.getMeta();
            if (isSkipped(scenarioMeta) || isIgnored(scenarioMeta)) {
                // this scenario should be excluded by filter
                processing.add(scenario);
            }
        }
    }
    if (processing.size() > 0) {
        final Story beforeStory = new Story();
        beforeStory.namedAs(BEFORE_STORIES);
        final Story afterStory = new Story();
        afterStory.namedAs(AFTER_STORIES);
        final Narrative narrative = story.getNarrative();
        beforeStory(beforeStory, false);
        afterStory(false);
        beforeStory(story, false);
        narrative(narrative);
        for (final Scenario filtered : processing) {
            final String scenarioKey = scenarioKey(story, filtered);
            if (!exclude.contains(scenarioKey)) {
                beforeScenario(filtered.getTitle());
                scenarioMeta(filtered.getMeta());
                final List<String> steps = filtered.getSteps();
                if (ExamplesTable.EMPTY == filtered.getExamplesTable() || filtered.getExamplesTable().getRows().size() == 0) {
                    for (final String step : steps) {
                        beforeStep(step);
                        successful(step);
                    }
                } else {
                    final ExamplesTable examples = filtered.getExamplesTable();
                    beforeExamples(steps, examples);
                    for (final Map<String, String> row : examples.getRows()) {
                        example(row);
                        for (final String step : steps) {
                            beforeStep(step);
                            successful(step);
                        }
                    }
                    afterExamples();
                }
                afterScenario();
                processed.add(scenarioKey(story, filtered));
            }
        }
        afterStory(false);
        beforeStory(afterStory, false);
        afterStory(false);
    }
    return processed;
}
Also used : Story(org.jbehave.core.model.Story)

Example 35 with Story

use of org.jbehave.core.model.Story in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldRunStoriesAsPathsInBatchIfBatchFlagIsSet.

@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesAsPathsInBatchIfBatchFlagIsSet() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls().doBatch(true);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    Configuration configuration = embedder.configuration();
    InjectableStepsFactory stepsFactory = embedder.stepsFactory();
    MetaFilter filter = embedder.metaFilter();
    StoryPathResolver resolver = configuration.storyPathResolver();
    List<String> storyPaths = new ArrayList<>();
    Map<String, Story> stories = new HashMap<>();
    for (Class<? extends Embeddable> embeddable : embeddables) {
        String storyPath = resolver.resolve(embeddable);
        storyPaths.add(storyPath);
        Story story = mockStory(Meta.EMPTY);
        stories.put(storyPath, story);
        when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
        when(story.getPath()).thenReturn(storyPath);
    }
    RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
    when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
    for (String storyPath : storyPaths) {
        doNothing().when(performableTree).perform(runContext, stories.get(storyPath));
    }
    // When
    embedder.runStoriesAsPaths(storyPaths);
    // Then
    for (String storyPath : storyPaths) {
        assertThat(out.toString(), containsString("Running story " + storyPath));
    }
}
Also used : PrintStream(java.io.PrintStream) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) StoryPathResolver(org.jbehave.core.io.StoryPathResolver) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) BatchFailures(org.jbehave.core.failures.BatchFailures) RunContext(org.jbehave.core.embedder.PerformableTree.RunContext) JUnitStory(org.jbehave.core.junit.JUnitStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Aggregations

Story (org.jbehave.core.model.Story)71 Test (org.junit.Test)58 Matchers.containsString (org.hamcrest.Matchers.containsString)41 GivenStory (org.jbehave.core.model.GivenStory)39 Scenario (org.jbehave.core.model.Scenario)29 Meta (org.jbehave.core.model.Meta)11 HashMap (java.util.HashMap)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 PrintStream (java.io.PrintStream)9 ArrayList (java.util.ArrayList)9 JUnitStory (org.jbehave.core.junit.JUnitStory)9 OutputStream (java.io.OutputStream)8 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)8 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)8 Configuration (org.jbehave.core.configuration.Configuration)8 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)8 BatchFailures (org.jbehave.core.failures.BatchFailures)8 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)8 Narrative (org.jbehave.core.model.Narrative)8 RunContext (org.jbehave.core.embedder.PerformableTree.RunContext)7