org.jbehave.core.reporters
Class StoryReporterBuilder

java.lang.Object
  extended by org.jbehave.core.reporters.StoryReporterBuilder

public class StoryReporterBuilder
extends java.lang.Object

A Builder for StoryReporters. It builds a DelegatingStoryReporter with delegates for a number of formats - mostly file-based ones except . It requires a FilePrintStreamFactory and provides default delegate instances for each format.

To build a reporter for a single story path with default and given formats:

 Class<MyStory> storyClass = MyStory.class;
 StoryPathResolver resolver = new UnderscoredCamelCaseResolver();
 String storyPath = resolver.resolve(storyClass);
 FilePrintStreamFactory printStreamFactory = new FilePrintStreamFactory(storyPath);
 StoryReporter reporter = new StoryReporterBuilder(printStreamFactory)
                                                                .outputLocationClass(storyClass)
                                                                .withDefaultFormats()
                                                                .withFormats(HTML, TXT)
                                                                .build(storyPath);
 

The builder is configured to build with the StoryReporterBuilder.Format.STATS as default format. To change the default formats the user can override the method:

 new StoryReporterBuilder(printStreamFactory){
    protected StoryReporterBuilder withDefaultFormats() {
       return withFormats(STATS);
    }
  }
 

The builder configures the file-based reporters to output to the default file directory FilePrintStreamFactory.FileConfiguration.OUTPUT_DIRECTORY as relative to the output location class source. In some case, e.g. with Ant class loader, the code source location may not be properly set. In this case, we may specify the absolute output directory. To change the default:

 new StoryReporterBuilder(printStreamFactory).outputTo("my-reports").outputAsAbsolute(true)
                                        .withDefaultFormats().withFormats(HTML,TXT)
                                        .build(storyPath);
 

The builder provides default instances for all reporters. To change the reporter for a specific instance, e.g. to report format TXT to .text files and to inject other non-default parameters, such as keywords for a different locale:

 new StoryReporterBuilder(printStreamFactory){
   public StoryReporter reporterFor(String storyPath, Format format){
       FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(storyPath, codeLocationClass));
       switch (format) {
           case TXT:
               factory.useConfiguration(new FileConfiguration("text"));
               return new PrintStreamStoryReporter(factory.createPrintStream(), new Properties(), new I18nKeywords(Locale), true);
            default:
               return super.reporterFor(format);
   }
 }
 


Nested Class Summary
static class StoryReporterBuilder.Format
           
static class StoryReporterBuilder.UnsupportedReporterFormatException
           
 
Constructor Summary
StoryReporterBuilder()
           
 
Method Summary
 java.util.Map<java.lang.String,StoryReporter> build(java.util.List<java.lang.String> storyPaths)
           
 StoryReporter build(java.lang.String storyPath)
           
static java.util.Properties defaultRenderingResources()
           
protected  FilePrintStreamFactory.FileConfiguration fileConfiguration(java.lang.String extension)
           
 java.util.List<java.lang.String> formatNames(boolean toLowerCase)
           
 StoryReporterBuilder outputAsAbsolute(boolean outputAbsolute)
           
 java.io.File outputDirectory()
           
 StoryReporterBuilder outputLocationClass(java.lang.Class<?> outputLocationClass)
           
 StoryReporterBuilder outputTo(java.lang.String outputDirectory)
           
 java.util.Properties renderingResources()
           
 StoryReporter reporterFor(java.lang.String storyPath, StoryReporterBuilder.Format format)
           
 StoryReporterBuilder useRenderingResources(java.util.Properties resources)
           
 StoryReporterBuilder withDefaultFormats()
           
 StoryReporterBuilder withFormats(StoryReporterBuilder.Format... formats)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StoryReporterBuilder

public StoryReporterBuilder()
Method Detail

defaultRenderingResources

public static java.util.Properties defaultRenderingResources()

outputTo

public StoryReporterBuilder outputTo(java.lang.String outputDirectory)

outputAsAbsolute

public StoryReporterBuilder outputAsAbsolute(boolean outputAbsolute)

outputLocationClass

public StoryReporterBuilder outputLocationClass(java.lang.Class<?> outputLocationClass)

withDefaultFormats

public StoryReporterBuilder withDefaultFormats()

withFormats

public StoryReporterBuilder withFormats(StoryReporterBuilder.Format... formats)

build

public StoryReporter build(java.lang.String storyPath)

build

public java.util.Map<java.lang.String,StoryReporter> build(java.util.List<java.lang.String> storyPaths)

reporterFor

public StoryReporter reporterFor(java.lang.String storyPath,
                                 StoryReporterBuilder.Format format)

outputDirectory

public java.io.File outputDirectory()

formatNames

public java.util.List<java.lang.String> formatNames(boolean toLowerCase)

renderingResources

public java.util.Properties renderingResources()

useRenderingResources

public StoryReporterBuilder useRenderingResources(java.util.Properties resources)

fileConfiguration

protected FilePrintStreamFactory.FileConfiguration fileConfiguration(java.lang.String extension)


Copyright © 2003-2010. All Rights Reserved.