[Yanel-commits] rev 20982 - in public/yanel/trunk: conf src/realms/test/yanel/rti src/resources/testing-control src/resources/testing-control/src/java/org/wyona/yanel/impl/resources src/resources/testing-control/xslt

josias at wyona.com josias at wyona.com
Tue Dec 19 10:00:49 CET 2006


Author: josias
Date: 2006-12-19 10:00:46 +0100 (Tue, 19 Dec 2006)
New Revision: 20982

Added:
   public/yanel/trunk/src/realms/test/yanel/rti/testing-control.html.yanel-rti
Removed:
   public/yanel/trunk/src/resources/testing-control/test.config.xml
   public/yanel/trunk/src/resources/testing-control/xslt/unittests.xsl
Modified:
   public/yanel/trunk/conf/yanel.xml
   public/yanel/trunk/src/resources/testing-control/build.xml
   public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java
   public/yanel/trunk/src/resources/testing-control/xslt/result2html.xsl
Log:
improved testing control resource, thanks to simon

Modified: public/yanel/trunk/conf/yanel.xml
===================================================================
--- public/yanel/trunk/conf/yanel.xml	2006-12-18 23:10:19 UTC (rev 20981)
+++ public/yanel/trunk/conf/yanel.xml	2006-12-19 09:00:46 UTC (rev 20982)
@@ -12,6 +12,7 @@
   <resource src="../src/resources/xml/"                         compile="true"/>
   <resource src="../src/realms/welcome-admin/yanel/resources/show-realms/"                 compile="true"/>
   <resource src="../src/resources/invoice/"                     compile="true"/>
+  <resource src="../src/resources/testing-control/"             compile="true"/>
   <resource src="../src/contributions/resources/atom/"          compile="true"/>
   <resource src="../src/contributions/resources/atom-entry/"    compile="true"/>
   <resource src="../src/contributions/resources/contact-form/"  compile="true"/>

