use of org.jbehave.core.model.Lifecycle in project jbehave-core by jbehave.
the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAfterUponOutcome.
@Test
public void shouldParseStoryWithLifecycleAfterUponOutcome() {
String wholeStory = "Lifecycle: " + NL + "After:" + NL + NL + "Outcome: ANY " + NL + "Given a step after any scenario" + NL + "Outcome: SUCCESS " + NL + "Given a step after successful scenario" + NL + "Outcome: FAILURE " + NL + "Given a step after failed scenario" + NL + "Scenario:" + NL + "Given a scenario";
Story story = parser.parseStory(wholeStory, storyPath);
List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
assertThat(beforeSteps.isEmpty(), equalTo(true));
Lifecycle lifecycle = story.getLifecycle();
List<String> afterSteps = lifecycle.getAfterSteps();
assertThat(afterSteps.get(0), equalTo("Given a step after any scenario"));
assertThat(afterSteps.get(1), equalTo("Given a step after successful scenario"));
assertThat(afterSteps.get(2), equalTo("Given a step after failed scenario"));
assertThat(lifecycle.getAfterSteps(Outcome.ANY).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.ANY).get(0), equalTo("Given a step after any scenario"));
assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).get(0), equalTo("Given a step after successful scenario"));
assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).get(0), equalTo("Given a step after failed scenario"));
Scenario scenario = story.getScenarios().get(0);
List<String> steps = scenario.getSteps();
assertThat(steps.get(0), equalTo("Given a scenario"));
}
use of org.jbehave.core.model.Lifecycle in project jbehave-core by jbehave.
the class RegexStoryParser method parseLifecycle.
private Lifecycle parseLifecycle(String storyAsText) {
String scenarioKeyword = keywords.scenario();
// use text before scenario keyword, if found
String beforeScenario = "";
if (StringUtils.contains(storyAsText, scenarioKeyword)) {
beforeScenario = StringUtils.substringBefore(storyAsText, scenarioKeyword);
}
Matcher findingLifecycle = findingLifecycle().matcher(beforeScenario);
String lifecycle = findingLifecycle.find() ? findingLifecycle.group(1).trim() : NONE;
Matcher findingBeforeAndAfter = compile(".*" + keywords.before() + "(.*)\\s*" + keywords.after() + "(.*)\\s*", DOTALL).matcher(lifecycle);
if (findingBeforeAndAfter.matches()) {
String beforeLifecycle = findingBeforeAndAfter.group(1).trim();
List<Steps> beforeSteps = parseBeforeLifecycle(beforeLifecycle);
String afterLifecycle = findingBeforeAndAfter.group(2).trim();
List<Steps> afterSteps = parseAfterLifecycle(afterLifecycle);
return new Lifecycle(beforeSteps, afterSteps);
}
Matcher findingBefore = compile(".*" + keywords.before() + "(.*)\\s*", DOTALL).matcher(lifecycle);
if (findingBefore.matches()) {
String beforeLifecycle = findingBefore.group(1).trim();
List<Steps> beforeSteps = parseBeforeLifecycle(beforeLifecycle);
return new Lifecycle(beforeSteps, Arrays.<Steps>asList());
}
Matcher findingAfter = compile(".*" + keywords.after() + "(.*)\\s*", DOTALL).matcher(lifecycle);
if (findingAfter.matches()) {
List<Steps> beforeSteps = asList();
String afterLifecycle = findingAfter.group(1).trim();
List<Steps> afterSteps = parseAfterLifecycle(afterLifecycle);
return new Lifecycle(beforeSteps, afterSteps);
}
return Lifecycle.EMPTY;
}
use of org.jbehave.core.model.Lifecycle in project jbehave-core by jbehave.
the class PerformableTree method performableScenario.
private PerformableScenario performableScenario(RunContext context, Story story, Map<String, String> storyParameters, FilteredStory filterContext, Meta storyMeta, boolean runBeforeAndAfterScenarioSteps, Scenario scenario) {
PerformableScenario performableScenario = new PerformableScenario(scenario, story.getPath());
// scenario also inherits meta from story
boolean scenarioAllowed = true;
if (failureOccurred(context) && context.configuration().storyControls().skipScenariosAfterFailure()) {
return performableScenario;
}
if (!filterContext.allowed(scenario)) {
scenarioAllowed = false;
}
performableScenario.allowed(scenarioAllowed);
if (scenarioAllowed) {
Lifecycle lifecycle = story.getLifecycle();
Meta storyAndScenarioMeta = scenario.getMeta().inheritFrom(storyMeta);
NormalPerformableScenario normalScenario = normalScenario(context, lifecycle, scenario, storyAndScenarioMeta, storyParameters);
// run before scenario steps, if allowed
if (runBeforeAndAfterScenarioSteps) {
normalScenario.addBeforeSteps(context.beforeOrAfterScenarioSteps(storyAndScenarioMeta, Stage.BEFORE, ScenarioType.NORMAL));
}
if (isParameterisedByExamples(scenario)) {
ExamplesTable table = scenario.getExamplesTable();
for (Map<String, String> scenarioParameters : table.getRows()) {
Meta exampleScenarioMeta = parameterMeta(context, scenarioParameters).inheritFrom(storyAndScenarioMeta);
boolean exampleScenarioAllowed = context.filter().allow(exampleScenarioMeta);
if (exampleScenarioAllowed) {
ExamplePerformableScenario exampleScenario = exampleScenario(context, lifecycle, scenario, storyAndScenarioMeta, scenarioParameters);
performableScenario.addExampleScenario(exampleScenario);
}
}
} else {
// plain old scenario
performableScenario.useNormalScenario(normalScenario);
}
// after scenario steps, if allowed
if (runBeforeAndAfterScenarioSteps) {
normalScenario.addAfterSteps(context.beforeOrAfterScenarioSteps(storyAndScenarioMeta, Stage.AFTER, ScenarioType.NORMAL));
}
}
return performableScenario;
}
use of org.jbehave.core.model.Lifecycle in project jbehave-core by jbehave.
the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAfterUponOutcomeAndMetaFilter.
@Test
public void shouldParseStoryWithLifecycleAfterUponOutcomeAndMetaFilter() {
String wholeStory = "Lifecycle: " + NL + "After:" + NL + NL + "Outcome: ANY " + NL + "MetaFilter: +all" + NL + "Given a step after any scenario" + NL + "Outcome: SUCCESS " + NL + "MetaFilter: +happy" + NL + "Given a step after successful scenario" + NL + "Outcome: FAILURE " + NL + "MetaFilter: +sad" + NL + "Given a step after failed scenario" + NL + "Scenario:" + NL + "Given a scenario";
Story story = parser.parseStory(wholeStory, storyPath);
List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
assertThat(beforeSteps.isEmpty(), equalTo(true));
Lifecycle lifecycle = story.getLifecycle();
List<String> afterSteps = lifecycle.getAfterSteps();
assertThat(afterSteps.get(0), equalTo("Given a step after any scenario"));
assertThat(afterSteps.get(1), equalTo("Given a step after successful scenario"));
assertThat(afterSteps.get(2), equalTo("Given a step after failed scenario"));
assertThat(new ArrayList<>(lifecycle.getOutcomes()), equalTo(Arrays.asList(Outcome.ANY, Outcome.SUCCESS, Outcome.FAILURE)));
assertThat(lifecycle.getAfterSteps(Outcome.ANY).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.ANY).get(0), equalTo("Given a step after any scenario"));
assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).get(0), equalTo("Given a step after successful scenario"));
assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).get(0), equalTo("Given a step after failed scenario"));
assertThat(lifecycle.getMetaFilter(Outcome.ANY).asString(), equalTo("+all"));
Keywords keywords = new Keywords();
assertThat(lifecycle.getAfterSteps(Outcome.ANY, Meta.createMeta("@all", keywords)).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.ANY, Meta.createMeta("@all", keywords)).get(0), equalTo("Given a step after any scenario"));
assertThat(lifecycle.getAfterSteps(Outcome.ANY, Meta.createMeta("@none", keywords)).size(), equalTo(0));
assertThat(lifecycle.getMetaFilter(Outcome.SUCCESS).asString(), equalTo("+happy"));
assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS, Meta.createMeta("@happy", keywords)).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS, Meta.createMeta("@happy", keywords)).get(0), equalTo("Given a step after successful scenario"));
assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS, Meta.createMeta("@none", keywords)).size(), equalTo(0));
assertThat(lifecycle.getMetaFilter(Outcome.FAILURE).asString(), equalTo("+sad"));
assertThat(lifecycle.getAfterSteps(Outcome.FAILURE, Meta.createMeta("@sad", keywords)).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.FAILURE, Meta.createMeta("@sad", keywords)).get(0), equalTo("Given a step after failed scenario"));
assertThat(lifecycle.getAfterSteps(Outcome.FAILURE, Meta.createMeta("@none", keywords)).size(), equalTo(0));
Scenario scenario = story.getScenarios().get(0);
List<String> steps = scenario.getSteps();
assertThat(steps.get(0), equalTo("Given a scenario"));
}
use of org.jbehave.core.model.Lifecycle in project jbehave-core by jbehave.
the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAfterUponOutcomeInNonEnglishLocale.
@Test
public void shouldParseStoryWithLifecycleAfterUponOutcomeInNonEnglishLocale() {
String wholeStory = "Lebenszyklus: " + NL + "Nach:" + NL + NL + "Ergebnis: JEDES " + NL + "Gegeben im Lager sind 200 T-Shirts" + NL + "Ergebnis: ERFOLG " + NL + "Gegeben im Lager sind 300 T-Shirts" + NL + "Ergebnis: FEHLER " + NL + "Gegeben im Lager sind 400 T-Shirts" + NL + "Szenario:" + NL + "Wenn ein Kunde 20 T-Shirts bestellt";
parser = new RegexStoryParser(new LocalizedKeywords(Locale.GERMAN), new LoadFromClasspath(), new TableTransformers());
Story story = parser.parseStory(wholeStory, storyPath);
List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
assertThat(beforeSteps.isEmpty(), equalTo(true));
Lifecycle lifecycle = story.getLifecycle();
List<String> afterSteps = lifecycle.getAfterSteps();
assertThat(afterSteps.get(0), equalTo("Gegeben im Lager sind 200 T-Shirts"));
assertThat(afterSteps.get(1), equalTo("Gegeben im Lager sind 300 T-Shirts"));
assertThat(afterSteps.get(2), equalTo("Gegeben im Lager sind 400 T-Shirts"));
assertThat(lifecycle.getAfterSteps(Outcome.ANY).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.ANY).get(0), equalTo("Gegeben im Lager sind 200 T-Shirts"));
assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).get(0), equalTo("Gegeben im Lager sind 300 T-Shirts"));
assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).size(), equalTo(1));
assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).get(0), equalTo("Gegeben im Lager sind 400 T-Shirts"));
Scenario scenario = story.getScenarios().get(0);
List<String> steps = scenario.getSteps();
assertThat(steps.get(0), equalTo("Wenn ein Kunde 20 T-Shirts bestellt"));
}
Aggregations