openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r1159903 - in /openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence: identity/TestCompundIdWithNull.java test/SingleEMFTestCase.java
Date Sat, 20 Aug 2011 19:04:14 GMT
Author: mikedd
Date: Sat Aug 20 19:04:13 2011
New Revision: 1159903

URL: http://svn.apache.org/viewvc?rev=1159903&view=rev
Log:
Only run TestCompundIdWithNull on Derby / Oracle.

Modified:
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestCompundIdWithNull.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java

Modified: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestCompundIdWithNull.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestCompundIdWithNull.java?rev=1159903&r1=1159902&r2=1159903&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestCompundIdWithNull.java
(original)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestCompundIdWithNull.java
Sat Aug 20 19:04:13 2011
@@ -23,6 +23,8 @@ import java.util.List;
 
 import javax.persistence.EntityManager;
 
+import org.apache.openjpa.jdbc.sql.DerbyDictionary;
+import org.apache.openjpa.jdbc.sql.OracleDictionary;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
@@ -41,6 +43,12 @@ import org.apache.openjpa.persistence.te
 public class TestCompundIdWithNull extends SingleEMFTestCase {
     private static boolean tablesCreated = false;
 	public void setUp() throws Exception {
+        // Works on Derby, Oracle.
+        setSupportedDatabases(DerbyDictionary.class, OracleDictionary.class);
+        if (isTestsDisabled()) {
+            return;
+        }
+	    
 	    // do not use CLEAR_TABLES or DROP_TABLES
 	    super.setUp(SimpleCompoundIdTestEntity.class, ComplexCompoundIdTestEntity.class, TypeEntity.class);
 	    if (!tablesCreated) {

Modified: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java?rev=1159903&r1=1159902&r2=1159903&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
(original)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
Sat Aug 20 19:04:13 2011
@@ -18,7 +18,9 @@
  */
 package org.apache.openjpa.persistence.test;
 
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
 
@@ -37,6 +39,8 @@ public abstract class SingleEMFTestCase
     extends PersistenceTestCase {
 
     protected OpenJPAEntityManagerFactorySPI emf;
+    
+    protected Boolean testsDisabled = false;
 
     /**
      * Call {@link #setUp(Object...)} with no arguments so that the emf
@@ -129,4 +133,47 @@ public abstract class SingleEMFTestCase
         return emf.getConfiguration().getLog("Tests");
     }
     
+    protected void setSupportedDatabases(Class<?> ... dbs) {
+        OpenJPAEntityManagerFactorySPI tempEMF = emf;
+        if (tempEMF == null) {
+            tempEMF = createEMF();
+        }
+        DBDictionary dict = ((JDBCConfiguration)tempEMF.getConfiguration()).getDBDictionaryInstance();
+        boolean supportedDB = false;
+        for (Class<?> db : dbs) {
+            if (dict.getClass().getCanonicalName().equalsIgnoreCase(db.getCanonicalName()))
{
+                supportedDB = true;
+                break;
+            }
+        }
+        setTestsDisabled(!supportedDB);
+        if (emf == null) {
+            closeEMF(tempEMF);
+        }
+    }
+    
+    protected void setTestsDisabled(boolean disable) {
+        synchronized (testsDisabled) {
+            testsDisabled = new Boolean(disable);
+        }
+    }
+    
+    protected boolean isTestsDisabled() {
+        synchronized (testsDisabled) {
+            return testsDisabled;
+        }
+    }
+    
+    /**
+     * Override to run the test and assert its state.
+     * @exception Throwable if any exception is thrown
+     */
+    @Override
+    protected void runTest() throws Throwable {
+        if (isTestsDisabled()) {
+            return;
+        }
+        super.runTest();
+    }
+    
 }



Mime
View raw message