use of org.jbehave.core.model.ExamplesTableFactory 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);
}
use of org.jbehave.core.model.ExamplesTableFactory 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"));
}
use of org.jbehave.core.model.ExamplesTableFactory 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"));
}
Aggregations