- Revision
- 1634
- Author
- mauro
- Date
- 2010-05-06 11:54:48 -0500 (Thu, 06 May 2010)
Log Message
JBEHAVE-283: Made report rendering failure aware, similarly to scenario runner.
Modified Paths
- trunk/core/distribution/src/site/content/release-notes.html
- trunk/core/distribution/src/site/content/reports.html
- trunk/core/distribution/src/site/content/running-scenarios.html
- trunk/core/examples/trader/build.xml
- trunk/core/examples/trader/pom.xml
- trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/AbstractScenarioTask.java
- trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ReportRendererTask.java
- trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ScenarioRunnerTask.java
- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/FreemarkerReportRenderer.java
- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/ReportRenderer.java
- trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ReportRendererMojo.java
- trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ScenarioRunnerMojo.java
Diff
Modified: trunk/core/distribution/src/site/content/release-notes.html (1633 => 1634)
--- trunk/core/distribution/src/site/content/release-notes.html 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/distribution/src/site/content/release-notes.html 2010-05-06 16:54:48 UTC (rev 1634) @@ -5,6 +5,24 @@ </head> <body> +<h1>JBehave Core - Version 2.5.5 (May 7, 2010)</h1> + +<h2> Improvement +</h2> +<ul> +<li>[<a href="" - Report Renderer should be failure aware +</li> +</ul> + +<h1>JBehave Core - Version 2.5.4 (May 5, 2010)</h1> + +<h2> Bug +</h2> +<ul> +<li>[<a href="" - Using GivenScenarios causes failed tests to be forgotten +</li> +</ul> + <h1>JBehave Core - Version 2.5.3 (May 3, 2010)</h1> <h2> Bug
Modified: trunk/core/distribution/src/site/content/reports.html (1633 => 1634)
--- trunk/core/distribution/src/site/content/reports.html 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/distribution/src/site/content/reports.html 2010-05-06 16:54:48 UTC (rev 1634) @@ -160,6 +160,13 @@ goal (c.f. <a href="" scenarios</a> for examples).</p> +<span class="followup">When running in a continuous-integration (CI) environment, it is +important to bear in mind that the two-phase process requires that the <b>ignoreFailure=true</b> +flag be set in the report generation (i.e. the running of the scenarios), so that all reports are +collected, while the <b>ignoreFailure</b> flag in the report rendering will determine the behaviour upon any scenario failures. +The default value for the rendering phase is <b>ignoreFailure=false</b> is adequate for CI builds. +</span> + <h2>Reporting Statistics</h2> <p>The scenario statistics report above is treated in the rendering
Modified: trunk/core/distribution/src/site/content/running-scenarios.html (1633 => 1634)
--- trunk/core/distribution/src/site/content/running-scenarios.html 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/distribution/src/site/content/running-scenarios.html 2010-05-06 16:54:48 UTC (rev 1634) @@ -45,7 +45,8 @@ <renderReports outputDirectory="${basedir}/target/jbehave-reports" formats="txt,html,xml" - templateProperties="defaultFormats=stats\nrenderedDirectory=rendered" /> + templateProperties="defaultFormats=stats\nrenderedDirectory=rendered" + ignoreFailure="[true|false]"/> ]]></script> @@ -106,6 +107,7 @@ <value>rendered</value> </property> </templateProperties> + <ignoreFailure>[true|false]</ignoreFailure> </configuration> <goals> <goal>render-reports</goal>
Modified: trunk/core/examples/trader/build.xml (1633 => 1634)
--- trunk/core/examples/trader/build.xml 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/examples/trader/build.xml 2010-05-06 16:54:48 UTC (rev 1634) @@ -54,15 +54,11 @@ classpathref="scenario.classpath" /> <scenarioRunner scenarioIncludes="**/scenarios/*.java" - sourceDirectory="${basedir}/src/main/java" - scenarioExcludes="**/scenarios/*NonSuccessful.java,**/i18n/scenarios/*.java" - batch="true" ignoreFailure="false" classLoaderInjected="false" /> - <scenarioRunner scenarioIncludes="**/scenarios/*.java" sourceDirectory="${basedir}/src/main/java" scenarioExcludes="**/i18n/scenarios/*.java" batch="true" ignoreFailure="true" classLoaderInjected="false" /> <scenarioRunner scenarioIncludes="**/i18n/scenarios/*.java" sourceDirectory="${basedir}/src/main/java" scenarioExcludes="**/scenarios/*NonSuccessful.java" - classLoaderInjected="true" /> + classLoaderInjected="true" ignoreFailure="false" /> </target> <target name="reports-resources"> @@ -95,7 +91,8 @@ classpathref="scenario.classpath" /> <reportRenderer outputDirectory="${basedir}/target/jbehave-reports" - formats="txt,html,xml" templateProperties="defaultFormats=stats" /> + formats="txt,html,xml" templateProperties="defaultFormats=stats" + ignoreFailure="true"/> </target>
Modified: trunk/core/examples/trader/pom.xml (1633 => 1634)
--- trunk/core/examples/trader/pom.xml 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/examples/trader/pom.xml 2010-05-06 16:54:48 UTC (rev 1634) @@ -92,12 +92,10 @@ </scenarioIncludes> <scenarioExcludes> <scenarioExclude>**/i18n/scenarios/*.java</scenarioExclude> - <scenarioExclude>**/scenarios/Failure*.java</scenarioExclude> - <scenarioExclude>**/scenarios/*NonSuccessful.java</scenarioExclude> </scenarioExcludes> <skip>false</skip> <batch>false</batch> - <ignoreFailure>false</ignoreFailure> + <ignoreFailure>true</ignoreFailure> <classLoaderInjected>false</classLoaderInjected> </configuration> <goals> @@ -173,6 +171,7 @@ <value>rendered</value> </property> </templateProperties> + <ignoreFailure>true</ignoreFailure> </configuration> <goals> <goal>render-reports</goal> @@ -191,13 +190,21 @@ <tasks> <taskdef name="scenarioRunner" classname="org.jbehave.ant.ScenarioRunnerTask" - classpathref="maven.runtime.classpath" /> + classpathref="maven.runtime.classpath"/> <scenarioRunner scenarioIncludes="**/scenarios/*.java" scenarioExcludes="**/i18n/scenarios/*.java" - classLoaderInjected="false" skip="${skip.ant.scenarios}" /> + classLoaderInjected="false" skip="${skip.ant.scenarios}" + ignoreFailure="true" /> <scenarioRunner scenarioIncludes="**/i18n/scenarios/*.java" - scenarioExcludes="" classLoaderInjected="true" - skip="${skip.ant.scenarios}" /> + scenarioExcludes="" + classLoaderInjected="false" skip="${skip.ant.scenarios}" + ignoreFailure="false" /> + <taskdef name="reportRenderer" + classname="org.jbehave.ant.ReportRendererTask" + classpathref="maven.runtime.classpath" /> + <reportRenderer outputDirectory="${basedir}/target/jbehave-reports" + formats="txt,html,xml" templateProperties="defaultFormats=stats" + ignoreFailure="true" /> </tasks> </configuration> <goals>
Modified: trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/AbstractScenarioTask.java (1633 => 1634)
--- trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/AbstractScenarioTask.java 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/AbstractScenarioTask.java 2010-05-06 16:54:48 UTC (rev 1634) @@ -209,7 +209,7 @@ this.scenarioExcludes = asList(scenarioExcludesCSV.split(",")); } - public void setclassLoaderInjected(boolean classLoaderInjected) { + public void setClassLoaderInjected(boolean classLoaderInjected) { this.classLoaderInjected = classLoaderInjected; } @@ -221,6 +221,4 @@ this.ignoreFailure = ignoreFailure; } - - }
Modified: trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ReportRendererTask.java (1633 => 1634)
--- trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ReportRendererTask.java 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ReportRendererTask.java 2010-05-06 16:54:48 UTC (rev 1634) @@ -31,6 +31,11 @@ private List<String> formats = asList(); /** + * The flag to ignore failures + */ + private boolean ignoreFailure = false; + + /** * The template properties */ private Properties templateProperties = new Properties(); @@ -47,6 +52,13 @@ log(message, MSG_WARN); throw new BuildException(message, e); } + int scenarios = renderer.countScenarios(); + int failed = renderer.countFailedScenarios(); + String message = "Rendered reports with "+scenarios+" scenarios (of which "+failed+" failed)"; + log(message, MSG_INFO); + if ( !ignoreFailure && failed > 0 ){ + throw new BuildException(message); + } } // Setters @@ -68,5 +80,7 @@ } } - + public void setIgnoreFailure(boolean ignoreFailure){ + this.ignoreFailure = ignoreFailure; + } }
Modified: trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ScenarioRunnerTask.java (1633 => 1634)
--- trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ScenarioRunnerTask.java 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ScenarioRunnerTask.java 2010-05-06 16:54:48 UTC (rev 1634) @@ -40,7 +40,8 @@ failedScenarios.put(scenarioName, e); } else { if (ignoreFailure()) { - log(message, e, MSG_WARN); + log(message, MSG_WARN); + e.printStackTrace(); } else { throw new BuildException(message, e); } @@ -48,7 +49,7 @@ } } if (batch && failedScenarios.size() > 0) { - String message = "Failure in runing scenarios: " + format(failedScenarios); + String message = "Failure in running scenarios: " + format(failedScenarios); if (ignoreFailure()) { log(message, MSG_WARN); } else {
Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/FreemarkerReportRenderer.java (1633 => 1634)
--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/FreemarkerReportRenderer.java 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/FreemarkerReportRenderer.java 2010-05-06 16:54:48 UTC (rev 1634) @@ -30,7 +30,7 @@ * views are injectable via the {...@link FreemarkerReportRender(Properties)} * constructor, but defaults are provided. To override, specify the the path the * new template under keys "index" and "single".</p> - * <p>The report renderer provids the following template resources: + * <p>The report renderer provides the following template resources: * <pre> * resources.setProperty("index", "ftl/jbehave-reports-index.ftl"); * resources.setProperty("single", "ftl/jbehave-reports-single.ftl"); @@ -44,6 +44,7 @@ private final Configuration configuration; private final Properties templateResources; + private List<Report> renderedReports = new ArrayList<Report>(); public FreemarkerReportRenderer() { this(defaultTemplateResources()); @@ -73,12 +74,34 @@ createIndex(outputDirectory, formats); } + public int countScenarios(){ + return count("scenarios", renderedReports); + } + + public int countFailedScenarios(){ + return count("scenariosFailed", renderedReports); + } + + private int count(String event, List<Report> renderedReports) { + int count = 0; + for (Report report : renderedReports) { + Properties stats = report.asProperties("stats"); + if ( stats != null ){ + if ( stats.containsKey(event)){ + int failed = Integer.parseInt((String)stats.get(event)); + count = count + failed; + } + } + } + return count; + } + private void createIndex(File outputDirectory, List<String> formats) { String outputName = templateResource("renderedDirectory")+"/index.html"; String resource = templateResource("index"); List<String> mergedFormats = mergeWithDefaults(formats); Map<String, List<File>> reportFiles = generatedReportFiles(outputDirectory, outputName, mergedFormats); - List<Report> renderedReports = renderedReports(reportFiles); + renderedReports = renderedReports(reportFiles); Map<String, Object> dataModel = newDataModel(); dataModel.put("reports", renderedReports); dataModel.put("date", new Date());
Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/ReportRenderer.java (1633 => 1634)
--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/ReportRenderer.java 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/ReportRenderer.java 2010-05-06 16:54:48 UTC (rev 1634) @@ -12,4 +12,8 @@ void render(File outputDirectory, List<String> formats); + int countScenarios(); + + int countFailedScenarios(); + }
Modified: trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ReportRendererMojo.java (1633 => 1634)
--- trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ReportRendererMojo.java 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ReportRendererMojo.java 2010-05-06 16:54:48 UTC (rev 1634) @@ -47,6 +47,13 @@ private Properties templateProperties = new Properties(); /** + * The flag to ignore failures + * + * @parameter + */ + private boolean ignoreFailure = false; + + /** * <i>Maven Internal</i>: The Doxia Site Renderer. * * @component @@ -91,17 +98,24 @@ } protected void executeReport(Locale locale) throws MavenReportException { - ReportRenderer reportRenderer = new FreemarkerReportRenderer(templateProperties); + ReportRenderer renderer = new FreemarkerReportRenderer(templateProperties); try { getLog().info("Rendering reports in '" + outputDirectory + "' using formats '" + formats + "'" + " and template properties '"+templateProperties+"'"); - reportRenderer.render(outputDirectory, formats); + renderer.render(outputDirectory, formats); } catch (RuntimeException e) { String message = "Failed to render reports in outputDirectory " + outputDirectory + " using formats " + formats + " and template properties '"+templateProperties+"'"; getLog().warn(message, e); throw new MavenReportException(message, e); } + int scenarios = renderer.countScenarios(); + int failed = renderer.countFailedScenarios(); + String message = "Rendered reports with "+scenarios+" scenarios (of which "+failed+" failed)"; + getLog().info(message); + if ( !ignoreFailure && failed > 0 ){ + throw new MavenReportException(message); + } } public String getOutputName() {
Modified: trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ScenarioRunnerMojo.java (1633 => 1634)
--- trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ScenarioRunnerMojo.java 2010-05-05 22:55:40 UTC (rev 1633) +++ trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ScenarioRunnerMojo.java 2010-05-06 16:54:48 UTC (rev 1634) @@ -50,7 +50,7 @@ } if (batch && failedScenarios.size() > 0) { - String message = "Failure in runing scenarios: " + format(failedScenarios); + String message = "Failure in running scenarios: " + format(failedScenarios); if ( ignoreFailure() ){ getLog().warn(message); } else {
To unsubscribe from this list please visit:
