[jboss-cvs] JBossAS SVN: r62384 - in branches/JBoss_4_0_1_SP1_CP/testsuite: src/main/org/jboss/test and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 17 18:50:52 EDT 2007


Author: jaroslaw.kijanowski
Date: 2007-04-17 18:50:52 -0400 (Tue, 17 Apr 2007)
New Revision: 62384

Added:
   branches/JBoss_4_0_1_SP1_CP/testsuite/src/main/org/jboss/test/compatibility/
   branches/JBoss_4_0_1_SP1_CP/testsuite/src/main/org/jboss/test/compatibility/matrix/
   branches/JBoss_4_0_1_SP1_CP/testsuite/src/main/org/jboss/test/compatibility/matrix/MatrixTestContainer.java
Modified:
   branches/JBoss_4_0_1_SP1_CP/testsuite/build.xml
Log:
fix compatibility matrix

Modified: branches/JBoss_4_0_1_SP1_CP/testsuite/build.xml
===================================================================
--- branches/JBoss_4_0_1_SP1_CP/testsuite/build.xml	2007-04-17 22:14:47 UTC (rev 62383)
+++ branches/JBoss_4_0_1_SP1_CP/testsuite/build.xml	2007-04-17 22:50:52 UTC (rev 62384)
@@ -2680,6 +2680,8 @@
               <classpath>
                 <pathelement location="${build.classes}"/>
                 <pathelement location="${build.resources}"/>
+                <pathelement path="${jboss.server.lib}/jboss.jar"/>
+                <pathelement path="${jboss.jmx.lib}/jboss-jmx.jar"/>
                 <fileset dir="${current-version-dir}" includes="*.jar"/>
                 <path refid="library.classpath" />
               </classpath>

