Search in sources :

Example 1 with ExamplesTable

use of org.jbehave.core.model.ExamplesTable in project jbehave-core by jbehave.

the class TableSteps method thenTheTransformedTableIs.

@Then("the table transformed by $transformer is: $table")
public void thenTheTransformedTableIs(String transformer, String table) {
    ExamplesTableProperties properties = new ExamplesTableProperties(new ExamplesTable(this.table).getProperties());
    String transformed = this.transformers.transform(transformer, this.table, properties);
    MatcherAssert.assertThat(transformed.trim(), Matchers.equalTo(table));
}
Also used : ExamplesTableProperties(org.jbehave.core.model.ExamplesTableProperties) ExamplesTable(org.jbehave.core.model.ExamplesTable) Then(org.jbehave.core.annotations.Then)

Example 2 with ExamplesTable

use of org.jbehave.core.model.ExamplesTable in project jbehave-core by jbehave.

the class ParameterConvertersBehaviour method shouldConvertMultilineTable.

@Test
public void shouldConvertMultilineTable() {
    ParameterConverter<ExamplesTable> converter = new ExamplesTableConverter(new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers()));
    Type type = ExamplesTable.class;
    assertThatTypesAreAccepted(converter, type);
    String value = "|col1|col2|\n|row11|row12|\n|row21|row22|\n";
    ExamplesTable table = converter.convertValue(value, type);
    assertThat(table.getRowCount(), is(2));
    Map<String, String> row1 = table.getRow(0);
    assertThat(row1.get("col1"), is("row11"));
    assertThat(row1.get("col2"), is("row12"));
    Map<String, String> row2 = table.getRow(1);
    assertThat(row2.get("col1"), is("row21"));
    assertThat(row2.get("col2"), is("row22"));
}
Also used : Type(java.lang.reflect.Type) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) ExamplesTable(org.jbehave.core.model.ExamplesTable) ExamplesTableFactory(org.jbehave.core.model.ExamplesTableFactory) ExamplesTableConverter(org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 3 with ExamplesTable

use of org.jbehave.core.model.ExamplesTable in project jbehave-core by jbehave.

the class PostStoryStatisticsCollectorBehaviour method narrateAnInterestingStory.

private void narrateAnInterestingStory() {
    Story story = new Story("/path/to/story", new Description("An interesting story"), new Narrative("renovate my house", "customer", "get a loan"), new ArrayList<Scenario>());
    reporter.dryRun();
    // begin story
    reporter.beforeStory(story, false);
    // 1st scenario
    reporter.beforeScenario(new Scenario("I ask for a loan", Meta.EMPTY));
    reporter.givenStories(asList("path/to/story1", "path/to/story2"));
    // 1st given story
    reporter.beforeStory(story, true);
    reporter.beforeScenario(new Scenario("a scenario without steps", Meta.EMPTY));
    reporter.afterScenario();
    reporter.afterStory(true);
    // 2nd given story
    reporter.beforeStory(story, true);
    reporter.beforeScenario(new Scenario("the bank has $300 to loan", Meta.EMPTY));
    reporter.givenStories(asList("path/to/nested/story1"));
    reporter.beforeStory(story, true);
    reporter.beforeScenario(new Scenario("initialise static", Meta.EMPTY));
    reporter.successful("the bank has customers");
    reporter.afterScenario();
    reporter.afterStory(true);
    reporter.afterScenario();
    reporter.afterStory(true);
    reporter.successful("Given I have a balance of $50");
    reporter.ignorable("!-- Then ignore me");
    reporter.comment("!-- A comment");
    reporter.successful("When I request $20");
    reporter.successful("When I ask Liz for a loan of $100");
    reporter.afterScenario();
    // 2nd scenario
    reporter.beforeScenario(new Scenario("A failing scenario", Meta.EMPTY));
    OutcomesTable outcomesTable = new OutcomesTable();
    outcomesTable.addOutcome("I don't return all", 100.0, equalTo(50.));
    try {
        outcomesTable.verify();
    } catch (UUIDExceptionWrapper e) {
        reporter.failedOutcomes("Then I don't return loan", ((OutcomesFailed) e.getCause()).outcomesTable());
    }
    reporter.notPerformed("Then I should have $20");
    ExamplesTable table = new ExamplesTable("|money|to|\n|$30|Mauro|\n|$50|Paul|\n");
    reporter.beforeExamples(asList("Given money <money>", "Then I give it to <to>"), table);
    reporter.example(table.getRow(0));
    reporter.example(table.getRow(1));
    reporter.afterExamples();
    reporter.afterScenario();
    // 3rd scenario
    reporter.beforeScenario(new Scenario("A pending scenario", Meta.EMPTY));
    reporter.pending("When I have some money");
    reporter.notPerformed("Then I should have $20");
    reporter.afterScenario();
    // end story
    reporter.afterStory(false);
}
Also used : Description(org.jbehave.core.model.Description) OutcomesFailed(org.jbehave.core.model.OutcomesTable.OutcomesFailed) Narrative(org.jbehave.core.model.Narrative) ExamplesTable(org.jbehave.core.model.ExamplesTable) Story(org.jbehave.core.model.Story) OutcomesTable(org.jbehave.core.model.OutcomesTable) Scenario(org.jbehave.core.model.Scenario) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper)

