Search in sources :

Example 1 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldRunStoriesApplyingFilter.

@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesApplyingFilter() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls();
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    final StoryReporter storyReporter = mock(StoryReporter.class);
    Configuration configuration = new MostUsefulConfiguration() {

        @Override
        public StoryReporter storyReporter(String storyPath) {
            return storyReporter;
        }
    };
    embedder.useConfiguration(configuration);
    InjectableStepsFactory stepsFactory = embedder.stepsFactory();
    StoryPathResolver resolver = configuration.storyPathResolver();
    List<String> storyPaths = new ArrayList<>();
    Map<String, Story> stories = new HashMap<>();
    Meta meta = mock(Meta.class);
    for (Class<? extends Embeddable> embeddable : embeddables) {
        String storyPath = resolver.resolve(embeddable);
        storyPaths.add(storyPath);
        Story story = mockStory(Meta.EMPTY);
        when(story.getMeta()).thenReturn(meta);
        stories.put(storyPath, story);
        when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
        when(story.getPath()).thenReturn(storyPath);
        assertThat(configuration.storyReporter(storyPath), sameInstance(storyReporter));
    }
    // When
    MetaFilter filter = mock(MetaFilter.class);
    when(filter.allow(meta)).thenReturn(false);
    RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
    when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
    embedder.runStoriesAsPaths(storyPaths);
    // Then
    for (String storyPath : storyPaths) {
        verify(performableTree, never()).perform(runContext, stories.get(storyPath));
    }
    assertThatReportsViewGenerated(out);
    assertThat(embedder.hasExecutorService(), is(false));
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) Meta(org.jbehave.core.model.Meta) StoryPathResolver(org.jbehave.core.io.StoryPathResolver) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) HashMap(java.util.HashMap) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) Matchers.containsString(org.hamcrest.Matchers.containsString) JUnitStory(org.jbehave.core.junit.JUnitStory) Story(org.jbehave.core.model.Story) PrintStream(java.io.PrintStream) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BatchFailures(org.jbehave.core.failures.BatchFailures) RunContext(org.jbehave.core.embedder.PerformableTree.RunContext) Test(org.junit.Test)

Example 2 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldNotRunScenariosNotAllowedByFilter.

@Test
public void shouldNotRunScenariosNotAllowedByFilter() 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());
    Meta meta = new Meta(asList("some property"));
    Story story = new Story("", Description.EMPTY, Meta.EMPTY, Narrative.EMPTY, asList(new Scenario("", meta, GivenStories.EMPTY, ExamplesTable.EMPTY, asList(""))));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
    String filterAsString = "-some property";
    MetaFilter filter = new MetaFilter(filterAsString);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWith(reporter, collector, strategy), asList(mySteps), story, filter);
    // Then
    verify(reporter).beforeStory(story, givenStory);
    verify(reporter).beforeScenario("");
    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) Test(org.junit.Test)

Example 3 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldNotPerformStepsAfterFailedOrPendingSteps.

@Test
public void shouldNotPerformStepsAfterFailedOrPendingSteps() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step firstStepNormal = mockSuccessfulStep("Given I succeed");
    Step secondStepPending = mock(Step.class, "secondStepPending");
    Step thirdStepNormal = mock(Step.class, "thirdStepNormal");
    Step fourthStepAlsoPending = mock(Step.class, "fourthStepAlsoPending");
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Scenario scenario = new Scenario();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), eq(scenario), eq(parameters))).thenReturn(asList(firstStepNormal, secondStepPending, thirdStepNormal, fourthStepAlsoPending));
    when(secondStepPending.perform(null)).thenReturn(pending("When I am pending"));
    when(thirdStepNormal.doNotPerform(Matchers.<UUIDExceptionWrapper>any())).thenReturn(notPerformed("Then I should not be performed"));
    when(fourthStepAlsoPending.doNotPerform(Matchers.<UUIDExceptionWrapper>any())).thenReturn(notPerformed("Then I should not be performed either"));
    Story story = new Story(asList(scenario));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWith(reporter, collector), asList(mySteps), story);
    // Then
    verify(firstStepNormal).perform(null);
    verify(secondStepPending).perform(null);
    verify(thirdStepNormal).doNotPerform(Matchers.<UUIDExceptionWrapper>any());
    verify(fourthStepAlsoPending).doNotPerform(Matchers.<UUIDExceptionWrapper>any());
    verify(reporter).successful("Given I succeed");
    verify(reporter).pending("When I am pending");
    verify(reporter).notPerformed("Then I should not be performed");
    verify(reporter).notPerformed("Then I should not be performed either");
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) Test(org.junit.Test)

