incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liu...@apache.org
Subject svn commit: r1384693 - in /incubator/ooo/trunk/test/testcommon/source/org/openoffice/test: OpenOffice.java common/CSVReporter.java common/FileUtil.java common/SystemUtil.java common/XMLReporter.java common/XMLReporter.xsl
Date Fri, 14 Sep 2012 09:20:05 GMT
Author: liuzhe
Date: Fri Sep 14 09:20:05 2012
New Revision: 1384693

URL: http://svn.apache.org/viewvc?rev=1384693&view=rev
Log:
"Add XMLReport.xsl and generate HTML"

Added:
    incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.xsl
Modified:
    incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/OpenOffice.java
    incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/CSVReporter.java
    incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/FileUtil.java
    incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/SystemUtil.java
    incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.java

Modified: incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/OpenOffice.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/OpenOffice.java?rev=1384693&r1=1384692&r2=1384693&view=diff
==============================================================================
--- incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/OpenOffice.java (original)
+++ incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/OpenOffice.java Fri Sep
14 09:20:05 2012
@@ -25,7 +25,9 @@ import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Map.Entry;
 import java.util.Properties;
+import java.util.Set;
 import java.util.UUID;
 import java.util.logging.Logger;
 
@@ -127,6 +129,10 @@ public class OpenOffice {
 		if (!versionFile.exists())
 			versionFile = new File(binParent, "version.ini");
 		versionProps = FileUtil.loadProperties(versionFile);
+		Set<Entry<Object, Object>> entries = versionProps.entrySet();
+		for (Entry<Object, Object> e : entries) {
+			System.setProperty("info.app." + e.getKey(), (String)e.getValue());
+		}
 		addArgs(id);
 	}
 

Modified: incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/CSVReporter.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/CSVReporter.java?rev=1384693&r1=1384692&r2=1384693&view=diff
==============================================================================
--- incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/CSVReporter.java
(original)
+++ incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/CSVReporter.java
Fri Sep 14 09:20:05 2012
@@ -1,5 +1,10 @@
 package org.openoffice.test.common;
 
+import java.io.File;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.junit.Ignore;
 import org.junit.runner.Description;
 import org.junit.runner.Result;
 import org.junit.runner.notification.Failure;
@@ -7,39 +12,105 @@ import org.junit.runner.notification.Run
 
 public class CSVReporter extends RunListener {
 
+	private File reportDir = Testspace.getFile("output/result");
+
+	private File file = null;
+
+	private String testClassName = null;
+
+	private long suiteStart = 0;
+
+	private long failures = 0;
+
+	private long errors = 0;
+
+	private long tests = 0;
+
+	private long ignored = 0;
+
+	private long testStart = 0;
+
+	@Override
+	public void testStarted(Description description) throws Exception {
+		System.out.println("testStarted");
+		if (!description.getClassName().equals(testClassName)) {
+			finishSuite();
+			startSuite(description);
+		}
+		
+
+	}
+
 	@Override
 	public void testAssumptionFailure(Failure failure) {
-		super.testAssumptionFailure(failure);
+
 	}
 
 	@Override
 	public void testFailure(Failure failure) throws Exception {
-		super.testFailure(failure);
+		System.out.println("testFailure");
+		if (failure.getException() instanceof AssertionError) {
+			failures++;
+		} else {
+			errors++;
+		}
 	}
 
 	@Override
 	public void testFinished(Description description) throws Exception {
-		super.testFinished(description);
+		System.out.println("testFinished");
+		tests++;
 	}
 
 	@Override
 	public void testIgnored(Description description) throws Exception {
-		super.testIgnored(description);
+		testStarted(description);
+		System.out.println("testIgnored");
+		ignored++;
+		Ignore ignore = description.getAnnotation(Ignore.class);
+		testFinished(description);
 	}
 
 	@Override
 	public void testRunFinished(Result result) throws Exception {
-		super.testRunFinished(result);
+		System.out.println("testRunFinished");
+		finishSuite();
 	}
 
 	@Override
 	public void testRunStarted(Description description) throws Exception {
-		super.testRunStarted(description);
+		System.out.println("testRunStarted");
 	}
 
-	@Override
-	public void testStarted(Description description) throws Exception {
-		super.testStarted(description);
+	private void startSuite(Description description) {
+		testClassName = description.getClassName();
+		suiteStart = System.currentTimeMillis();
+		failures = 0;
+		errors = 0;
+		tests = 0;
+		ignored = 0;
+
+		file = new File(reportDir, testClassName + ".csv");
+	}
+
+	private void finishSuite() {
+		if (testClassName == null)
+			return;
+
+	
+		Set<Entry<Object, Object>> entries = System.getProperties().entrySet();
+		for (Entry<Object, Object> e : entries) {
+//			Element prop = doc.createElement("property");
+//			prop.setAttribute("name", "" + e.getKey());
+//			prop.setAttribute("value", "" + e.getValue());
+//			props.appendChild(prop);
+		}
+
+		store();
+	}
+
+	private void store() {
+
 	}
 
 }

Modified: incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/FileUtil.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/FileUtil.java?rev=1384693&r1=1384692&r2=1384693&view=diff
==============================================================================
--- incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/FileUtil.java (original)
+++ incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/FileUtil.java Fri
Sep 14 09:20:05 2012
@@ -48,11 +48,10 @@ import javax.xml.parsers.DocumentBuilder
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
 import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathExpression;
 import javax.xml.xpath.XPathExpressionException;
@@ -107,18 +106,35 @@ public class FileUtil {
 	}
 	
 	public static boolean storeXML(Document doc, File file) {
-	    try {
-	        Source source = new DOMSource(doc);
-	        file.getParentFile().mkdirs();
-	        Result result = new StreamResult(file);
-	        Transformer xformer = TransformerFactory.newInstance().newTransformer();
-	        xformer.transform(source, result);
-	        return true;
-	    } catch (Exception e) {
-	    	return false;
-	    } 
+		try {
+			file.getParentFile().mkdirs();
+			TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new StreamResult(file));
+			return true;
+		} catch (Exception e) {
+			return false;
+		}
+	}
+	
+	public static boolean storeXML(Document doc, File file, File xls) {
+		try {
+			file.getParentFile().mkdirs();
+			TransformerFactory.newInstance().newTransformer(new StreamSource(xls)).transform(new DOMSource(doc),
new StreamResult(file));
+			return true;
+		} catch (Exception e) {
+			return false;
+		}
 	}
 	
