Search in sources :

Example 6 with Parameters

use of org.jbehave.core.steps.Parameters in project jbehave-core by jbehave.

the class ExamplesTableBehaviour method shouldConvertParameterValuesOfTableRow.

@Test
public void shouldConvertParameterValuesOfTableRow() throws Exception {
    // Given
    ExamplesTableFactory factory = createFactory(new MethodReturningConverter(methodFor("convertDate"), this));
    // When
    String tableAsString = "|one|two|\n|11|22|\n|1/1/2010|2/2/2010|";
    ExamplesTable examplesTable = factory.createExamplesTable(tableAsString);
    // Then
    Parameters integers = examplesTable.getRowAsParameters(0);
    assertThat(integers.<Integer>valueAs("one", Integer.class), equalTo(11));
    assertThat(integers.<Integer>valueAs("two", Integer.class), equalTo(22));
    Parameters dates = examplesTable.getRowAsParameters(1);
    assertThat(dates.<Date>valueAs("one", Date.class), equalTo(convertDate("1/1/2010")));
    assertThat(dates.<Date>valueAs("two", Date.class), equalTo(convertDate("2/2/2010")));
}
Also used : AsParameters(org.jbehave.core.annotations.AsParameters) Parameters(org.jbehave.core.steps.Parameters) MethodReturningConverter(org.jbehave.core.steps.ParameterConverters.MethodReturningConverter) Test(org.junit.Test)

Example 7 with Parameters

use of org.jbehave.core.steps.Parameters in project jbehave-core by jbehave.

the class ExamplesTableBehaviour method shouldParseTableWithBlankValues.

@Test
public void shouldParseTableWithBlankValues() {
    String tableWithEmptyValues = "|one|two|\n |||\n | ||\n || |\n";
    ExamplesTable table = new ExamplesTable(tableWithEmptyValues);
    assertThat(table.getRowCount(), equalTo(3));
    for (Parameters row : table.getRowsAsParameters()) {
        Map<String, String> values = row.values();
        assertThat(values.size(), equalTo(2));
        for (String column : values.keySet()) {
            assertThat(isBlank(values.get(column)), is(true));
        }
    }
    assertThat(table.asString(), equalTo("|one|two|\n|||\n|||\n|||\n"));
}
Also used : AsParameters(org.jbehave.core.annotations.AsParameters) Parameters(org.jbehave.core.steps.Parameters) Test(org.junit.Test)

Example 8 with Parameters

use of org.jbehave.core.steps.Parameters in project jbehave-core by jbehave.

the class ExamplesTableBehaviour method shouldAllowAdditionAndModificationOfRowValues.

@Test
public void shouldAllowAdditionAndModificationOfRowValues() throws Exception {
    // Given
    ExamplesTableFactory factory = createFactory();
    // When
    String tableAsString = "|one|two|\n|11|12|\n|21|22|";
    ExamplesTable examplesTable = factory.createExamplesTable(tableAsString);
    Map<String, String> values = new HashMap<>();
    values.put("one", "111");
    values.put("three", "333");
    examplesTable.withRowValues(0, values);
    Map<String, String> otherValues = new HashMap<>();
    otherValues.put("two", "222");
    examplesTable.withRowValues(1, otherValues);
    // Then
    Parameters firstRow = examplesTable.getRowAsParameters(0);
    assertThat(firstRow.<Integer>valueAs("one", Integer.class), equalTo(111));
    assertThat(firstRow.<Integer>valueAs("two", Integer.class), equalTo(12));
    assertThat(firstRow.<Integer>valueAs("three", Integer.class), equalTo(333));
    Parameters secondRow = examplesTable.getRowAsParameters(1);
    assertThat(secondRow.<Integer>valueAs("one", Integer.class), equalTo(21));
    assertThat(secondRow.<Integer>valueAs("two", Integer.class), equalTo(222));
    assertThat(secondRow.<String>valueAs("three", String.class), equalTo(""));
    assertThat(examplesTable.asString(), equalTo("|one|two|three|\n|111|12|333|\n|21|222||\n"));
}
Also used : AsParameters(org.jbehave.core.annotations.AsParameters) Parameters(org.jbehave.core.steps.Parameters) Test(org.junit.Test)

Example 9 with Parameters

use of org.jbehave.core.steps.Parameters in project jbehave-core by jbehave.

the class ExamplesTableBehaviour method shouldParseTableWithCommentsInValues.