Added: public/yanel/trunk/src/realms/test/yanel/rti/testing-control.html.yanel-rti
===================================================================
--- public/yanel/trunk/src/realms/test/yanel/rti/testing-control.html.yanel-rti	2006-12-18 23:10:19 UTC (rev 20981)
+++ public/yanel/trunk/src/realms/test/yanel/rti/testing-control.html.yanel-rti	2006-12-19 09:00:46 UTC (rev 20982)
@@ -0,0 +1 @@
+<{http://www.wyona.org/yanel/resource/1.0}testing-control/>

Modified: public/yanel/trunk/src/resources/testing-control/build.xml
===================================================================
--- public/yanel/trunk/src/resources/testing-control/build.xml	2006-12-18 23:10:19 UTC (rev 20981)
+++ public/yanel/trunk/src/resources/testing-control/build.xml	2006-12-19 09:00:46 UTC (rev 20982)
@@ -24,12 +24,8 @@
     <property name="testframework.dir" value="${yanel.home.dir}/src/test"/>
     <property name="junit.build.dir" value="${yanel.home.dir}/build/test/junit"/>
     <property name="htmlunit.build.dir" value="${yanel.home.dir}/build/test/htmlunit"/>
-    <property name="test.results.dir" value="${yanel.home.dir}/src/test/test-result"/>
-    
   </target>
 
-
-
   <target name="compile" description="Compile Java classes" depends="init">
 
     <mkdir dir="${resource.classes.dir}"/>
@@ -44,20 +40,14 @@
   </target>
 
   <target name="build-testframework-test" description="builds tests" depends="init">
-    <ant dir="${testframework.dir}" target="build" inheritall="false"/>
+    <ant dir="${build.dir}/../src/test" target="build" inheritall="false"/>
   </target>
 
   <target name="test2webapp" depends="build-testframework-test">
-    <copy todir="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/classes">
-      <fileset dir="${junit.build.dir}"/>
-    </copy>
-    <copy todir="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/classes">
-      <fileset dir="${htmlunit.build.dir}"/>
-    </copy>
-    <copy file="test.config.xml" todir="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/classes"/>
-    <replace file="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/classes/test.config.xml" value="${yanel.home.dir}">
-      <replacetoken>@YANELHOMEDIR@</replacetoken>
-    </replace>
+    <jar destfile="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/lib/yanel-HtmlUnitTests.jar"
+      basedir="${build.dir}/test/htmlunit"/>
+    <jar destfile="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/lib/yanel-JunitTests.jar"
+      basedir="${build.dir}/test/junit"/>
   </target>
 
   <target name="clean" depends="init">
@@ -70,7 +60,5 @@
       <fileset refid="maven2.resource.fileset"/>
       <mapper type="flatten"/>
     </copy>
-    <!-- <antcall target="build-testframework-test"/>
-    <antcall target="test2webapp"/> -->
   </target>
 </project>

Modified: public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java
===================================================================
--- public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java	2006-12-18 23:10:19 UTC (rev 20981)
+++ public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java	2006-12-19 09:00:46 UTC (rev 20982)
@@ -21,14 +21,17 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileReader;
+import java.io.InputStream;
 import java.io.StringBufferInputStream;
 import java.io.StringReader;
+import java.io.OutputStream;
 import java.net.URL;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.List;
 import java.util.Calendar;
+import java.util.Random;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.Servlet;
@@ -52,11 +55,14 @@
 import org.apache.tools.ant.DirectoryScanner;
 import org.apache.tools.ant.types.PatternSet;
 import org.apache.tools.ant.types.FileSet;
-import org.apache.tools.ant.taskdefs.optional.junit.*;
+import org.apache.tools.ant.types.ZipFileSet;
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitTask;
+import org.apache.tools.ant.taskdefs.optional.junit.BatchTest;
+import org.apache.tools.ant.taskdefs.optional.junit.FormatterElement;
+import org.apache.tools.ant.taskdefs.optional.junit.AggregateTransformer.Format;
 import org.apache.tools.ant.taskdefs.Copy;
 import org.apache.tools.ant.taskdefs.Tstamp;
 import org.apache.tools.ant.taskdefs.Delete;
-import org.apache.tools.ant.taskdefs.optional.junit.AggregateTransformer.Format;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
 
@@ -76,32 +82,26 @@
 import org.wyona.yarep.util.YarepUtil;
 import org.wyona.yanel.impl.resources.ResultAggregator;
 
+import org.apache.commons.io.FileUtils;
+
 /**
  * 
  */
 public class TestingControlResource extends Resource implements ViewableV1 {
 
-    private static final String DEFAULT_CONFIGURATION_FILE = "test.config.xml";
+    private static final String JUNIT_JAR = "yanel-JunitTests.jar";
+    private static final String HTMLUNIT_JAR = "yanel-HtmlUnitTests.jar";
     private static Category log = Category.getInstance(TestingControlResource.class);
-    private String YanelHomeDir;
 
+    private File JunitJarLocation;
+    private File HtmlunitJarLocation;
+    private File tmpResultDir;
+    private String errorMessage;
+
     /**
      * 
      */
     public TestingControlResource() {
-        URL propertiesURL = TestingControlResource.class.getClassLoader()
-                .getResource(DEFAULT_CONFIGURATION_FILE);
-        if (propertiesURL == null) {
-            log.error("No such resource: " + DEFAULT_CONFIGURATION_FILE);
-        }
-        try {
-            DefaultConfigurationBuilder configbuilder = new DefaultConfigurationBuilder();
-            File configfile = new File(propertiesURL.getFile());
-            Configuration config = configbuilder.buildFromFile(configfile);
-            YanelHomeDir = config.getChild("yanel-home-dir").getValue();
-        } catch (Exception e) {
-            log.error(e);
-        }
     }
 
     /**
@@ -128,22 +128,53 @@
      */
     public View getView(HttpServletRequest request, String viewId) throws Exception {
         Path path = new Path(request.getServletPath());
+
+        // the junit and htmlunit jars
+        String WEBINFPath = request.getSession().getServletContext().getRealPath("WEB-INF");
+        HtmlunitJarLocation = new File(WEBINFPath + File.separator + "lib" + File.separator
+                + HTMLUNIT_JAR);
+        JunitJarLocation = new File(WEBINFPath + File.separator + "lib" + File.separator
+                + JUNIT_JAR);
+
+        if (!HtmlunitJarLocation.exists()) {
+            errorMessage = errorMessage + "\n HtmlUnit-Tests not found.";
+        }
+        if (!JunitJarLocation.exists()) {
+            errorMessage = errorMessage + "\n JUnit-Tests not found.";
+        }
+
+        // create tmp-directroy to write the tests
+        if (!new File(request.getSession().getServletContext().getRealPath("tmp")).exists()) {
+            if (!new File(request.getSession().getServletContext().getRealPath("tmp")).mkdir()) {
+                errorMessage = errorMessage + "\n Creation of tmp directory faild.";
+            }
+        }
+
+        //prepare tmpResultDir
+        String uuid = new java.rmi.server.UID().toString();
+        tmpResultDir = new File(request.getSession().getServletContext().getRealPath("tmp"
+                + File.separator + "test-results-" + uuid));
+
         String submit = request.getParameter("submit");
         String type = request.getParameter("type");
-        String archive = request.getParameter("archive");
+        String archivedResults = request.getParameter("archived-results");
         String[] testnames = request.getParameterValues("testnames");
+
         View defaultView = new View();
-        if (submit == null) {
-            return plainRequest(path, defaultView);
-        } else {
-            if (type.equals("test")) {
+        if (errorMessage != null) {
+            return error();
+        }
+        if (submit != null) {
+            if (testnames != null) {
                 return executeTests(path, defaultView, testnames);
             }
-            if (type.equals("show")) {
-                return showArchive(path, defaultView, archive);
+            if (archivedResults != null) {
+                return showArchive(path, defaultView, archivedResults);
             }
+            return plainRequest(path, defaultView);
+        } else {
+            return plainRequest(path, defaultView);
         }
-        return null;
     }
 
     private View plainRequest(Path path, View defaultView) throws Exception,
@@ -161,43 +192,55 @@
         sb.append("<body>");
         sb.append("<div id=\"contenBody\">");
         sb.append("<h1>Testing Control</h1>");
-        sb.append("<form>");
+        sb.append("<form method=\"post\">");
         sb.append("<p>Following htmlunit tests are available:</p>");
-        sb.append("<p>Number of Test: " + getAllTestNames("htmlunit").length + "</p>");
 
-        for (int i = 0; i < this.getAllTestNames("htmlunit").length; i++) {
+        String[] allHtmlUnitTestNames = getAllTestNames("htmlunit");
+        sb.append("<p>Number of Test: " + allHtmlUnitTestNames.length + "</p>");
+
+        for (int i = 0; i < allHtmlUnitTestNames.length; i++) {
             sb.append("<p>"
-                    + this.getAllTestNames("htmlunit")[i].substring(this.getAllTestNames("htmlunit")[i].lastIndexOf("/") + 1));
+                    + allHtmlUnitTestNames[i].substring(allHtmlUnitTestNames[i].lastIndexOf("/") + 1));
             sb.append("<input type=\"checkbox\" name=\"testnames\" value=\""
-                    + this.getAllTestNames("htmlunit")[i] + "\"/></p>");
+                    + allHtmlUnitTestNames[i] + "\"/></p>");
         }
 
+        sb.append("<hr/>");
         sb.append("<p>Following junit tests are available:</p>");
-        sb.append("<p>Number of Test: " + getAllTestNames("junit").length + "</p>");
+        String[] allJUnitTestNames = getAllTestNames("junit");
+        sb.append("<p>Number of Test: " + allJUnitTestNames.length + "</p>");
 
-        for (int i = 0; i < this.getAllTestNames("junit").length; i++) {
+        for (int i = 0; i < allJUnitTestNames.length; i++) {
             sb.append("<p>"
-                    + this.getAllTestNames("junit")[i].substring(this.getAllTestNames("junit")[i].lastIndexOf("/") + 1));
-            sb.append("<input type=\"checkbox\" name=\"testnames\" value=\""
-                    + this.getAllTestNames("junit")[i] + "\"/></p>");
+                    + allJUnitTestNames[i].substring(allJUnitTestNames[i].lastIndexOf("/") + 1));
+            sb.append("<input type=\"checkbox\" name=\"testnames\" value=\"" + allJUnitTestNames[i]
+                    + "\"/></p>");
         }
 
-        sb.append("<input type=\"hidden\" name=\"type\" value=\"test\"/>");
         sb.append("<input type=\"submit\" name=\"submit\" value=\"Test\"/>");
         sb.append("</form>");
 
-        sb.append("<form>");
-        sb.append("<br/>Archived Test-Results: <select name=\"archive\">");
-        File testResultArchiveDir = new File(YanelHomeDir + "/src/test/test-results-archive");
-        String[] archivedTests = testResultArchiveDir.list();
-        for (int i = 0; i < archivedTests.length; i++) {
-            if (archivedTests[i].matches("[\\d]{4,4}[-][\\d]{2,2}[-][\\d]{2,2}[-][\\d]{2,2}[-][\\d]{2,2}[-][\\d]{2,2}[-]tests\\.xml")) {
-                sb.append("<option value=\"" + archivedTests[i] + "\">" + archivedTests[i]
-                        + "</option>");
+        sb.append("<form method=\"post\">");
+        sb.append("<br/>Archived Test-Results: <select name=\"archived-results\">");
+        try {
+            org.wyona.yarep.core.Path testResultArchivePath = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.getParent()
+                    .toString()
+                    + "/test-results-archive/"),
+                    getRepositoryFactory())
+                    .getPath();
+            org.wyona.yarep.core.Path[] children = contentRepo.getChildren(testResultArchivePath);
+            for (int i = 0; i < children.length; i++) {
+                if (contentRepo.isResource(children[i])
+                        && children[i].getName()
+                                .matches("[\\d]{4,4}[-][\\d]{2,2}[-][\\d]{2,2}[-][\\d]{2,2}[-][\\d]{2,2}[-][\\d]{2,2}[-]tests\\.xml")) {
+                    sb.append("<option value=\"" + children[i] + "\">" + children[i].getName()
+                            + "</option>");
+                }
             }
+        } catch (Exception e) {
+            log.error(e);
         }
         sb.append("</select>");
-        sb.append("<input type=\"hidden\" name=\"type\" value=\"show\"/>");
         sb.append("<input type=\"submit\" name=\"submit\" value=\"Show\"/>");
         sb.append("</form>");
 
@@ -230,46 +273,50 @@
         contentRepo = rp.getRepo();
 
         // delete the resultdir before making new tests
-        emptyResultDir();
+        tmpResultDir.mkdir();
 
         // executing the tests
-        this.executeTests(testnames, "htmlunit");
-        this.executeTests(testnames, "junit");
+        executeTests(testnames);
 
         // geting the test results
         DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
         Document result = builder.newDocument();
 
-        File testResultDir = new File(YanelHomeDir + "/src/test/test-results");
-        File testResultArchiveDir = new File(YanelHomeDir + "/src/test/test-results-archive");
-
         Project project = new Project();
-
+        
+        // aggregate all tests in the tmp dir
         try {
             ResultAggregator junitreport = new ResultAggregator();
             junitreport.setTaskName("JUnitReport");
             junitreport.setProject(project);
 
             FileSet fs_report = new FileSet();
-            fs_report.setDir(testResultDir);
+            fs_report.setDir(tmpResultDir);
             fs_report.setProject(project);
 
             PatternSet.NameEntry ne = fs_report.createInclude();
             ne.setName("**/TEST-*.xml");
             junitreport.addFileSet(fs_report);
 
-            junitreport.setTodir(testResultArchiveDir);
-            junitreport.setTofile(getTime() + "-tests.xml");
-
             junitreport.init();
-            // archives an aggregation of test-results in test-result-archives
-            junitreport.execute();
-            //get the result to show for this request
+            // get the result to show for this request
             result = junitreport.getDocument();
         } catch (Exception e) {
             log.error(e);
         }
 
+        //delete the test dir
+        FileUtils.deleteDirectory(tmpResultDir);
+
+        // write test result to repo
+        OutputStream out = contentRepo.getOutputStream(new Path("/test-results-archive/"
+                + getTime() + "-tests.xml"));
+        javax.xml.transform.TransformerFactory.newInstance()
+                .newTransformer()
+                .transform(new javax.xml.transform.dom.DOMSource(result),
+                        new javax.xml.transform.stream.StreamResult(out));
+        out.close();
+
         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
         File result2htmlXsltFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile()
                 .getParentFile()
@@ -295,25 +342,28 @@
         return defaultView;
     }
 
-    private View showArchive(Path path, View defaultView, String archive) throws Exception,
+    private View showArchive(Path path, View defaultView, String archivedResults) throws Exception,
             TransformerConfigurationException, TransformerFactoryConfigurationError,
             NoSuchNodeException, TransformerException {
         Repository contentRepo;
         RepoPath rp = contentRepo(path);
         contentRepo = rp.getRepo();
 
-        File ResultArchive = new File(YanelHomeDir + "/src/test/test-results-archive/"+archive);
-
         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
         File result2htmlXsltFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile()
                 .getParentFile()
                 .getAbsolutePath(), "xslt" + File.separator + "result2html.xsl");
         Transformer transResult2html = TransformerFactory.newInstance()
                 .newTransformer(new StreamSource(result2htmlXsltFile));
-        
-        FileReader archfile = new FileReader(ResultArchive);
-        transResult2html.transform(new StreamSource(archfile), new StreamResult(byteArrayOutputStream));
+        transResult2html.setParameter("testing.result.title",
+                archivedResults.substring(archivedResults.lastIndexOf("/") + 1,
+                        archivedResults.length()));
 
+        InputStream inputStream = rp.getRepo()
+                .getInputStream(new org.wyona.yarep.core.Path(archivedResults));
+        transResult2html.transform(new StreamSource(inputStream),
+                new StreamResult(byteArrayOutputStream));
+
         Transformer transformer = TransformerFactory.newInstance()
                 .newTransformer(getXSLTStreamSource(path, contentRepo));
         transformer.setParameter("yanel.path.name", path.getName());
@@ -336,19 +386,6 @@
                 getRepositoryFactory());
     }
 
-    private Transformer prepareTransformer(Path path) throws Exception,
-            TransformerConfigurationException, TransformerFactoryConfigurationError,
-            NoSuchNodeException {
-        Repository contentRepo;
-        RepoPath rp = contentRepo(path);
-        contentRepo = rp.getRepo();
-        Transformer transformer = TransformerFactory.newInstance()
-                .newTransformer(getXSLTStreamSource(path, contentRepo));
-        transformer.setParameter("yanel.path.name", path.getName());
-        transformer.setParameter("yanel.path", path.toString());
-        return transformer;
-    }
-
     /**
      * 
      */
@@ -436,32 +473,26 @@
      * @return an array with the aviable tests.
      */
     private String[] getAllTestNames(String htmlOrJunit) {
-
-        File basedir = new File(YanelHomeDir + "/build/test/" + htmlOrJunit);
-        File resultdir = new File(YanelHomeDir + "/src/test/test-result");
-
         Project project = new Project();
-
         try {
             JUnitTask junit = new JUnitTask();
 
+            ZipFileSet zipfileset = new ZipFileSet();
+            zipfileset.setProject(project);
+            if (htmlOrJunit.equals("htmlunit")) {
+                zipfileset.setSrc(HtmlunitJarLocation);
+            } else {
+                zipfileset.setSrc(JunitJarLocation);
+            }
+            zipfileset.setIncludes("**/*Test.class");
+            zipfileset.setExcludes("**/Abstract*.class");
+
             BatchTest batchTest = junit.createBatchTest();
+            batchTest.addFileSet(zipfileset);
 
-            org.apache.tools.ant.types.FileSet fileset = new org.apache.tools.ant.types.FileSet();
+            DirectoryScanner directoryscanner = zipfileset.getDirectoryScanner(project);
 
-            fileset.setProject(project);
-            fileset.setDir(basedir);
-            fileset.setIncludes("**/*Test.class");
-            fileset.setExcludes("**/Abstract*.class");
-
-            batchTest.setTodir(resultdir);
-            batchTest.addFileSet(fileset);
-
-            DirectoryScanner directoryscanner = fileset.getDirectoryScanner(project);
-
-            String[] files = directoryscanner.getIncludedFiles();
-
-            return files;
+            return directoryscanner.getIncludedFiles();
         } catch (Exception e) {
             log.error(e);
         }
@@ -471,13 +502,9 @@
     /**
      * Executes Tests.
      * @param testnames which should be executed.
-     * @param htmlOrJunit type of tests which should be executed. can be htmlunit or junit.
      */
-    private void executeTests(String[] testnames, String htmlOrJunit) throws Exception {
+    private void executeTests(String[] testnames) throws Exception {
 
-        File basedir = new File(YanelHomeDir + "/build/test/" + htmlOrJunit);
-        File resultdir = new File(YanelHomeDir + "/src/test/test-results");
-
         Project project = new Project();
         project.init();
 
@@ -485,23 +512,26 @@
             JUnitTask junit = new JUnitTask();
             junit.setProject(project);
 
-            FileSet fileset = new FileSet();
-            fileset.setProject(project);
-            fileset.setDir(basedir);
+            ZipFileSet junitzipfileset = new ZipFileSet();
+            ZipFileSet htmlzipfileset = new ZipFileSet();
+            htmlzipfileset.setProject(project);
+            junitzipfileset.setProject(project);
 
+            htmlzipfileset.setSrc(HtmlunitJarLocation);
+            junitzipfileset.setSrc(JunitJarLocation);
+
             String includes = "";
             for (int i = 0; i < testnames.length; i++) {
                 includes = includes + testnames[i] + ",";
             }
-            fileset.setIncludes(includes);
+            htmlzipfileset.setIncludes(includes);
+            junitzipfileset.setIncludes(includes);
 
             BatchTest batchTest = junit.createBatchTest();
-            batchTest.setTodir(resultdir);
-            batchTest.addFileSet(fileset);
+            batchTest.setTodir(tmpResultDir);
+            batchTest.addFileSet(htmlzipfileset);
+            batchTest.addFileSet(junitzipfileset);
 
-            DirectoryScanner directoryscanner = fileset.getDirectoryScanner(project);
-            String[] files = directoryscanner.getIncludedFiles();
-
             FormatterElement formatter = new FormatterElement();
             formatter.setUseFile(true);
             FormatterElement.TypeAttribute typeattribute = new FormatterElement.TypeAttribute();
@@ -516,7 +546,6 @@
             junit.setPrintsummary(summaryattr);
 
             org.apache.tools.ant.types.Commandline.Argument cmdline = junit.createJvmarg();
-            cmdline.setValue("-Djunit.base.dir=" + YanelHomeDir + "/build/test/" + htmlOrJunit);
 
             junit.setHaltonerror(false);
             junit.setHaltonfailure(false);
@@ -530,31 +559,6 @@
     }
 
     /**
-     * remove old test from the result-dir
-     */
-    private void emptyResultDir() {
-        File testResultDir = new File(YanelHomeDir + "/src/test/test-results");
-
-        Project project = new Project();
-        project.init();
-
-        try {
-            FileSet fileset = new FileSet();
-            fileset.setProject(project);
-            fileset.setDir(testResultDir);
-
-            final Delete task = (Delete) project.createTask("delete");
-            task.setTaskName("delete old tests");
-            task.addFileset(fileset);
-            task.init();
-            task.execute();
-
-        } catch (Exception e) {
-            log.error(e);
-        }
-    }
-
-    /**
      * get time as string
      * @return timestamp (yyyy-MM-dd-HH-mm-ss)
      */
@@ -566,4 +570,27 @@
         String time = sdf.format(cal.getTime());
         return time;
     }
+    /**
+     * get an error screen
+     * @return a view with an error screen
+     */
+    private View error() {
+        View defaultView = new View();
+        StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
+        sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
+        sb.append("<head>");
+        sb.append("<title>Testing Control</title>");
+        sb.append("</head>");
+        sb.append("<body>");
+        sb.append("<div id=\"contenBody\">");
+        sb.append("<h1>Testing Control, something is wrong:</h1>");
+        sb.append(errorMessage);
+        sb.append("</div>");
+        sb.append("</body>");
+        sb.append("</html>");
+
+        defaultView.setMimeType("application/xhtml+xml");
+        defaultView.setInputStream(new java.io.StringBufferInputStream(sb.toString()));
+        return defaultView;
+    }
 }

Deleted: public/yanel/trunk/src/resources/testing-control/test.config.xml
===================================================================
--- public/yanel/trunk/src/resources/testing-control/test.config.xml	2006-12-18 23:10:19 UTC (rev 20981)
+++ public/yanel/trunk/src/resources/testing-control/test.config.xml	2006-12-19 09:00:46 UTC (rev 20982)
@@ -1,4 +0,0 @@
-<?xml version="1.0"?>
-<config>
-  <yanel-home-dir>@YANELHOMEDIR@</yanel-home-dir>
-</config>
\ No newline at end of file

Modified: public/yanel/trunk/src/resources/testing-control/xslt/result2html.xsl
===================================================================
--- public/yanel/trunk/src/resources/testing-control/xslt/result2html.xsl	2006-12-18 23:10:19 UTC (rev 20981)
+++ public/yanel/trunk/src/resources/testing-control/xslt/result2html.xsl	2006-12-19 09:00:46 UTC (rev 20982)
@@ -1,33 +1,80 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
+  xmlns="http://www.w3.org/1999/xhtml"
+  >
   <xsl:output method="html"/>
   
+  <xsl:param name="testing.result.title" select="'current test'"/>
+  
   <xsl:variable name="testsuite.list" select="//testsuite"/>
+  <xsl:variable name="testcase.list" select="$testsuite.list/testcase"/>
+  <xsl:variable name="testcase.error.list" select="$testcase.list/error"/>
+  <xsl:variable name="testcase.failure.list" select="$testcase.list/failure"/>
   
   <xsl:template match="/">
-    <html xmlns="http://www.w3.org/1999/xhtml">
+    <html>
       <head>
         <title>Testing Results</title>
       </head>
       <body>
         <div id="contenBody">
-          <xsl:apply-templates/>
+          <h1>Testing results of <xsl:value-of select="$testing.result.title"/></h1>
+          <p>Executed Testcases: <xsl:value-of select="count($testcase.list)"/></p>
+          <p>Successful: <xsl:value-of select="count($testcase.list) - count($testcase.failure.list) - count($testcase.error.list)"/>,
+          Failures: <xsl:value-of select="count($testcase.failure.list)"/>,
+          Errors: <xsl:value-of select="count($testcase.error.list)"/></p>
+          <hr/>
+          <xsl:apply-templates select="//testsuite"/>
         </div>
       </body>
     </html>
   </xsl:template>
 
   <xsl:template match="testsuite">
-    <p>
-       Name: <xsl:value-of select="@name"/>
-       Errors: <xsl:value-of select="@errors"/>
-       Failures: <xsl:value-of select="@failures"/>
-       Packagesname: <xsl:value-of select="@package"/> 
-       Execution Time: <xsl:value-of select="@time"/>
-       <xsl:apply-templates/>
+    <h3>Name: <xsl:value-of select="@name"/></h3>
+    <xsl:choose>
+      <xsl:when test="testcase[failure]">
+        <h4 style="color:orange">
+          Failure occurred!
+        </h4>
+      </xsl:when>
+      <xsl:when test="testcase[error]">
+        <h4 style="color:red">
+          Error occurred!
+        </h4>
+      </xsl:when>
+      <xsl:otherwise>
+        <h4 style="color:green">
+          Test Successful!
+        </h4>
+      </xsl:otherwise>
+    </xsl:choose>
+    
+    <p>Errors:<xsl:value-of select="@errors"/>, Failures:<xsl:value-of select="@failures"/>,
+      Execution Time: <xsl:value-of select="@time"/>
     </p>
+    <p>Packagesname: <xsl:value-of select="@package"/></p> 
+    <p></p>
+    <xsl:apply-templates select="testcase"/>
+    <hr/>
   </xsl:template>
+
+  <xsl:template match="testcase[failure]">
+    <p>Message: <xsl:value-of select="failure/@message"/></p>
+    <p>Type: <xsl:value-of select="failure/@type"/></p>
+    Failure: <xsl:value-of select="."/>
+    <xsl:apply-templates select="../system-out"/>
+    <xsl:apply-templates select="../system-err"/>
+  </xsl:template>
   
+  <xsl:template match="testcase[error]">
+    <p>Message: <xsl:value-of select="error/@message"/></p>
+    <p>Type: <xsl:value-of select="error/@type"/></p>
+    Failure: <xsl:value-of select="."/>
+    <xsl:apply-templates select="../system-out"/>
+    <xsl:apply-templates select="../system-err"/>
+  </xsl:template>
+  
   <xsl:template match="system-out">
     <p>System-out: 
     <xsl:value-of select="."/>

Deleted: public/yanel/trunk/src/resources/testing-control/xslt/unittests.xsl
===================================================================
--- public/yanel/trunk/src/resources/testing-control/xslt/unittests.xsl	2006-12-18 23:10:19 UTC (rev 20981)
+++ public/yanel/trunk/src/resources/testing-control/xslt/unittests.xsl	2006-12-19 09:00:46 UTC (rev 20982)
@@ -1,292 +0,0 @@
-<?xml version="1.0"?>
-<!--********************************************************************************
- * CruiseControl, a Continuous Integration Toolkit
- * Copyright (c) 2001, ThoughtWorks, Inc.
- * 651 W Washington Ave. Suite 600
- * Chicago, IL 60661 USA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *     + Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *
- *     + Redistributions in binary form must reproduce the above
- *       copyright notice, this list of conditions and the following
- *       disclaimer in the documentation and/or other materials provided
- *       with the distribution.
- *
- *     + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
- *       names of its contributors may be used to endorse or promote
- *       products derived from this software without specific prior
- *       written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ********************************************************************************-->
-<xsl:stylesheet
-    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
-    xmlns:lxslt="http://xml.apache.org/xslt">
-
-    <xsl:output method="html"/>
-
-    <xsl:variable name="testsuite.list" select="//testsuite"/>
-    <xsl:variable name="testsuite.error.count" select="count($testsuite.list/error)"/>
-    <xsl:variable name="testcase.list" select="$testsuite.list/testcase"/>
-    <xsl:variable name="testcase.error.list" select="$testcase.list/error"/>
-    <xsl:variable name="testcase.failure.list" select="$testcase.list/failure"/>
-    <xsl:variable name="totalErrorsAndFailures" select="count($testcase.error.list) + count($testcase.failure.list) + $testsuite.error.count"/>
-
-    <xsl:template match="/" mode="unittests">
-      <html xmlns="http://www.w3.org/1999/xhtml">
-        <head>
-        <title>Example Resource</title>
-        </head>
-        <body>
-        <div id="contenBody">
-        <table align="center" cellpadding="2" cellspacing="0" border="0" width="98%">
-
-            <!-- Unit Tests -->
-            <tr>
-                <td class="unittests-sectionheader" colspan="4">
-                   &#160;Unit Tests: (<xsl:value-of select="count($testcase.list)"/>)
-                </td>
-            </tr>
-
-            <xsl:choose>
-                <xsl:when test="count($testsuite.list) = 0">
-                    <tr>
-                        <td colspan="2" class="unittests-data">
-                            No Tests Run
-                        </td>
-                    </tr>
-                    <tr>
-                        <td colspan="2" class="unittests-error">
-                            This project doesn't have any tests
-                        </td>
-                    </tr>
-                </xsl:when>
-
-                <xsl:when test="$totalErrorsAndFailures = 0">
-                    <tr>
-                        <td colspan="2" class="unittests-data">
-                            All Tests Passed
-                        </td>
-                    </tr>
-                </xsl:when>
-            </xsl:choose>
-            <tr>
-              <td>
-                 <table align="center" cellpadding="2" cellspacing="0" border="0" width="98%">
-                    <xsl:apply-templates select="$testcase.error.list" mode="unittests"/>
-                    <xsl:apply-templates select="$testcase.failure.list" mode="unittests"/>
-                 </table>
-              </td>
-            </tr>
-            <tr/>
-            <tr><td colspan="2">&#160;</td></tr>
-
-            <!-- <xsl:if test="$totalErrorsAndFailures > 0"> -->
-
-              <tr>
-                <td class="unittests-sectionheader" colspan="4">
-                    &#160;Unit Test Error Details:&#160;(<xsl:value-of select="$totalErrorsAndFailures"/>)
-                </td>
-              </tr>
-
-              <!-- (PENDING) Why doesn't this work if set up as variables up top? -->
-              <xsl:call-template name="testdetail">
-                <xsl:with-param name="detailnodes" select="//testsuite/testcase[.//error]"/>
-              </xsl:call-template>
-
-              <xsl:call-template name="testdetail">
-                <xsl:with-param name="detailnodes" select="//testsuite/testcase[.//failure]"/>
-              </xsl:call-template>
-            <!-- </xsl:if> -->
-        </table>
-        </div>
-        </body>
-        </html>
-    </xsl:template>
-
-    <!-- UnitTest Errors -->
-    <xsl:template match="error" mode="unittests">
-        <tr>
-            <xsl:if test="position() mod 2 = 0">
-                <xsl:attribute name="class">unittests-oddrow</xsl:attribute>
-            </xsl:if>
-
-            <td class="unittests-data" width="50">
-                error
-            </td>
-            <td class="unittests-data" width="300">
-                <xsl:value-of select="../@name"/>
-            </td>
-            <td class="unittests-data" width="400">
-                <xsl:value-of select="..//..//@name"/>
-            </td>
-        </tr>
-    </xsl:template>
-
-    <!-- UnitTest Failures -->
-    <xsl:template match="failure" mode="unittests">
-        <tr>
-            <xsl:if test="($testsuite.error.count + position()) mod 2 = 0">
-                <xsl:attribute name="class">unittests-oddrow</xsl:attribute>
-            </xsl:if>
-
-            <td class="unittests-data" width="50">
-                failure
-            </td>
-            <td class="unittests-data" width="300">
-                <xsl:value-of select="../@name"/>
-            </td>
-            <td class="unittests-data" width="400">
-                <xsl:value-of select="..//..//@name"/>
-            </td>
-        </tr>
-    </xsl:template>
-
-    <!-- UnitTest Errors And Failures Detail Template -->
-    <xsl:template name="testdetail">
-      <xsl:param name="detailnodes"/>
-
-      <xsl:for-each select="$detailnodes">
-    <tr>
-        <td colspan="2">
-        <table width="100%" border="0" cellspacing="0">
-
-        <tr class="unittests-title">
-        <td width="50">Test:&#160;</td>
-            <td>
-                <xsl:value-of select="@name"/>
-            </td>
-        </tr>
-        <tr class="unittests-data">
-        <td>Class:&#160;</td>
-            <td>
-                <xsl:value-of select="..//@name"/>
-            </td>
-        </tr>
-
-        <xsl:if test="error">
-        <xsl:call-template name="test-data">
-            <xsl:with-param name="word" select="error"/>
-            <xsl:with-param name="type" select="'error'"/>
-        </xsl:call-template>
-        </xsl:if>
-
-        <xsl:if test="failure">
-        <xsl:call-template name="test-data">
-            <xsl:with-param name="word" select="failure"/>
-            <xsl:with-param name="type" select="'failure'"/>
-        </xsl:call-template>
-        </xsl:if>
-
-              </table>
-        </td>
-    </tr>
-
-      </xsl:for-each>
-    </xsl:template>
-
-    <xsl:template name="test-data">
-        <xsl:param name="word"/>
-        <xsl:param name="type"/>
-        <tr>
-        <td/>
-            <td>
-        <xsl:call-template name="stack-trace">
-            <xsl:with-param name="word" select="$word"/>
-            <xsl:with-param name="type" select="$type"/>
-        </xsl:call-template>
-            </td>
-        </tr>
-    </xsl:template>
-
-    <xsl:template name="stack-trace">
-        <xsl:param name="word"/>
-        <xsl:param name="type"/>
-    <table width="100%" border="1" cellspacing="0" cellpadding="2">
-        <tr>
-            <td>
-                <table width="100%" border="0" cellspacing="0" cellpadding="0">
-                    <xsl:call-template name="br-replace">
-                    <xsl:with-param name="word" select="$word"/>
-                    <xsl:with-param name="type" select="$type"/>
-                    <xsl:with-param name="count" select="0"/>
-                    </xsl:call-template>
-                </table>
-            </td>
-        </tr>
-        </table>
-    </xsl:template>
-
-    <xsl:template name="br-replace">
-        <xsl:param name="word"/>
-        <xsl:param name="type"/>
-        <xsl:param name="count"/>
-<!-- </xsl:text> on next line on purpose to get newline -->
-<xsl:variable name="stackstart"><xsl:text>	at</xsl:text></xsl:variable>
-<xsl:variable name="cr"><xsl:text>
-</xsl:text></xsl:variable>
-        <xsl:choose>
-            <xsl:when test="contains($word,$cr)">
-        <tr>
-        <xsl:attribute name="class">unittests-<xsl:value-of select="$type"/></xsl:attribute>
-        <xsl:if test="$count mod 2 != 0">
-            <xsl:attribute name="bgcolor">#EEEEEE</xsl:attribute>
-        </xsl:if>
-        <xsl:if test="$count != 0 and starts-with($word,$stackstart)">
-            <td width="30"/>
-            <td>
-                <xsl:value-of select="substring-before($word,$cr)"/>&#160;
-            </td>
-        </xsl:if>
-        <xsl:if test="$count != 0 and not(starts-with($word,$stackstart))">
-            <td colspan="2">
-                <xsl:value-of select="substring-before($word,$cr)"/>&#160;
-            </td>
-        </xsl:if>
-        <xsl:if test="$count = 0">
-            <td colspan="2">
-                <xsl:value-of select="substring-before($word,$cr)"/>&#160;
-            </td>
-        </xsl:if>
-        </tr>
-                <xsl:call-template name="br-replace">
-                    <xsl:with-param name="word" select="substring-after($word,$cr)"/>
-            <xsl:with-param name="type" select="$type"/>
-                    <xsl:with-param name="count" select="$count + 1"/>
-                </xsl:call-template>
-            </xsl:when>
-            <xsl:otherwise>
-        <tr>
-        <xsl:attribute name="class">unittests-<xsl:value-of select="$type"/></xsl:attribute>
-        <xsl:if test="$count mod 2 != 0">
-            <xsl:attribute name="bgcolor">#EEEEEE</xsl:attribute>
-        </xsl:if>
-        <td width="30"/>
-        <td>
-                <xsl:value-of select="$word"/>
-        </td>
-        </tr>
-            </xsl:otherwise>
-        </xsl:choose>
-    </xsl:template>
-
-    <xsl:template match="/">
-        <xsl:apply-templates select="." mode="unittests"/>
-    </xsl:template>
-</xsl:stylesheet>




More information about the Yanel-commits mailing list