Search in sources :

Example 31 with Scenario

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

the class StoryMapperBehaviour method shouldMapStoriesAllowedByFilter.

@Test
public void shouldMapStoriesAllowedByFilter() throws Throwable {
    // Given
    Meta meta1 = mock(Meta.class, "meta1");
    Story story1 = new Story("/path/to/story1", Description.EMPTY, meta1, Narrative.EMPTY, asList(new Scenario("scenario1", meta1)));
    Meta meta2 = mock(Meta.class, "meta2");
    Story story2 = new Story("/path/to/story2", Description.EMPTY, meta2, Narrative.EMPTY, asList(new Scenario("scenario2", meta2)));
    MetaFilter filter = mock(MetaFilter.class);
    String filterAsString = "-some property";
    // When
    StoryMapper mapper = new StoryMapper();
    when(meta1.inheritFrom(meta1)).thenReturn(meta1);
    when(meta2.inheritFrom(meta2)).thenReturn(meta2);
    when(filter.allow(meta1)).thenReturn(false);
    when(filter.allow(meta2)).thenReturn(true);
    when(filter.asString()).thenReturn(filterAsString);
    mapper.map(story1, filter);
    mapper.map(story2, filter);
    // Then
    StoryMaps storyMaps = mapper.getStoryMaps();
    assertThat(storyMaps.getMaps().size(), equalTo(1));
    StoryMap storyMap = storyMaps.getMap(filterAsString);
    assertThat(storyMap.getMetaFilter(), equalTo(filterAsString));
    assertThat(storyMap.getStories().get(0).getPath(), equalTo(story2.getPath()));
    assertThat(storyMap.getStoryPaths(), equalTo(asList(story2.getPath())));
}
Also used : Meta(org.jbehave.core.model.Meta) StoryMap(org.jbehave.core.model.StoryMap) Story(org.jbehave.core.model.Story) StoryMaps(org.jbehave.core.model.StoryMaps) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 32 with Scenario

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

the class RegexStoryParser method parseScenario.

private Scenario parseScenario(String scenarioAsText) {
    String title = findScenarioTitle(scenarioAsText);
    String scenarioWithoutKeyword = removeStart(scenarioAsText, keywords.scenario()).trim();
    String scenarioWithoutTitle = removeStart(scenarioWithoutKeyword, title);
    scenarioWithoutTitle = startingWithNL(scenarioWithoutTitle);
    Meta meta = findScenarioMeta(scenarioWithoutTitle);
    ExamplesTable examplesTable = findExamplesTable(scenarioWithoutTitle);
    GivenStories givenStories = findScenarioGivenStories(scenarioWithoutTitle);
    if (givenStories.requireParameters()) {
        givenStories.useExamplesTable(examplesTable);
    }
    List<String> steps = findSteps(scenarioWithoutTitle);
    return new Scenario(title, meta, givenStories, examplesTable, steps);
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) Meta(org.jbehave.core.model.Meta) ExamplesTable(org.jbehave.core.model.ExamplesTable) Scenario(org.jbehave.core.model.Scenario)

Example 33 with Scenario

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

the class RegexStoryParser method parseStory.

public Story parseStory(String storyAsText, String storyPath) {
    Description description = parseDescriptionFrom(storyAsText);
    Meta meta = parseStoryMetaFrom(storyAsText);
    Narrative narrative = parseNarrativeFrom(storyAsText);
    GivenStories givenStories = parseGivenStories(storyAsText);
    Lifecycle lifecycle = parseLifecycle(storyAsText);
    List<Scenario> scenarios = parseScenariosFrom(storyAsText);
    Story story = new Story(storyPath, description, meta, narrative, givenStories, lifecycle, scenarios);
    if (storyPath != null) {
        story.namedAs(new File(storyPath).getName());
    }
    return story;
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) Meta(org.jbehave.core.model.Meta) Description(org.jbehave.core.model.Description) Narrative(org.jbehave.core.model.Narrative) Lifecycle(org.jbehave.core.model.Lifecycle) Story(org.jbehave.core.model.Story) File(java.io.File) Scenario(org.jbehave.core.model.Scenario)

