use of org.jbehave.core.model.TableTransformers in project jbehave-core by jbehave.
the class CoreEmbedder method configuration.
@Override
public Configuration configuration() {
Class<? extends CoreEmbedder> embedderClass = this.getClass();
TableTransformers tableTransformers = new TableTransformers();
LoadFromClasspath resourceLoader = new LoadFromClasspath(embedderClass.getClassLoader());
return new MostUsefulConfiguration().useStoryLoader(resourceLoader).useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(embedderClass)).withDefaultFormats().withFormats(CONSOLE, TXT, HTML, XML).withCrossReference(new CrossReference())).useTableTransformers(tableTransformers).useParameterConverters(new ParameterConverters(resourceLoader, tableTransformers).addConverters(// use custom date pattern
new DateConverter(new SimpleDateFormat("yyyy-MM-dd")))).useStepPatternParser(new RegexPrefixCapturingPatternParser(// use '%' instead of '$' to identify parameters
"%")).useStepMonitor(new SilentStepMonitor());
}
use of org.jbehave.core.model.TableTransformers 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);
}
use of org.jbehave.core.model.TableTransformers 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"));
}
use of org.jbehave.core.model.TableTransformers in project jbehave-core by jbehave.
the class StepCandidateBehaviour method shouldNotMatchOrIgnoreStepWhenStartingWordNotFound.
@Test
public void shouldNotMatchOrIgnoreStepWhenStartingWordNotFound() throws Exception {
Method method = SomeSteps.class.getMethod("aMethod");
Keywords keywords = new LocalizedKeywords() {
@Override
public String startingWordFor(StepType stepType) {
throw new StartingWordNotFound(stepType, new HashMap<StepType, String>());
}
};
ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
StepCandidate candidate = new StepCandidate("windows on the $nth floor", 0, WHEN, method, null, null, new StepsContext(), keywords, new RegexPrefixCapturingPatternParser(), parameterConverters, new ParameterControls());
assertThat(candidate.matches("When windows on the 1st floor"), is(false));
assertThat(candidate.ignore("!-- windows on the 1st floor"), is(false));
}
use of org.jbehave.core.model.TableTransformers in project jbehave-core by jbehave.
the class ConcurrencyBehaviour method shouldAllowConcurrentAdditionOfParameterConvertersInThreadSafeMode.
@Test
public void shouldAllowConcurrentAdditionOfParameterConvertersInThreadSafeMode() {
final ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath(), new ParameterControls(), new TableTransformers(), true);
final boolean[] active = new boolean[] { true };
final ParameterConverter[] toAdd = new ParameterConverter[] { mock(ParameterConverter.class, "one"), mock(ParameterConverter.class, "two"), mock(ParameterConverter.class, "three") };
Thread t = new Thread(new Runnable() {
@Override
public void run() {
while (active[0]) {
parameterConverters.addConverters(toAdd);
}
}
});
t.start();
parameterConverters.convert("test", String.class);
active[0] = false;
}
Aggregations