use of org.jbehave.core.configuration.MostUsefulConfiguration 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.configuration.MostUsefulConfiguration 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.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunStoriesApplyingFilter.
@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesApplyingFilter() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls();
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
final StoryReporter storyReporter = mock(StoryReporter.class);
Configuration configuration = new MostUsefulConfiguration() {
@Override
public StoryReporter storyReporter(String storyPath) {
return storyReporter;
}
};
embedder.useConfiguration(configuration);
InjectableStepsFactory stepsFactory = embedder.stepsFactory();
StoryPathResolver resolver = configuration.storyPathResolver();
List<String> storyPaths = new ArrayList<>();
Map<String, Story> stories = new HashMap<>();
Meta meta = mock(Meta.class);
for (Class<? extends Embeddable> embeddable : embeddables) {
String storyPath = resolver.resolve(embeddable);
storyPaths.add(storyPath);
Story story = mockStory(Meta.EMPTY);
when(story.getMeta()).thenReturn(meta);
stories.put(storyPath, story);
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
assertThat(configuration.storyReporter(storyPath), sameInstance(storyReporter));
}
// When
MetaFilter filter = mock(MetaFilter.class);
when(filter.allow(meta)).thenReturn(false);
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
embedder.runStoriesAsPaths(storyPaths);
// Then
for (String storyPath : storyPaths) {
verify(performableTree, never()).perform(runContext, stories.get(storyPath));
}
assertThatReportsViewGenerated(out);
assertThat(embedder.hasExecutorService(), is(false));
}
use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldMapStoriesAsEmbeddables.
@Test
public void shouldMapStoriesAsEmbeddables() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
String myEmbeddableName = MyStoryMaps.class.getName();
List<String> classNames = asList(myEmbeddableName);
Embeddable myEmbeddable = new MyStoryMaps();
List<Embeddable> embeddables = asList(myEmbeddable);
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
// When
Configuration configuration = new MostUsefulConfiguration();
Embedder embedder = embedderWith(performableTree, new EmbedderControls(), monitor);
embedder.useClassLoader(classLoader);
embedder.useConfiguration(configuration);
embedder.runAsEmbeddables(classNames);
// Then
for (Embeddable embeddable : embeddables) {
assertThat(out.toString(), containsString("Running embeddable " + embeddable.getClass().getName()));
}
assertThat(MyStoryMaps.run, is(true));
}
use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunStoriesAsEmbeddables.
@Test
public void shouldRunStoriesAsEmbeddables() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls();
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
String myEmbeddableName = MyEmbeddable.class.getName();
String myOtherEmbeddableName = MyOtherEmbeddable.class.getName();
List<String> classNames = asList(myEmbeddableName, myOtherEmbeddableName);
Embeddable myEmbeddable = new MyEmbeddable();
Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
List<Embeddable> embeddables = asList(myEmbeddable, myOtherEmbeddable);
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
// When
Configuration configuration = new MostUsefulConfiguration();
CandidateSteps steps = mock(CandidateSteps.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
embedder.useClassLoader(classLoader);
embedder.useConfiguration(configuration);
embedder.useCandidateSteps(asList(steps));
embedder.runAsEmbeddables(classNames);
// Then
for (Embeddable embeddable : embeddables) {
assertThat(out.toString(), containsString("Running embeddable " + embeddable.getClass().getName()));
}
}
Aggregations