Mercurial > hg > rhino-tests
changeset 11:581695c2fab3 draft
Various enhancements of report generator tool:
* src/org/RhinoTests/Reporter/StringUtils.java:
* src/org/RhinoTests/Reporter/TestResult.java:
* src/org/RhinoTests/Reporter/GraphPagesGenerator.java:
Added support for new placeholder types - JRE info + OS info.
* src/org/RhinoTests/Reporter/IndexPageGenerator.java:
Changed method of replacement names of placeholders to their real values.
* templates/index.html:
Added new placeholder types to this template - JRE info + OS info.
* Makefile: Fixed command which creates report directory.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Tue, 17 Jul 2012 13:49:01 +0200 |
parents | be25709c3ecd |
children | bdd13e29e245 |
files | ChangeLog Makefile src/org/RhinoTests/Reporter/GraphPagesGenerator.java src/org/RhinoTests/Reporter/IndexPageGenerator.java src/org/RhinoTests/Reporter/StringUtils.java src/org/RhinoTests/Reporter/TestResult.java templates/index.html |
diffstat | 7 files changed, 169 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Jul 16 16:16:03 2012 +0200 +++ b/ChangeLog Tue Jul 17 13:49:01 2012 +0200 @@ -1,3 +1,15 @@ +2012-07-17 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/Reporter/StringUtils.java: + * src/org/RhinoTests/Reporter/TestResult.java: + * src/org/RhinoTests/Reporter/GraphPagesGenerator.java: + Added support for new placeholder types - JRE info + OS info. + * src/org/RhinoTests/Reporter/IndexPageGenerator.java: + Changed method of replacement names of placeholders to their real values. + * templates/index.html: + Added new placeholder types to this template - JRE info + OS info. + * Makefile: Fixed command which creates report directory. + 2012-07-16 Pavel Tisnovsky <ptisnovs@redhat.com> * Makefile: Make sure the report dir is created when
--- a/Makefile Mon Jul 16 16:16:03 2012 +0200 +++ b/Makefile Tue Jul 17 13:49:01 2012 +0200 @@ -112,7 +112,7 @@ done report: $(ALL_CLASSES) - mkdir $(REPORT_DIR) + mkdir -p $(REPORT_DIR) cp -u $(TEMPLATE_DIR)/style.css $(REPORT_DIR)/style.css $(JAVA) -cp $(BUILD_DIR) org.RhinoTests.Reporter.Reporter -template-dir=$(TEMPLATE_DIR) -log-dir=$(LOGS_DIR) -report-dir=$(REPORT_DIR) -date=$(DATE) -tests="$(TESTS)"
--- a/src/org/RhinoTests/Reporter/GraphPagesGenerator.java Mon Jul 16 16:16:03 2012 +0200 +++ b/src/org/RhinoTests/Reporter/GraphPagesGenerator.java Tue Jul 17 13:49:01 2012 +0200 @@ -53,10 +53,8 @@ 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, 20); createHtmlPageFromTemplate(testResults, params, 30); createHtmlPageFromTemplate(testResults, params, -1); }
--- a/src/org/RhinoTests/Reporter/IndexPageGenerator.java Mon Jul 16 16:16:03 2012 +0200 +++ b/src/org/RhinoTests/Reporter/IndexPageGenerator.java Tue Jul 17 13:49:01 2012 +0200 @@ -40,9 +40,13 @@ package org.RhinoTests.Reporter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * @@ -51,12 +55,14 @@ public class IndexPageGenerator { - public static void generate(Map<String, Map<String, List<String>>> testResults, CommandLineParameters params) { + public static void generate(Map<String, Map<String, List<String>>> testResults, CommandLineParameters params) { + String date = params.getDate(); if (!testResults.containsKey(params.getDate())) { - throw new RuntimeException("Results for " + params.getDate() + " don't exist"); + throw new RuntimeException("Results for " + date + " don't exist"); } - Map<String, List<String>> testResultForDate = testResults.get(params.getDate()); + Map<String, List<String>> testResultForDate = testResults.get(date); TestResult testResult = TestResult.readSummary(testResultForDate); + testResult.setDate(date); createIndexPageFromTemplate(testResult, params); } @@ -64,24 +70,40 @@ List<String> template = FileUtils.readTextFile(params.getTemplateDir() + "/index.html"); List<String> out = new LinkedList<String>(); // iterate through whole template + Pattern pattern = Pattern.compile("\\$\\{.*\\}"); for (String templateLine : template) { - // replace text in template where needed - if (templateLine.contains("${DATE}")) { - templateLine = templateLine.replace("${DATE}", params.getDate()); - } - if (templateLine.contains("${PASSED}")) { - templateLine = templateLine.replace("${PASSED}", "" + testResult.getPassed()); - } - if (templateLine.contains("${FAILED}")) { - templateLine = templateLine.replace("${FAILED}", "" + testResult.getFailed()); - } - if (templateLine.contains("${ERROR}")) { - templateLine = templateLine.replace("${ERROR}", "" + testResult.getError()); - } - out.add(templateLine); + out.add(replacePlaceholder(testResult, pattern, templateLine)); } // write list of string to a file with given name FileUtils.writeTextFile(params.getReportDir() + "/index.html", out); } + private static String replacePlaceholder(TestResult testResult, Pattern pattern, String templateLine) { + Matcher matcher = pattern.matcher(templateLine); + // if some pattern ${PLACEHOLDER} is found on the template line, + // it is replaced by the result value of method TestResult.getPlaceholder() + if (matcher.find()) { + String matcherGroup = matcher.group(); + String placeholderName = StringUtils.getPlaceholderMethodName(matcherGroup); + try { + Method method = testResult.getClass().getMethod(placeholderName); + Object result = method.invoke(testResult); + if (result != null) { + return templateLine.replace(matcherGroup, result.toString()); + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + return templateLine; + } + }
--- a/src/org/RhinoTests/Reporter/StringUtils.java Mon Jul 16 16:16:03 2012 +0200 +++ b/src/org/RhinoTests/Reporter/StringUtils.java Tue Jul 17 13:49:01 2012 +0200 @@ -48,7 +48,8 @@ * @author Pavel Tisnovsky */ public class StringUtils { - /** + + /** * Get substring from given string in case that both delimiters are strings * too. * @@ -79,4 +80,48 @@ // trim unnecessary leading and trailing whitespace characters return s.trim(); } + + /** + * Convert UPPER_CASE_STYLE name into a CamelCase + * + * @param string + * input string which could contains names divided by underscore + * character + * @return camel case variant of the input string + */ + public static String toCamelCase(String string) { + String[] parts = string.split("_"); + String camelCaseString = ""; + for (String part : parts) { + camelCaseString = camelCaseString + convertToProperCase(part); + } + return camelCaseString; + } + + /** + * Convert a string to a new form where the first letter is upper case and + * other letters are lower case + * + * @param string + * input string + * @return input string with capitalized first letter + */ + public static String convertToProperCase(String string) { + return string.substring(0, 1).toUpperCase() + string.substring(1).toLowerCase(); + } + + /** + * Convert "PLACEHOLDER_NAME" into the name of the getter: + * "getPlaceholderName" + * + * @param placeholderName + * @return + */ + public static String getPlaceholderMethodName(String placeholderName) { + String temporaryName = placeholderName.substring(1); + temporaryName = temporaryName.substring(1, temporaryName.length() - 1); + temporaryName = "get" + StringUtils.toCamelCase(temporaryName.toLowerCase()); + return temporaryName; + } + }
--- a/src/org/RhinoTests/Reporter/TestResult.java Mon Jul 16 16:16:03 2012 +0200 +++ b/src/org/RhinoTests/Reporter/TestResult.java Tue Jul 17 13:49:01 2012 +0200 @@ -53,11 +53,13 @@ private int passed; private int failed; private int error; + private String date; public TestResult() { this.setPassed(0); this.setFailed(0); this.setError(0); + this.setDate(null); } /** @@ -122,5 +124,37 @@ } return testResult; } - + + public String getDate() { + return this.date; + } + + public String getOsName() { + return System.getProperty("os.name"); + } + + public String getOsVer() { + return System.getProperty("os.version"); + } + + public String getOsArch() { + return System.getProperty("os.arch"); + } + + public String getJavaVersion() { + return System.getProperty("java.version"); + } + + public String getVmName() { + return System.getProperty("java.vm.version"); + } + + public String getVmVersion() { + return System.getProperty("java.vm.name"); + } + + public void setDate(String date) { + this.date = date; + } + }
--- a/templates/index.html Mon Jul 16 16:16:03 2012 +0200 +++ b/templates/index.html Tue Jul 17 13:49:01 2012 +0200 @@ -2,14 +2,14 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> - <title>Rhino tests report</title> + <title>Rhino tests report: JDK ${JAVA_VERSION}</title> <meta name="Author" content="Pavel Tisnovsky" /> <meta name="Generator" content="org.RhinoTests.Reporter.Reporter" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link type="text/css" rel="StyleSheet" href="style.css" /> </head> <html> - <h1>Rhino tests report</h1> + <h1>Rhino tests report: JDK ${JAVA_VERSION}</h1> <br /> @@ -49,11 +49,43 @@ </tr> <tr><td colspan='4' class='table-header'>Graphs</td></tr> <tr> - <td> </td><td colspan='3'><a href='graph_all_tests.html'>All tests</a></td> + <td> </td><td colspan='3'><a href='graph_all.html'>All tests</a></td> </tr> <tr> <td> </td><td colspan='3'>Last <i>n</i> results: <a href='graph_10.html'>[10]</a><a href='graph_20.html'>[20]</a><a href='graph_30.html'>[30]</a></td> </tr> + <tr> + <td colspan='4'> </td> + </tr> + <tr><td colspan='4' class='table-header'>System info</td></tr> + <tr> + <td>OS name</td> + <td colspan='3'>${OS_NAME}</td> + </tr> + <tr> + <td>Version</td> + <td colspan='3'>${OS_VER}</td> + </tr> + <tr> + <td>Architecture</td> + <td colspan='3'>${OS_ARCH}</td> + </tr> + <tr> + <td colspan='4'> </td> + </tr> + <tr><td colspan='4' class='table-header'>JDK/JRE info</td></tr> + <tr> + <td>Java version</td> + <td colspan='3'>${JAVA_VERSION}</td> + </tr> + <tr> + <td>VM name</td> + <td colspan='3'>${VM_NAME}</td> + </tr> + <tr> + <td>VM version</td> + <td colspan='3'>${VM_VERSION}</td> + </tr> </table> </html>