Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jbehave.core.reporters
Class StoryReporterBuilder

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

    public class StoryReporterBuilder

extends Object

A Builder for `StoryReporter`s. 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(CodeLocations.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(CodeLocations.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)

If failure trace is reported, it is with the full stack trace. In some cases, it's useful to have it compressed, eliminating unnecessary lines that are not very informative:

     new StoryReporterBuilder().withFailureTraceCompression(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`
`static class` | `StoryReporterBuilder.ProvidedFormat` A Format that wraps a StoryReporter instance provided.

Constructor Summary
`StoryReporterBuilder()`

Method Summary
`Map<String,StoryReporter>` | `build(List<String> storyPaths)`
`StoryReporter` | `build(String storyPath)`
`URL` | `codeLocation()`
`boolean` | `compressFailureTrace()`
`CrossReference` | `crossReference()`
`FilePrintStreamFactory.FileConfiguration` | `fileConfiguration(String extension)`
`protected FilePrintStreamFactory` | `filePrintStreamFactory(String storyPath)`
`List<String>` | `formatNames(boolean toLowerCase)`
`List<Format>` | `formats()`
`boolean` | `hasCrossReference()`
`Keywords` | `keywords()`
`boolean` | `multiThreading()`
`File` | `outputDirectory()`
`FilePrintStreamFactory.FilePathResolver` | `pathResolver()`
`String` | `relativeDirectory()`
`StoryReporter` | `reporterFor(String storyPath, Format format)`
`StoryReporter` | `reporterFor(String storyPath, StoryReporterBuilder.Format format)`
`boolean` | `reportFailureTrace()`
`Properties` | `viewResources()`
`StoryReporterBuilder` | `withCodeLocation(URL codeLocation)`
`StoryReporterBuilder` | `withCrossReference(CrossReference crossReference)`
`StoryReporterBuilder` | `withDefaultFormats()`
`StoryReporterBuilder` | `withFailureTrace(boolean reportFailureTrace)`
`StoryReporterBuilder` | `withFailureTraceCompression(boolean compressFailureTrace)`
`StoryReporterBuilder` | `withFormats(Format... formats)`
`StoryReporterBuilder` | `withFormats(StoryReporterBuilder.Format... formats)` Deprecated. Use `withFormats(org.jbehave.core.reporters.Format... formats)`
`StoryReporterBuilder` | `withKeywords(Keywords keywords)`
`StoryReporterBuilder` | `withMultiThreading(boolean multiThreading)`
`StoryReporterBuilder` | `withPathResolver(FilePrintStreamFactory.FilePathResolver pathResolver)`
`StoryReporterBuilder` | `withRelativeDirectory(String relativeDirectory)`
`StoryReporterBuilder` | `withReporters(StoryReporter... reporters)`
`StoryReporterBuilder` | `withViewResources(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 File outputDirectory()

### relativeDirectory

    public String relativeDirectory()

### pathResolver

    public FilePrintStreamFactory.FilePathResolver pathResolver()

### codeLocation

    public URL codeLocation()

### formats

    public List<Format> formats()

### formatNames

    public List<String> formatNames(boolean toLowerCase)

### keywords

    public Keywords keywords()

### multiThreading

    public boolean multiThreading()

### reportFailureTrace

    public boolean reportFailureTrace()

### compressFailureTrace

    public boolean compressFailureTrace()

### viewResources

    public Properties viewResources()

### withRelativeDirectory

    public StoryReporterBuilder withRelativeDirectory(String relativeDirectory)

### withPathResolver

    public StoryReporterBuilder withPathResolver(FilePrintStreamFactory.FilePathResolver pathResolver)

### withCodeLocation

    public StoryReporterBuilder withCodeLocation(URL codeLocation)

### crossReference

    public CrossReference crossReference()

### hasCrossReference

    public boolean hasCrossReference()

### withCrossReference

    public StoryReporterBuilder withCrossReference(CrossReference crossReference)

### withDefaultFormats

    public StoryReporterBuilder withDefaultFormats()

### withFormats

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

  Deprecated. Use `withFormats(org.jbehave.core.reporters.Format... formats)`

### withFormats

    public StoryReporterBuilder withFormats(Format... formats)

### withReporters

    public StoryReporterBuilder withReporters(StoryReporter... reporters)

### withFailureTrace

    public StoryReporterBuilder withFailureTrace(boolean reportFailureTrace)

### withFailureTraceCompression

    public StoryReporterBuilder withFailureTraceCompression(boolean compressFailureTrace)

### withKeywords

    public StoryReporterBuilder withKeywords(Keywords keywords)

### withMultiThreading

    public StoryReporterBuilder withMultiThreading(boolean multiThreading)

### withViewResources

    public StoryReporterBuilder withViewResources(Properties resources)

### build

    public StoryReporter build(String storyPath)

### build

    public Map<String,StoryReporter> build(List<String> storyPaths)

### reporterFor

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

### reporterFor

    public StoryReporter reporterFor(String storyPath,
                                     Format format)

### filePrintStreamFactory

    protected FilePrintStreamFactory filePrintStreamFactory(String storyPath)

### fileConfiguration

    public FilePrintStreamFactory.FileConfiguration fileConfiguration(String extension)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2013. All Rights Reserved.