use of org.jbehave.core.failures.UUIDExceptionWrapper 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();
}
use of org.jbehave.core.failures.UUIDExceptionWrapper in project jbehave-core by jbehave.
the class DelegatingStoryReporterBehaviour method shouldDelegateReporterEvents.
@Test
public void shouldDelegateReporterEvents() {
// Given
StoryReporter delegate = mock(StoryReporter.class);
DelegatingStoryReporter delegator = new DelegatingStoryReporter(delegate);
List<String> givenStoryPaths = asList("path/to/story1", "path/to/story2");
GivenStories givenStories = new GivenStories(StringUtils.join(givenStoryPaths, ","));
ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n");
UUIDExceptionWrapper anException = new UUIDExceptionWrapper(new IllegalArgumentException());
Story story = new Story();
boolean givenStory = false;
Scenario scenario = new Scenario();
String filter = "-some property";
// When
delegator.dryRun();
delegator.beforeStory(story, givenStory);
delegator.storyNotAllowed(story, filter);
delegator.beforeScenario(scenario);
delegator.beforeScenario("My scenario 1");
delegator.scenarioNotAllowed(scenario, filter);
delegator.scenarioMeta(Meta.EMPTY);
delegator.givenStories(givenStoryPaths);
delegator.givenStories(givenStories);
delegator.successful("Given step 1.1");
delegator.ignorable("!-- Then ignore me");
delegator.comment("!-- comment");
delegator.pending("When step 1.2");
delegator.notPerformed("Then step 1.3");
delegator.beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
delegator.example(examplesTable.getRow(0));
delegator.afterExamples();
delegator.afterScenario();
delegator.beforeScenario("My scenario 2");
delegator.successful("Given step 2.1");
delegator.successful("When step 2.2");
delegator.failed("Then step 2.3", anException);
delegator.afterScenario();
delegator.afterStory(givenStory);
// Then
assertThat(delegator.toString(), containsString(delegate.toString()));
InOrder inOrder = inOrder(delegate);
inOrder.verify(delegate).dryRun();
inOrder.verify(delegate).beforeStory(story, givenStory);
inOrder.verify(delegate).storyNotAllowed(story, filter);
inOrder.verify(delegate).beforeScenario(scenario);
inOrder.verify(delegate).beforeScenario("My scenario 1");
inOrder.verify(delegate).scenarioNotAllowed(scenario, filter);
inOrder.verify(delegate).scenarioMeta(Meta.EMPTY);
inOrder.verify(delegate).givenStories(givenStoryPaths);
inOrder.verify(delegate).givenStories(givenStories);
inOrder.verify(delegate).successful("Given step 1.1");
inOrder.verify(delegate).ignorable("!-- Then ignore me");
inOrder.verify(delegate).comment("!-- comment");
inOrder.verify(delegate).pending("When step 1.2");
inOrder.verify(delegate).notPerformed("Then step 1.3");
inOrder.verify(delegate).beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
inOrder.verify(delegate).example(examplesTable.getRow(0));
inOrder.verify(delegate).afterExamples();
inOrder.verify(delegate).afterScenario();
inOrder.verify(delegate).beforeScenario("My scenario 2");
inOrder.verify(delegate).successful("Given step 2.1");
inOrder.verify(delegate).successful("When step 2.2");
inOrder.verify(delegate).failed("Then step 2.3", anException);
inOrder.verify(delegate).afterScenario();
inOrder.verify(delegate).afterStory(givenStory);
}
use of org.jbehave.core.failures.UUIDExceptionWrapper in project jbehave-core by jbehave.
the class OutcomesTable method verify.
public void verify() {
boolean failed = false;
failedOutcomes.clear();
for (Outcome<?> outcome : outcomes) {
if (!outcome.isVerified()) {
failedOutcomes.add(outcome);
failed = true;
break;
}
}
if (failed) {
failureCause = new UUIDExceptionWrapper(new OutcomesFailed(this));
throw failureCause;
}
}
use of org.jbehave.core.failures.UUIDExceptionWrapper in project jbehave-core by jbehave.
the class StepCreatorBehaviour method shouldInjectExceptionThatHappenedIfTargetMethodExpectsIt.
@Test
public void shouldInjectExceptionThatHappenedIfTargetMethodExpectsIt() throws Exception {
// Given
SomeSteps stepsInstance = new SomeSteps();
parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
StepCreator stepCreator = stepCreatorUsing(stepsInstance, mock(StepMatcher.class), new ParameterControls());
// When
Step stepWithMeta = stepCreator.createBeforeOrAfterStep(SomeSteps.methodFor("aMethodThatExpectsUUIDExceptionWrapper"), mock(Meta.class));
UUIDExceptionWrapper occurredFailure = new UUIDExceptionWrapper();
StepResult stepResult = stepWithMeta.perform(occurredFailure);
// Then
assertThat(stepResult, instanceOf(Silent.class));
assertThat((UUIDExceptionWrapper) stepsInstance.args, is(occurredFailure));
}
use of org.jbehave.core.failures.UUIDExceptionWrapper in project jbehave-core by jbehave.
the class StepCreatorBehaviour method shouldInjectNoFailureIfNoExceptionHappenedAndTargetMethodExpectsIt.
@Test
public void shouldInjectNoFailureIfNoExceptionHappenedAndTargetMethodExpectsIt() throws Exception {
// Given
SomeSteps stepsInstance = new SomeSteps();
parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
StepCreator stepCreator = stepCreatorUsing(stepsInstance, mock(StepMatcher.class), new ParameterControls());
// When
Step stepWithMeta = stepCreator.createBeforeOrAfterStep(SomeSteps.methodFor("aMethodThatExpectsUUIDExceptionWrapper"), mock(Meta.class));
UUIDExceptionWrapper occurredFailure = new UUIDExceptionWrapper();
StepResult stepResult = stepWithMeta.perform(occurredFailure);
// Then
assertThat(stepResult, instanceOf(Silent.class));
assertThat((UUIDExceptionWrapper) stepsInstance.args, is(occurredFailure));
}
Aggregations