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.failures.BatchFailures; |
11 | |
import org.jbehave.core.model.Meta; |
12 | |
import org.jbehave.core.model.StoryMaps; |
13 | |
import org.jbehave.core.reporters.ReportsCount; |
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
public class PrintStreamEmbedderMonitor implements EmbedderMonitor { |
20 | |
private PrintStream output; |
21 | |
|
22 | |
public PrintStreamEmbedderMonitor() { |
23 | 77 | this(System.out); |
24 | 77 | } |
25 | |
|
26 | 106 | public PrintStreamEmbedderMonitor(PrintStream output) { |
27 | 106 | this.output = output; |
28 | 106 | } |
29 | |
|
30 | |
public void batchFailed(BatchFailures failures) { |
31 | 3 | print("Failed to run batch " + failures); |
32 | 3 | } |
33 | |
|
34 | |
public void embeddableFailed(String name, Throwable cause) { |
35 | 1 | print("Failed to run embeddable " + name); |
36 | 1 | printStackTrace(cause); |
37 | 1 | } |
38 | |
|
39 | |
public void embeddablesSkipped(List<String> classNames) { |
40 | 1 | print("Skipped embeddables " + classNames); |
41 | 1 | } |
42 | |
|
43 | |
public void metaNotAllowed(Meta meta, MetaFilter filter) { |
44 | 7 | print(meta + " not allowed by filter '" + filter.asString() + "'"); |
45 | 7 | } |
46 | |
|
47 | |
public void runningEmbeddable(String name) { |
48 | 15 | print("Running embeddable " + name); |
49 | 15 | } |
50 | |
|
51 | |
public void runningStory(String path) { |
52 | 25 | print("Running story " + path); |
53 | 25 | } |
54 | |
|
55 | |
public void storyFailed(String path, Throwable cause) { |
56 | 3 | print("Failed to run story " + path); |
57 | 3 | printStackTrace(cause); |
58 | 3 | } |
59 | |
|
60 | |
public void storiesSkipped(List<String> storyPaths) { |
61 | 1 | print("Skipped stories " + storyPaths); |
62 | 1 | } |
63 | |
|
64 | |
public void annotatedInstanceNotOfType(Object annotatedInstance, Class<?> type) { |
65 | 1 | print("Annotated instance " + annotatedInstance + " if not of type " + type); |
66 | 1 | } |
67 | |
|
68 | |
public void generatingReportsView(File outputDirectory, List<String> formats, Properties viewProperties) { |
69 | 17 | print("Generating reports view to '" + outputDirectory + "' using formats '" + formats + "'" |
70 | |
+ " and view properties '" + viewProperties + "'"); |
71 | 17 | } |
72 | |
|
73 | |
public void reportsViewGenerationFailed(File outputDirectory, List<String> formats, Properties viewProperties, |
74 | |
Throwable cause) { |
75 | 1 | print("Failed to generate reports view to '" + outputDirectory + "' using formats '" + formats |
76 | |
+ "' and view properties '" + viewProperties + "'"); |
77 | 1 | } |
78 | |
|
79 | |
public void reportsViewGenerated(ReportsCount count) { |
80 | 16 | print("Reports view generated with " + count.getStories() + " stories containing " + count.getScenarios() + " scenarios (of which " |
81 | |
+ count.getScenariosFailed() + " failed)"); |
82 | 16 | if (count.getStoriesNotAllowed() > 0 || count.getScenariosNotAllowed() > 0) { |
83 | 1 | print("Meta filters did not allow " + count.getStoriesNotAllowed() + " stories and " + count.getScenariosNotAllowed() |
84 | |
+ " scenarios"); |
85 | |
} |
86 | 16 | } |
87 | |
|
88 | |
public void reportsViewNotGenerated() { |
89 | 1 | print("Reports view not generated"); |
90 | 1 | } |
91 | |
|
92 | |
public void mappingStory(String storyPath, List<String> metaFilters) { |
93 | 2 | print("Mapping story " + storyPath + " with meta filters " + metaFilters); |
94 | 2 | } |
95 | |
|
96 | |
public void generatingMapsView(File outputDirectory, StoryMaps storyMaps, Properties viewProperties) { |
97 | 1 | print("Generating maps view to '" + outputDirectory + "' using story maps '" + storyMaps + "'" |
98 | |
+ " and view properties '" + viewProperties + "'"); |
99 | 1 | } |
100 | |
|
101 | |
public void mapsViewGenerationFailed(File outputDirectory, StoryMaps storyMaps, Properties viewProperties, |
102 | |
Throwable cause) { |
103 | 0 | print("Generating maps view to '" + outputDirectory + "' using story maps '" + storyMaps + "'" |
104 | |
+ " and view properties '" + viewProperties + "'"); |
105 | 0 | } |
106 | |
|
107 | |
public void processingSystemProperties(Properties properties) { |
108 | 22 | print("Processing system properties " + properties); |
109 | 22 | } |
110 | |
|
111 | |
public void systemPropertySet(String name, String value) { |
112 | 2 | print("System property '" + name + "' set to '"+value+"'"); |
113 | 2 | } |
114 | |
|
115 | |
@Override |
116 | |
public String toString() { |
117 | 2 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); |
118 | |
} |
119 | |
|
120 | |
protected void print(String message) { |
121 | 120 | output.println(message); |
122 | 120 | } |
123 | |
|
124 | |
protected void printStackTrace(Throwable e) { |
125 | 4 | e.printStackTrace(output); |
126 | 4 | } |
127 | |
|
128 | |
} |