mirror of https://github.com/apache/openjpa.git
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:
parent
a543403d2a
commit
5113654485
|
@ -244,12 +244,4 @@ public class TestValidatingLEM extends SingleEMFTestCase {
|
|||
closeEMF(emf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal convenience method for getting the OpenJPA logger
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Log getLog() {
|
||||
return emf.getConfiguration().getLog("Tests");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,12 +39,11 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
|||
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 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
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 class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
}
|
||||
|
||||
public void testGeneratedAUTO() {
|
||||
if (skipTests)
|
||||
return;
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
|
||||
em.getTransaction().begin();
|
||||
|
@ -243,9 +237,6 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
}
|
||||
|
||||
public void testGeneratedTABLE() {
|
||||
if (skipTests)
|
||||
return;
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
|
||||
em.getTransaction().begin();
|
||||
|
@ -391,9 +382,6 @@ public class TestMultipleSchemaNames extends SingleEMFTestCase {
|
|||
}
|
||||
|
||||
public void testGeneratedIDENTITY() {
|
||||
if (skipTests)
|
||||
return;
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
|
||||
|
||||
|
|
|
@ -133,6 +133,7 @@ public class TestQueryTimeout extends SQLListenerTestCase {
|
|||
} 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 @@ public class TestQueryTimeout extends SQLListenerTestCase {
|
|||
getLog().info("TestQueryTimeout tests are being skipped, " +
|
||||
"due to " + dict.platform + " not supporting Query Timeouts.");
|
||||
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
|
||||
* the expected type for a given DB platform.
|
||||
|
|
|
@ -54,6 +54,7 @@ public abstract class AbstractPersistenceTestCase extends TestCase {
|
|||
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 @@ 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
|
||||
* 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 {
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
protected void setTestsDisabled(boolean disable) {
|
||||
synchronized (testsDisabled) {
|
||||
testsDisabled = new Boolean(disable);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isTestsDisabled() {
|
||||
synchronized (testsDisabled) {
|
||||
return testsDisabled.booleanValue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,8 +22,12 @@ import java.util.List;
|
|||
|
||||
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 @@ public abstract class SingleEMFTestCase
|
|||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -256,12 +256,4 @@ public class TestValidationMode extends SingleEMFTestCase {
|
|||
closeEMF(emf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal convenience method for getting the OpenJPA logger
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Log getLog() {
|
||||
return emf.getConfiguration().getLog("Tests");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import junit.textui.TestRunner;
|
|||
|
||||
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 @@ import org.apache.openjpa.persistence.xmlmapping.xmlbindings.myaddress.USAAddres
|
|||
*/
|
||||
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 @@ public class TestXMLCustomerOrder
|
|||
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 @@ public class TestXMLCustomerOrder
|
|||
|
||||
@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 @@ public class TestXMLCustomerOrder
|
|||
|
||||
@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 @@ public class TestXMLCustomerOrder
|
|||
|
||||
@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 @@ public class TestXMLCustomerOrder
|
|||
|
||||
@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 @@ public class TestXMLCustomerOrder
|
|||
|
||||
@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 @@ public class TestXMLCustomerOrder
|
|||
|
||||
@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 @@ public class TestXMLCustomerOrder
|
|||
|
||||
@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 class TestXMLCustomerOrder
|
|||
}
|
||||
|
||||
public void testUpdate() {
|
||||
if (skipTests) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
|
@ -273,10 +230,6 @@ public class TestXMLCustomerOrder
|
|||
}
|
||||
|
||||
public void testNullify() {
|
||||
if (skipTests) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
|
@ -298,10 +251,6 @@ public class TestXMLCustomerOrder
|
|||
}
|
||||
|
||||
public void testXMLStringToConstantIntComparison() {
|
||||
if (skipTests) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
try {
|
||||
em.createQuery(
|
||||
|
@ -316,10 +265,6 @@ public class TestXMLCustomerOrder
|
|||
}
|
||||
|
||||
public void testXMLListToConstantStringComparison() {
|
||||
if (skipTests) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
try {
|
||||
em.createQuery(
|
||||
|
@ -334,10 +279,6 @@ public class TestXMLCustomerOrder
|
|||
}
|
||||
|
||||
public void testSubclassPropertyInXMLFieldComparison() {
|
||||
if (skipTests) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
try {
|
||||
em.createQuery(
|
||||
|
|
Loading…
Reference in New Issue