Search in sources :

Example 6 with ParameterConverters

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

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

the class ConfigurationProducer method getConfiguration.

@Produces
@WeldConfiguration
public Configuration getConfiguration() {
    LoadFromClasspath resourceLoader = new LoadFromClasspath(getClass().getClassLoader());
    TableTransformers tableTransformers = new TableTransformers();
    return new MostUsefulConfiguration().useStoryControls(new StoryControls().doDryRun(false).doSkipScenariosAfterFailure(false)).useStoryLoader(resourceLoader).useStoryReporterBuilder(new StoryReporterBuilder().withDefaultFormats().withFormats(CONSOLE, HTML, TXT, XML)).useParameterConverters(new ParameterConverters(resourceLoader, tableTransformers).addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd")))).useTableTransformers(tableTransformers);
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) DateConverter(org.jbehave.core.steps.ParameterConverters.DateConverter) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ParameterConverters(org.jbehave.core.steps.ParameterConverters) StoryControls(org.jbehave.core.embedder.StoryControls) SimpleDateFormat(java.text.SimpleDateFormat) TableTransformers(org.jbehave.core.model.TableTransformers) Produces(javax.enterprise.inject.Produces) WeldConfiguration(org.jbehave.core.annotations.weld.WeldConfiguration)

Example 8 with ParameterConverters

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

the class SerenityJBehave method defaultConfiguration.

// private static final CrossReference xref = new CrossReference();
/**
 * Returns a default JBehave configuration object suitable for ThucydidesWebdriverIntegration tests.
 */
public static Configuration defaultConfiguration(net.thucydides.core.webdriver.Configuration systemConfiguration, List<Format> formats, Embeddable embeddable) {
    Class<? extends Embeddable> embeddableClass = embeddable.getClass();
    Properties viewResources = new Properties();
    viewResources.put("decorateNonHtml", "true");
    TableTransformers tableTransformers = new TableTransformers();
    UTF8StoryLoader utf8StoryLoader = new UTF8StoryLoader();
    return new ParanamerConfiguration().useTableTransformers(tableTransformers).useParameterConverters(new ParameterConverters(utf8StoryLoader, tableTransformers).addConverters(new ParameterConverters.DateConverter(), new DateListConverter(), new DateTimeConverter(), new DateTimeListConverter(), new YearMonthConverter(), new YearMonthListConverter(), new TimeConverter(), new TimeListConverter(), new ParameterConverters.EnumConverter(), new ParameterConverters.EnumListConverter())).useStoryReporterBuilder(new StoryReporterBuilder().withDefaultFormats().withFormats(formats.toArray(new Format[0])).withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)).withViewResources(viewResources).withPathResolver(new FilePrintStreamFactory.ResolveToPackagedName()).withFailureTrace(true).withFailureTraceCompression(true).withReporters(new SerenityReporter(systemConfiguration))).useStoryLoader(utf8StoryLoader).useFailureStrategy(new IgnoreAssumptionViolations());
}
Also used : ParanamerConfiguration(org.jbehave.core.configuration.ParanamerConfiguration) StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) Properties(java.util.Properties) TableTransformers(org.jbehave.core.model.TableTransformers) ParameterConverters(org.jbehave.core.steps.ParameterConverters) FilePrintStreamFactory(org.jbehave.core.reporters.FilePrintStreamFactory)

Example 9 with ParameterConverters

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

Example 10 with ParameterConverters

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

the class ExamplesTableBehaviour method shouldParseTableWithDifferentSeparators.

@Test
public void shouldParseTableWithDifferentSeparators() {
    String headerSeparator = "||";
    String valueSeparator = "|";
    String tableWithCustomSeparator = wikiTableAsString;
    TableTransformers tableTransformers = new TableTransformers();
    ParameterControls parameterControls = new ParameterControls();
    ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath(), parameterControls, tableTransformers, true);
    ExamplesTable table = new ExamplesTable(tableWithCustomSeparator, headerSeparator, valueSeparator, parameterConverters, parameterControls, tableTransformers);
    assertThat(table.getHeaderSeparator(), equalTo(headerSeparator));
    assertThat(table.getValueSeparator(), equalTo(valueSeparator));
    ensureColumnOrderIsPreserved(table);
    assertThat(table.asString(), equalTo(tableWithCustomSeparator));
}
Also used : ParameterControls(org.jbehave.core.steps.ParameterControls) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) ParameterConverters(org.jbehave.core.steps.ParameterConverters) Test(org.junit.Test)

Aggregations

ParameterConverters (org.jbehave.core.steps.ParameterConverters)11 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)9 TableTransformers (org.jbehave.core.model.TableTransformers)8 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)7 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)7 ParameterControls (org.jbehave.core.steps.ParameterControls)7 SimpleDateFormat (java.text.SimpleDateFormat)5 Properties (java.util.Properties)5 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)5 DateConverter (org.jbehave.core.steps.ParameterConverters.DateConverter)5 RegexStoryParser (org.jbehave.core.parsers.RegexStoryParser)4 StoryControls (org.jbehave.core.embedder.StoryControls)3 ExamplesTableFactory (org.jbehave.core.model.ExamplesTableFactory)3 ExamplesTableConverter (org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter)3 Produces (javax.enterprise.inject.Produces)2 WeldConfiguration (org.jbehave.core.annotations.weld.WeldConfiguration)2 RegexPrefixCapturingPatternParser (org.jbehave.core.parsers.RegexPrefixCapturingPatternParser)2 Test (org.junit.Test)2 URL (java.net.URL)1 Keywords (org.jbehave.core.configuration.Keywords)1