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);
 StoryReporter reporter = new StoryReporterBuilder().withCodeLocation(StoryLocation.codeLocationFromClass(storyClass))
         .withDefaultFormats().withFormats(TXT, HTML, XML).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() {
     protected StoryReporterBuilder withDefaultFormats() {
         return withFormats(STATS);
     }
 }
 

The builder configures the file-based reporters to output to the default file directory FileConfiguration#DIRECTORY as relative to the code location. In some case, e.g. with Ant class loader, the code source location from class may not be properly set. In this case, we may specify it from a file:

 new StoryReporterBuilder().withCodeLocation(StoryLocation.codeLocationFromFile(new File("target/classes")))
         .withDefaultFormats().withFormats(TXT, HTML, XML).build(storyPath);
 

By default, the reporters will output minimal failure information, the single line describing the failure cause and the outcomes if failures occur. To configure the failure trace to be reported as well:

 new StoryReporterBuilder().withFailureTrace(true)
 

To specify the use of keywords for a given locale:

 new StoryReporterBuilder().withKeywords(new LocalisedKeywords(Locale.IT)
 

The builder provides default instances for all reporters, using the default output patterns. 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 the custom output patterns:

 new StoryReporterBuilder(){
   public StoryReporter reporterFor(String storyPath, Format format){
       FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(storyPath, codeLocation));
       switch (format) {
           case TXT:
               factory.useConfiguration(new FileConfiguration("text"));
               Properties customPatterns = new Properties();
               customPatterns.setProperty("successful", "{0}(YEAH!!!)\n");
               return new TxtOutput(factory.createPrintStream(), customPatterns, keywords);
            default:
               return super.reporterFor(format);
   }
 }
 


Nested Class Summary
static class StoryReporterBuilder.Format
           
 
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)
           
 java.net.URL codeLocation()
           
protected  FilePrintStreamFactory.FileConfiguration fileConfiguration(java.lang.String extension)
           
protected  FilePrintStreamFactory filePrintStreamFactory(java.lang.String storyPath)
           
 java.util.List<java.lang.String> formatNames(boolean toLowerCase)
           
 java.util.List<StoryReporterBuilder.Format> formats()
           
 Keywords keywords()
           
 java.io.File outputDirectory()
           
 FilePrintStreamFactory.FilePathResolver pathResolver()
           
 java.lang.String relativeDirectory()
           
 StoryReporter reporterFor(java.lang.String storyPath, StoryReporterBuilder.Format format)
           
 boolean reportFailureTrace()
           
 java.util.Properties viewResources()
           
 StoryReporterBuilder withCodeLocation(java.net.URL codeLocation)
           
 StoryReporterBuilder withDefaultFormats()
           
 StoryReporterBuilder withFailureTrace(boolean reportFailureTrace)
           
 StoryReporterBuilder withFormats(StoryReporterBuilder.Format... formats)
           
 StoryReporterBuilder withKeywords(Keywords keywords)
           
 StoryReporterBuilder withPathResolver(FilePrintStreamFactory.FilePathResolver pathResolver)
           
 StoryReporterBuilder withRelativeDirectory(java.lang.String relativeDirectory)
           
 StoryReporterBuilder withViewResources(java.util.Properties resources)
           
 
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

outputDirectory

public java.io.File outputDirectory()

relativeDirectory

public java.lang.String relativeDirectory()

pathResolver

public FilePrintStreamFactory.FilePathResolver pathResolver()

codeLocation

public java.net.URL codeLocation()

formats

public java.util.List<StoryReporterBuilder.Format> formats()

formatNames

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

keywords

public Keywords keywords()

reportFailureTrace

public boolean reportFailureTrace()

viewResources

public java.util.Properties viewResources()

withRelativeDirectory

public StoryReporterBuilder withRelativeDirectory(java.lang.String relativeDirectory)

withPathResolver

public StoryReporterBuilder withPathResolver(FilePrintStreamFactory.FilePathResolver pathResolver)

withCodeLocation

public StoryReporterBuilder withCodeLocation(java.net.URL codeLocation)

withDefaultFormats

public StoryReporterBuilder withDefaultFormats()

withFormats

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

withFailureTrace

public StoryReporterBuilder withFailureTrace(boolean reportFailureTrace)

withKeywords

public StoryReporterBuilder withKeywords(Keywords keywords)

withViewResources

public StoryReporterBuilder withViewResources(java.util.Properties resources)

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)

filePrintStreamFactory

protected FilePrintStreamFactory filePrintStreamFactory(java.lang.String storyPath)

fileConfiguration

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


Copyright © 2003-2010. All Rights Reserved.