Mercurial > hg > rhino-tests
changeset 58:54e2a2055eec draft
First version of generator of history result pages.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Thu, 01 Nov 2012 10:23:59 +0100 |
parents | c9ebb01301a7 |
children | 700199dfbe1c |
files | ChangeLog src/org/RhinoTests/Reporter/HistoryPagesGenerator.java |
diffstat | 2 files changed, 216 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Oct 23 13:35:27 2012 +0200 +++ b/ChangeLog Thu Nov 01 10:23:59 2012 +0100 @@ -1,3 +1,8 @@ +2012-11-01 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/Reporter/HistoryPagesGenerator.java: + First version of generator of history result pages. + 2012-10-23 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/Reporter/StringUtils.java:
--- a/src/org/RhinoTests/Reporter/HistoryPagesGenerator.java Tue Oct 23 13:35:27 2012 +0200 +++ b/src/org/RhinoTests/Reporter/HistoryPagesGenerator.java Thu Nov 01 10:23:59 2012 +0100 @@ -40,11 +40,17 @@ package org.RhinoTests.Reporter; +import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + + /** - * + * History page(s) generator. + * * @author Pavel Tisnovsky */ public class HistoryPagesGenerator @@ -52,8 +58,209 @@ public static void generate(Map<String, Map<String, List<String>>> testResults, CommandLineParameters params) { - // TODO Auto-generated method stub - + createHtmlPageFromTemplate(testResults, params, 10, TestType.FAILED); + createHtmlPageFromTemplate(testResults, params, 20, TestType.FAILED); + createHtmlPageFromTemplate(testResults, params, 30, TestType.FAILED); + createHtmlPageFromTemplate(testResults, params, -1, TestType.ALL); + createHtmlPageFromTemplate(testResults, params, -1, TestType.FAILED); } - + + private static void createHtmlPageFromTemplate(Map<String, Map<String, List<String>>> testResults, CommandLineParameters params, int testCount, TestType testType) + { + List<String> template = FileUtils.readTextFile(params.getTemplateDir() + "/hist.html"); + List<String> out = new LinkedList<String>(); + List<String> dateList = getDateList(testResults, testCount, testType); + // list of all tests + Set<String> testList = getTestList(testResults, dateList); + + // iterate through whole template + for (String templateLine : template) { + // replace text in template where needed + if (templateLine.contains("${RESULTS}")) + { + String testCountMessage = generateTitleMessage(testCount, testType); + templateLine = templateLine.replace("${RESULTS}", testCountMessage); + out.add(templateLine); + } + else if (templateLine.contains("${TABLE_DATA}")) + { + renderTableData(out, testResults, dateList, testList); + } + else + { + out.add(templateLine); + } + } + + // write list of string to a file with given name + String outName = createOutputFileName(testCount, testType); + FileUtils.writeTextFile(params.getReportDir() + "/" + outName + ".html", out); + } + + private static List<String> getDateList(Map<String, Map<String, List<String>>> testResults, int testCount, TestType testType) { + List<String> dates = new LinkedList<String>(); + for (Map.Entry<String, Map<String, List<String>>> oneResult : testResults.entrySet()) { + dates.add(oneResult.getKey()); + } + if (testCount >= 0) { + dates = dates.subList(dates.size() - testCount, dates.size()); + } + return dates; + } + + private static Set<String> getTestList(Map<String, Map<String, List<String>>> testResults, List<String> dateList) { + Set<String> failedTests = new TreeSet<String>(); + + for (String date : dateList) + { + for (Map.Entry<String, List<String>> test : testResults.get(date).entrySet()) + { + failedTests.addAll(grepTests(test.getValue(), "FAILED: ")); + } + } + for (int i = 0; i < dateList.size() - 1; i++) + { + String date1 = dateList.get(i); + String date2 = dateList.get(i + 1); + Set<String> passedTests1 = new TreeSet<String>(); + Set<String> passedTests2 = new TreeSet<String>(); + + for (Map.Entry<String, List<String>> test : testResults.get(date1).entrySet()) + { + passedTests1.addAll(grepTests(test.getValue(), "PASSED: ")); + } + for (Map.Entry<String, List<String>> test : testResults.get(date2).entrySet()) + { + passedTests2.addAll(grepTests(test.getValue(), "PASSED: ")); + } + + Set<String> diff1 = new TreeSet<String>(); + Set<String> diff2 = new TreeSet<String>(); + diff1.addAll(passedTests1); + diff2.addAll(passedTests2); + diff1.removeAll(passedTests2); + diff2.removeAll(passedTests1); + failedTests.addAll(diff1); + failedTests.addAll(diff2); + } + return failedTests; + } + + /** + * @param failedTests + * @param log + */ + private static Set<String> grepTests(List<String> log, String prefix) { + Set<String> result = new TreeSet<String>(); + for (String line : log) + { + if (line.startsWith(prefix)) + { + String testName = line.substring(prefix.length()); + if (testName.indexOf(' ') >= 0) + { + testName = testName.substring(0, testName.indexOf(' ')); + } + if (testName.indexOf(':') >= 0) + { + testName = testName.substring(0, testName.indexOf(':')); + } + result.add(testName); + } + } + return result; + } + + /** + * @param testCount + * @param testType + * @return + */ + private static String generateTitleMessage(int testCount, TestType testType) { + return testCount == -1 ? testType == TestType.ALL ? "all results" : "failed tests" : "last " + testCount + " results"; + } + + /** + * @param testCount + * @return + */ + private static String createOutputFileName(int testCount, TestType testType) { + String s = testCount == -1 ? testType == TestType.ALL ? "all_tests" : "failed_tests" : "" + testCount; + return "hist_" + s; + } + + private static void renderTableData(List<String> out, Map<String, Map<String, List<String>>> testResults, List<String> dateList, Set<String> testList) { + printFirstTableLine(out, dateList); + printRestOfTable(out, testResults, dateList, testList); + } + + /** + * @param out + * @param dateList + */ + private static void printFirstTableLine(List<String> out, List<String> dateList) { + out.add("<tr><td class='group-id'>Test name/Date:</td>"); + for (String date : dateList) + { + String d1 = date.substring(0, 4); + String d2 = date.substring(5); + out.add("<td>" + d1 + "<br />" + d2 + "</td>"); + } + out.add("</tr>"); + } + + private static void printRestOfTable(List<String> out, Map<String, Map<String, List<String>>> testResults, List<String> dateList, Set<String> testList) { + for (String testName : testList) + { + out.add("<tr><td>" + testName + "</td>"); + for (String date : dateList) + { + TestStatus testStatus = getTestStatus(testName, date, testResults); + String cssClass = testStatus == TestStatus.PASSED ? "passed-header" : testStatus == TestStatus.FAILED ? "failed-header" : "empty"; + out.add("<td class='" + cssClass + "'> </td>"); + } + out.add("</tr>"); + } + } + + private static TestStatus getTestStatus(String testName, String date, Map<String, Map<String, List<String>>> testResults) + { + String simpleName = date + "/" + testName.substring("org.RhinoTests.".length(), testName.lastIndexOf('.')) + ".log"; + for (Map.Entry<String, List<String>> test : testResults.get(date).entrySet()) + { + if (test.getKey().endsWith(simpleName)) + { + List<String> log = test.getValue(); + for (String line : log) + { + if (line.startsWith("FAILED: ")) + { + String tn = line.substring("FAILED: ".length()); + if (tn.indexOf(' ') >= 0) + { + tn = tn.substring(0, tn.indexOf(' ')); + } + if (tn.indexOf(':') >= 0) + { + tn = tn.substring(0, tn.indexOf(':')); + } + if (tn.equals(testName)) + { + return TestStatus.FAILED; + } + } + if (line.startsWith("PASSED: ")) + { + String tn = line.substring("PASSED: ".length()); + if (tn.equals(testName)) + { + return TestStatus.PASSED; + } + } + } + } + } + return TestStatus.NOT_FOUND; + } + }