use of org.jbehave.core.failures.RestartingScenarioFailure in project jbehave-core by jbehave.
the class StoryNarrator method narrateAnInterestingStory.
static void narrateAnInterestingStory(StoryReporter reporter, boolean withFailure) {
Properties meta = new Properties();
meta.setProperty("theme", "testing");
meta.setProperty("author", "Mauro");
Lifecycle.Steps beforeScenarioSteps = new Lifecycle.Steps(Scope.SCENARIO, asList("Given a scenario step"));
Lifecycle.Steps beforeStorySteps = new Lifecycle.Steps(Scope.STORY, asList("Given a story step"));
Lifecycle.Steps afterScenarioSteps = new Lifecycle.Steps(Scope.SCENARIO, asList("Given a scenario step"));
Lifecycle.Steps afterStorySteps = new Lifecycle.Steps(Scope.STORY, asList("Given a story step"));
Lifecycle lifecycle = new Lifecycle(asList(beforeScenarioSteps, beforeStorySteps), asList(afterScenarioSteps, afterStorySteps));
Story story = new Story("/path/to/story", new Description("An interesting story & special chars"), new Meta(meta), new Narrative("renovate my house", "customer", "get a loan"), GivenStories.EMPTY, lifecycle, new ArrayList<Scenario>());
boolean givenStory = false;
reporter.beforeStory(story, givenStory);
reporter.dryRun();
reporter.narrative(story.getNarrative());
reporter.lifecyle(lifecycle);
reporter.beforeScenario(new Scenario("I ask for a loan", Meta.EMPTY));
reporter.beforeGivenStories();
reporter.givenStories(asList("/given/story1", "/given/story2"));
reporter.afterGivenStories();
reporter.successful("Given I have a balance of $50");
reporter.ignorable("!-- Then ignore me");
reporter.comment("!-- A comment");
reporter.successful("When I request $20");
reporter.successful("When I ask Liz for a loan of $100");
reporter.successful("When I ask Liz for a loan of $" + StepCreator.PARAMETER_VALUE_START + "99" + StepCreator.PARAMETER_VALUE_END);
reporter.successful("When I write special chars <>&\"");
reporter.successful("When I write special chars in parameter " + StepCreator.PARAMETER_VALUE_START + "<>&\"" + StepCreator.PARAMETER_VALUE_END);
reporter.successful("When I write two parameters " + StepCreator.PARAMETER_VALUE_START + ",,," + StepCreator.PARAMETER_VALUE_END + " and " + StepCreator.PARAMETER_VALUE_START + "&&&" + StepCreator.PARAMETER_VALUE_END);
reporter.restarted("Then I should... - try again", new RestartingScenarioFailure("hi"));
reporter.restartedStory(story, new RestartingStoryFailure("Restarted Story"));
reporter.storyCancelled(story, new StoryDuration(1).setDurationInSecs(2));
if (withFailure) {
reporter.failed("Then I should have a balance of $30", new UUIDExceptionWrapper(new Exception("Expected <30> got <25>")));
} else {
reporter.pending("Then I should have a balance of $30");
}
reporter.notPerformed("Then I should have $20");
OutcomesTable outcomesTable = new OutcomesTable(new LocalizedKeywords(), "dd/MM/yyyy");
outcomesTable.addOutcome("I don't return all", 100.0, equalTo(50.));
Date actualDate = dateFor("01/01/2011");
Date expectedDate = dateFor("02/01/2011");
outcomesTable.addOutcome("A wrong date", actualDate, new IsDateEqual(expectedDate, outcomesTable.getDateFormat()));
try {
outcomesTable.verify();
} catch (UUIDExceptionWrapper e) {
reporter.failedOutcomes("Then I don't return loan", ((OutcomesFailed) e.getCause()).outcomesTable());
}
reporter.afterScenario();
reporter.beforeScenario(new Scenario("Parametrised Scenario", Meta.EMPTY));
ExamplesTable table = new ExamplesTable("|money|to|\n|$30|Mauro|\n|$50|Paul|\n");
reporter.beforeExamples(asList("Given money <money>", "Then I give it to <to>"), table);
reporter.example(table.getRow(0));
reporter.successful("Given money $30");
reporter.successful("Then I give it to Mauro");
reporter.example(table.getRow(1));
reporter.successful("Given money $50");
reporter.successful("Then I give it to Paul");
if (withFailure) {
reporter.failed("Then I should have a balance of $30", new UUIDExceptionWrapper(new Exception("Expected <30> got <25>")));
} else {
reporter.pending("Then I should have a balance of $30");
}
reporter.afterExamples();
reporter.afterScenario();
String method1 = "@When(\"something \\\"$param\\\"\")\n" + "@Pending\n" + "public void whenSomething() {\n" + " // PENDING\n" + "}\n";
String method2 = "@Then(\"something is <param1>\")\n" + "@Pending\n" + "public void thenSomethingIsParam1() {\n" + " // PENDING\n" + "}\n";
reporter.pendingMethods(asList(method1, method2));
reporter.afterStory(givenStory);
}
use of org.jbehave.core.failures.RestartingScenarioFailure in project jbehave-core by jbehave.
the class StoryRunner method runStepsWhileKeepingState.
private void runStepsWhileKeepingState(RunContext context, List<Step> steps) throws InterruptedException {
if (steps == null || steps.size() == 0) {
return;
}
State state = context.state();
for (Step step : steps) {
try {
context.interruptIfCancelled();
state = state.run(step);
} catch (RestartingScenarioFailure e) {
reporter.get().restarted(step.toString(), e);
throw e;
}
}
context.stateIs(state);
}
Aggregations