openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r813506 - in /openjpa/trunk: openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/p...
Date Thu, 10 Sep 2009 16:40:43 GMT
Author: dwoods
Date: Thu Sep 10 16:40:37 2009
New Revision: 813506

URL: http://svn.apache.org/viewvc?rev=813506&view=rev
Log:
add common setTestsDisabled()/isTestsDisabled() in AbstractPersistenceTestCase which is used
by runTest() to automatically skip all tests.  added new setSupportedDatabases()/setUnsupportedDatabases()
methods in SingleEMFTestCase to set the testsDisabled flag in AbstractPTC, along with moving
a getLog() method from some testcases into the base SingleEMFTC class for everyone to use.

Modified:
    openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestValidatingLEM.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestQueryProperties.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryTimeout.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationMode.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/query/TestXMLCustomerOrder.java

Modified: openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestValidatingLEM.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestValidatingLEM.java?rev=813506&r1=813505&r2=813506&view=diff
==============================================================================
--- openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestValidatingLEM.java
(original)
+++ openjpa/trunk/openjpa-integration/validation/src/test/java/org/apache/openjpa/integration/validation/TestValidatingLEM.java
Thu Sep 10 16:40:37 2009
@@ -244,12 +244,4 @@
         closeEMF(emf);
     }    
 
-    /**
-     * Internal convenience method for getting the OpenJPA logger
-     * 
-     * @return
-     */
-    private Log getLog() {
-        return emf.getConfiguration().getLog("Tests");
-    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestQueryProperties.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestQueryProperties.java?rev=813506&r1=813505&r2=813506&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestQueryProperties.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestQueryProperties.java
Thu Sep 10 16:40:37 2009
@@ -311,12 +311,4 @@
         }
     }
     
-    /**
-     * Internal convenience method for getting the OpenJPA logger
-     * 
-     * @return
-     */
-    private Log getLog() {
-        return emf.getConfiguration().getLog("Tests");
-    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java?rev=813506&r1=813505&r2=813506&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
Thu Sep 10 16:40:37 2009
@@ -2807,12 +2807,4 @@
         }
     }
     
