/hg/rhino-tests: First version of test result graph generator.
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Mon Jul 9 03:12:15 PDT 2012
changeset d78d71a7859b in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=d78d71a7859b
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Mon Jul 09 12:14:59 2012 +0200
First version of test result graph generator.
diffstat:
ChangeLog | 5 +
src/org/RhinoTests/Reporter/GraphPagesGenerator.java | 111 +++++++++++++++++-
2 files changed, 109 insertions(+), 7 deletions(-)
diffs (139 lines):
diff -r 7e2bc401aae8 -r d78d71a7859b ChangeLog
--- 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 at redhat.com>
+
+ * src/org/RhinoTests/Reporter/GraphPagesGenerator.java:
+ First version of test result graph generator.
+
2012-07-03 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/RhinoTests/Reporter/HistoryPagesGenerator.java:
diff -r 7e2bc401aae8 -r d78d71a7859b src/org/RhinoTests/Reporter/GraphPagesGenerator.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()
- {
- // TODO
- return;
+ 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 + "],";
+ }
+
+ 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++;
+ }
+ }
+
}
More information about the distro-pkg-dev
mailing list