You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2011/03/16 18:23:41 UTC

svn commit: r1082226 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/derbynet/GetCurrentPropertiesTest.java junit/TestConfiguration.java

Author: kahatlen
Date: Wed Mar 16 17:23:41 2011
New Revision: 1082226

URL: http://svn.apache.org/viewvc?rev=1082226&view=rev
Log:
DERBY-5100: GetCurrentPropertiesTest depends on implicit ordering of test cases

Made the test ordering explicit.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.java?rev=1082226&r1=1082225&r2=1082226&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/GetCurrentPropertiesTest.java Wed Mar 16 17:23:41 2011
@@ -25,7 +25,6 @@ import java.util.Properties;
 import java.util.Enumeration;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import junit.framework.Test;
-import junit.framework.TestSuite;
 import org.apache.derby.drda.NetworkServerControl;
 import org.apache.derbyTesting.junit.NetworkServerTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -52,15 +51,20 @@ public class GetCurrentPropertiesTest ex
 
     public static Test suite()
     {
-        TestSuite suite = new TestSuite("GetCurrentPropertiesTest");
-        Test test = TestConfiguration
-            .clientServerSuite(GetCurrentPropertiesTest.class);
+        // Use a fixed order for the test cases so that we know the exact
+        // order in which they run. Some of them depend on the connection
+        // number having a specific value, which can only be guaranteed if
+        // we know exactly how many connections have been opened, hence the
+        // need for a fixed order. Some also depend on seeing property values
+        // set by the previous test case.
+        Test test =
+                TestConfiguration.orderedSuite(GetCurrentPropertiesTest.class);
+        test = TestConfiguration.clientServerDecorator(test);
         // Install a security manager using the special policy file.
         test = decorateWithPolicy(test);
-        suite.addTest(test);
         // return suite; to ensure that nothing interferes with setting of
         // properties, wrap in singleUseDatabaseDecorator 
-        return TestConfiguration.singleUseDatabaseDecorator(suite);
+        return TestConfiguration.singleUseDatabaseDecorator(test);
     }
     /**
      * Construct the name of the server policy file.
@@ -104,7 +108,7 @@ public class GetCurrentPropertiesTest ex
      * 
      * @throws Exception
      */
-    public void testPropertiesBeforeConnection() throws Exception {
+    public void test_01_propertiesBeforeConnection() throws Exception {
         Properties p = null;
         String  userDir = getSystemProperty( "user.dir" );
         String traceDir = userDir + File.separator + "system";
@@ -138,7 +142,7 @@ public class GetCurrentPropertiesTest ex
      * 
      * @throws Exception
      */
-    public void testPropertiesAfterConnection() throws Exception { 
+    public void test_02_propertiesAfterConnection() throws Exception {
         Properties p = null;
         String  userDir = getSystemProperty( "user.dir" );
         String traceDir = userDir + File.separator + "system";
@@ -176,7 +180,7 @@ public class GetCurrentPropertiesTest ex
      * 
      * @throws Exception
      */
-    public void testPropertiesTraceOn() throws Exception { 
+    public void test_03_propertiesTraceOn() throws Exception {
         Properties p = null;
 
         NetworkServerControl nsctrl = NetworkServerTestSetup.getNetworkServerControl();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=1082226&r1=1082225&r2=1082226&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Wed Mar 16 17:23:41 2011
@@ -28,8 +28,11 @@ import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Properties;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.Iterator;
 
 import junit.extensions.TestSetup;
 import junit.framework.Assert;
@@ -413,6 +416,39 @@ public final class TestConfiguration {
         
         return suiteName;
     }
+
+    /**
+     * A comparator that orders {@code TestCase}s lexicographically by
+     * their names.
+     */
+    private static final Comparator TEST_ORDERER = new Comparator() {
+        public int compare(Object o1, Object o2) {
+            TestCase t1 = (TestCase) o1;
+            TestCase t2 = (TestCase) o2;
+            return t1.getName().compareTo(t2.getName());
+        }
+    };
+
+    /**
+     * Create a test suite with all the test cases in the specified class. The
+     * test cases should be ordered lexicographically by their names.
+     *
+     * @param testClass the class with the test cases
+     * @return a lexicographically ordered test suite
+     */
+    public static Test orderedSuite(Class testClass) {
+        // Extract all tests from the test class and order them.
+        ArrayList tests = Collections.list(new TestSuite(testClass).tests());
+        Collections.sort(tests, TEST_ORDERER);
+
+        // Build a new test suite with the tests in lexicographic order.
+        TestSuite suite = new TestSuite(suiteName(testClass));
+        for (Iterator it = tests.iterator(); it.hasNext(); ) {
+            suite.addTest((Test) it.next());
+        }
+
+        return suite;
+    }
     
     /**
      * Create a suite for the passed test class that includes