Mercurial > hg > rhino-tests
changeset 9:d78d71a7859b draft
First version of test result graph generator.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Mon, 09 Jul 2012 12:14:59 +0200 |
parents | 7e2bc401aae8 |
children | be25709c3ecd |
files | ChangeLog src/org/RhinoTests/Reporter/GraphPagesGenerator.java |
diffstat | 2 files changed, 109 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Jul 03 17:41:22 2012 +0200 +++ b/ChangeLog Mon Jul 09 12:14:59 2012 +0200 @@ -1,3 +1,8 @@ +2012-07-09 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/Reporter/GraphPagesGenerator.java: + First version of test result graph generator. + 2012-07-03 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/Reporter/HistoryPagesGenerator.java:
--- a/src/org/RhinoTests/Reporter/GraphPagesGenerator.java Tue Jul 03 17:41:22 2012 +0200 +++ b/src/org/RhinoTests/Reporter/GraphPagesGenerator.java Mon Jul 09 12:14:59 2012 +0200 @@ -40,19 +40,116 @@ package org.RhinoTests.Reporter; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + /** * * @author Pavel Tisnovsky */ -public class GraphPagesGenerator -{ +public class GraphPagesGenerator { + + public static void generate(Map<String, Map<String, List<String>>> testResults, CommandLineParameters params) { + createHtmlPageFromTemplate(testResults, params, 1); + createHtmlPageFromTemplate(testResults, params, 2); + createHtmlPageFromTemplate(testResults, params, 5); + createHtmlPageFromTemplate(testResults, params, 10); + createHtmlPageFromTemplate(testResults, params, 30); + createHtmlPageFromTemplate(testResults, params, -1); + } + + private static void createHtmlPageFromTemplate(Map<String, Map<String, List<String>>> testResults, CommandLineParameters params, int testCount) { + List<String> template = FileUtils.readTextFile(params.getTemplateDir() + "/graph.html"); + List<String> out = new LinkedList<String>(); + List<TestResult> testResultList = processTestResultList(testResults, testCount); + + // iterate through whole template + for (String templateLine : template) { + // replace text in template where needed + if (templateLine.contains("${TEST_COUNT}")) { + String testCountMessage = testCount == -1 ? "all" : "the last " + testCount; + templateLine = templateLine.replace("${TEST_COUNT}", testCountMessage); + out.add(templateLine); + } + else if (templateLine.contains("${GRAPH_DATA_PASSED}")) { + renderGraphDataPassed(out, testResultList); + } + else if (templateLine.contains("${GRAPH_DATA_FAILED}")) { + renderGraphDataFailed(out, testResultList); + } + else if (templateLine.contains("${GRAPH_DATA_ERROR}")) { + renderGraphDataError(out, testResultList); + } + else if (templateLine.contains("${TABLE_DATA}")) { + renderTableData(out, testResults, testCount); + } + else { + out.add(templateLine); + } + } + // write list of string to a file with given name + String outName = testCount == -1 ? "graph_all" : "graph_" + testCount; + FileUtils.writeTextFile(params.getReportDir() + "/" + outName + ".html", out); + } + + private static String oneRecord(int i, int cnt) { + return "[" + (i+1) + ", " + cnt + "],"; + } - public static void generate() - { - // TODO - return; + private static void renderGraphDataPassed(List<String> out, List<TestResult> testResultList) { + for (int i = 0; i < testResultList.size(); i++) { + out.add(oneRecord(i, testResultList.get(i).getPassed())); + } + } + + private static void renderGraphDataFailed(List<String> out, List<TestResult> testResultList) { + for (int i = 0; i < testResultList.size(); i++) { + out.add(oneRecord(i, testResultList.get(i).getFailed())); + } + } + + private static void renderGraphDataError(List<String> out, List<TestResult> testResultList) { + for (int i = 0; i < testResultList.size(); i++) { + out.add(oneRecord(i, testResultList.get(i).getError())); + } } - + + private static List<TestResult> processTestResultList( + Map<String, Map<String, List<String>>> testResults, int testCount) { + List<TestResult> testResultList = new LinkedList<TestResult>(); + int threshold = testCount == -1 ? 0 : testResults.size() - testCount; + int index = 0; + for (Map.Entry<String, Map<String, List<String>>> oneResult : testResults.entrySet()) { + if (index >= threshold) { + TestResult testResult = TestResult.readSummary(oneResult.getValue()); + testResultList.add(testResult); + } + index++; + } + return testResultList; + } + + private static void renderTableData(List<String> out, + Map<String, Map<String, List<String>>> testResults, int testCount) { + int threshold = testCount == -1 ? 0 : testResults.size() - testCount; + int index = 0; + int rowIndex = 1; + for (Map.Entry<String, Map<String, List<String>>> oneResult : testResults.entrySet()) { + if (index >= threshold) { + String date = oneResult.getKey(); + TestResult testResult = TestResult.readSummary(oneResult.getValue()); + out.add("<tr><td>" + rowIndex + "</td><td><a href='log_" + date + ".html'> " + date + " </a></td>"); + out.add("<td style='color:#006000;text-align:right;'>" + testResult.getPassed() + "</td>"); + out.add("<td style='color:#800000;text-align:right;'>" + testResult.getFailed() + "</td>"); + out.add("<td style='color:#000080;text-align:right;'>" + testResult.getError() + "</td>"); + out.add("</tr>"); + } + index++; + rowIndex++; + } + } + }