db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r552999 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/lang/CollationTest.java junit/Decorator.java
Date Tue, 03 Jul 2007 22:12:06 GMT
Author: djd
Date: Tue Jul  3 15:12:05 2007
New Revision: 552999

URL: http://svn.apache.org/viewvc?view=rev&rev=552999
Log:
Add a decorator that creates a database with terrority collation and switch CollationTest
to use that collator. This then makes CollationTest fit the normal pattern of single 
connection tests that get their JDBC objects from the utility methods.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.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/CollationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?view=diff&rev=552999&r1=552998&r2=552999
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Tue Jul  3 15:12:05 2007
@@ -31,10 +31,13 @@
 import javax.sql.DataSource;
 
 import junit.framework.Test;
+import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.XML;
 //import org.apache.derby.iapi.types.XML;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.Decorator;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.JDBCDataSource;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -88,14 +91,9 @@
    * @throws SQLException
    */
 public void testDefaultCollation() throws SQLException {
-      DataSource ds = JDBCDataSource.getDataSourceLogical("defaultdb");
-      JDBCDataSource.setBeanProperty(ds, "connectionAttributes", 
-                  "create=true");
 
-      
-      Connection conn = ds.getConnection();
-      conn.setAutoCommit(false);
-      Statement s = conn.createStatement();
+      getConnection().setAutoCommit(false);
+      Statement s = createStatement();
       PreparedStatement ps;
       ResultSet rs;
       
@@ -231,7 +229,7 @@
       //Since all schemas (ie user and system) have the same collation, the 
       //following test won't fail.
       s.executeUpdate("set schema APP");
-      ps = conn.prepareStatement("SELECT TABLENAME FROM SYS.SYSTABLES WHERE " +
+      ps = prepareStatement("SELECT TABLENAME FROM SYS.SYSTABLES WHERE " +
       		" ? = TABLENAME");
       ps.setString(1, "SYSCOLUMNS");
       rs = ps.executeQuery();
@@ -239,7 +237,7 @@
 
       //Since all schemas (ie user and system) have the same collation, the 
       //following test won't fail.
-      ps = conn.prepareStatement("SELECT TABLENAME FROM SYS.SYSTABLES WHERE " +
+      ps = prepareStatement("SELECT TABLENAME FROM SYS.SYSTABLES WHERE " +
 		" SUBSTR(?,2) = TABLENAME");
       ps.setString(1, " SYSCOLUMNS");
       rs = ps.executeQuery();
@@ -247,12 +245,12 @@
 
       //Since all schemas (ie user and system) have the same collation, the 
       //following test won't fail.
-      ps = conn.prepareStatement("SELECT TABLENAME FROM SYS.SYSTABLES WHERE " +
+      ps = prepareStatement("SELECT TABLENAME FROM SYS.SYSTABLES WHERE " +
 		" LTRIM(?) = TABLENAME");
       ps.setString(1, " SYSCOLUMNS");
       rs = ps.executeQuery();
       JDBC.assertFullResultSet(rs,new String[][] {{"SYSCOLUMNS"}});
-      ps = conn.prepareStatement("SELECT TABLENAME FROM SYS.SYSTABLES WHERE " +
+      ps = prepareStatement("SELECT TABLENAME FROM SYS.SYSTABLES WHERE " +
 		" RTRIM(?) = TABLENAME");
       ps.setString(1, "SYSCOLUMNS  ");
       rs = ps.executeQuery();
@@ -260,18 +258,14 @@
 
       //Since all schemas (ie user and system) have the same collation, the 
       //following test won't fail.
-      ps = conn.prepareStatement("SELECT COUNT(*) FROM CUSTOMER WHERE " + 
+      ps = prepareStatement("SELECT COUNT(*) FROM CUSTOMER WHERE " + 
       		" ? IN (SELECT TABLENAME FROM SYS.SYSTABLES)");
       ps.setString(1, "SYSCOLUMNS");
       rs = ps.executeQuery();
       JDBC.assertFullResultSet(rs,new String[][] {{"7"}});
       //End of parameter testing
       
-      conn.commit();
-
-      dropTable(s);
       s.close();
-      conn.close();
       }
       
   /**
@@ -279,16 +273,9 @@
    * @throws SQLException
    */
 public void testPolishCollation() throws SQLException {
-      DataSource ds = JDBCDataSource.getDataSourceLogical("poldb");
-      JDBCDataSource.setBeanProperty(ds, "connectionAttributes", 
-                  "create=true;territory=pl;collation=TERRITORY_BASED");
 
-      
-      Connection conn = ds.getConnection();
-      conn.setAutoCommit(false);
-      PreparedStatement ps;
-      ResultSet rs;
-      Statement s = conn.createStatement();
+      getConnection().setAutoCommit(false);
+      Statement s = createStatement();
       
       setUpTable(s);
 
@@ -341,11 +328,7 @@
       		new String[][] {{"aacorn"}});   
 
       commonTestingForTerritoryBasedDB(s);
-
-      conn.commit();
-      dropTable(s);
-      conn.close();
-      
+    
       }    
   
 
@@ -355,16 +338,10 @@
    * @throws SQLException
    */
 public void testNorwayCollation() throws SQLException {
-      DataSource ds = JDBCDataSource.getDataSourceLogical("nordb");
-      JDBCDataSource.setBeanProperty(ds, "connectionAttributes", 
-                  "create=true;territory=no;collation=TERRITORY_BASED");
 
-      
-      Connection conn = ds.getConnection();
-      conn.setAutoCommit(false);
-      Statement s = conn.createStatement();
-      PreparedStatement ps;
-      ResultSet rs;
+      getConnection().setAutoCommit(false);
+      Statement s = createStatement();
+
       setUpTable(s);
 
       //The collation should be TERRITORY_BASED for this database
@@ -414,11 +391,8 @@
 
       commonTestingForTerritoryBasedDB(s);
 
-      conn.commit();
-
-      dropTable(s);
       s.close();
-      conn.close();
+
       }
   
 
@@ -428,15 +402,9 @@
   * @throws SQLException
   */
 public void testEnglishCollation() throws SQLException {
-      DataSource ds = JDBCDataSource.getDataSourceLogical("endb");
-      JDBCDataSource.setBeanProperty(ds, "connectionAttributes", 
-                  "create=true;territory=en;collation=TERRITORY_BASED");
-      
-      Connection conn = ds.getConnection();
-      conn.setAutoCommit(false);
-      Statement s = conn.createStatement();
-      PreparedStatement ps;
-      ResultSet rs;
+
+      getConnection().setAutoCommit(false);
+      Statement s = createStatement();
       setUpTable(s);
 
       //The collation should be TERRITORY_BASED for this database
@@ -489,11 +457,7 @@
 
       commonTestingForTerritoryBasedDB(s);
 
-      conn.commit();
-      
-      dropTable(s);
       s.close();
-      conn.close();
       }
 
 private void commonTestingForTerritoryBasedDB(Statement s) throws SQLException{
@@ -995,13 +959,30 @@
    * is a server side operation.
    */
   public static Test suite() {
+      
+      TestSuite suite = new TestSuite("CollationTest");
 
-        Test test =  TestConfiguration.embeddedSuite(CollationTest.class);
-        test = TestConfiguration.additionalDatabaseDecorator(test, "defaultdb");
-        test = TestConfiguration.additionalDatabaseDecorator(test, "endb");
-        test = TestConfiguration.additionalDatabaseDecorator(test, "nordb");
-        test = TestConfiguration.additionalDatabaseDecorator(test, "poldb");
-        return test;
+        suite.addTest(new CleanDatabaseTestSetup(
+                new CollationTest("testDefaultCollation")));
+        suite.addTest(collatedSuite("en", "testEnglishCollation"));
+        suite.addTest(collatedSuite("no", "testNorwayCollation"));
+        suite.addTest(collatedSuite("pl", "testPolishCollation"));
+        return suite;
     }
+  
+  /**
+   * Return a suite that uses a single use database with
+   * a primary fixture from this test plus potentially other
+   * fixtures.
+   * @param locale Locale to use for the database
+   * @param baseFixture Base fixture from this test.
+   * @return
+   */
+  private static Test collatedSuite(String locale, String baseFixture)
+  {
+      TestSuite suite = new TestSuite("CollationTest:territory="+locale);
+      suite.addTest(new CollationTest(baseFixture));
+      return Decorator.territoryCollatedDatabase(suite, 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?view=diff&rev=552999&r1=552998&r2=552999
==============================================================================
--- 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 Tue Jul
 3 15:12:05 2007
@@ -108,29 +108,14 @@
      */
     public static Test encryptedDatabase(Test test, final String algorithm)
     {
-        test = new BaseTestSetup(test) {
-            
-            /**
-             * Create an encrypted database using a
-             * JDBC data source.
-             */
-            protected void setUp() throws SQLException
-            {
-                String bootPhrase = getBootPhrase(64);
-                DataSource ds = JDBCDataSource.getDataSource();
-                        
-                JDBCDataSource.setBeanProperty(ds,
-                        "createDatabase", "create");
-                JDBCDataSource.setBeanProperty(ds,
-                        "connectionAttributes",
-                        "dataEncryption=true;bootPassword=" + bootPhrase +
-                        ";encryptionAlgorithm=" + algorithm);
-                
-                ds.getConnection().close();
-            }
-        };
+        String bootPhrase = getBootPhrase(64);
+        
+        String attributes =
+            "dataEncryption=true;bootPassword=" + bootPhrase +
+             ";encryptionAlgorithm=" + algorithm;
+
+        return attributesDatabase(attributes, test);
         
-        return TestConfiguration.singleUseDatabaseDecorator(test);
     }
     
     private static String getBootPhrase(int length)
@@ -147,5 +132,56 @@
         }
         
         return new String(bp);
+    }
+    
+    /**
+     * 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.
+     */
+    public static Test territoryCollatedDatabase(Test test, final String locale)
+    {
+        
+        String attributes = "collation=TERRITORY_BASED;territory=" + locale;
+        
+        return attributesDatabase(attributes, test);
+    }
+    
+    /**
+     * Decorate a test (or suite of tests) to use a single use database
+     * as the default database. The database is created by the setUp
+     * method of the decorator. The database will be created using
+     * a JDBC data source with createDatabase set to create and
+     * connectionAttributes set to the passed in attributes.
+     * 
+     * 
+     * @param attributes Value to set connectionAttributes to when creating
+     * the database.
+     * @param test Test to decorate
+     * @return Decorated test
+     */
+    private static Test attributesDatabase(final String attributes, Test test)
+    {
+        test = new BaseTestSetup(test) {
+            
+            /**
+             * Create a  database
+             * using a JDBC data source with connectionAttributes set.
+             */
+            protected void setUp() throws SQLException
+            {
+                DataSource ds = JDBCDataSource.getDataSource();
+                               
+                JDBCDataSource.setBeanProperty(ds,
+                        "createDatabase", "create");
+                JDBCDataSource.setBeanProperty(ds,
+                        "connectionAttributes", attributes);
+                                
+                ds.getConnection().close();
+            }
+        };
+        
+        return TestConfiguration.singleUseDatabaseDecorator(test);
     }
 }



Mime
View raw message