+	public static boolean storeXML(Document doc, File file, InputStream xls) {
+		try {
+			file.getParentFile().mkdirs();
+			TransformerFactory.newInstance().newTransformer(new StreamSource(xls)).transform(new DOMSource(doc),
new StreamResult(file));
+			return true;
+		} catch (Exception e) {
+			return false;
+		}
+	}
+	  
 	/**
 	 * Get a string by XPATH from a xml file
 	 * @param xml

Modified: incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/SystemUtil.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/SystemUtil.java?rev=1384693&r1=1384692&r2=1384693&view=diff
==============================================================================
--- incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/SystemUtil.java
(original)
+++ incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/SystemUtil.java
Fri Sep 14 09:20:05 2012
@@ -66,6 +66,13 @@ public class SystemUtil {
 			output.setLength(0);
 			if (exec(new String[]{"lsb_release", "-rs"}, output) == 0)
 				osVersion = output.toString().trim();	
+			
+			System.setProperty("info.os.name", SystemUtil.getOSName());
+			System.setProperty("info.os.version", SystemUtil.getOSVersion());
+			System.setProperty("info.os.arch", SystemUtil.getOSArch());
+			System.setProperty("info.os.arch", SystemUtil.getOSArch());
+			System.setProperty("info.ip", SystemUtil.getIPAddress());
+			System.setProperty("info.hostname", SystemUtil.getHostName());
 		}
 	}
 
@@ -473,16 +480,27 @@ public class SystemUtil {
 	}
 
 	/**
-	 * Get local machine ip address
-	 * */
-
+	 * Get local host's IP
+	 * @return
+	 */
 	public static String getIPAddress() {
-		InetAddress addr = null;
 		try {
-			addr = InetAddress.getLocalHost();
+			return InetAddress.getLocalHost().getHostAddress().toString();
+		} catch (UnknownHostException e) {
+			return null;
+		}
+	}
+	
+	/**
+	 * Get local host name
+	 * @return
+	 */
+	public static String getHostName() {
+		try {
+			return InetAddress.getLocalHost().getHostName();
 		} catch (UnknownHostException e) {
-			e.printStackTrace();
+			return null;
 		}
-		return addr.getHostAddress().toString();
+		
 	}
 }

Modified: incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.java?rev=1384693&r1=1384692&r2=1384693&view=diff
==============================================================================
--- incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.java
(original)
+++ incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.java
Fri Sep 14 09:20:05 2012
@@ -1,6 +1,9 @@
 package org.openoffice.test.common;
 
 import java.io.File;