Example 4 with ExamplesTable

use of org.jbehave.core.model.ExamplesTable in project jbehave-core by jbehave.

the class SilentSuccessFilterBehaviour method shouldPassSilentlyOutputFromSuccessfulScenarios.

@Test
public void shouldPassSilentlyOutputFromSuccessfulScenarios() {
    // Given
    ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n");
    UUIDExceptionWrapper anException = new UUIDExceptionWrapper(new IllegalArgumentException());
    Story story = new Story();
    GivenStories givenStories = new GivenStories("path/to/story1,path/to/story2");
    List<String> givenStoryPaths = asList("path/to/story1", "path/to/story2");
    // When
    Scenario scenario1 = new Scenario("My scenario 1", Meta.EMPTY);
    filter.dryRun();
    filter.beforeStory(story, false);
    filter.beforeScenario(scenario1);
    filter.scenarioMeta(Meta.EMPTY);
    filter.successful("Given step 1.1");
    filter.ignorable("!-- Then ignore me");
    filter.comment("!-- A comment");
    filter.successful("When step 1.2");
    filter.successful("Then step 1.3");
    filter.afterScenario();
    Scenario scenario2 = new Scenario("My scenario 2", Meta.EMPTY);
    filter.beforeScenario(scenario2);
    filter.givenStories(givenStories);
    filter.givenStories(givenStoryPaths);
    filter.successful("Given step 2.1");
    filter.pending("When step 2.2");
    filter.notPerformed("Then step 2.3");
    filter.afterScenario();
    Scenario scenario3 = new Scenario("My scenario 3", Meta.EMPTY);
    filter.beforeScenario(scenario3);
    filter.beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
    Map<String, String> tableRow = new HashMap<>();
    filter.example(tableRow);
    filter.successful("Given step 3.1");
    filter.successful("When step 3.2");
    filter.ignorable("!-- Then ignore me too");
    filter.comment("!-- One more comment");
    filter.failed("Then step 3.3", anException);
    OutcomesTable outcomesTable = new OutcomesTable();
    filter.failedOutcomes("When failed outcomes", outcomesTable);
    filter.afterExamples();
    filter.afterScenario();
    Scenario scenario4 = new Scenario("My scenario 4", Meta.EMPTY);
    filter.beforeScenario(scenario4);
    filter.successful("Given step 4.1");
    filter.successful("When step 4.2");
    filter.successful("Then step 4.3");
    filter.afterScenario();
    filter.afterStory(false);
    // Then
    InOrder inOrder = inOrder(delegate);
    // Scenarios 1 and 4 are successful
    verify(delegate, never()).beforeScenario(scenario1);
    verify(delegate, never()).successful("Given step 1.1");
    verify(delegate, never()).ignorable("!-- Then ignore me");
    verify(delegate, never()).comment("!-- A comment");
    verify(delegate, never()).successful("When step 1.2");
    verify(delegate, never()).successful("Then step 1.3");
    verify(delegate, never()).beforeScenario(scenario4);
    verify(delegate, never()).successful("Given step 4.1");
    verify(delegate, never()).successful("When step 4.2");
    verify(delegate, never()).successful("Then step 4.3");
    // Scenarios 2 and 3 have pending or failed steps
    inOrder.verify(delegate).dryRun();
    inOrder.verify(delegate).beforeStory(story, false);
    inOrder.verify(delegate).beforeScenario(scenario2);
    inOrder.verify(delegate).givenStories(givenStories);
    inOrder.verify(delegate).givenStories(givenStoryPaths);
    inOrder.verify(delegate).successful("Given step 2.1");
    inOrder.verify(delegate).pending("When step 2.2");
    inOrder.verify(delegate).notPerformed("Then step 2.3");
    inOrder.verify(delegate).afterScenario();
    inOrder.verify(delegate).beforeScenario(scenario3);
    inOrder.verify(delegate).beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
    inOrder.verify(delegate).example(tableRow);
    inOrder.verify(delegate).successful("Given step 3.1");
    inOrder.verify(delegate).successful("When step 3.2");
    inOrder.verify(delegate).ignorable("!-- Then ignore me too");
    inOrder.verify(delegate).comment("!-- One more comment");
    inOrder.verify(delegate).failed("Then step 3.3", anException);
    inOrder.verify(delegate).failedOutcomes("When failed outcomes", outcomesTable);
    inOrder.verify(delegate).afterExamples();
    inOrder.verify(delegate).afterScenario();
    inOrder.verify(delegate).afterStory(false);
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) InOrder(org.mockito.InOrder) HashMap(java.util.HashMap) ExamplesTable(org.jbehave.core.model.ExamplesTable) Story(org.jbehave.core.model.Story) OutcomesTable(org.jbehave.core.model.OutcomesTable) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 5 with ExamplesTable

