- Revision
- 1461
- Author
- mauro
- Date
- 2009-12-23 11:57:34 -0600 (Wed, 23 Dec 2009)
Log Message
JBEHAVE-227: Added XmlPrintStreamScenarioReporter. Updated trader examples to include in the formats being generated and rendered.
Modified Paths
- trunk/core/examples/trader/build.xml
- trunk/core/examples/trader/pom.xml
- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java
- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporterBehaviour.java
Added Paths
Diff
Modified: trunk/core/examples/trader/build.xml (1460 => 1461)
--- trunk/core/examples/trader/build.xml 2009-12-23 00:18:58 UTC (rev 1460) +++ trunk/core/examples/trader/build.xml 2009-12-23 17:57:34 UTC (rev 1461) @@ -98,7 +98,7 @@ classpathref="scenario.classpath" /> <reportRenderer outputDirectory="${basedir}/target/jbehave-reports" - formats="html,txt,stats" /> + formats="txt,html,xml,stats" /> </target>
Modified: trunk/core/examples/trader/pom.xml (1460 => 1461)
--- trunk/core/examples/trader/pom.xml 2009-12-23 00:18:58 UTC (rev 1460) +++ trunk/core/examples/trader/pom.xml 2009-12-23 17:57:34 UTC (rev 1461) @@ -145,9 +145,10 @@ <phase>post-integration-test</phase> <configuration> <formats> + <format>txt</format> <format>html</format> + <format>xml</format> <format>stats</format> - <format>txt</format> </formats> </configuration> <goals>
Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java (1460 => 1461)
--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java 2009-12-23 00:18:58 UTC (rev 1460) +++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java 2009-12-23 17:57:34 UTC (rev 1461) @@ -8,12 +8,13 @@ import org.jbehave.scenario.parser.ScenarioDefiner; import org.jbehave.scenario.parser.ScenarioNameResolver; import org.jbehave.scenario.parser.UnderscoredCamelCaseResolver; -import org.jbehave.scenario.reporters.StatisticsScenarioReporter; import org.jbehave.scenario.reporters.DelegatingScenarioReporter; import org.jbehave.scenario.reporters.FilePrintStreamFactory; import org.jbehave.scenario.reporters.HtmlPrintStreamScenarioReporter; import org.jbehave.scenario.reporters.PrintStreamScenarioReporter; import org.jbehave.scenario.reporters.ScenarioReporter; +import org.jbehave.scenario.reporters.StatisticsScenarioReporter; +import org.jbehave.scenario.reporters.XmlPrintStreamScenarioReporter; import org.jbehave.scenario.reporters.FilePrintStreamFactory.FileConfiguration; public class TraderScenario extends JUnitScenario { @@ -38,6 +39,9 @@ // report to .html file in HTML format new HtmlPrintStreamScenarioReporter(new FilePrintStreamFactory(scenarioClass, converter, new FileConfiguration("html")).getPrintStream()), + // report to .xml file in XML format + new XmlPrintStreamScenarioReporter(new FilePrintStreamFactory(scenarioClass, converter, + new FileConfiguration("xml")).getPrintStream()), // report to .stats file in Properties format new StatisticsScenarioReporter(new FilePrintStreamFactory(scenarioClass, converter, new FileConfiguration("stats")).getPrintStream()));
Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporterBehaviour.java (1460 => 1461)
--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporterBehaviour.java 2009-12-23 00:18:58 UTC (rev 1460) +++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporterBehaviour.java 2009-12-23 17:57:34 UTC (rev 1461) @@ -129,7 +129,48 @@ + "</div><!-- after scenario -->\n" + "</div><!-- after story -->\n"; ensureThatOutputIs(out, expected); } + + @Test + public void shouldReportEventsToXmlPrintStream() { + // Given + final OutputStream out = new ByteArrayOutputStream(); + PrintStreamFactory factory = new PrintStreamFactory() { + public PrintStream getPrintStream() { + return new PrintStream(out); + } + }; + ScenarioReporter reporter = new XmlPrintStreamScenarioReporter(factory.getPrintStream()); + + // When + narrateAnInterestingStory(reporter); + + // Then + String expected = + "<story path=\"/path/to/story\" title=\"An interesting story\">\n" + + "<scenario keyword=\"Scenario:\" title=\"I ask for a loan\">\n" + + "<givenScenarios keyword=\"GivenScenarios:\"paths=\"[/given/scenario1,/given/scenario2]\"</givenScenarios>\n" + + "<step outcome=\"successful\">Given I have a balance of $50</step>\n" + + "<step outcome=\"successful\">When I request $20</step>\n" + + "<step outcome=\"successful\">When I ask Liz for a loan of $100</step>\n" + + "<step outcome=\"pending\" keyword=\"PENDING\">Then I should have a balance of $30</step>\n" + + "<step outcome=\"notPerformed\" keyword=\"NOT PERFORMED\">Then I should have $20</step>\n" + + "<step outcome=\"failed\" keyword=\"FAILED\">Then I don't return loan</step>\n" + + "<examples keyword=\"Examples:\">\n" + + "<parameters>\n" + + "<names><name>money</name><name>to</name></names>\n" + + "<values><value>$30</value><value>Mauro</value></values>\n" + + "<values><value>$50</value><value>Paul</value></values>\n" + + "</parameters>\n" + + "\n<example keyword=\"Example:\">{to=Mauro, money=$30}</example>\n" + + "\n<example keyword=\"Example:\">{to=Paul, money=$50}</example>\n" + + "</examples>\n" + + "</scenario>\n" + + "</story>\n"; + ensureThatOutputIs(out, expected); + } + + private void narrateAnInterestingStory(ScenarioReporter reporter) { StoryDefinition story = new StoryDefinition(new Blurb("An interesting story"), new ArrayList<ScenarioDefinition>(), "/path/to/story"); @@ -156,7 +197,7 @@ private void ensureThatOutputIs(OutputStream out, String expected) { // JUnit assertion allows easier comparison of strings in IDE assertEquals(expected, dos2unix(out.toString())); - // ensureThat(out.toString(), equalTo(expected)); + //ensureThat(out.toString(), equalTo(expected)); } private String dos2unix(String string) {
Added: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/XmlPrintStreamScenarioReporter.java (0 => 1461)
--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/XmlPrintStreamScenarioReporter.java (rev 0) +++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/XmlPrintStreamScenarioReporter.java 2009-12-23 17:57:34 UTC (rev 1461) @@ -0,0 +1,71 @@ +package org.jbehave.scenario.reporters; + +import java.io.PrintStream; +import java.util.Properties; + +import org.jbehave.scenario.definition.KeyWords; + +/** + * <p> + * Scenario reporter that outputs to a PrintStream, as XML. It extends + * {...@link PrintStreamScenarioReporter}, providing XML-based default output + * patterns, which can be overridden via the {...@link + * XmlPrintStreamScenarioReporter(PrintStream,Properties)} constructor. + * </p> + * + * @author Mauro Talevi + */ +public class XmlPrintStreamScenarioReporter extends PrintStreamScenarioReporter { + + public XmlPrintStreamScenarioReporter(PrintStream output) { + this(output, defaultHtmlPatterns()); + } + + public XmlPrintStreamScenarioReporter(PrintStream output, Properties outputPatterns) { + super(mergeWithDefault(outputPatterns), Format.XML); + usePrintStream(output); + } + + public XmlPrintStreamScenarioReporter(PrintStream output, Properties outputPatterns, + KeyWords keywords, boolean reportErrors) { + super(output, mergeWithDefault(outputPatterns), Format.XML, keywords, reportErrors); + } + + private static Properties mergeWithDefault(Properties outputPatterns) { + Properties patterns = defaultHtmlPatterns(); + // override any default pattern + patterns.putAll(outputPatterns); + return patterns; + } + + private static Properties defaultHtmlPatterns() { + Properties patterns = new Properties(); + patterns.setProperty("successful", "<step outcome=\"successful\">{0}</step>\n"); + patterns.setProperty("pending", "<step outcome=\"pending\" keyword=\"{1}\">{0}</step>\n"); + patterns.setProperty("notPerformed", "<step outcome=\"notPerformed\" keyword=\"{1}\">{0}</step>\n"); + patterns.setProperty("failed", "<step outcome=\"failed\" keyword=\"{1}\">{0}</step>\n"); + patterns.setProperty("beforeStory", "<story path=\"{1}\" title=\"{0}\">\n"); + patterns.setProperty("afterStory", "</story>\n"); + patterns.setProperty("beforeScenario", "<scenario keyword=\"{0}\" title=\"{1}\">\n"); + patterns.setProperty("afterScenario", "</scenario>\n"); + patterns.setProperty("afterScenarioWithFailure", "<failure>{0}</failure>\n</scenario>\n"); + patterns.setProperty("givenScenarios", "<givenScenarios keyword=\"{0}\"paths=\"{1}\"</givenScenarios>\n"); + patterns.setProperty("beforeExamples", "<examples keyword=\"{0}\">\n"); + patterns.setProperty("afterExamples", "</examples>\n"); + patterns.setProperty("examplesTableStart", "<parameters>\n"); + patterns.setProperty("examplesTableHeadStart", "<names>"); + patterns.setProperty("examplesTableHeadCell", "<name>{0}</name>"); + patterns.setProperty("examplesTableHeadEnd", "</names>\n"); + patterns.setProperty("examplesTableBodyStart", ""); + patterns.setProperty("examplesTableRowStart", "<values>"); + patterns.setProperty("examplesTableCell", "<value>{0}</value>"); + patterns.setProperty("examplesTableRowEnd", "</values>\n"); + patterns.setProperty("examplesTableBodyEnd", ""); + patterns.setProperty("examplesTableEnd", "</parameters>\n"); + patterns.setProperty("example", "\n<example keyword=\"{0}\">{1}</example>\n"); + patterns.setProperty("parameterValueStart", "<parameter>"); + patterns.setProperty("parameterValueEnd", "</parameter>"); + return patterns; + } + +}
To unsubscribe from this list please visit:
