Search in sources :

Example 6 with ParameterConverter

use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.

the class ParameterConvertersBehaviour method shouldConvertMultilineTableToParameters.

@Test
public void shouldConvertMultilineTableToParameters() {
    ParameterConverter converter = new ExamplesTableParametersConverter(new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers()));
    Type type = new TypeLiteral<List<MyParameters>>() {
    }.getType();
    assertThatTypesAreAccepted(converter, type);
    String value = "|col1|col2|\n|row11|row12|\n|row21|row22|\n";
    @SuppressWarnings("unchecked") List<MyParameters> parameters = (List<MyParameters>) converter.convertValue(value, type);
    assertThat(parameters.size(), is(2));
    MyParameters row1 = parameters.get(0);
    assertThat(row1.col1, is("row11"));
    assertThat(row1.col2, is("row12"));
    MyParameters row2 = parameters.get(1);
    assertThat(row2.col1, is("row21"));
    assertThat(row2.col2, is("row22"));
}
Also used : Type(java.lang.reflect.Type) AbstractParameterConverter(org.jbehave.core.steps.ParameterConverters.AbstractParameterConverter) ParameterConverter(org.jbehave.core.steps.ParameterConverters.ParameterConverter) ExamplesTableParametersConverter(org.jbehave.core.steps.ParameterConverters.ExamplesTableParametersConverter) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) MyParameters(org.jbehave.core.steps.SomeSteps.MyParameters) ExamplesTableFactory(org.jbehave.core.model.ExamplesTableFactory) Arrays.asList(java.util.Arrays.asList) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 7 with ParameterConverter

use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.

the class ParameterConvertersBehaviour method shouldDefineDefaultConverters.

@SuppressWarnings("unchecked")
@Test
public void shouldDefineDefaultConverters() {
    LoadFromClasspath resourceLoader = new LoadFromClasspath();
    TableTransformers tableTransformers = new TableTransformers();
    ParameterControls parameterControls = new ParameterControls();
    ParameterConverters converters = new ParameterConverters(resourceLoader, parameterControls, tableTransformers, true);
    ParameterConverter<?>[] defaultConverters = converters.defaultConverters(resourceLoader, parameterControls, tableTransformers, Locale.ENGLISH, ",");
    assertThatDefaultConvertersInclude(defaultConverters, BooleanConverter.class, NumberConverter.class, StringListConverter.class, DateConverter.class, EnumConverter.class, ExamplesTableConverter.class, ExamplesTableParametersConverter.class);
}
Also used : AbstractParameterConverter(org.jbehave.core.steps.ParameterConverters.AbstractParameterConverter) ParameterConverter(org.jbehave.core.steps.ParameterConverters.ParameterConverter) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 8 with ParameterConverter

use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.

the class ParameterConvertersBehaviour method shouldConvertParameterFromMethodReturningValue.

@Test
public void shouldConvertParameterFromMethodReturningValue() throws IntrospectionException {
    Method method = SomeSteps.methodFor("aMethodReturningExamplesTable");
    ParameterConverter converter = new MethodReturningConverter(method, new SomeSteps());
    assertThatTypesAreAccepted(converter, method.getReturnType());
    String value = "|col1|col2|\n|row11|row12|\n|row21|row22|\n";
    ExamplesTable table = (ExamplesTable) converter.convertValue(value, ExamplesTable.class);
    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 : AbstractParameterConverter(org.jbehave.core.steps.ParameterConverters.AbstractParameterConverter) ParameterConverter(org.jbehave.core.steps.ParameterConverters.ParameterConverter) ExamplesTable(org.jbehave.core.model.ExamplesTable) MethodReturningConverter(org.jbehave.core.steps.ParameterConverters.MethodReturningConverter) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 9 with ParameterConverter

use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.

the class ParameterConvertersBehaviour method shouldConvertSinglelineTableToParameters.

@Test
public void shouldConvertSinglelineTableToParameters() {
    ParameterConverter converter = new ExamplesTableParametersConverter(new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers()));
    Type type = MyParameters.class;
    assertThatTypesAreAccepted(converter, type);
    String value = "|col1|col2|\n|row11|row12|\n";
    MyParameters parameters = (MyParameters) converter.convertValue(value, type);
    assertThat(parameters.col1, is("row11"));
    assertThat(parameters.col2, is("row12"));
}
Also used : Type(java.lang.reflect.Type) AbstractParameterConverter(org.jbehave.core.steps.ParameterConverters.AbstractParameterConverter) ParameterConverter(org.jbehave.core.steps.ParameterConverters.ParameterConverter) ExamplesTableParametersConverter(org.jbehave.core.steps.ParameterConverters.ExamplesTableParametersConverter) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) MyParameters(org.jbehave.core.steps.SomeSteps.MyParameters) ExamplesTableFactory(org.jbehave.core.model.ExamplesTableFactory) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Aggregations

ParameterConverter (org.jbehave.core.steps.ParameterConverters.ParameterConverter)9 Test (org.junit.Test)8 AbstractParameterConverter (org.jbehave.core.steps.ParameterConverters.AbstractParameterConverter)7 Type (java.lang.reflect.Type)4 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)4 TableTransformers (org.jbehave.core.model.TableTransformers)4 Arrays.asList (java.util.Arrays.asList)3 Method (java.lang.reflect.Method)2 ExamplesTableFactory (org.jbehave.core.model.ExamplesTableFactory)2 ExamplesTableParametersConverter (org.jbehave.core.steps.ParameterConverters.ExamplesTableParametersConverter)2 MethodReturningConverter (org.jbehave.core.steps.ParameterConverters.MethodReturningConverter)2 MyParameters (org.jbehave.core.steps.SomeSteps.MyParameters)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ExamplesTable (org.jbehave.core.model.ExamplesTable)1 EnumListConverter (org.jbehave.core.steps.ParameterConverters.EnumListConverter)1 NumberListConverter (org.jbehave.core.steps.ParameterConverters.NumberListConverter)1