Package org.jbehave.core.reporters
Class PrintStreamOutput
- java.lang.Object
-
- org.jbehave.core.reporters.NullStoryReporter
-
- org.jbehave.core.reporters.PrintStreamOutput
-
- All Implemented Interfaces:
StoryReporter
- Direct Known Subclasses:
HtmlOutput,JsonOutput,TxtOutput,XmlOutput
public abstract class PrintStreamOutput extends NullStoryReporter
Abstract story reporter that outputs to a PrintStream.
The output of the reported event is configurable via:
- custom output patterns, providing only the patterns that differ from default
- keywords localised for different languages, providing the formatOutcome Locale
- flag to report failure trace
Let's look at example of providing custom output patterns, e.g. for the failed event.
we'd need to provide the custom pattern, say we want to have something like "(step being executed) <<< FAILED", keyed on the method name:Properties patterns = new Properties(); patterns.setProperty("failed", "{0} <<< {1}");The pattern is by default processed and formatted by theMessageFormat. Both theformat(String key, String defaultPattern, Object... args)andlookupPattern(String key, String defaultPattern)methods are override-able and a different formatter or pattern lookup can be used by subclasses.If the keyword "FAILED" (or any other keyword used by the reporter) needs to be expressed in a different language, all we need to do is to provide an instance of
LocalizedKeywordsusing the appropriateLocale, e.g.Keywords keywords = new LocalizedKeywords(new Locale("it"));
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPrintStreamOutput.Format
-
Constructor Summary
Constructors Modifier Constructor Description protectedPrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties defaultPatterns, Properties outputPatterns, Keywords keywords)protectedPrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties defaultPatterns, Properties outputPatterns, Keywords keywords, boolean reportFailureTrace, boolean compressFailureTrace)protectedPrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties outputPatterns, Keywords keywords, boolean reportFailureTrace, boolean compressFailureTrace)
-
Method Summary
Modifier and Type Method Description voidafterComposedSteps()voidafterExamples()voidafterGivenStories()voidafterScenario(Timing timing)voidafterScenarios()voidafterScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)voidafterStoriesSteps(StepCollector.Stage stage)voidafterStory(boolean givenOrRestartingStory)voidafterStorySteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)voidbeforeComposedSteps()voidbeforeExamples(List<String> steps, ExamplesTable table)voidbeforeGivenStories()voidbeforeScenario(Scenario scenario)voidbeforeScenarios()voidbeforeScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)voidbeforeStep(Step step)voidbeforeStoriesSteps(StepCollector.Stage stage)voidbeforeStory(Story story, boolean givenStory)voidbeforeStorySteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)voidcomment(String step)booleancompressFailureTrace()PrintStreamOutputdoCompressFailureTrace(boolean compressFailureTrace)PrintStreamOutputdoReportFailureTrace(boolean reportFailureTrace)voiddryRun()protected Object[]escape(PrintStreamOutput.Format format, Object... args)Escapes args' string values according to formatvoidexample(Map<String,String> tableRow, int exampleIndex)voidfailed(String step, Throwable storyFailure)voidfailedOutcomes(String step, OutcomesTable table)protected Stringformat(String key, String defaultPattern, Object... args)Formats event output by key, usually equal to the method name.protected StringformatTable(ExamplesTable table)protected StringformatVerbatim(Verbatim verbatim)voidgivenStories(List<String> storyPaths)voidgivenStories(GivenStories givenStories)voidignorable(String step)voidlifecycle(Lifecycle lifecycle)protected StringlookupPattern(String key, String defaultPattern)Looks up the format pattern for the event output by key, conventionally equal to the method name.voidnarrative(Narrative narrative)voidnotPerformed(String step)protected voidoverwritePattern(String key, String pattern)voidpending(StepCreator.PendingStep step)protected voidprint(PrintStream output, String text)protected voidprint(String text)Prints text to output stream, replacing parameter start and end placeholdersbooleanreportFailureTrace()voidrestarted(String step, Throwable cause)voidrestartedStory(Story story, Throwable cause)voidscenarioExcluded(Scenario scenario, String filter)voidstoryCancelled(Story story, StoryDuration storyDuration)voidstoryExcluded(Story story, String filter)voidsuccessful(String step)StringtoString()protected StringtransformPrintingTable(String text, String tableStart, String tableEnd)protected StringtransformPrintingVerbatim(String text, String verbatimStart, String verbatimEnd)-
Methods inherited from class org.jbehave.core.reporters.NullStoryReporter
pending, pendingMethods
-
-
-
-
Field Detail
-
NL
public static final String NL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PrintStreamOutput
protected PrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties defaultPatterns, Properties outputPatterns, Keywords keywords)
-
PrintStreamOutput
protected PrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties defaultPatterns, Properties outputPatterns, Keywords keywords, boolean reportFailureTrace, boolean compressFailureTrace)
-
PrintStreamOutput
protected PrintStreamOutput(PrintStreamOutput.Format format, PrintStream output, Properties outputPatterns, Keywords keywords, boolean reportFailureTrace, boolean compressFailureTrace)
-
-
Method Detail
-
beforeStep
public void beforeStep(Step step)
- Specified by:
beforeStepin interfaceStoryReporter- Overrides:
beforeStepin classNullStoryReporter
-
successful
public void successful(String step)
- Specified by:
successfulin interfaceStoryReporter- Overrides:
successfulin classNullStoryReporter
-
ignorable
public void ignorable(String step)
- Specified by:
ignorablein interfaceStoryReporter- Overrides:
ignorablein classNullStoryReporter
-
comment
public void comment(String step)
- Specified by:
commentin interfaceStoryReporter- Overrides:
commentin classNullStoryReporter
-
pending
public void pending(StepCreator.PendingStep step)
- Specified by:
pendingin interfaceStoryReporter- Overrides:
pendingin classNullStoryReporter
-
notPerformed
public void notPerformed(String step)
- Specified by:
notPerformedin interfaceStoryReporter- Overrides:
notPerformedin classNullStoryReporter
-
failed
public void failed(String step, Throwable storyFailure)
- Specified by:
failedin interfaceStoryReporter- Overrides:
failedin classNullStoryReporter
-
failedOutcomes
public void failedOutcomes(String step, OutcomesTable table)
- Specified by:
failedOutcomesin interfaceStoryReporter- Overrides:
failedOutcomesin classNullStoryReporter
-
storyExcluded
public void storyExcluded(Story story, String filter)
- Specified by:
storyExcludedin interfaceStoryReporter- Overrides:
storyExcludedin classNullStoryReporter
-
storyCancelled
public void storyCancelled(Story story, StoryDuration storyDuration)
- Specified by:
storyCancelledin interfaceStoryReporter- Overrides:
storyCancelledin classNullStoryReporter
-
beforeStory
public void beforeStory(Story story, boolean givenStory)
- Specified by:
beforeStoryin interfaceStoryReporter- Overrides:
beforeStoryin classNullStoryReporter
-
beforeScenarios
public void beforeScenarios()
- Specified by:
beforeScenariosin interfaceStoryReporter- Overrides:
beforeScenariosin classNullStoryReporter
-
afterScenarios
public void afterScenarios()
- Specified by:
afterScenariosin interfaceStoryReporter- Overrides:
afterScenariosin classNullStoryReporter
-
narrative
public void narrative(Narrative narrative)
- Specified by:
narrativein interfaceStoryReporter- Overrides:
narrativein classNullStoryReporter
-
lifecycle
public void lifecycle(Lifecycle lifecycle)
- Specified by:
lifecyclein interfaceStoryReporter- Overrides:
lifecyclein classNullStoryReporter
-
beforeScenarioSteps
public void beforeScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
- Specified by:
beforeScenarioStepsin interfaceStoryReporter- Overrides:
beforeScenarioStepsin classNullStoryReporter
-
afterScenarioSteps
public void afterScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
- Specified by:
afterScenarioStepsin interfaceStoryReporter- Overrides:
afterScenarioStepsin classNullStoryReporter
-
beforeComposedSteps
public void beforeComposedSteps()
- Specified by:
beforeComposedStepsin interfaceStoryReporter- Overrides:
beforeComposedStepsin classNullStoryReporter
-
afterComposedSteps
public void afterComposedSteps()
- Specified by:
afterComposedStepsin interfaceStoryReporter- Overrides:
afterComposedStepsin classNullStoryReporter
-
beforeStoriesSteps
public void beforeStoriesSteps(StepCollector.Stage stage)
- Specified by:
beforeStoriesStepsin interfaceStoryReporter- Overrides:
beforeStoriesStepsin classNullStoryReporter
-
afterStoriesSteps
public void afterStoriesSteps(StepCollector.Stage stage)
- Specified by:
afterStoriesStepsin interfaceStoryReporter- Overrides:
afterStoriesStepsin classNullStoryReporter
-
beforeStorySteps
public void beforeStorySteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
- Specified by:
beforeStoryStepsin interfaceStoryReporter- Overrides:
beforeStoryStepsin classNullStoryReporter
-
afterStorySteps
public void afterStorySteps(StepCollector.Stage stage, Lifecycle.ExecutionType type)
- Specified by:
afterStoryStepsin interfaceStoryReporter- Overrides:
afterStoryStepsin classNullStoryReporter
-
afterStory
public void afterStory(boolean givenOrRestartingStory)
- Specified by:
afterStoryin interfaceStoryReporter- Overrides:
afterStoryin classNullStoryReporter
-
beforeGivenStories
public void beforeGivenStories()
- Specified by:
beforeGivenStoriesin interfaceStoryReporter- Overrides:
beforeGivenStoriesin classNullStoryReporter
-
givenStories
public void givenStories(GivenStories givenStories)
- Specified by:
givenStoriesin interfaceStoryReporter- Overrides:
givenStoriesin classNullStoryReporter
-
givenStories
public void givenStories(List<String> storyPaths)
- Specified by:
givenStoriesin interfaceStoryReporter- Overrides:
givenStoriesin classNullStoryReporter
-
afterGivenStories
public void afterGivenStories()
- Specified by:
afterGivenStoriesin interfaceStoryReporter- Overrides:
afterGivenStoriesin classNullStoryReporter
-
scenarioExcluded
public void scenarioExcluded(Scenario scenario, String filter)
- Specified by:
scenarioExcludedin interfaceStoryReporter- Overrides:
scenarioExcludedin classNullStoryReporter
-
beforeScenario
public void beforeScenario(Scenario scenario)
- Specified by:
beforeScenarioin interfaceStoryReporter- Overrides:
beforeScenarioin classNullStoryReporter
-
afterScenario
public void afterScenario(Timing timing)
- Specified by:
afterScenarioin interfaceStoryReporter- Overrides:
afterScenarioin classNullStoryReporter
-
beforeExamples
public void beforeExamples(List<String> steps, ExamplesTable table)
- Specified by:
beforeExamplesin interfaceStoryReporter- Overrides:
beforeExamplesin classNullStoryReporter
-
example
public void example(Map<String,String> tableRow, int exampleIndex)
- Specified by:
examplein interfaceStoryReporter- Overrides:
examplein classNullStoryReporter
-
afterExamples
public void afterExamples()
- Specified by:
afterExamplesin interfaceStoryReporter- Overrides:
afterExamplesin classNullStoryReporter
-
dryRun
public void dryRun()
- Specified by:
dryRunin interfaceStoryReporter- Overrides:
dryRunin classNullStoryReporter
-
restarted
public void restarted(String step, Throwable cause)
- Specified by:
restartedin interfaceStoryReporter- Overrides:
restartedin classNullStoryReporter
-
restartedStory
public void restartedStory(Story story, Throwable cause)
- Specified by:
restartedStoryin interfaceStoryReporter- Overrides:
restartedStoryin classNullStoryReporter
-
format
protected String format(String key, String defaultPattern, Object... args)
Formats event output by key, usually equal to the method name.- Parameters:
key- the event keydefaultPattern- the default pattern to return if a custom pattern is not foundargs- the args used to format output- Returns:
- A formatted event output
-
formatTable
protected String formatTable(ExamplesTable table)
-
escape
protected Object[] escape(PrintStreamOutput.Format format, Object... args)
Escapes args' string values according to format- Parameters:
format- the Format used by the PrintStreamargs- the array of args to escape- Returns:
- The cloned and escaped array of args
-
lookupPattern
protected String lookupPattern(String key, String defaultPattern)
Looks up the format pattern for the event output by key, conventionally equal to the method name. The pattern is used by the {#format(String,String,Object...)} method and by default is formatted using theMessageFormat.format(String, Object...)method. If no pattern is found for key or needs to be overridden, the default pattern should be returned.- Parameters:
key- the format pattern keydefaultPattern- the default pattern if no pattern is- Returns:
- The format patter for the given key
-
reportFailureTrace
public boolean reportFailureTrace()
-
doReportFailureTrace
public PrintStreamOutput doReportFailureTrace(boolean reportFailureTrace)
-
compressFailureTrace
public boolean compressFailureTrace()
-
doCompressFailureTrace
public PrintStreamOutput doCompressFailureTrace(boolean compressFailureTrace)
-
print
protected void print(String text)
Prints text to output stream, replacing parameter start and end placeholders- Parameters:
text- the String to print
-
print
protected void print(PrintStream output, String text)
-
transformPrintingTable
protected String transformPrintingTable(String text, String tableStart, String tableEnd)
-
transformPrintingVerbatim
protected String transformPrintingVerbatim(String text, String verbatimStart, String verbatimEnd)
-
-