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.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@813506 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald Woods 2009-09-10 16:40:37 +00:00
parent a543403d2a
commit 5113654485
10 changed files with 95 additions and 134 deletions

View File

@ -244,12 +244,4 @@ public class TestValidatingLEM extends SingleEMFTestCase {
closeEMF(emf); closeEMF(emf);
} }
/**
* Internal convenience method for getting the OpenJPA logger
*
* @return
*/
private Log getLog() {
return emf.getConfiguration().getLog("Tests");
}
} }

View File

@ -311,12 +311,4 @@ public class TestQueryProperties extends SingleEMFTestCase {
} }
} }
/**
* Internal convenience method for getting the OpenJPA logger
*
* @return
*/
private Log getLog() {
return emf.getConfiguration().getLog("Tests");
}
} }

View File

@ -2807,12 +2807,4 @@ public class TestEmbeddable extends SQLListenerTestCase {
} }
} }
/**
* Internal convenience method for getting the OpenJPA logger
*
* @return
*/
private Log getLog() {
return emf.getConfiguration().getLog("Tests");
}
} }

View File

@ -39,12 +39,11 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
public class TestMultipleSchemaNames extends SingleEMFTestCase { public class TestMultipleSchemaNames extends SingleEMFTestCase {
static private DBDictionary dict = null; static private DBDictionary dict = null;
static private Boolean skipTests = null;
public void setUp() { public void setUp() {
// Need to skip tests on MySQL, Oracle and MS SQL Server // Need to skip tests on MySQL, Oracle and MS SQL Server
// See createSchemas() comment at the bottom // See createSchemas() comment at the bottom
if ((dict == null) || (skipTests == null)) { if (dict == null) {
OpenJPAEntityManagerFactorySPI emf = createEMF(); OpenJPAEntityManagerFactorySPI emf = createEMF();
OpenJPAEntityManagerSPI em = emf.createEntityManager(); OpenJPAEntityManagerSPI em = emf.createEntityManager();
JDBCConfiguration conf = (JDBCConfiguration) em.getConfiguration(); JDBCConfiguration conf = (JDBCConfiguration) em.getConfiguration();
@ -53,17 +52,15 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
if ((dict instanceof MySQLDictionary) || if ((dict instanceof MySQLDictionary) ||
(dict instanceof OracleDictionary) || (dict instanceof OracleDictionary) ||
(dict instanceof SQLServerDictionary)) { (dict instanceof SQLServerDictionary)) {
skipTests = Boolean.TRUE; setTestsDisabled(true);
// do some logging // do some logging
emf.getConfiguration().getLog("Tests").trace( emf.getConfiguration().getLog("Tests").trace(
"TestMultipleSchemaNames() - Skipping all tests - Not supported on this DB"); "TestMultipleSchemaNames() - Skipping all tests - Not supported on this DB");
} else { }
skipTests = Boolean.FALSE;
}
closeEMF(emf); closeEMF(emf);
} }
if (skipTests) { if (isTestsDisabled()) {
return; return;
} }
@ -163,9 +160,6 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
} }
public void testGeneratedAUTO() { public void testGeneratedAUTO() {
if (skipTests)
return;
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
OpenJPAEntityManager kem = OpenJPAPersistence.cast(em); OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
em.getTransaction().begin(); em.getTransaction().begin();
@ -243,9 +237,6 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
} }
public void testGeneratedTABLE() { public void testGeneratedTABLE() {
if (skipTests)
return;
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
OpenJPAEntityManager kem = OpenJPAPersistence.cast(em); OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
em.getTransaction().begin(); em.getTransaction().begin();
@ -391,9 +382,6 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
} }
public void testGeneratedIDENTITY() { public void testGeneratedIDENTITY() {
if (skipTests)
return;
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
OpenJPAEntityManager kem = OpenJPAPersistence.cast(em); OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);

View File

@ -133,6 +133,7 @@ public class TestQueryTimeout extends SQLListenerTestCase {
} else { } else {
// unknown db, so skip all timeout tests // unknown db, so skip all timeout tests
skipTests = skipExceptionTests = noSelectTimeouts = true; skipTests = skipExceptionTests = noSelectTimeouts = true;
setTestsDisabled(true);
getLog().info("TestQueryTimeout tests are being skipped, due " + getLog().info("TestQueryTimeout tests are being skipped, due " +
"to " + dict.platform + " not supporting Query Timeouts."); "to " + dict.platform + " not supporting Query Timeouts.");
} }
@ -140,6 +141,7 @@ public class TestQueryTimeout extends SQLListenerTestCase {
getLog().info("TestQueryTimeout tests are being skipped, " + getLog().info("TestQueryTimeout tests are being skipped, " +
"due to " + dict.platform + " not supporting Query Timeouts."); "due to " + dict.platform + " not supporting Query Timeouts.");
skipTests = skipExceptionTests = true; skipTests = skipExceptionTests = true;
setTestsDisabled(true);
} }
} }
@ -1042,15 +1044,6 @@ public class TestQueryTimeout extends SQLListenerTestCase {
} }
} }
/**
* 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 * Internal convenience method for checking that the given Exception matches
* the expected type for a given DB platform. * the expected type for a given DB platform.

View File

@ -54,6 +54,7 @@ public abstract class AbstractPersistenceTestCase extends TestCase {
public static final String RETAIN_DATA = "Retain data after test run"; public static final String RETAIN_DATA = "Retain data after test run";
private boolean retainDataOnTearDown; private boolean retainDataOnTearDown;
protected boolean _fresh = false; protected boolean _fresh = false;
private Boolean testsDisabled = Boolean.FALSE;
public static final String ALLOW_FAILURE_LOG = "log"; public static final String ALLOW_FAILURE_LOG = "log";
public static final String ALLOW_FAILURE_IGNORE = "ignore"; public static final String ALLOW_FAILURE_IGNORE = "ignore";
@ -463,8 +464,10 @@ public abstract class AbstractPersistenceTestCase extends TestCase {
} }
/** /**
* Overrides to allow tests annotated with @AllowFailure to fail. If the test is in error then the normal pathway is * Overrides to allow tests annotated with @AllowFailure to fail.
* executed. * 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 @Override
public void runBare() throws Throwable { public void runBare() throws Throwable {
@ -499,6 +502,18 @@ public abstract class AbstractPersistenceTestCase extends TestCase {
} }
} }
/**
* 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 * Affirms if the test case or the test method is annotated with
* *
@ -587,4 +602,17 @@ public abstract class AbstractPersistenceTestCase extends TestCase {
assertFalse(String.format("Expected %s:%s not to exist in cache", clss, id), cache.contains(clss, id)); 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();
}
}
} }

View File

@ -22,8 +22,12 @@ import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.meta.ClassMapping; 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.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
/** /**
* Base class for OpenJPA-specific Test Case. * Base class for OpenJPA-specific Test Case.
@ -156,4 +160,52 @@ public abstract class SingleEMFTestCase
protected ClassMapping [] getMappings() { protected ClassMapping [] getMappings() {
return (ClassMapping [] ) emf.getConfiguration().getMetaDataRepositoryInstance().getMetaDatas(); 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");
}
} }

View File

@ -161,13 +161,4 @@ public class TestValidationFactory extends SingleEMFTestCase {
} }
} }
/**
* Internal convenience method for getting the OpenJPA logger
*
* @return
*/
private Log getLog() {
return emf.getConfiguration().getLog("Tests");
}
} }