Example 4 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldReportAnyFailuresAndHandleThemAfterStory.

@Test
public void shouldReportAnyFailuresAndHandleThemAfterStory() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step firstStepExceptional = mock(Step.class);
    Step secondStepNotPerformed = mock(Step.class);
    StepResult failed = failed("When I fail", new UUIDExceptionWrapper(new IllegalStateException()));
    StepResult notPerformed = notPerformed("Then I should not be performed");
    when(firstStepExceptional.perform(null)).thenReturn(failed);
    when(secondStepNotPerformed.doNotPerform(Matchers.<UUIDExceptionWrapper>any())).thenReturn(notPerformed);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Scenario scenario = new Scenario();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), eq(scenario), eq(parameters))).thenReturn(asList(firstStepExceptional, secondStepNotPerformed));
    Story story = new Story(asList(scenario));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWith(reporter, collector, failureStrategy), asList(mySteps), story);
    // Then
    verify(firstStepExceptional).perform(null);
    verify(secondStepNotPerformed).doNotPerform(Matchers.<UUIDExceptionWrapper>any());
    InOrder inOrder = inOrder(reporter, failureStrategy);
    inOrder.verify(reporter).beforeStory((Story) anyObject(), eq(givenStory));
    inOrder.verify(reporter).beforeScenario((String) anyObject());
    inOrder.verify(reporter).failed("When I fail", failed.getFailure());
    inOrder.verify(reporter).notPerformed("Then I should not be performed");
    inOrder.verify(reporter).afterScenario();
    inOrder.verify(reporter).afterStory(givenStory);
    inOrder.verify(failureStrategy).handleFailure(failed.getFailure());
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) InOrder(org.mockito.InOrder) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) AbstractStepResult(org.jbehave.core.steps.AbstractStepResult) Test(org.junit.Test)

Example 5 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldRunStepsInStoryAndReportResultsToReporter.

@Test
public void shouldRunStepsInStoryAndReportResultsToReporter() 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));
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    UUIDExceptionWrapper failure = new UUIDExceptionWrapper(new IllegalArgumentException());
    Step pendingStep = mock(Step.class, "pendingStep");
    Step successfulStep = mock(Step.class, "successfulStep");
    Step failingStep = mock(Step.class, "failingStep");
    when(successfulStep.perform(Matchers.<UUIDExceptionWrapper>any())).thenReturn(successful("successfulStep"));
    when(successfulStep.doNotPerform(failure)).thenReturn(notPerformed("successfulStep"));
    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));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);
    // When
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWith(reporter, collector, failureStrategy), asList(mySteps), story);
    // Then
    InOrder inOrder = inOrder(reporter, failureStrategy);
    inOrder.verify(reporter).beforeStory(story, false);
    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(false);
    inOrder.verify(failureStrategy).handleFailure(failure);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) InOrder(org.mockito.InOrder) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) Test(org.junit.Test)

Aggregations

StoryReporter (org.jbehave.core.reporters.StoryReporter)32 Test (org.junit.Test)32 ConcurrentStoryReporter (org.jbehave.core.reporters.ConcurrentStoryReporter)24 AbstractStep (org.jbehave.core.steps.StepCreator.AbstractStep)19 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)16 Configuration (org.jbehave.core.configuration.Configuration)15 AbstractStepResult (org.jbehave.core.steps.AbstractStepResult)10 InOrder (org.mockito.InOrder)8 Method (java.lang.reflect.Method)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)2 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)2 RunContext (org.jbehave.core.embedder.PerformableTree.RunContext)2 BatchFailures (org.jbehave.core.failures.BatchFailures)2 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)2