Search in sources :

Example 21 with TableTransformers

use of org.jbehave.core.model.TableTransformers 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 22 with TableTransformers

use of org.jbehave.core.model.TableTransformers 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)

Example 23 with TableTransformers

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

the class ParameterConvertersBehaviour method shouldNotConvertToListOfCustomObjectsWhenElementConverterIsNotAdded.

@Test
public void shouldNotConvertToListOfCustomObjectsWhenElementConverterIsNotAdded() {
    expectedException.expect(ParameterConvertionFailed.class);
    expectedException.expectMessage("No parameter converter for java.util.List<org.jbehave.core.steps.ParameterConvertersBehaviour$Bar>");
    ParameterConverters parameterConverters = new ParameterConverters(new TableTransformers());
    Type type = new TypeLiteral<List<Bar>>() {
    }.getType();
    parameterConverters.convert("foo", type);
}
Also used : Type(java.lang.reflect.Type) Arrays.asList(java.util.Arrays.asList) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 24 with TableTransformers

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

the class ChainedRowBehaviour method shouldChainRowValuesWithoutOverwritingAlreadyExisting.

@Test
public void shouldChainRowValuesWithoutOverwritingAlreadyExisting() throws Exception {
    Map<String, String> map1 = new HashMap<>();
    map1.put("one", "11");
    Map<String, String> map2 = new HashMap<>();
    map2.put("one", "21");
    map2.put("two", "22");
    ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
    Map<String, String> chainedValues = new ChainedRow(new ConvertedParameters(map1, parameterConverters), new ConvertedParameters(map2, parameterConverters)).values();
    assertThat(chainedValues.get("one"), equalTo("11"));
    assertThat(chainedValues.get("two"), equalTo("22"));
}
Also used : HashMap(java.util.HashMap) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 25 with TableTransformers

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

the class ConfigurationProducer method getConfiguration.

@Produces
@WeldConfiguration
Configuration getConfiguration() {
    Properties viewResources = new Properties();
    viewResources.setProperty("index", "my-reports-index.ftl");
    viewResources.setProperty("decorateNonHtml", "true");
    TableTransformers tableTransformers = new TableTransformers();
    LoadFromURL resourceLoader = new LoadFromURL();
    return new MostUsefulConfiguration().useStoryControls(new StoryControls().doDryRun(true).doSkipScenariosAfterFailure(true)).useFailureStrategy(new SilentlyAbsorbingFailure()).useStoryLoader(resourceLoader).useStepPatternParser(new RegexPrefixCapturingPatternParser("MyPrefix")).useStoryReporterBuilder(new StoryReporterBuilder().withDefaultFormats().withFormats(CONSOLE, HTML, TXT, XML).withKeywords(new LocalizedKeywords(Locale.ITALIAN)).withRelativeDirectory("my-output-directory").withViewResources(viewResources).withFailureTrace(true)).useParameterConverters(new ParameterConverters(resourceLoader, tableTransformers).addConverters(new CustomConverter(), new MyDateConverter())).useTableTransformers(tableTransformers);
}
Also used : SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) RegexPrefixCapturingPatternParser(org.jbehave.core.parsers.RegexPrefixCapturingPatternParser) StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) LoadFromURL(org.jbehave.core.io.LoadFromURL) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ParameterConverters(org.jbehave.core.steps.ParameterConverters) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) StoryControls(org.jbehave.core.embedder.StoryControls) Properties(java.util.Properties) TableTransformers(org.jbehave.core.model.TableTransformers) Produces(javax.enterprise.inject.Produces) WeldConfiguration(org.jbehave.core.annotations.weld.WeldConfiguration)

Aggregations

TableTransformers (org.jbehave.core.model.TableTransformers)25 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)22 Test (org.junit.Test)16 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)8 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)8 ParameterConverters (org.jbehave.core.steps.ParameterConverters)8 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)7 ExamplesTableFactory (org.jbehave.core.model.ExamplesTableFactory)7 SimpleDateFormat (java.text.SimpleDateFormat)5 Properties (java.util.Properties)5 RegexStepMatcher (org.jbehave.core.parsers.RegexStepMatcher)5 RegexStoryParser (org.jbehave.core.parsers.RegexStoryParser)5 StepMatcher (org.jbehave.core.parsers.StepMatcher)5 ParametrisedStep (org.jbehave.core.steps.StepCreator.ParametrisedStep)5 Type (java.lang.reflect.Type)4 DateConverter (org.jbehave.core.steps.ParameterConverters.DateConverter)4 ParameterConverter (org.jbehave.core.steps.ParameterConverters.ParameterConverter)4 HashMap (java.util.HashMap)3 StoryControls (org.jbehave.core.embedder.StoryControls)3 RegexPrefixCapturingPatternParser (org.jbehave.core.parsers.RegexPrefixCapturingPatternParser)3