Search in sources :

Example 11 with Configuration

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

the class StoryRunnerBehaviour method shouldRunScenarioAndLifecycleStepsInCorrectOrderWithExamplesTable.

@Test
public void shouldRunScenarioAndLifecycleStepsInCorrectOrderWithExamplesTable() throws Throwable {
    // Given
    ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n|3|4|\n");
    Map<String, String> tableRow1 = examplesTable.getRow(0);
    Map<String, String> tableRow2 = examplesTable.getRow(1);
    Scenario scenario1 = new Scenario("my title 1", Meta.EMPTY, GivenStories.EMPTY, examplesTable, asList("step <one>", "step <two>"));
    Story story = new Story(new Description("my blurb"), Narrative.EMPTY, asList(scenario1));
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    Configuration configuration = configurationWith(reporter, collector, failureStrategy);
    configuration.storyControls().doDryRun(true);
    CandidateSteps mySteps = new Steps(configuration);
    Step firstStep = mockSuccessfulStep("step <one>");
    Step secondStep = mockSuccessfulStep("step <two>");
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, tableRow1)).thenReturn(asList(firstStep, secondStep));
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, tableRow2)).thenReturn(asList(firstStep, secondStep));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
    givenBeforeAndAfterScenarioSteps(ScenarioType.NORMAL, collector, mySteps);
    givenBeforeAndAfterScenarioSteps(ScenarioType.ANY, collector, mySteps);
    givenBeforeAndAfterScenarioSteps(ScenarioType.EXAMPLE, collector, mySteps);
    givenLifecycleSteps(collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configuration, asList(mySteps), story);
    // Then
    InOrder inOrder = inOrder(reporter, failureStrategy);
    inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.NORMAL));
    inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.EXAMPLE));
    inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.ANY));
    inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.BEFORE));
    inOrder.verify(reporter).successful("step <one>");
    inOrder.verify(reporter).successful("step <two>");
    inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.AFTER));
    inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.ANY));
    inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.EXAMPLE));
    inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.EXAMPLE));
    inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.ANY));
    inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.BEFORE));
    inOrder.verify(reporter).successful("step <one>");
    inOrder.verify(reporter).successful("step <two>");
    inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.AFTER));
    inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.ANY));
    inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.EXAMPLE));
    inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.NORMAL));
}
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) Test(org.junit.Test)

Example 12 with Configuration

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

the class StoryRunnerBehaviour method shouldRunScenarioWithExamplesTable.

@Test
public void shouldRunScenarioWithExamplesTable() throws Throwable {
    // Given
    ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n");
    Map<String, String> tableRow = examplesTable.getRow(0);
    Scenario scenario1 = new Scenario("my title 1", Meta.EMPTY, GivenStories.EMPTY, examplesTable, asList("step <one>", "step <two>"));
    Story story = new Story(new Description("my blurb"), Narrative.EMPTY, asList(scenario1));
    Step step = mock(Step.class);
    StepResult result = mock(StepResult.class);
    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.storyControls().doDryRun(true);
    CandidateSteps mySteps = new Steps(configuration);
    Step firstStep = mockSuccessfulStep("step <one>");
    Step secondStep = mockSuccessfulStep("step <two>");
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, tableRow)).thenReturn(asList(firstStep, secondStep));
    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).successful("step <one>");
    inOrder.verify(reporter).successful("step <two>");
    inOrder.verify(reporter).afterScenario();
    inOrder.verify(reporter).afterStory(givenStory);
}
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 13 with Configuration

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

the class LocalizedKeywordsBehaviour method shouldAllowKeywordsToBeConfigured.

@Test
public void shouldAllowKeywordsToBeConfigured() {
    Configuration configuration = new MostUsefulConfiguration();
    ensureKeywordsAreLocalised(configuration, new Locale("en"));
    configuration.useKeywords(new LocalizedKeywords(new Locale("it")));
    ensureKeywordsAreLocalised(configuration, new Locale("it"));
}
Also used : Locale(java.util.Locale) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Test(org.junit.Test)

Example 14 with Configuration

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

the class ConfigurableEmbedderBehaviour method shouldAllowAdditionOfSteps.

@Test
public void shouldAllowAdditionOfSteps() 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(configuration, steps);
    story.useEmbedder(embedder);
    story.run();
    // Then
    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) Embedder(org.jbehave.core.embedder.Embedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 15 with Configuration

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

the class StepsBehaviour method shouldAllowLocalizationOfSteps.

@Test
public void shouldAllowLocalizationOfSteps() {
    Configuration configuration = new MostUsefulConfiguration();
    configuration.useKeywords(new LocalizedKeywords(new Locale("it")));
    LocalizedSteps steps = new LocalizedSteps(configuration);
    List<StepCandidate> candidates = steps.listCandidates();
    assertThat(candidates.size(), equalTo(3));
    findCandidate(candidates, "GIVEN un dato che").createMatchedStep("Dato che un dato che", tableRow).perform(null);
    findCandidate(candidates, "WHEN un quando").createMatchedStep("Quando un quando", tableRow).perform(null);
    findCandidate(candidates, "THEN un allora").createMatchedStep("Allora un allora", tableRow).perform(null);
    assertThat(steps.givens, equalTo(1));
    assertThat(steps.whens, equalTo(1));
    assertThat(steps.thens, equalTo(1));
}
Also used : Locale(java.util.Locale) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) 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