use of org.jbehave.core.model.ExamplesTable in project jbehave-core by jbehave.

the class SilentSuccessFilterBehaviour method shouldPassSilentlyOutputFromSuccessfulScenariosWithDeprecatedBeforeScenario.

@Test
public void shouldPassSilentlyOutputFromSuccessfulScenariosWithDeprecatedBeforeScenario() {
    // Given
    ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n");
    UUIDExceptionWrapper anException = new UUIDExceptionWrapper(new IllegalArgumentException());
    Story story = new Story();
    GivenStories givenStories = new GivenStories("path/to/story1,path/to/story2");
    List<String> givenStoryPaths = asList("path/to/story1", "path/to/story2");
    // When
    filter.dryRun();
    filter.beforeStory(story, false);
    filter.beforeScenario("My scenario 1");
    filter.scenarioMeta(Meta.EMPTY);
    filter.successful("Given step 1.1");
    filter.ignorable("!-- Then ignore me");
    filter.comment("!-- A comment");
    filter.successful("When step 1.2");
    filter.successful("Then step 1.3");
    filter.afterScenario();
    filter.beforeScenario("My scenario 2");
    filter.givenStories(givenStories);
    filter.givenStories(givenStoryPaths);
    filter.successful("Given step 2.1");
    filter.pending("When step 2.2");
    filter.notPerformed("Then step 2.3");
    filter.afterScenario();
    filter.beforeScenario("My scenario 3");
    filter.beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
    Map<String, String> tableRow = new HashMap<>();
    filter.example(tableRow);
    filter.successful("Given step 3.1");
    filter.successful("When step 3.2");
    filter.ignorable("!-- Then ignore me too");
    filter.comment("!-- One more comment");
    filter.failed("Then step 3.3", anException);
    OutcomesTable outcomesTable = new OutcomesTable();
    filter.failedOutcomes("When failed outcomes", outcomesTable);
    filter.afterExamples();
    filter.afterScenario();
    filter.beforeScenario("My scenario 4");
    filter.successful("Given step 4.1");
    filter.successful("When step 4.2");
    filter.successful("Then step 4.3");
    filter.afterScenario();
    filter.afterStory(false);
    // Then
    InOrder inOrder = inOrder(delegate);
    // Scenarios 1 and 4 are successful
    verify(delegate, never()).beforeScenario("My scenario 1");
    verify(delegate, never()).successful("Given step 1.1");
    verify(delegate, never()).ignorable("!-- Then ignore me");
    verify(delegate, never()).comment("!-- A comment");
    verify(delegate, never()).successful("When step 1.2");
    verify(delegate, never()).successful("Then step 1.3");
    verify(delegate, never()).beforeScenario("My scenario 4");
    verify(delegate, never()).successful("Given step 4.1");
    verify(delegate, never()).successful("When step 4.2");
    verify(delegate, never()).successful("Then step 4.3");
    // Scenarios 2 and 3 have pending or failed steps
    inOrder.verify(delegate).dryRun();
    inOrder.verify(delegate).beforeStory(story, false);
    inOrder.verify(delegate).beforeScenario("My scenario 2");
    inOrder.verify(delegate).givenStories(givenStories);
    inOrder.verify(delegate).givenStories(givenStoryPaths);
    inOrder.verify(delegate).successful("Given step 2.1");
    inOrder.verify(delegate).pending("When step 2.2");
    inOrder.verify(delegate).notPerformed("Then step 2.3");
    inOrder.verify(delegate).afterScenario();
    inOrder.verify(delegate).beforeScenario("My scenario 3");
    inOrder.verify(delegate).beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
    inOrder.verify(delegate).example(tableRow);
    inOrder.verify(delegate).successful("Given step 3.1");
    inOrder.verify(delegate).successful("When step 3.2");
    inOrder.verify(delegate).ignorable("!-- Then ignore me too");
    inOrder.verify(delegate).comment("!-- One more comment");
    inOrder.verify(delegate).failed("Then step 3.3", anException);
    inOrder.verify(delegate).failedOutcomes("When failed outcomes", outcomesTable);
    inOrder.verify(delegate).afterExamples();
    inOrder.verify(delegate).afterScenario();
    inOrder.verify(delegate).afterStory(false);
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) InOrder(org.mockito.InOrder) HashMap(java.util.HashMap) ExamplesTable(org.jbehave.core.model.ExamplesTable) Story(org.jbehave.core.model.Story) OutcomesTable(org.jbehave.core.model.OutcomesTable) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Aggregations

ExamplesTable (org.jbehave.core.model.ExamplesTable)13 Test (org.junit.Test)6 Scenario (org.jbehave.core.model.Scenario)5 Story (org.jbehave.core.model.Story)5 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)4 GivenStories (org.jbehave.core.model.GivenStories)4 Meta (org.jbehave.core.model.Meta)3 OutcomesTable (org.jbehave.core.model.OutcomesTable)3 InOrder (org.mockito.InOrder)3 HashMap (java.util.HashMap)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Method (java.lang.reflect.Method)1 Type (java.lang.reflect.Type)1 Then (org.jbehave.core.annotations.Then)1 Keywords (org.jbehave.core.configuration.Keywords)1 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)1 Description (org.jbehave.core.model.Description)1 ExamplesTableFactory (org.jbehave.core.model.ExamplesTableFactory)1 ExamplesTableProperties (org.jbehave.core.model.ExamplesTableProperties)1 GivenStory (org.jbehave.core.model.GivenStory)1