Example 34 with Scenario

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

the class SilentSuccessFilterBehaviour method shouldNotPassSilentlyOutputNotAllowedByMetaFilter.

@Test
public void shouldNotPassSilentlyOutputNotAllowedByMetaFilter() {
    // Given
    Story story = new Story();
    Scenario scenario = new Scenario();
    String metaFilter = "";
    // When
    filter.storyNotAllowed(story, metaFilter);
    filter.scenarioNotAllowed(scenario, metaFilter);
    // Then
    InOrder inOrder = inOrder(delegate);
    inOrder.verify(delegate).storyNotAllowed(story, metaFilter);
    inOrder.verify(delegate).scenarioNotAllowed(scenario, metaFilter);
}
Also used : InOrder(org.mockito.InOrder) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 35 with Scenario

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

the class PerformableTree method performableStory.

private PerformableStory performableStory(RunContext context, Story story, Map<String, String> storyParameters) {
    PerformableStory performableStory = new PerformableStory(story, context.configuration().keywords(), context.givenStory());
    // determine if story is allowed
    boolean storyAllowed = true;
    FilteredStory filteredStory = context.filter(story);
    Meta storyMeta = story.getMeta();
    if (!filteredStory.allowed()) {
        storyAllowed = false;
    }
    performableStory.allowed(storyAllowed);
    if (storyAllowed) {
        performableStory.addBeforeSteps(context.beforeOrAfterStorySteps(story, Stage.BEFORE));
        performableStory.addBeforeSteps(context.lifecycleSteps(story.getLifecycle(), storyMeta, Stage.BEFORE, Scope.STORY));
        // determine if before and after scenario steps should be run
        boolean runBeforeAndAfterScenarioSteps = shouldRunBeforeOrAfterScenarioSteps(context);
        for (Scenario scenario : story.getScenarios()) {
            Map<String, String> scenarioParameters = new HashMap<>(storyParameters);
            PerformableScenario performableScenario = performableScenario(context, story, scenarioParameters, filteredStory, storyMeta, runBeforeAndAfterScenarioSteps, scenario);
            if (performableScenario.hasNormalScenario() || performableScenario.hasExamples()) {
                performableStory.add(performableScenario);
            }
        }
        // Add Given stories only if story contains scenarios
        if (!performableStory.getScenarios().isEmpty()) {
            Map<String, String> givenStoryParameters = new HashMap<>(storyParameters);
            addMetaParameters(givenStoryParameters, storyMeta);
            if (story.hasGivenStories()) {
                performableStory.addGivenStories(performableGivenStories(context, story.getGivenStories(), givenStoryParameters));
            }
        }
        performableStory.addAfterSteps(context.lifecycleSteps(story.getLifecycle(), storyMeta, Stage.AFTER, Scope.STORY));
        performableStory.addAfterSteps(context.beforeOrAfterStorySteps(story, Stage.AFTER));
    }
    return performableStory;
}
Also used : Meta(org.jbehave.core.model.Meta) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Scenario(org.jbehave.core.model.Scenario)

Aggregations

Scenario (org.jbehave.core.model.Scenario)35 Story (org.jbehave.core.model.Story)29 Test (org.junit.Test)27 Matchers.containsString (org.hamcrest.Matchers.containsString)20 GivenStory (org.jbehave.core.model.GivenStory)20 Meta (org.jbehave.core.model.Meta)9 ExamplesTable (org.jbehave.core.model.ExamplesTable)5 GivenStories (org.jbehave.core.model.GivenStories)5 Lifecycle (org.jbehave.core.model.Lifecycle)5 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)4 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)3 Narrative (org.jbehave.core.model.Narrative)3 InOrder (org.mockito.InOrder)3 HashMap (java.util.HashMap)2 ExamplePerformableScenario (org.jbehave.core.embedder.PerformableTree.ExamplePerformableScenario)2 PerformableScenario (org.jbehave.core.embedder.PerformableTree.PerformableScenario)2 Description (org.jbehave.core.model.Description)2 OutcomesTable (org.jbehave.core.model.OutcomesTable)2 Description (org.junit.runner.Description)2 File (java.io.File)1