+import java.io.InputStream;
+import java.util.Map.Entry;
+import java.util.Set;
 
 import org.junit.Ignore;
 import org.junit.runner.Description;
@@ -9,59 +12,154 @@ import org.junit.runner.notification.Fai
 import org.junit.runner.notification.RunListener;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.ProcessingInstruction;
 
 public class XMLReporter extends RunListener {
 
+	private File reportDir = Testspace.getFile("output/result");
+	
 	private File file = null;
 	
 	private Document doc = null;
 	
-	private Element root = null;
-	 
+	private Element testsuiteEl = null;
+	
+	private Element testcaseEl = null;
+	
+	private String testClassName = null;
+	
+	private long suiteStart = 0;
+	
+	private long failures = 0;
+	
+	private long errors = 0;
+	
+	private long tests = 0;
+	
+	private long ignored = 0;
+	
+	private long testStart = 0;
+	
+	@Override
+	public void testStarted(Description description) throws Exception {
+		System.out.println("testStarted");
+		if (!description.getClassName().equals(testClassName)) {
+			finishSuite();
+			startSuite(description);
+		}
+		testcaseEl = doc.createElement("testcase");
+		testcaseEl.setAttribute("name", description.getDisplayName());
+		testcaseEl.setAttribute("classname", description.getClassName());
+		testcaseEl.setAttribute("methodname", description.getMethodName());
+		testsuiteEl.appendChild(testcaseEl);
+		testStart = System.currentTimeMillis();
+	}
+	
 	@Override
 	public void testAssumptionFailure(Failure failure) {
-		System.out.println("testAssumptionFailure");
+
 	}
 
 	@Override
 	public void testFailure(Failure failure) throws Exception {
 		System.out.println("testFailure");
+		if (failure.getException() instanceof AssertionError) {
+			failures++;
+			Element failureEl = doc.createElement("failure");
+			failureEl.setAttribute("message", failure.getMessage());
+			failureEl.setAttribute("type", failure.getTestHeader());
+			failureEl.setTextContent(failure.getTrace());
+			testcaseEl.appendChild(failureEl);
+		} else {
+			errors++;
+			Element errorEl = doc.createElement("error");
+			errorEl.setAttribute("message", failure.getMessage());
+			errorEl.setAttribute("type", failure.getTestHeader());
+			errorEl.setTextContent(failure.getTrace());
+			testcaseEl.appendChild(errorEl);
+		}
 	}
 
 	@Override
 	public void testFinished(Description description) throws Exception {
 		System.out.println("testFinished");
+		tests++;
+		testcaseEl.setAttribute("time", Double.toString((System.currentTimeMillis() - testStart)
/ 1000.0));
+		store();
 	}
 
 	@Override
 	public void testIgnored(Description description) throws Exception {
-		Ignore a = description.getAnnotation(Ignore.class);
-		System.out.println("testIgnored" + a.value());
+		testStarted(description);
+		System.out.println("testIgnored");
+		ignored++;
+		Ignore ignore = description.getAnnotation(Ignore.class);
+		Element ignoredEl = doc.createElement("ignored");
+		ignoredEl.setAttribute("message", ignore.value());
+		testcaseEl.appendChild(ignoredEl);
+		
+		testFinished(description);
 	}
 
 	@Override
 	public void testRunFinished(Result result) throws Exception {
 		System.out.println("testRunFinished");
-		FileUtil.storeXML(doc, file);
+		finishSuite();
 	}
 
 	@Override
 	public void testRunStarted(Description description) throws Exception {
 		System.out.println("testRunStarted");
-		file = Testspace.getFile("output/result/" + description.getClassName() + ".xml");
+	}
+
+	private void startSuite(Description description) {
+		testClassName = description.getClassName();
+		suiteStart = System.currentTimeMillis();
+		failures = 0;
+		errors = 0;
+		tests = 0;
+		ignored = 0;
+		
+		file = new File(reportDir, testClassName + ".xml");
 		doc = FileUtil.newXML();
-		root = doc.createElement("testsuites");
-		doc.appendChild(root);
+	
+		testsuiteEl = doc.createElement("testsuite");
+		testsuiteEl.setAttribute("name", testClassName);
+		testsuiteEl.setAttribute("start", Long.toString(suiteStart));
+		doc.appendChild(testsuiteEl);
+	}
+	
+	private void finishSuite() {
+		if (testClassName == null)
+			return;
 		
-		System.out.println(SystemUtil.getOSName());
-		System.out.println(SystemUtil.getOSVersion());
-		System.out.println(SystemUtil.getOSArch());
+		testsuiteEl.setAttribute("time", Double.toString((System.currentTimeMillis() - testStart)
/ 1000.0));
+		testsuiteEl.setAttribute("failures", Long.toString(failures));
+		testsuiteEl.setAttribute("errors", Long.toString(errors));
+		testsuiteEl.setAttribute("tests", Long.toString(tests));
+		testsuiteEl.setAttribute("ignored", Long.toString(ignored));
+		Element props = doc.createElement("properties");
+		testsuiteEl.appendChild(props);
+		Set<Entry<Object, Object>> entries = System.getProperties().entrySet();
+		for (Entry<Object, Object> e : entries) {
+			Element prop = doc.createElement("property");
+			prop.setAttribute("name", "" + e.getKey());
+			prop.setAttribute("value", "" + e.getValue());
+			props.appendChild(prop);
+		}
+		
+		store();
 	}
 
-	@Override
-	public void testStarted(Description description) throws Exception {
-		System.out.println("testStarted");
+	private void store() {
+		if (doc != null) {
+			FileUtil.storeXML(doc, file);
+			File htmlFile = new File(reportDir, testClassName + ".html");
+			InputStream is = getClass().getResourceAsStream("XMLReporter.xsl");
+			if (is != null) {
+				FileUtil.storeXML(doc, htmlFile, is);
+			}
+		}
 	}
 
-	
 }

Added: incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.xsl
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.xsl?rev=1384693&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.xsl
(added)
+++ incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.xsl
Fri Sep 14 09:20:05 2012
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:output method="xml" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" />
+<xsl:template match="/">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+	<style>
+.Success {
+	background:#22cc22;
+}
+.Failure {
+	background:#FF4444;
+}
+.Ignored {
+	background:#FFFF44;
+}
+.Error {
+	background:#FF0000;
+}
+.recordTable {
+    border-collapse:collapse;
+}
+.recordTable thead th{
+    padding:5px 10px 5px 10px;
+    color:#fff;
+    font-size: 14px;
+    background-color:#222;
+    border-right:1px dotted #666;
+}
+
+.recordTable tbody td{
+    padding:5px 10px 5px 10px;
+    background-color:#f0f0f0;
+    border-right:1px dotted #999;
+    color:#333;
+}
+
+	</style>
+	<title>JUnit Report</title>
+</head>
+<body>
+<xml id="data" style="display:none">
+	<xsl:copy-of select="*" />
+</xml>
+
+<table>
+	<thead>
+		<tr><th>Class</th><th>Name</th><th>Platform</th><th>Platform</th><th>Platform</th><th>Platform</th></tr>
+	</thead>
+	<tbody>
+	</tbody>
+</table>
+
+<table class="recordTable">
+	<thead>
+		<tr><th>Name</th><th>Status</th><th width="80%">Message</th><th>Time</th><th>Screenshot</th></tr>
+	</thead>
+	<tbody id="recordTable">
+	</tbody>
+</table>
+
+
+<script>
+<xsl:text disable-output-escaping='yes'>
+<![CDATA[
+function $(id) {
+	return document.getElementById(id);
+}
+
+function $$(e, tag) {
+	var els = e.getElementsByTagName(tag);
+	return els[0] || null;
+}
+
+function $$s(e, tag) {
+	return e.getElementsByTagName(tag);
+}
+
+function refresh() {
+	var data = $('data');
+	var testsuiteEl = $$(data, 'testsuite');
+	var testcaseEls = $$s(data, 'testcase');
+	var html = '';
+	for (var i = 0; i < testcaseEls.length; i++){
+		var e = testcaseEls[i], c;
+		var status = 'Success', message = '';
+		if (c = $$(e, 'failure')) {
+			status = 'Failure';
+			message = c.getAttribute("message");
+		} else if (c = $$(e, 'error')) {
+			status = 'Error';
+			message = c.getAttribute("message");
+		} else if (c = $$(e, 'ignored')) {
+			status = 'Ignored';
+			message = c.getAttribute("message");
+		}
+		message = message.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g,
"&gt;");
+		html += '<tr class="' + status + '"><td>' + e.getAttribute("name") + '</td><td>'
+ status + '</td><td>' + message + '</td><td>' + e.getAttribute("time")
+ '</td><td>' + '*' + '</td></tr>';
+	}
+	
+	$("recordTable").innerHTML = html;
+}
+
+refresh();
+
+]]>
+</xsl:text>
+</script>
+</body>
+</html>
+</xsl:template>
+</xsl:stylesheet>    
+   
\ No newline at end of file



Mime
View raw message