Added: branches/JBoss_4_0_1_SP1_CP/testsuite/src/main/org/jboss/test/compatibility/matrix/MatrixTestContainer.java
===================================================================
--- branches/JBoss_4_0_1_SP1_CP/testsuite/src/main/org/jboss/test/compatibility/matrix/MatrixTestContainer.java	                        (rev 0)
+++ branches/JBoss_4_0_1_SP1_CP/testsuite/src/main/org/jboss/test/compatibility/matrix/MatrixTestContainer.java	2007-04-17 22:50:52 UTC (rev 62384)
@@ -0,0 +1,249 @@
+/*
+ *
+ * JBoss, the OpenSource webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.compatibility.test.matrix;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestListener;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+
+import java.lang.reflect.Method;
+import java.util.logging.Logger;
+import java.util.Hashtable;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * This class is a container for other tests used for the MatrixTest.
+ * For each version used by the Matrix verification we are containing a bunch of other tests.
+ *
+ * This class uses list of variables defined by the testSuite and they have to be in the System.getProperties()
+ * jbosstest.hometest = Contains where we are loading the testcases
+ * jbosstest.executionlist = A comma based list of .class files. Each file has to begin with ${jbosstest.hometest}
+ * jbosstest.versionname = The name of the version being tested
+ *
+ * @author clebert.suconic at jboss.com
+ */
+public class MatrixTestContainer extends TestCase
+{
+    static Logger log = Logger.getLogger("MatrixTestContainer");
+
+    /** Used to similuate tests while renaming its names. */
+    private static class DummyTestCase extends TestCase
+    {
+        DummyTestCase(String name)
+        {
+            super (name);
+        }
+    }
+
+    /** We need this proxy just to inform failures*/
+    private static class TestSuiteProxy extends TestSuite
+    {
+        ArrayList loadFailures;
+        public TestSuiteProxy(ArrayList loadFailures)
+        {
+            this.loadFailures=loadFailures;
+        }
+
+        public void run(TestResult testResult)
+        {
+            Iterator iter = loadFailures.iterator();
+            while (iter.hasNext())
+            {
+                LoadFailure load = (LoadFailure)iter.next();
+                TestCase test = new DummyTestCase(load.className);
+                testResult.startTest(test);
+                testResult.addError(test,load.exception);
+            }
+
+            loadFailures.clear();
+
+            super.run(testResult);
+        }
+
+
+    }
+
+    private static class LoadFailure
+    {
+        String className;
+        Throwable exception;
+
+        public LoadFailure(String className, Throwable exception)
+        {
+            this.className=className;
+            this.exception=exception;
+        }
+    }
+
+    /**
+     * One of the goals of this class also is to keep original classNames into testNames. So, you will realize several proxies existent here to
+     * keep these class names while executing method names.
+     */
+    static class TestProxy extends TestCase
+    {
+        Hashtable hashTests = new Hashtable();
+
+
+
+        public TestProxy(Test testcase, String name)
+        {
+            super(name);
+            this.testcase = testcase;
+        }
+
+        public int countTestCases()
+        {
+            return testcase.countTestCases();
+        }
+
+        /**
+         * Create a dummy test renaming its content
+         * @param test
+         * @return
+         */
+        private Test createDummyTest(Test test)
+        {
+            Test dummyTest = (Test)hashTests.get(test);
+            if (dummyTest==null)
+            {
+                if (test instanceof TestCase)
+                {
+                    dummyTest = new DummyTestCase(this.getName() + ":"+ ((TestCase)test).getName());
+                } else
+                if (test instanceof TestSuite)
+                {
+                    dummyTest = new DummyTestCase(this.getName() + ":"+ ((TestCase)test).getName());
+                }
+                else
+                {
+                    // if can't recover the name, don't create a proxy
+                    log.warning("Couldn't find a name for " + test.toString() + ", class=" + test.getClass().getName());
+
+                    dummyTest = new DummyTestCase(test.getClass().getName());
+                }
+
+                hashTests.put(test,dummyTest);
+            }
+
+            return dummyTest;
+        }
+
+        public void run(final TestResult result)
+        {
+            TestResult subResult = new TestResult();
+            subResult.addListener(new TestListener()
+            {
+                public void addError(Test subtest, Throwable throwable)
+                {
+                    Test dummyTest = createDummyTest(subtest);
+                    result.addError(dummyTest, throwable);
+                }
+
+                public void addFailure(Test subtest, AssertionFailedError assertionFailedError)
+                {
+                    Test dummyTest = createDummyTest(subtest);
+                    result.addFailure(dummyTest, assertionFailedError);
+                }
+
+                public void endTest(Test subtest)
+                {
+                    Test dummyTest = createDummyTest(subtest);
+                    result.endTest(dummyTest);
+                }
+
+                public void startTest(Test subtest)
+                {
+                    Test dummyTest = createDummyTest(subtest);
+                    result.startTest(dummyTest);
+                }
+            });
+            testcase.run(subResult);
+        }
+
+        Test testcase;
+    }
+
+    private static Test createSuite(Class clazz) throws Exception
+    {
+        Method method = null;
+        try
+        {
+            method = clazz.getMethod("suite", null);
+        }
+        catch (Exception e)
+        {
+        }
+
+        if (method != null)
+        {
+            return (Test) method.invoke(null, null);
+        } else
+        {
+            TestSuite suiteTmp = new TestSuite();
+            suiteTmp.addTestSuite(clazz);
+            return suiteTmp;
+        }
+    }
+
+    private static void copySuite(Test source, TestSuite destination, String baseName)
+    {
+        destination.addTest(new TestProxy(source,baseName));
+    }
+
+    public static Test suite()
+    {
+        try
+        {
+            String homedir = (String) System.getProperties().get("jbosstest.hometest");
+
+            String executionList = (String) System.getProperties().get("jbosstest.executionlist");
+
+            String[] tests = executionList.split(",");
+
+            ArrayList loadFailures = new ArrayList();
+
+            TestSuite suite = new TestSuiteProxy(loadFailures);
+
+            for (int classesCount = 0; classesCount < tests.length; classesCount++)
+            {
+                String testName = null;
+                try
+                {
+                    testName = tests[classesCount].substring(homedir.length() + 1);
+                    testName = testName.replace('/', '.');
+                    testName = testName.substring(0, testName.length() - 6); // - ".class".length()
+
+                    Class clazz = Class.forName(testName);
+                    Test suiteTmp = createSuite(clazz);
+                    copySuite(suiteTmp, suite, testName + ":");
+                } catch (Throwable e)
+                {
+                    loadFailures.add(new LoadFailure(testName,e));
+                    log.info("Error Loading " + testName);
+                    e.printStackTrace();
+                    log.warning(e.getMessage());
+                }
+            }
+
+            log.info("All classes loaded, executing tests");
+
+            return suite;
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+            return null;
+        }
+
+
+    }
+
+}




More information about the jboss-cvs-commits mailing list