-    /**
-     * Internal convenience method for getting the OpenJPA logger
-     * 
-     * @return
-     */
-    private Log getLog() {
-        return emf.getConfiguration().getLog("Tests");
-    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java?rev=813506&r1=813505&r2=813506&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestMultipleSchemaNames.java
Thu Sep 10 16:40:37 2009
@@ -39,12 +39,11 @@
 public class TestMultipleSchemaNames extends SingleEMFTestCase {
 
     static private DBDictionary dict = null;
-    static private Boolean skipTests = null;
     
     public void setUp() {
         // Need to skip tests on MySQL, Oracle and MS SQL Server
         // See createSchemas() comment at the bottom
-        if ((dict == null) || (skipTests == null)) {
+        if (dict == null) {
             OpenJPAEntityManagerFactorySPI emf = createEMF();
             OpenJPAEntityManagerSPI em = emf.createEntityManager();
             JDBCConfiguration conf = (JDBCConfiguration) em.getConfiguration();
@@ -53,17 +52,15 @@
             if ((dict instanceof MySQLDictionary) ||
                     (dict instanceof OracleDictionary) ||
                     (dict instanceof SQLServerDictionary)) {
-                skipTests = Boolean.TRUE;
+                setTestsDisabled(true);
                 // do some logging
                 emf.getConfiguration().getLog("Tests").trace(
                     "TestMultipleSchemaNames() - Skipping all tests - Not supported on this
DB");
-            } else {
-                skipTests = Boolean.FALSE;
-            }            
+            }
             closeEMF(emf);
         }
         
-        if (skipTests) {
+        if (isTestsDisabled()) {
             return;
         }
 
@@ -163,9 +160,6 @@
     }
 
     public void testGeneratedAUTO() {
-        if (skipTests)
-            return;
-
         EntityManager em = emf.createEntityManager();
         OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
         em.getTransaction().begin();
@@ -243,9 +237,6 @@
     }
 
     public void testGeneratedTABLE() {
-        if (skipTests)
-            return;
-
         EntityManager em = emf.createEntityManager();
         OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
         em.getTransaction().begin();
@@ -391,9 +382,6 @@
     }
     
     public void testGeneratedIDENTITY() {
-        if (skipTests)
-            return;
-
         EntityManager em = emf.createEntityManager();
         OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryTimeout.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryTimeout.java?rev=813506&r1=813505&r2=813506&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryTimeout.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryTimeout.java
Thu Sep 10 16:40:37 2009
@@ -133,6 +133,7 @@
             } else {
                 // unknown db, so skip all timeout tests
                 skipTests = skipExceptionTests = noSelectTimeouts = true;
+                setTestsDisabled(true);
                 getLog().info("TestQueryTimeout tests are being skipped, due " +
                     "to " + dict.platform + " not supporting Query Timeouts.");
             }
@@ -140,6 +141,7 @@
             getLog().info("TestQueryTimeout tests are being skipped, " +
                 "due to " + dict.platform + " not supporting Query Timeouts.");
             skipTests = skipExceptionTests = true;
+            setTestsDisabled(true);
         }
     }
 
@@ -1043,15 +1045,6 @@
     }
 
     /**
-     * Internal convenience method for getting the OpenJPA logger
-     * 
-     * @return
-     */
-    private Log getLog() {
-        return emf.getConfiguration().getLog("Tests");
-    }
-
-    /**
      * Internal convenience method for checking that the given Exception matches
      * the expected type for a given DB platform.
      * 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java?rev=813506&r1=813505&r2=813506&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java
Thu Sep 10 16:40:37 2009
@@ -54,6 +54,7 @@
     public static final String RETAIN_DATA = "Retain data after test run";
     private boolean retainDataOnTearDown;
     protected boolean _fresh = false;
+    private Boolean testsDisabled = Boolean.FALSE;
 
     public static final String ALLOW_FAILURE_LOG = "log";
     public static final String ALLOW_FAILURE_IGNORE = "ignore";
@@ -463,8 +464,10 @@
     }
 
     /**
-     * Overrides to allow tests annotated with @AllowFailure to fail. If the test is in error
then the normal pathway is
-     * executed.
+     * Overrides to allow tests annotated with @AllowFailure to fail.
+     * If @DatabasePlatform value matches the current JDBC driver or
+     * tests have been disabled, then the test will not be run.
+     * If the test is in error then the normal pathway is executed.
      */
     @Override
     public void runBare() throws Throwable {
@@ -500,6 +503,18 @@
     }
 
     /**
+     * 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();
+    }
+    
+    /**
      * Affirms if the test case or the test method is annotated with
      * 
      * @AllowFailure. Method level annotation has higher precedence than Class level annotation.
@@ -587,4 +602,17 @@
             assertFalse(String.format("Expected %s:%s not to exist in cache", clss, id),
cache.contains(clss, id));
         }
     }
+    
+    protected void setTestsDisabled(boolean disable) {
+        synchronized (testsDisabled) {
+            testsDisabled = new Boolean(disable);
+        }
+    }
+    
+    protected boolean isTestsDisabled() {
+        synchronized (testsDisabled) {
+            return testsDisabled.booleanValue();
+        }
+    }
+
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java?rev=813506&r1=813505&r2=813506&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
Thu Sep 10 16:40:37 2009
@@ -22,8 +22,12 @@
 
 import javax.persistence.EntityManager;
 
+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;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
 
 /**
  * Base class for OpenJPA-specific Test Case.
@@ -156,4 +160,52 @@
     protected ClassMapping [] getMappings() {
         return (ClassMapping [] ) emf.getConfiguration().getMetaDataRepositoryInstance().getMetaDatas();
  
     }
+    
+    protected void setUnsupportedDatabases(Class<?> ... dbs) {
+        OpenJPAEntityManagerFactorySPI tempEMF = emf;
+        if (tempEMF == null) {
+            tempEMF = createEMF();
+        }
+        OpenJPAEntityManagerSPI em = tempEMF.createEntityManager();
+        JDBCConfiguration conf = (JDBCConfiguration) em.getConfiguration();
+        DBDictionary dict = conf.getDBDictionaryInstance();
+        for (Class<?> db : dbs) {
+            if (dict.getClass().getCanonicalName().equalsIgnoreCase(db.getCanonicalName()))
{
+                setTestsDisabled(true);
+                break;
+            }
+        }
+        if (emf == null) {
+            closeEMF(tempEMF);
+        } else {
+            em.close();
+        }
+    }
+    
+    protected void setSupportedDatabases(Class<?> ... dbs) {
+        OpenJPAEntityManagerFactorySPI tempEMF = emf;
+        if (tempEMF == null) {
+            tempEMF = createEMF();
+        }
+        OpenJPAEntityManagerSPI em = tempEMF.createEntityManager();
+        JDBCConfiguration conf = (JDBCConfiguration) em.getConfiguration();
+        DBDictionary dict = conf.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);
+        } else {
+            em.close();
+        }
+    }
+    
+    protected Log getLog() {
+        return emf.getConfiguration().getLog("Tests");
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java?rev=813506&r1=813505&r2=813506&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java
Thu Sep 10 16:40:37 2009
@@ -161,13 +161,4 @@
         }
     }
 
-
-    /**
-     * Internal convenience method for getting the OpenJPA logger
-     * 
-     * @return
-     */
-    private Log getLog() {
-        return emf.getConfiguration().getLog("Tests");
-    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationMode.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationMode.java?rev=813506&r1=813505&r2=813506&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationMode.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationMode.java
Thu Sep 10 16:40:37 2009
@@ -256,12 +256,4 @@
         closeEMF(emf);
     }    
 
-    /**
-     * Internal convenience method for getting the OpenJPA logger
-     * 
-     * @return
-     */
-    private Log getLog() {
-        return emf.getConfiguration().getLog("Tests");
-    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/query/TestXMLCustomerOrder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/query/TestXMLCustomerOrder.java?rev=813506&r1=813505&r2=813506&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/query/TestXMLCustomerOrder.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/query/TestXMLCustomerOrder.java
Thu Sep 10 16:40:37 2009
@@ -28,6 +28,7 @@
 
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
@@ -51,8 +52,6 @@
  */
 public class TestXMLCustomerOrder
     extends SingleEMFTestCase {
-
-    private static Boolean skipTests = null;
     
     private static final int ORDER_1_OID = 10;
     private static final double ORDER_1_AMOUNT = 850;
@@ -63,26 +62,16 @@
     private static final boolean ORDER_2_DELIVERED = false;
 
     public void setUp() {
-        // skip test if dictionary has no support for XML column type
-        if (skipTests == null) {
-            if (!dictionarySupportsXMLColumn()) {
-                skipTests = Boolean.TRUE;
-                // do some logging
-                OpenJPAEntityManagerFactorySPI emf = createEMF();
-                emf.getConfiguration().getLog("Tests").trace(
-                    "TestXMLCustomerOrder() - Skipping all tests - No XML Column support");
-                closeEMF(emf);
-            } else {
-                skipTests = Boolean.FALSE;
-            }
-        }
+        setUp(Customer.class, Customer.CustomerKey.class, Order.class,
+            EAddress.class, CLEAR_TABLES);
 
-        if (skipTests) {
+        // skip test if dictionary has no support for XML column type
+        setTestsDisabled(!dictionarySupportsXMLColumn());
+        if (isTestsDisabled()) {
+            getLog().trace("TestXMLCustomerOrder() - Skipping all tests - No XML Column support");
             return;
         }
         
-        setUp(Customer.class, Customer.CustomerKey.class, Order.class,
-            EAddress.class, CLEAR_TABLES);
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
         persistEntities(em);
@@ -92,10 +81,6 @@
 
     @SuppressWarnings("unchecked")
     public void testXMLFieldProjection() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         List<Address> addrs = em.createQuery(
             "select o.shipAddress from Order o order by o.oid")
@@ -116,10 +101,6 @@
     
     @SuppressWarnings("unchecked")
     public void testXMLFieldInEntity() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         List<Order> orders = em.createQuery(
             "select o from Order o order by o.oid")
@@ -142,10 +123,6 @@
 
     @SuppressWarnings("unchecked")
     public void testXMLStringToXMLStringComparison() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         List<Object[]> orders = em.createQuery(
             "select o, o2 from Order o, Order o2 where o.shipAddress.city " +
@@ -171,10 +148,6 @@
 
     @SuppressWarnings("unchecked")
     public void testXMLStringToEmbeddedStringComparison() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         List<Order> orders = em.createQuery(
             "select o from Order o, Customer c where o.shipAddress.city " +
@@ -190,10 +163,6 @@
 
     @SuppressWarnings("unchecked")
     public void testXMLStringToConstantStringComparison() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         List<Order> orders = em.createQuery(
             "select o from Order o where o.shipAddress.city = 'San Jose'")
@@ -208,10 +177,6 @@
 
     @SuppressWarnings("unchecked")
     public void testXMLStringToParameterStringComparison() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         Query query = em.createQuery(
             "select o from Order o where o.shipAddress.city = :city");
@@ -227,10 +192,6 @@
 
     @SuppressWarnings("unchecked")
     public void testParameterStringToXMLStringComparison() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         Query query = em.createQuery(
             "select o from Order o where :city = o.shipAddress.city");
@@ -245,10 +206,6 @@
     }
 
     public void testUpdate() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
 
@@ -273,10 +230,6 @@
     }
 
     public void testNullify() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
 
@@ -298,10 +251,6 @@
     }
 
     public void testXMLStringToConstantIntComparison() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         try {
             em.createQuery(
@@ -316,10 +265,6 @@
     }
 
     public void testXMLListToConstantStringComparison() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         try {
             em.createQuery(
@@ -334,10 +279,6 @@
     }
 
     public void testSubclassPropertyInXMLFieldComparison() {
-        if (skipTests) {
-            return;
-        }
-        
         EntityManager em = emf.createEntityManager();
         try {
             em.createQuery(



Mime
View raw message