incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liu...@apache.org
Subject svn commit: r1384366 - in /incubator/ooo/trunk/test/testcommon/source/org/openoffice/test: Runner.java common/CSVReporter.java common/FileUtil.java common/SystemUtil.java common/XMLReporter.java
Date Thu, 13 Sep 2012 15:21:28 GMT
Author: liuzhe
Date: Thu Sep 13 15:21:27 2012
New Revision: 1384366

URL: http://svn.apache.org/viewvc?rev=1384366&view=rev
Log:
Add test runner

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

Added: incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/Runner.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/Runner.java?rev=1384366&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/Runner.java (added)
+++ incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/Runner.java Thu Sep 13
15:21:27 2012
@@ -0,0 +1,55 @@
+package org.openoffice.test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+
+import org.junit.runner.Description;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunListener;
+import org.openoffice.test.common.CSVReporter;
+import org.openoffice.test.common.Logger;
+import org.openoffice.test.common.XMLReporter;
+
+public class Runner {
+	private static Logger log = Logger.getLogger(Runner.class);
+
+	public static void main(String... args) {
+		JUnitCore core = new JUnitCore();
+		core.addListener(new XMLReporter());
+		core.addListener(new CSVReporter());
+		String prop = System.getProperty("listener");
+		if (prop != null) {
+			String[] listeners = prop.split(",");
+			for (String l : listeners) {
+				try {
+					l = l.trim();
+					Class<?> klass = Class.forName(l);
+					Object obj = klass.newInstance();
+					core.addListener((RunListener) obj);
+				} catch (Exception e) {
+					log.log(Level.SEVERE, "Listener is not added!", e);
+				}
+			}
+		}
+
+		List<Class<?>> classes = new ArrayList<Class<?>>();
+		List<Failure> missingClasses = new ArrayList<Failure>();
+		for (String each : args)
+			try {
+				classes.add(Class.forName(each));
+			} catch (ClassNotFoundException e) {
+				Description description = Description.createSuiteDescription(each);
+				Failure failure = new Failure(description, e);
+				missingClasses.add(failure);
+			}
+
+		Result result = core.run(classes.toArray(new Class[0]));
+		for (Failure each : missingClasses)
+			result.getFailures().add(each);
+
+		System.exit(result.wasSuccessful() ? 0 : 1);
+	}
+}

Added: 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=1384366&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/CSVReporter.java
(added)
+++ incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/CSVReporter.java
Thu Sep 13 15:21:27 2012
@@ -0,0 +1,45 @@
+package org.openoffice.test.common;
+
+import org.junit.runner.Description;
+import org.junit.runner.Result;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunListener;
+
+public class CSVReporter extends RunListener {
+
+	@Override
+	public void testAssumptionFailure(Failure failure) {
+		super.testAssumptionFailure(failure);
+	}
+
+	@Override
+	public void testFailure(Failure failure) throws Exception {
+		super.testFailure(failure);
+	}
+
+	@Override
+	public void testFinished(Description description) throws Exception {
+		super.testFinished(description);
+	}
+
+	@Override
+	public void testIgnored(Description description) throws Exception {
+		super.testIgnored(description);
+	}
+
+	@Override
+	public void testRunFinished(Result result) throws Exception {
+		super.testRunFinished(result);
+	}
+
+	@Override
+	public void testRunStarted(Description description) throws Exception {
+		super.testRunStarted(description);
+	}
+
+	@Override
+	public void testStarted(Description description) throws Exception {
+		super.testStarted(description);
+	}
+
+}

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=1384366&r1=1384365&r2=1384366&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 Thu
Sep 13 15:21:27 2012
@@ -24,7 +24,6 @@
 package org.openoffice.test.common;
 
 import java.io.BufferedReader;
-import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -46,6 +45,14 @@ import java.util.zip.ZipInputStream;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
+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.xpath.XPath;
 import javax.xml.xpath.XPathExpression;
 import javax.xml.xpath.XPathExpressionException;
@@ -85,6 +92,34 @@ public class FileUtil {
 	}
 	
 	/**
+	 * Create a new xml document
+	 * @return
+	 */
+	public static Document newXML() {
+		try {
+			DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
+			dbfac.setNamespaceAware(true);
+			DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
+			return docBuilder.newDocument();
+		} catch (Exception e) {
+			return null;
+		}
+	}
+	
+	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;
+	    } 
+	}
+	
+	/**
 	 * Get a string by XPATH from a xml file
 	 * @param xml
 	 * @param xpathStr

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=1384366&r1=1384365&r2=1384366&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
Thu Sep 13 15:21:27 2012
@@ -48,9 +48,26 @@ public class SystemUtil {
 
 	private static Clipboard sysClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
 
-	private static final String OSNAME = System.getProperty("os.name");
+	private static final File SCRIPT_TEMP_DIR = Testspace.getFile("bin");
 
-	public static final File SCRIPT_TEMP_DIR = Testspace.getFile("bin");
+	private static String platform = System.getProperty("os.name");
+	
+	private static String osName = System.getProperty("os.name");
+	
+	private static String osVersion  = System.getProperty("os.version");
+	
+	private static String osArch = System.getProperty("os.arch");
+	
+	static {
+		if (isLinux()) {
+			StringBuffer output = new StringBuffer();
+			if (exec(new String[]{"lsb_release", "-is"}, output) == 0)
+				osName = output.toString().trim();
+			output.setLength(0);
+			if (exec(new String[]{"lsb_release", "-rs"}, output) == 0)
+				osVersion = output.toString().trim();	
+		}
+	}
 
 	/**
 	 * Play beep sound! The method doesn't work, if the code is executed on
@@ -63,17 +80,29 @@ public class SystemUtil {
 	}
 
 	public static boolean isWindows() {
-		return OSNAME.startsWith("Windows");
+		return platform.startsWith("Windows");
 	}
 
 	public static boolean isLinux() {
-		return OSNAME.startsWith("Linux");
+		return platform.startsWith("Linux");
 	}
 
 	public static boolean isMac() {
-		return OSNAME.startsWith("Mac");
+		return platform.startsWith("Mac");
 	}
 
+	public static String getOSName() {
+		return osName;
+	}
+	
+	public static String getOSVersion() {
+		return osVersion;
+	}
+	
+	public static String getOSArch() {
+		return osArch;
+	}
+	
 	/**
 	 * Set the contents of the clipboard to the provided text
 	 */
@@ -227,6 +256,10 @@ public class SystemUtil {
 		}
 	}
 
+	public static int exec(String[] cmd, StringBuffer output) {
+		return exec(cmd, null, null, output, output);
+	}
+	
 	/**
 	 * Make the current thread sleep some seconds.
 	 * 

Added: 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=1384366&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.java
(added)
+++ incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/XMLReporter.java
Thu Sep 13 15:21:27 2012
@@ -0,0 +1,67 @@
+package org.openoffice.test.common;
+
+import java.io.File;
+
+import org.junit.Ignore;
+import org.junit.runner.Description;
+import org.junit.runner.Result;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunListener;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class XMLReporter extends RunListener {
+
+	private File file = null;
+	
+	private Document doc = null;
+	
+	private Element root = null;
+	 
+	@Override
+	public void testAssumptionFailure(Failure failure) {
+		System.out.println("testAssumptionFailure");
+	}
+
+	@Override
+	public void testFailure(Failure failure) throws Exception {
+		System.out.println("testFailure");
+	}
+
+	@Override
+	public void testFinished(Description description) throws Exception {
+		System.out.println("testFinished");
+	}
+
+	@Override
+	public void testIgnored(Description description) throws Exception {
+		Ignore a = description.getAnnotation(Ignore.class);
+		System.out.println("testIgnored" + a.value());
+	}
+
+	@Override
+	public void testRunFinished(Result result) throws Exception {
+		System.out.println("testRunFinished");
+		FileUtil.storeXML(doc, file);
+	}
+
+	@Override
+	public void testRunStarted(Description description) throws Exception {
+		System.out.println("testRunStarted");
+		file = Testspace.getFile("output/result/" + description.getClassName() + ".xml");
+		doc = FileUtil.newXML();
+		root = doc.createElement("testsuites");
+		doc.appendChild(root);
+		
+		System.out.println(SystemUtil.getOSName());
+		System.out.println(SystemUtil.getOSVersion());
+		System.out.println(SystemUtil.getOSArch());
+	}
+
+	@Override
+	public void testStarted(Description description) throws Exception {
+		System.out.println("testStarted");
+	}
+
+	
+}



Mime
View raw message