Search in sources :

Example 1 with ExamplesTableConverter

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

the class CoreStories method configuration.

@Override
public Configuration configuration() {
    // alternative use #useConfiguration() in the constructor
    if (super.hasConfiguration()) {
        return super.configuration();
    }
    Class<? extends Embeddable> embeddableClass = this.getClass();
    Properties viewResources = new Properties();
    viewResources.put("decorateNonHtml", "true");
    viewResources.put("reports", "ftl/jbehave-reports.ftl");
    LoadFromClasspath resourceLoader = new LoadFromClasspath(embeddableClass);
    TableTransformers tableTransformers = new TableTransformers();
    ParameterControls parameterControls = new ParameterControls();
    // Start from default ParameterConverters instance
    ParameterConverters parameterConverters = new ParameterConverters(resourceLoader, tableTransformers);
    // factory to allow parameter conversion and loading from external
    // resources (used by StoryParser too)
    ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), resourceLoader, parameterConverters, parameterControls, tableTransformers);
    // add custom converters
    parameterConverters.addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd")), new ExamplesTableConverter(examplesTableFactory));
    return new MostUsefulConfiguration().useStoryLoader(resourceLoader).useStoryParser(new RegexStoryParser(examplesTableFactory)).useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)).withDefaultFormats().withViewResources(viewResources).withFormats(contextFormat, CONSOLE, TXT, HTML_TEMPLATE, XML_TEMPLATE).withFailureTrace(true).withFailureTraceCompression(true).withCrossReference(xref).withSurefireReporter(new SurefireReporter(embeddableClass))).useParameterConverters(parameterConverters).useParameterControls(parameterControls).useTableTransformers(tableTransformers);
}
Also used : ParameterControls(org.jbehave.core.steps.ParameterControls) DateConverter(org.jbehave.core.steps.ParameterConverters.DateConverter) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) ExamplesTableConverter(org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter) Properties(java.util.Properties) TableTransformers(org.jbehave.core.model.TableTransformers) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) ParameterConverters(org.jbehave.core.steps.ParameterConverters) ExamplesTableFactory(org.jbehave.core.model.ExamplesTableFactory) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with ExamplesTableConverter

use of org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter 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 ExamplesTableConverter

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

the class MyStories method configuration.

@Override
public Configuration configuration() {
    Class<? extends Embeddable> embeddableClass = this.getClass();
    LoadFromClasspath resourceLoader = new LoadFromClasspath(embeddableClass);
    TableTransformers tableTransformers = new TableTransformers();
    ParameterControls parameterControls = new ParameterControls();
    // Start from default ParameterConverters instance
    ParameterConverters parameterConverters = new ParameterConverters(resourceLoader, tableTransformers);
    // factory to allow parameter conversion and loading from external resources (used by StoryParser too)
    ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), resourceLoader, parameterConverters, parameterControls, tableTransformers);
    // add custom converters
    parameterConverters.addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd")), new ExamplesTableConverter(examplesTableFactory));
    return new MostUsefulConfiguration().useStoryLoader(resourceLoader).useStoryParser(new RegexStoryParser(examplesTableFactory)).useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)).withDefaultFormats().withFormats(CONSOLE, TXT, HTML, XML)).useParameterConverters(parameterConverters).useParameterControls(parameterControls).useTableTransformers(tableTransformers);
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) ParameterControls(org.jbehave.core.steps.ParameterControls) DateConverter(org.jbehave.core.steps.ParameterConverters.DateConverter) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) ExamplesTableConverter(org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter) TableTransformers(org.jbehave.core.model.TableTransformers) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) ParameterConverters(org.jbehave.core.steps.ParameterConverters) ExamplesTableFactory(org.jbehave.core.model.ExamplesTableFactory) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with ExamplesTableConverter

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

the class CoreStory method configuration.

@Override
public Configuration configuration() {
    Class<? extends Embeddable> embeddableClass = this.getClass();
    Properties viewResources = new Properties();
    viewResources.put("decorateNonHtml", "true");
    LoadFromClasspath resourceLoader = new LoadFromClasspath(embeddableClass);
    TableTransformers tableTransformers = new TableTransformers();
    ParameterControls parameterControls = new ParameterControls();
    // Start from default ParameterConverters instance
    ParameterConverters parameterConverters = new ParameterConverters(resourceLoader, tableTransformers);
    // factory to allow parameter conversion and loading from external
    // resources (used by StoryParser too)
    ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), resourceLoader, parameterConverters, parameterControls, tableTransformers);
    // add custom converters
    parameterConverters.addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd")), new ExamplesTableConverter(examplesTableFactory));
    return new MostUsefulConfiguration().useStoryControls(new StoryControls().doDryRun(false).doSkipScenariosAfterFailure(false)).useStoryLoader(resourceLoader).useStoryParser(new RegexStoryParser(examplesTableFactory)).useStoryPathResolver(new UnderscoredCamelCaseResolver()).useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)).withDefaultFormats().withPathResolver(new ResolveToPackagedName()).withViewResources(viewResources).withFormats(CONSOLE, TXT, HTML_TEMPLATE, XML).withCrossReference(xref).withFailureTrace(true).withFailureTraceCompression(true)).useParameterConverters(parameterConverters).useParameterControls(parameterControls).useTableTransformers(tableTransformers);
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) ParameterControls(org.jbehave.core.steps.ParameterControls) DateConverter(org.jbehave.core.steps.ParameterConverters.DateConverter) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) ExamplesTableConverter(org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter) StoryControls(org.jbehave.core.embedder.StoryControls) Properties(java.util.Properties) TableTransformers(org.jbehave.core.model.TableTransformers) UnderscoredCamelCaseResolver(org.jbehave.core.io.UnderscoredCamelCaseResolver) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) ParameterConverters(org.jbehave.core.steps.ParameterConverters) ExamplesTableFactory(org.jbehave.core.model.ExamplesTableFactory) SimpleDateFormat(java.text.SimpleDateFormat) ResolveToPackagedName(org.jbehave.core.reporters.FilePrintStreamFactory.ResolveToPackagedName)

Aggregations

LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)4 ExamplesTableFactory (org.jbehave.core.model.ExamplesTableFactory)4 TableTransformers (org.jbehave.core.model.TableTransformers)4 ExamplesTableConverter (org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter)4 SimpleDateFormat (java.text.SimpleDateFormat)3 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)3 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)3 RegexStoryParser (org.jbehave.core.parsers.RegexStoryParser)3 ParameterControls (org.jbehave.core.steps.ParameterControls)3 ParameterConverters (org.jbehave.core.steps.ParameterConverters)3 DateConverter (org.jbehave.core.steps.ParameterConverters.DateConverter)3 Properties (java.util.Properties)2 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)2 Type (java.lang.reflect.Type)1 StoryControls (org.jbehave.core.embedder.StoryControls)1 UnderscoredCamelCaseResolver (org.jbehave.core.io.UnderscoredCamelCaseResolver)1 ExamplesTable (org.jbehave.core.model.ExamplesTable)1 ResolveToPackagedName (org.jbehave.core.reporters.FilePrintStreamFactory.ResolveToPackagedName)1 Test (org.junit.Test)1