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 dj...@apache.org on 2008/01/04 22:47:49 UTC

svn commit: r609020 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/lang/CollationTest2.java junit/Decorator.java

Author: djd
Date: Fri Jan  4 13:47:49 2008
New Revision: 609020

URL: http://svn.apache.org/viewvc?rev=609020&view=rev
Log:
Improve CollationTest2 to use the existing decorator to create territory collated databases rather than having multiple mechanisms to create such databases. This will then allow the test to use the standard utility methods rather than duplicated standard code.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest2.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest2.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest2.java?rev=609020&r1=609019&r2=609020&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest2.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest2.java Fri Jan  4 13:47:49 2008
@@ -38,9 +38,11 @@
 
 import junit.framework.Assert;
 import junit.framework.Test;
+import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.Decorator;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.JDBCDataSource;
 import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
@@ -112,51 +114,7 @@
     private static final int    TEST_ENGLISH            = 1;
     private static final int    TEST_POLISH             = 2;
     private static final int    TEST_NORWAY             = 3;
-    private static final int    TEST_DEFAULT_TERRITORY  = 4;
 
-    /**
-     * logical database names to use for the DataSource connection.
-     * <p>
-     * Order of array is important, each entry should map to the logical
-     * database name associated with the TEST_* constants.  So for example
-     * the logical name for the ENGLISH database should be in 
-     * TEST_DATABASE[TEST_ENGLISH].
-     **/
-    private static final String[] TEST_DATABASE = 
-    {
-        "defaultdb2",
-        "enddb2",
-        "poldb2",
-        "nordb2",
-        "defaultdb3"
-    };
-
-
-    /**
-     * connection attribute to use to specify the territory.
-     * <p>
-     * Order of array is important, each entry should map to the territory
-     * for the associated TEST_* constants.  So for example
-     * the territory id POLISH database should be in 
-     * TEST_DATABASE[TEST_POLISH].
-     **/
-    private static final String[] TEST_CONNECTION_ATTRIBUTE =
-    {
-        null,
-        "en",
-        "pl",
-        "no_NO",
-        null
-    };
-
-    private static final String[] TEST_COLLATION_ATTRIBUTE =
-    {
-        null,
-        ";collation=TERRITORY_BASED",
-        ";collation=TERRITORY_BASED",
-        ";collation=TERRITORY_BASED",
-        ";collation=TERRITORY_BASED"
-    };
 
     private static final String[] NAMES =
     {
@@ -813,45 +771,6 @@
      **************************************************************************
      */
 
-    /**
-     * Creates a database and return connection to database.
-     * <p>
-     * Creates a database with territory/collation as indicated by db_index
-     * test case.  
-     * Database name:       TEST_DATABASE[db_index]
-     * territory attribute: TEST_CONNECTION_ATTRIBUTE[db_index]
-     **/
-    private Connection setUpDBandOpenConnection(int db_index) 
-        throws SQLException 
-    {
-        DataSource ds = 
-            JDBCDataSource.getDataSourceLogical(TEST_DATABASE[db_index]);
-
-        // what territory, if any to specify
-        String territory_str = 
-            (TEST_CONNECTION_ATTRIBUTE[db_index] == null) ?  
-                "" : ";territory=" + TEST_CONNECTION_ATTRIBUTE[db_index];
-
-        String collation_str = 
-            (TEST_COLLATION_ATTRIBUTE[db_index] == null) ?  
-                "" : ";collation=TERRITORY_BASED";
-
-        // build strings of the form:
-        // create=true
-        // create=true;territory=en;collation=TERRITORY_BASED
-        // create=true;collation=TERRITORY_BASED
-        String conn_string = "create=true" + territory_str + collation_str;
-
-        if (verbose_debug)
-            System.out.println("connection attribute string: " + conn_string);
-
-        JDBCDataSource.setBeanProperty(ds, "connectionAttributes", conn_string);
-
-        Connection conn = ds.getConnection();
-
-        return(conn);
-    }
-
     private void setUpTable(Connection conn) throws SQLException 
     {
         Statement s = conn.createStatement();
@@ -2052,33 +1971,29 @@
 
     public void testDefaultCollation() throws SQLException
     {
-        Connection conn = setUpDBandOpenConnection(TEST_DEFAULT);
-        Assert.assertTrue(isDatabaseBasicCollation(conn));
+        Connection conn = getConnection();
+        assertTrue(isDatabaseBasicCollation(conn));
         runTestIter(conn, TEST_DEFAULT);
-        conn.close();
     }
     public void testEnglishCollation() throws SQLException
     {
-        Connection conn = setUpDBandOpenConnection(TEST_ENGLISH);
-        Assert.assertTrue(!isDatabaseBasicCollation(conn));
+        Connection conn = getConnection();
+        assertFalse(isDatabaseBasicCollation(conn));
         runTestIter(conn, TEST_ENGLISH);
-        conn.close();
     }
 
     public void testPolishCollation() throws SQLException
     {
-        Connection conn = setUpDBandOpenConnection(TEST_POLISH);
-        Assert.assertTrue(!isDatabaseBasicCollation(conn));
+        Connection conn = getConnection();
+        assertFalse(isDatabaseBasicCollation(conn));
         runTestIter(conn, TEST_POLISH);
-        conn.close();
     }
     public void testNorwayCollation() throws SQLException
     {
-        Connection conn = setUpDBandOpenConnection(TEST_NORWAY);
-        Assert.assertTrue(!isDatabaseBasicCollation(conn));
+        Connection conn = getConnection();
+        assertFalse(isDatabaseBasicCollation(conn));
         runDerby2670(conn);
         runTestIter(conn, TEST_NORWAY);
-        conn.close();
     }
     /**
      * Test creating a TERRITORY_BASED collated database by only setting
@@ -2115,21 +2030,25 @@
 
         if (run_test)
         {
-            Connection conn = setUpDBandOpenConnection(TEST_DEFAULT_TERRITORY);
-            Assert.assertTrue(!isDatabaseBasicCollation(conn));
+            Connection conn = getConnection();
+            assertFalse(isDatabaseBasicCollation(conn));
             runTestIter(conn, db_index);
-            conn.close();
         }
     }
     
     public static Test suite() 
     {
         // only test in embedded mode, all tests are server side actions.
-        Test test =  
-               TestConfiguration.embeddedSuite(CollationTest2.class);
-
+        
+        TestSuite suite = new TestSuite("CollationTest2");
+        suite.addTest(new CollationTest2("testDefaultCollation"));
+        suite.addTest(collatedTest("en", "testEnglishCollation"));
+        suite.addTest(collatedTest("no_NO", "testNorwayCollation"));
+        suite.addTest(collatedTest("pl", "testPolishCollation"));
+        suite.addTest(collatedTest(null, "testDefaultJVMTerritoryCollation"));
+        
         // add support to use external files for import/export calls.
-        test = new SupportFilesSetup(test);
+        Test test = new SupportFilesSetup(suite);
 
         // turn on log statement text for sequence of statements in derby.log.  
         if (verbose_debug)
@@ -2139,26 +2058,12 @@
             test = new SystemPropertyTestSetup(test, props);
         }
 
-        // database to use for testing default collation.
-        test = TestConfiguration.additionalDatabaseDecorator(
-                    test, TEST_DATABASE[TEST_DEFAULT]);
-
-        // database to use for testing collation, english territory.
-        test = TestConfiguration.additionalDatabaseDecorator(
-                    test, TEST_DATABASE[TEST_ENGLISH]);
-
-        // database to use for testing collation, polish territory.
-        test = TestConfiguration.additionalDatabaseDecorator(
-                    test, TEST_DATABASE[TEST_POLISH]);
-
-        // database to use for testing collation, norway territory.
-        test = TestConfiguration.additionalDatabaseDecorator(
-                    test, TEST_DATABASE[TEST_NORWAY]);
-
-        // database to use for testing collation, default jvm territory
-        test = TestConfiguration.additionalDatabaseDecorator(
-                    test, TEST_DATABASE[TEST_DEFAULT_TERRITORY]);
-
         return test;
+    }
+    
+    private static Test collatedTest(String locale, String fixture)
+    {
+        return Decorator.territoryCollatedDatabase(
+                new CollationTest2(fixture), locale);
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java?rev=609020&r1=609019&r2=609020&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java Fri Jan  4 13:47:49 2008
@@ -137,12 +137,17 @@
      * Decorate a set of tests to use an single
      * use database with TERRITORY_BASED collation
      * set to the passed in locale. Database is created
-     * on by the setUp method of the decorator.
+     * by the setUp method of the decorator.
+     * @param locale Locale used to set territory JDBC attribute. If null
+     * then only collation=TERRITORY_BASED will be set.
      */
     public static Test territoryCollatedDatabase(Test test, final String locale)
     {
         
-        String attributes = "collation=TERRITORY_BASED;territory=" + locale;
+        String attributes = "collation=TERRITORY_BASED";
+        
+        if (locale != null)
+            attributes = attributes.concat(";territory=" + locale);
         
         return attributesDatabase(attributes, test);
     }