| 1 | |
package org.jbehave.core.embedder; |
| 2 | |
|
| 3 | |
import java.io.File; |
| 4 | |
import java.io.PrintStream; |
| 5 | |
import java.util.List; |
| 6 | |
import java.util.Properties; |
| 7 | |
|
| 8 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 9 | |
import org.apache.commons.lang.builder.ToStringStyle; |
| 10 | |
import org.jbehave.core.ConfigurableEmbedder; |
| 11 | |
import org.jbehave.core.failures.BatchFailures; |
| 12 | |
import org.jbehave.core.model.Meta; |
| 13 | |
import org.jbehave.core.model.Story; |
| 14 | |
import org.jbehave.core.model.StoryMaps; |
| 15 | |
import org.jbehave.core.reporters.ReportsCount; |
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
public class PrintStreamEmbedderMonitor implements EmbedderMonitor { |
| 22 | |
private PrintStream output; |
| 23 | |
|
| 24 | |
public PrintStreamEmbedderMonitor() { |
| 25 | 71 | this(System.out); |
| 26 | 71 | } |
| 27 | |
|
| 28 | 100 | public PrintStreamEmbedderMonitor(PrintStream output) { |
| 29 | 100 | this.output = output; |
| 30 | 100 | } |
| 31 | |
|
| 32 | |
public void batchFailed(BatchFailures failures) { |
| 33 | 3 | print("Failed to run batch " + failures); |
| 34 | 3 | } |
| 35 | |
|
| 36 | |
public void embeddableFailed(String name, Throwable cause) { |
| 37 | 1 | print("Failed to run embeddable " + name); |
| 38 | 1 | printStackTrace(cause); |
| 39 | 1 | } |
| 40 | |
|
| 41 | |
public void embeddableNotConfigurable(String name) { |
| 42 | 0 | print("Embeddable " + name + " must be an instance of "+ConfigurableEmbedder.class); |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
public void embeddablesSkipped(List<String> classNames) { |
| 46 | 1 | print("Skipped embeddables " + classNames); |
| 47 | 1 | } |
| 48 | |
|
| 49 | |
public void metaNotAllowed(Meta meta, MetaFilter filter) { |
| 50 | 7 | print(meta + " excluded by filter '" + filter.asString() + "'"); |
| 51 | 7 | } |
| 52 | |
|
| 53 | |
public void runningEmbeddable(String name) { |
| 54 | 15 | print("Running embeddable " + name); |
| 55 | 15 | } |
| 56 | |
|
| 57 | |
public void runningStory(String path) { |
| 58 | 26 | print("Running story " + path); |
| 59 | 26 | } |
| 60 | |
|
| 61 | |
public void storyFailed(String path, Throwable cause) { |
| 62 | 3 | print("Failed to run story " + path); |
| 63 | 3 | printStackTrace(cause); |
| 64 | 3 | } |
| 65 | |
|
| 66 | |
public void storiesSkipped(List<String> storyPaths) { |
| 67 | 1 | print("Skipped stories " + storyPaths); |
| 68 | 1 | } |
| 69 | |
|
| 70 | |
public void annotatedInstanceNotOfType(Object annotatedInstance, Class<?> type) { |
| 71 | 1 | print("Annotated instance " + annotatedInstance + " if not of type " + type); |
| 72 | 1 | } |
| 73 | |
|
| 74 | |
public void generatingReportsView(File outputDirectory, List<String> formats, Properties viewProperties) { |
| 75 | 17 | print("Generating reports view to '" + outputDirectory + "' using formats '" + formats + "'" |
| 76 | |
+ " and view properties '" + viewProperties + "'"); |
| 77 | 17 | } |
| 78 | |
|
| 79 | |
public void reportsViewGenerationFailed(File outputDirectory, List<String> formats, Properties viewProperties, |
| 80 | |
Throwable cause) { |
| 81 | 1 | print("Failed to generate reports view to '" + outputDirectory + "' using formats '" + formats |
| 82 | |
+ "' and view properties '" + viewProperties + "'"); |
| 83 | 1 | } |
| 84 | |
|
| 85 | |
public void reportsViewGenerated(ReportsCount count) { |
| 86 | 16 | print("Reports view generated with " + count.getStories() + " stories (of which " + count.getStoriesPending() |
| 87 | |
+ " pending) containing " + "" + count.getScenarios() + " scenarios (of which " |
| 88 | |
+ count.getScenariosFailed() + " failed and " + count.getScenariosPending() + " pending)"); |
| 89 | 16 | if (count.getStoriesNotAllowed() > 0 || count.getScenariosNotAllowed() > 0) { |
| 90 | 1 | print("Meta filters did not allow " + count.getStoriesNotAllowed() + " stories and " + count.getScenariosNotAllowed() |
| 91 | |
+ " scenarios"); |
| 92 | |
} |
| 93 | 16 | } |
| 94 | |
|
| 95 | |
public void reportsViewNotGenerated() { |
| 96 | 1 | print("Reports view not generated"); |
| 97 | 1 | } |
| 98 | |
|
| 99 | |
public void mappingStory(String storyPath, List<String> metaFilters) { |
| 100 | 2 | print("Mapping story " + storyPath + " with meta filters " + metaFilters); |
| 101 | 2 | } |
| 102 | |
|
| 103 | |
public void generatingMapsView(File outputDirectory, StoryMaps storyMaps, Properties viewProperties) { |
| 104 | 1 | print("Generating maps view to '" + outputDirectory + "' using story maps '" + storyMaps + "'" |
| 105 | |
+ " and view properties '" + viewProperties + "'"); |
| 106 | 1 | } |
| 107 | |
|
| 108 | |
public void mapsViewGenerationFailed(File outputDirectory, StoryMaps storyMaps, Properties viewProperties, |
| 109 | |
Throwable cause) { |
| 110 | 0 | print("Failed to generating maps view to '" + outputDirectory + "' using story maps '" + storyMaps + "'" |
| 111 | |
+ " and view properties '" + viewProperties + "'"); |
| 112 | 0 | printStackTrace(cause); |
| 113 | 0 | } |
| 114 | |
|
| 115 | |
public void generatingNavigatorView(File outputDirectory, Properties viewProperties) { |
| 116 | 0 | print("Generating navigator view to '" + outputDirectory + "' using view properties '" + viewProperties + "'"); |
| 117 | 0 | } |
| 118 | |
|
| 119 | |
public void navigatorViewGenerationFailed(File outputDirectory, Properties viewProperties, Throwable cause) { |
| 120 | 0 | print("Failed to generating navigator view to '" + outputDirectory + "' using view properties '" + viewProperties + "'"); |
| 121 | 0 | printStackTrace(cause); |
| 122 | 0 | } |
| 123 | |
|
| 124 | |
public void navigatorViewNotGenerated() { |
| 125 | 0 | print("Navigator view not generated, as the CrossReference has not been declared in the StoryReporterBuilder"); |
| 126 | 0 | } |
| 127 | |
|
| 128 | |
public void processingSystemProperties(Properties properties) { |
| 129 | 22 | print("Processing system properties " + properties); |
| 130 | 22 | } |
| 131 | |
|
| 132 | |
public void systemPropertySet(String name, String value) { |
| 133 | 2 | print("System property '" + name + "' set to '"+value+"'"); |
| 134 | 2 | } |
| 135 | |
|
| 136 | |
public void storyTimeout(long durationInSecs, Story story) { |
| 137 | 0 | print("Story " + story.getPath() + " has timed out after " + durationInSecs + " seconds"); |
| 138 | 0 | } |
| 139 | |
|
| 140 | |
public void usingThreads(int threads) { |
| 141 | 15 | print("Using " + threads + " threads"); |
| 142 | 15 | } |
| 143 | |
|
| 144 | |
@Override |
| 145 | |
public String toString() { |
| 146 | 2 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); |
| 147 | |
} |
| 148 | |
|
| 149 | |
protected void print(String message) { |
| 150 | 136 | output.println(message); |
| 151 | 136 | } |
| 152 | |
|
| 153 | |
protected void printStackTrace(Throwable e) { |
| 154 | 4 | e.printStackTrace(output); |
| 155 | 4 | } |
| 156 | |
|
| 157 | |
|
| 158 | |
} |