Search in sources :

Example 16 with Parameters

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

the class ExamplesTableBehaviour method shouldReplaceNamedParameterValues.

@Test
public void shouldReplaceNamedParameterValues() throws Exception {
    // Given
    ExamplesTableFactory factory = createFactory();
    // When
    String tableAsString = "|Name|Value|\n|name1|<value>|";
    Map<String, String> namedParameters = new HashMap<>();
    namedParameters.put("value", "value1");
    ExamplesTable table = factory.createExamplesTable(tableAsString).withNamedParameters(namedParameters);
    // Then
    Parameters firstRow = table.getRowsAsParameters(true).get(0);
    Map<String, String> firstRowValues = firstRow.values();
    assertThat(firstRowValues.containsKey("Value"), is(true));
    assertThat(firstRow.<String>valueAs("Value", String.class), is("value1"));
}
Also used : AsParameters(org.jbehave.core.annotations.AsParameters) Parameters(org.jbehave.core.steps.Parameters) Test(org.junit.Test)

Example 17 with Parameters

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

the class ExamplesTableBehaviour method shouldKeepExactValueInReplacedNamedParameterValues.

/**
 * The values given named parameter values as strings should not suffer any modification after are replaced in table.
 *
 * @see {@link String#replaceAll(String, String)} to see why are not present in values the '\' and '$' characters.
 */
@Test
public void shouldKeepExactValueInReplacedNamedParameterValues() throws Exception {
    // Given
    ExamplesTableFactory factory = createFactory();
    String problematicNamedParameterValueCharacters = "value having the \\ backslash and the $ dollar character";
    // When
    String tableAsString = "|Name|Value|\n|name|<value>|";
    Map<String, String> namedParameters = new HashMap<>();
    namedParameters.put("value", problematicNamedParameterValueCharacters);
    ExamplesTable table = factory.createExamplesTable(tableAsString).withNamedParameters(namedParameters);
    // Then
    Parameters firstRow = table.getRowsAsParameters(true).get(0);
    Map<String, String> firstRowValues = firstRow.values();
    assertThat(firstRowValues.containsKey("Value"), is(true));
    assertThat(firstRow.<String>valueAs("Value", String.class), is(problematicNamedParameterValueCharacters));
}
Also used : AsParameters(org.jbehave.core.annotations.AsParameters) Parameters(org.jbehave.core.steps.Parameters) 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