@Test
public void shouldParseTableWithCommentsInValues() {
    String tableWithEmptyValues = "{commentSeparator=#}\n|one #comment|two|\n |11 #comment|12 #comment|\n |21|22|\n";
    ExamplesTable table = new ExamplesTable(tableWithEmptyValues);
    assertThat(table.getRowCount(), equalTo(2));
    for (Parameters row : table.getRowsAsParameters()) {
        Map<String, String> values = row.values();
        assertThat(values.size(), equalTo(2));
        for (String column : values.keySet()) {
            assertThat(values.get(column), not(containsString("#comment")));
        }
    }
    assertThat(table.asString(), equalTo("{commentSeparator=#}\n|one|two|\n|11|12|\n|21|22|\n"));
}
Also used : AsParameters(org.jbehave.core.annotations.AsParameters) Parameters(org.jbehave.core.steps.Parameters) Test(org.junit.Test)

Example 10 with Parameters

use of org.jbehave.core.steps.Parameters in project jbehave-core by jbehave.

the class ExamplesTableBehaviour method shouldConvertParameterValuesOfTableRowWithDefaults.

@Test
public void shouldConvertParameterValuesOfTableRowWithDefaults() throws Exception {
    // Given
    ExamplesTableFactory factory = createFactory(new MethodReturningConverter(methodFor("convertDate"), this));
    // When
    String tableDefaultsAsString = "|three|\n|99|";
    ExamplesTable defaultsTable = factory.createExamplesTable(tableDefaultsAsString);
    Parameters defaults = defaultsTable.getRowAsParameters(0);
    String tableAsString = "|one|\n|11|\n|22|";
    ExamplesTable examplesTable = factory.createExamplesTable(tableAsString).withDefaults(defaults);
    // Then
    Parameters firstRow = examplesTable.getRowAsParameters(0);
    Map<String, String> firstRowValues = firstRow.values();
    assertThat(firstRowValues.containsKey("one"), is(true));
    assertThat(firstRow.<String>valueAs("one", String.class), is("11"));
    assertThat(firstRow.<Integer>valueAs("one", Integer.class), is(11));
    assertThat(firstRowValues.containsKey("three"), is(true));
    assertThat(firstRow.<String>valueAs("three", String.class), is("99"));
    assertThat(firstRow.<Integer>valueAs("three", Integer.class), is(99));
    assertThat(firstRowValues.containsKey("XX"), is(false));
    assertThat(firstRow.valueAs("XX", Integer.class, 13), is(13));
    Parameters secondRow = examplesTable.getRowAsParameters(1);
    Map<String, String> secondRowValues = secondRow.values();
    assertThat(secondRowValues.containsKey("one"), is(true));
    assertThat(secondRow.<String>valueAs("one", String.class), is("22"));
    assertThat(secondRow.<Integer>valueAs("one", Integer.class), is(22));
    assertThat(secondRowValues.containsKey("three"), is(true));
    assertThat(secondRow.<String>valueAs("three", String.class), is("99"));
    assertThat(secondRow.<Integer>valueAs("three", Integer.class), is(99));
    assertThat(secondRowValues.containsKey("XX"), is(false));
    assertThat(secondRow.valueAs("XX", Integer.class, 13), is(13));
}
Also used : AsParameters(org.jbehave.core.annotations.AsParameters) Parameters(org.jbehave.core.steps.Parameters) MethodReturningConverter(org.jbehave.core.steps.ParameterConverters.MethodReturningConverter) Test(org.junit.Test)

Aggregations

Parameters (org.jbehave.core.steps.Parameters)17 AsParameters (org.jbehave.core.annotations.AsParameters)10 Test (org.junit.Test)10 Then (org.jbehave.core.annotations.Then)6 Range (com.github.javaparser.Range)3 OutcomesTable (org.jbehave.core.model.OutcomesTable)2 MethodReturningConverter (org.jbehave.core.steps.ParameterConverters.MethodReturningConverter)2 Locale (java.util.Locale)1 Given (org.jbehave.core.annotations.Given)1 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)1 RowNotFound (org.jbehave.core.model.ExamplesTable.RowNotFound)1 ValueNotFound (org.jbehave.core.steps.ConvertedParameters.ValueNotFound)1 Organization (org.jbehave.example.spring.security.domain.Organization)1 UserBuilder (org.jbehave.example.spring.security.domain.UserBuilder)1