View File

@ -256,12 +256,4 @@ public class TestValidationMode extends SingleEMFTestCase {
closeEMF(emf); closeEMF(emf);
} }
/**
* Internal convenience method for getting the OpenJPA logger
*
* @return
*/
private Log getLog() {
return emf.getConfiguration().getLog("Tests");
}
} }

View File

@ -28,6 +28,7 @@ import junit.textui.TestRunner;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.sql.DBDictionary; 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.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI; import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
import org.apache.openjpa.persistence.test.SingleEMFTestCase; import org.apache.openjpa.persistence.test.SingleEMFTestCase;
@ -51,8 +52,6 @@ import org.apache.openjpa.persistence.xmlmapping.xmlbindings.myaddress.USAAddres
*/ */
public class TestXMLCustomerOrder public class TestXMLCustomerOrder
extends SingleEMFTestCase { extends SingleEMFTestCase {
private static Boolean skipTests = null;
private static final int ORDER_1_OID = 10; private static final int ORDER_1_OID = 10;
private static final double ORDER_1_AMOUNT = 850; private static final double ORDER_1_AMOUNT = 850;
@ -63,26 +62,16 @@ public class TestXMLCustomerOrder
private static final boolean ORDER_2_DELIVERED = false; private static final boolean ORDER_2_DELIVERED = false;
public void setUp() { public void setUp() {
// skip test if dictionary has no support for XML column type setUp(Customer.class, Customer.CustomerKey.class, Order.class,
if (skipTests == null) { EAddress.class, CLEAR_TABLES);
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;
}
}
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; return;
} }
setUp(Customer.class, Customer.CustomerKey.class, Order.class,
EAddress.class, CLEAR_TABLES);
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
em.getTransaction().begin(); em.getTransaction().begin();
persistEntities(em); persistEntities(em);
@ -92,10 +81,6 @@ public class TestXMLCustomerOrder
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testXMLFieldProjection() { public void testXMLFieldProjection() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
List<Address> addrs = em.createQuery( List<Address> addrs = em.createQuery(
"select o.shipAddress from Order o order by o.oid") "select o.shipAddress from Order o order by o.oid")
@ -116,10 +101,6 @@ public class TestXMLCustomerOrder
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testXMLFieldInEntity() { public void testXMLFieldInEntity() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
List<Order> orders = em.createQuery( List<Order> orders = em.createQuery(
"select o from Order o order by o.oid") "select o from Order o order by o.oid")
@ -142,10 +123,6 @@ public class TestXMLCustomerOrder
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testXMLStringToXMLStringComparison() { public void testXMLStringToXMLStringComparison() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
List<Object[]> orders = em.createQuery( List<Object[]> orders = em.createQuery(
"select o, o2 from Order o, Order o2 where o.shipAddress.city " + "select o, o2 from Order o, Order o2 where o.shipAddress.city " +
@ -171,10 +148,6 @@ public class TestXMLCustomerOrder
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testXMLStringToEmbeddedStringComparison() { public void testXMLStringToEmbeddedStringComparison() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
List<Order> orders = em.createQuery( List<Order> orders = em.createQuery(
"select o from Order o, Customer c where o.shipAddress.city " + "select o from Order o, Customer c where o.shipAddress.city " +
@ -190,10 +163,6 @@ public class TestXMLCustomerOrder
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testXMLStringToConstantStringComparison() { public void testXMLStringToConstantStringComparison() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
List<Order> orders = em.createQuery( List<Order> orders = em.createQuery(
"select o from Order o where o.shipAddress.city = 'San Jose'") "select o from Order o where o.shipAddress.city = 'San Jose'")
@ -208,10 +177,6 @@ public class TestXMLCustomerOrder
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testXMLStringToParameterStringComparison() { public void testXMLStringToParameterStringComparison() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
Query query = em.createQuery( Query query = em.createQuery(
"select o from Order o where o.shipAddress.city = :city"); "select o from Order o where o.shipAddress.city = :city");
@ -227,10 +192,6 @@ public class TestXMLCustomerOrder
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testParameterStringToXMLStringComparison() { public void testParameterStringToXMLStringComparison() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
Query query = em.createQuery( Query query = em.createQuery(
"select o from Order o where :city = o.shipAddress.city"); "select o from Order o where :city = o.shipAddress.city");
@ -245,10 +206,6 @@ public class TestXMLCustomerOrder
} }
public void testUpdate() { public void testUpdate() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
em.getTransaction().begin(); em.getTransaction().begin();
@ -273,10 +230,6 @@ public class TestXMLCustomerOrder
} }
public void testNullify() { public void testNullify() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
em.getTransaction().begin(); em.getTransaction().begin();
@ -298,10 +251,6 @@ public class TestXMLCustomerOrder
} }
public void testXMLStringToConstantIntComparison() { public void testXMLStringToConstantIntComparison() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
try { try {
em.createQuery( em.createQuery(
@ -316,10 +265,6 @@ public class TestXMLCustomerOrder
} }
public void testXMLListToConstantStringComparison() { public void testXMLListToConstantStringComparison() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
try { try {
em.createQuery( em.createQuery(
@ -334,10 +279,6 @@ public class TestXMLCustomerOrder
} }
public void testSubclassPropertyInXMLFieldComparison() { public void testSubclassPropertyInXMLFieldComparison() {
if (skipTests) {
return;
}
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
try { try {
em.createQuery( em.createQuery(