Search in sources :

Example 1 with GivenStory

use of org.jbehave.core.model.GivenStory 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 2 with GivenStory

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

the class RegexStoryParserBehaviour method shouldParseStoryWithScenarioContainingParametrisedGivenStories.

@Test
public void shouldParseStoryWithScenarioContainingParametrisedGivenStories() {
    String wholeStory = "GivenStories: path/to/one#{0}, path/to/two#{1}, path/to/three#{2}, path/to/four#{a}, path/to/five" + NL + NL + "Given a step" + NL + "Examples:" + NL + "|one|two|" + NL + "|11|12|" + NL + "|21|22|";
    Story story = parser.parseStory(wholeStory, storyPath);
    Scenario scenario = story.getScenarios().get(0);
    GivenStories givenStories = scenario.getGivenStories();
    assertThat(givenStories.asString(), equalTo("path/to/one#{0}, path/to/two#{1}, path/to/three#{2}, path/to/four#{a}, path/to/five"));
    assertThat(givenStories.toString(), containsString(givenStories.asString()));
    assertThat(givenStories.getPaths(), equalTo(asList(// matches first parameters row
    "path/to/one#{0}", // matches second parameters row
    "path/to/two#{1}", // does not match any parameters row
    "path/to/three#{2}", // does not use valid anchor (an int)
    "path/to/four#{a}", // does not require parameters
    "path/to/five")));
    assertThat(givenStories.requireParameters(), equalTo(true));
    GivenStory givenStory1 = givenStories.getStories().get(0);
    assertThat(givenStory1.hasAnchor(), equalTo(true));
    assertThat(givenStory1.getAnchor(), equalTo("0"));
    assertThat(givenStory1.getPath(), equalTo("path/to/one"));
    assertThat(givenStory1.getParameters().get("one"), equalTo("11"));
    assertThat(givenStory1.getParameters().get("two"), equalTo("12"));
    GivenStory givenStory2 = givenStories.getStories().get(1);
    assertThat(givenStory2.hasAnchor(), equalTo(true));
    assertThat(givenStory2.getAnchor(), equalTo("1"));
    assertThat(givenStory2.getPath(), equalTo("path/to/two"));
    assertThat(givenStory2.getParameters().get("one"), equalTo("21"));
    assertThat(givenStory2.getParameters().get("two"), equalTo("22"));
    GivenStory givenStory3 = givenStories.getStories().get(2);
    assertThat(givenStory3.hasAnchor(), equalTo(true));
    assertThat(givenStory3.getAnchor(), equalTo("2"));
    assertThat(givenStory3.getPath(), equalTo("path/to/three"));
    assertThat(givenStory3.getParameters().size(), equalTo(0));
    GivenStory givenStory4 = givenStories.getStories().get(3);
    assertThat(givenStory4.hasAnchor(), equalTo(true));
    assertThat(givenStory4.getAnchor(), equalTo("a"));
    assertThat(givenStory4.getPath(), equalTo("path/to/four"));
    assertThat(givenStory4.getParameters().size(), equalTo(0));
    GivenStory givenStory5 = givenStories.getStories().get(4);
    assertThat(givenStory5.hasAnchor(), equalTo(false));
    assertThat(givenStory5.getAnchor(), equalTo(EMPTY));
    assertThat(givenStory5.getPath(), equalTo("path/to/five"));
    assertThat(givenStory5.getParameters().size(), equalTo(0));
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) GivenStory(org.jbehave.core.model.GivenStory) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 3 with GivenStory

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

the class RegexStoryParserBehaviour method shouldParseStoryWithGivenStoriesWithAnchorParameters.

@Test
public void shouldParseStoryWithGivenStoriesWithAnchorParameters() {
    String wholeStory = "GivenStories: path1#{id1:scenario1;id2:scenario2}" + NL + "Scenario: A scenario" + NL + "Given a step";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getPath(), equalTo(storyPath));
    assertThat(story.getGivenStories().getStories().size(), equalTo(1));
    GivenStory givenStory = story.getGivenStories().getStories().get(0);
    assertThat(givenStory.hasAnchorParameters(), equalTo(true));
    Map<String, String> anchorParameters = givenStory.getAnchorParameters();
    assertThat(anchorParameters.size(), equalTo(2));
    assertThat(anchorParameters.get("id1"), equalTo("scenario1"));
    assertThat(anchorParameters.get("id2"), equalTo("scenario2"));
}
Also used : GivenStory(org.jbehave.core.model.GivenStory) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 4 with GivenStory

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

the class PrintStreamOutput method givenStories.

@Override
public void givenStories(GivenStories givenStories) {
    print(format("givenStoriesStart", "{0}\n", keywords.givenStories()));
    for (GivenStory givenStory : givenStories.getStories()) {
        print(format("givenStory", "{0}{1}\n", givenStory.asString(), (givenStory.hasAnchor() ? givenStory.getParameters() : "")));
    }
    print(format("givenStoriesEnd", NL));
}
Also used : GivenStory(org.jbehave.core.model.GivenStory)

Example 5 with GivenStory

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

the class StoryRunner method runGivenStories.

private void runGivenStories(GivenStories givenStories, Map<String, String> parameters, RunContext context) throws Throwable {
    if (givenStories.getPaths().size() > 0) {
        reporter.get().givenStories(givenStories);
        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());
            run(childContext, story, parameters);
        }
    }
}
Also used : GivenStory(org.jbehave.core.model.GivenStory) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story)

Aggregations

GivenStory (org.jbehave.core.model.GivenStory)5 Story (org.jbehave.core.model.Story)4 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 GivenStories (org.jbehave.core.model.GivenStories)1 Scenario (org.jbehave.core.model.Scenario)1