| 1 | /* |
| 2 | * JTiger Unit Testing Framework for J2SE 1.5 |
| 3 | * Copyright (C) 2005 Tony Morris |
| 4 | * |
| 5 | * This software is licenced under the |
| 6 | * Common Public Licence version 1.0 |
| 7 | * http://www.opensource.org/licenses/cpl1.0.php |
| 8 | * |
| 9 | * You received a copy of this licence with this software. |
| 10 | */ |
| 11 | package org.jtiger.report.html; |
| 12 | |
| 13 | import java.io.File; |
| 14 | import java.util.Date; |
| 15 | import org.jtiger.framework.FixtureResultsHandler; |
| 16 | import org.jtiger.framework.FixtureResultsHandlerException; |
| 17 | import org.jtiger.framework.ReadOnlyArray; |
| 18 | import static org.jtiger.report.html.IndexHtmlFileWriterFactory.newIndexHtmlFileWriter; |
| 19 | import static org.jtiger.report.html.FixtureResultConverterFactory.newFixtureResultConverter; |
| 20 | import static org.jtiger.report.html.FixturesHtmlFileWriterFactory.newFixturesHtmlFileWriter; |
| 21 | import static org.jtiger.report.html.FixtureHtmlFileWriterFactory.newFixtureHtmlFileWriter; |
| 22 | import static org.jtiger.report.html.FixturesFilenamePolicyFactory.newFixturesFilenamePolicy; |
| 23 | import static org.jtiger.report.html.OverallResultConverterFactory.newOverallResultConverter; |
| 24 | import static org.jtiger.report.html.OverallHtmlFileWriterFactory.newOverallHtmlFileWriter; |
| 25 | import static org.jtiger.report.html.OverallTotalFactory.newOverallTotal; |
| 26 | |
| 27 | /** |
| 28 | * A result handler that produces a HTML report of test run results. |
| 29 | * The report is written to a directory which is passed in the parameters to |
| 30 | * {@link #handleResult(org.jtiger.framework.FixtureResults, org.jtiger.framework.ReadOnlyArray) the handleResult method}. |
| 31 | * |
| 32 | * @author %javadoc.author.tag% |
| 33 | * @version %version%<br/> |
| 34 | * <i>Build Number %build.number%</i><br/> |
| 35 | * <i>Build Time %build.time% CET (GMT + 1)</i> |
| 36 | */ |
| 37 | public final class HtmlFixtureResultsHandler implements FixtureResultsHandler |
| 38 | { |
| 39 | /** |
| 40 | * Create a default <tt>HtmlFixtureResultsHandler</tt>. |
| 41 | */ |
| 42 | public HtmlFixtureResultsHandler() |
| 43 | { |
| 44 | |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Write a HTML report of the given test run results to a directory which is passed in the parameters. |
| 49 | * If the <tt>params</tt> are empty, the current directory is used to write the report to. |
| 50 | * |
| 51 | * @param results The test run results to produce the HTML report of. |
| 52 | * @param params The parameters that contain at least one parameter which is the directory to write the HTML report |
| 53 | * to otherwise the current directory is used. |
| 54 | * @throws FixtureResultsHandlerException If an error occurs while writing the HTML report. |
| 55 | */ |
| 56 | public void handleResult(final org.jtiger.framework.FixtureResults results, final ReadOnlyArray<String> params) throws FixtureResultsHandlerException |
| 57 | { |
| 58 | final File destination; |
| 59 | |
| 60 | if(params == null || params.length() == 0) |
| 61 | { |
| 62 | destination = new File("."); |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | destination = new File(params.get(0)); |
| 67 | } |
| 68 | |
| 69 | destination.mkdirs(); |
| 70 | final IndexHtmlFileWriter ihfw = newIndexHtmlFileWriter(); |
| 71 | ihfw.writeIndexHtmlFile(destination); |
| 72 | final String buildTime = new Date().toString(); |
| 73 | |
| 74 | final ReadOnlyArray<FixtureResults> frs = newFixtureResultConverter().convertFixtureResults(results); |
| 75 | |
| 76 | newFixturesHtmlFileWriter().writeFixturesHtml(frs, destination); |
| 77 | |
| 78 | FilenamePolicy policy = newFixturesFilenamePolicy(); |
| 79 | |
| 80 | final FixtureHtmlFileWriter fhfw = newFixtureHtmlFileWriter(); |
| 81 | |
| 82 | for(FixtureResults fr : frs) |
| 83 | { |
| 84 | fhfw.writeFixtureHtml(fr, destination, policy, buildTime); |
| 85 | } |
| 86 | |
| 87 | final ReadOnlyArray<OverallResult> overallResults = newOverallResultConverter().convertOverallResult(frs); |
| 88 | |
| 89 | final OverallHtmlFileWriter ohfw = newOverallHtmlFileWriter(); |
| 90 | policy = newFixturesFilenamePolicy(); |
| 91 | ohfw.writeOverallHtml(overallResults, destination, policy, newOverallTotal(results), buildTime); |
| 92 | } |
| 93 | } |