Search in sources :

Example 41 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldNotRunScenariosNotAllowedByFilterOnScenarioElement.

@Test
public void shouldNotRunScenariosNotAllowedByFilterOnScenarioElement() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy strategy = mock(FailureStrategy.class);
    CandidateSteps mySteps = new Steps();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), (Scenario) anyObject(), eq(parameters))).thenReturn(Arrays.<Step>asList());
    Story story = new Story("", Description.EMPTY, Meta.EMPTY, Narrative.EMPTY, asList(new Scenario("excluded_title", Meta.EMPTY, GivenStories.EMPTY, ExamplesTable.EMPTY, asList(""))));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
    String filterAsString = "-scenario_title excluded_title";
    MetaFilter filter = new MetaFilter(filterAsString);
    // When
    StoryRunner runner = new StoryRunner();
    Configuration configuration = configurationWith(reporter, collector, strategy);
    configuration.storyControls().useScenarioMetaPrefix("scenario_");
    runner.run(configuration, asList(mySteps), story, filter);
    // Then
    verify(reporter).beforeStory(story, givenStory);
    verify(reporter).beforeScenario("excluded_title");
    verify(reporter).scenarioNotAllowed(story.getScenarios().get(0), filterAsString);
    verify(reporter).afterScenario();
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Test(org.junit.Test)

Example 42 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldReportStoryCancellation.

@Test
public void shouldReportStoryCancellation() {
    // Given
    Configuration configuration = mock(Configuration.class, Mockito.RETURNS_DEEP_STUBS);
    when(configuration.storyControls().dryRun()).thenReturn(false);
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    when(configuration.storyReporter(Matchers.anyString())).thenReturn(reporter);
    Story story = mock(Story.class);
    String storyPath = "story/path";
    when(story.getPath()).thenReturn(storyPath);
    RuntimeException expected = new RuntimeException();
    when(story.getMeta()).thenThrow(expected);
    InjectableStepsFactory stepsFactory = mock(InjectableStepsFactory.class);
    MetaFilter metaFilter = mock(MetaFilter.class);
    State state = mock(State.class);
    // When
    long durationInSecs = 2;
    long timeoutInSecs = 1;
    StoryDuration storyDuration = new StoryDuration(timeoutInSecs);
    try {
        StoryRunner runner = new StoryRunner();
        runner.cancelStory(story, storyDuration);
        runner.run(configuration, stepsFactory, story, metaFilter, state);
        throw new AssertionError("A exception should be thrown");
    } catch (Throwable e) {
        // Then
        assertThat(e.equals(expected), is(true));
    }
    verify(reporter).storyCancelled(story, storyDuration);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) State(org.jbehave.core.embedder.StoryRunner.State) Test(org.junit.Test)

Example 43 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldRunStepsInDryRunMode.

@Test
public void shouldRunStepsInDryRunMode() throws Throwable {
    // Given
    Scenario scenario1 = new Scenario("my title 1", asList("failingStep", "successfulStep"));
    Scenario scenario2 = new Scenario("my title 2", asList("successfulStep"));
    Scenario scenario3 = new Scenario("my title 3", asList("successfulStep", "pendingStep"));
    Story story = new Story(new Description("my blurb"), Narrative.EMPTY, asList(scenario1, scenario2, scenario3));
    Step step = mock(Step.class);
    StepResult result = mock(StepResult.class, "result");
    when(step.perform(null)).thenReturn(result);
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    Configuration configuration = configurationWith(reporter, collector, failureStrategy);
    configuration.doDryRun(true);
    CandidateSteps mySteps = new Steps(configuration);
    UUIDExceptionWrapper failure = new UUIDExceptionWrapper(new IllegalArgumentException());
    Step successfulStep = mockSuccessfulStep("successfulStep");
    Step pendingStep = mock(Step.class, "pendingStep");
    Step failingStep = mock(Step.class, "failingStep");
    when(pendingStep.perform(Matchers.<UUIDExceptionWrapper>any())).thenReturn(pending("pendingStep"));
    when(pendingStep.doNotPerform(failure)).thenReturn(pending("pendingStep"));
    when(failingStep.perform(Matchers.<UUIDExceptionWrapper>any())).thenReturn(failed("failingStep", failure));
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, parameters)).thenReturn(asList(failingStep, successfulStep));
    when(collector.collectScenarioSteps(asList(mySteps), scenario2, parameters)).thenReturn(asList(successfulStep));
    when(collector.collectScenarioSteps(asList(mySteps), scenario3, parameters)).thenReturn(asList(successfulStep, pendingStep));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configuration, asList(mySteps), story);
    // Then
    InOrder inOrder = inOrder(reporter, failureStrategy);
    inOrder.verify(reporter).beforeStory(story, givenStory);
    inOrder.verify(reporter).beforeScenario("my title 1");
    inOrder.verify(reporter).failed("failingStep", failure);
    inOrder.verify(reporter).notPerformed("successfulStep");
    inOrder.verify(reporter).afterScenario();
    inOrder.verify(reporter).beforeScenario("my title 2");
    inOrder.verify(reporter).successful("successfulStep");
    inOrder.verify(reporter).afterScenario();
    inOrder.verify(reporter).beforeScenario("my title 3");
    inOrder.verify(reporter).successful("successfulStep");
    inOrder.verify(reporter).pending("pendingStep");
    inOrder.verify(reporter).afterScenario();
    inOrder.verify(reporter).afterStory(givenStory);
    inOrder.verify(failureStrategy).handleFailure(failure);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) InOrder(org.mockito.InOrder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) AbstractStepResult(org.jbehave.core.steps.AbstractStepResult) Test(org.junit.Test)

Example 44 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class ConfigurableEmbedderBehaviour method shouldRunMultipleStories.

@Test
public void shouldRunMultipleStories() throws Throwable {
    // Given
    Embedder embedder = mock(Embedder.class);
    Configuration configuration = mock(Configuration.class);
    CandidateSteps steps = mock(CandidateSteps.class);
    // When
    MyStories story = new MyStories(configuration, steps);
    story.useEmbedder(embedder);
    story.run();
    // Then
    verify(embedder).runStoriesAsPaths(asList("org/jbehave/core/story1", "org/jbehave/core/story2"));
}
Also used : MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) Embedder(org.jbehave.core.embedder.Embedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 45 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class ConfigurableEmbedderBehaviour method shouldAllowOverrideOfDefaultConfiguration.

@Test
public void shouldAllowOverrideOfDefaultConfiguration() throws Throwable {
    // Given
    Embedder embedder = mock(Embedder.class);
    Configuration configuration = mock(Configuration.class);
    StoryPathResolver pathResolver = mock(StoryPathResolver.class);
    when(embedder.configuration()).thenReturn(configuration);
    when(configuration.storyPathResolver()).thenReturn(pathResolver);
    Class<MyStory> storyClass = MyStory.class;
    String storyPath = "/path/to/story";
    when(pathResolver.resolve(storyClass)).thenReturn(storyPath);
    CandidateSteps steps = mock(CandidateSteps.class);
    // When
    MyStory story = new MyStory(new MostUsefulConfiguration(), steps);
    assertThat(story.configuration(), is(not(sameInstance(configuration))));
    story.useConfiguration(configuration);
    assertThat(story.configuration(), is(sameInstance(configuration)));
    story.useEmbedder(embedder);
    story.run();
    // Then
    verify(embedder).useConfiguration(configuration);
    verify(embedder).useCandidateSteps(Mockito.eq(Arrays.asList(steps)));
    verify(embedder).runStoriesAsPaths(asList(storyPath));
}
Also used : StoryPathResolver(org.jbehave.core.io.StoryPathResolver) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Aggregations

Configuration (org.jbehave.core.configuration.Configuration)64 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)61 Test (org.junit.Test)55 AnnotationBuilder (org.jbehave.core.configuration.AnnotationBuilder)18 StoryReporter (org.jbehave.core.reporters.StoryReporter)15 ConcurrentStoryReporter (org.jbehave.core.reporters.ConcurrentStoryReporter)13 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 OutputStream (java.io.OutputStream)10 PrintStream (java.io.PrintStream)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)10 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)10 AbstractStep (org.jbehave.core.steps.StepCreator.AbstractStep)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 JUnitStory (org.jbehave.core.junit.JUnitStory)8 Story (org.jbehave.core.model.Story)8 SimpleDateFormat (java.text.SimpleDateFormat)7 RunContext (org.jbehave.core.embedder.PerformableTree.RunContext)7