Search in sources :

Example 11 with UUIDExceptionWrapper

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();
}
Also used : ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper)

Example 12 with UUIDExceptionWrapper

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);
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) InOrder(org.mockito.InOrder) ExamplesTable(org.jbehave.core.model.ExamplesTable) Matchers.containsString(org.hamcrest.Matchers.containsString) Story(org.jbehave.core.model.Story) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 13 with UUIDExceptionWrapper

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;
    }
}
Also used : UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper)

Example 14 with UUIDExceptionWrapper

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));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) Meta(org.jbehave.core.model.Meta) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Silent(org.jbehave.core.steps.AbstractStepResult.Silent) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) TableTransformers(org.jbehave.core.model.TableTransformers) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 15 with UUIDExceptionWrapper

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));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) Meta(org.jbehave.core.model.Meta) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Silent(org.jbehave.core.steps.AbstractStepResult.Silent) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) TableTransformers(org.jbehave.core.model.TableTransformers) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Aggregations

UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)24 Test (org.junit.Test)18 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)7 Story (org.jbehave.core.model.Story)7 Properties (java.util.Properties)5 OutcomesTable (org.jbehave.core.model.OutcomesTable)5 OutcomesFailed (org.jbehave.core.model.OutcomesTable.OutcomesFailed)5 ExamplesTable (org.jbehave.core.model.ExamplesTable)4 Meta (org.jbehave.core.model.Meta)4 Scenario (org.jbehave.core.model.Scenario)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 GivenStories (org.jbehave.core.model.GivenStories)3 InOrder (org.mockito.InOrder)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)2 GivenStory (org.jbehave.core.model.GivenStory)2 TableTransformers (org.jbehave.core.model.TableTransformers)2 RegexStepMatcher (org.jbehave.core.parsers.RegexStepMatcher)2 StepMatcher (org.jbehave.core.parsers.StepMatcher)2