mirror of https://github.com/apache/openjpa.git
OPENJPA-1764 test can only be run against Derby, due to openjpa.ConnectionUserName being used as a schema name
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1021525 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a99e618f5a
commit
7f332d9cf8
|
@ -27,32 +27,43 @@ import javax.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.RollbackException;
|
import javax.persistence.RollbackException;
|
||||||
|
|
||||||
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
||||||
|
import org.apache.openjpa.jdbc.sql.DB2Dictionary;
|
||||||
import org.apache.openjpa.jdbc.sql.DBDictionary;
|
import org.apache.openjpa.jdbc.sql.DBDictionary;
|
||||||
import org.apache.openjpa.jdbc.sql.DerbyDictionary;
|
import org.apache.openjpa.jdbc.sql.DerbyDictionary;
|
||||||
import org.apache.openjpa.persistence.ArgumentException;
|
import org.apache.openjpa.persistence.ArgumentException;
|
||||||
|
import org.apache.openjpa.persistence.OpenJPAEntityManager;
|
||||||
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.AbstractPersistenceTestCase;
|
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||||
|
|
||||||
public class TestOverrideNonJtaDataSource extends AbstractPersistenceTestCase {
|
public class TestOverrideNonJtaDataSource extends SingleEMFTestCase {
|
||||||
private String defaultJndiName = "jdbc/mocked";
|
private String defaultJndiName = "jdbc/mocked";
|
||||||
private String[] jndiNames = { "jdbc/mocked1" };
|
private String[] jndiNames = { "jdbc/mocked1" };
|
||||||
|
|
||||||
protected void init(String cfName) {
|
protected void init(String cfName) {
|
||||||
EntityManagerFactory emf = getEmf("openjpa.ConnectionFactoryName", cfName, true);
|
EntityManagerFactory emf1 = getEmf("openjpa.ConnectionFactoryName", cfName, true);
|
||||||
EntityManager em = emf.createEntityManager();
|
EntityManager em = emf1.createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.createQuery("Delete from confPerson").executeUpdate();
|
em.createQuery("Delete from confPerson").executeUpdate();
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
closeEMF(emf);
|
closeEMF(emf1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setUp() {
|
public void setUp() throws Exception {
|
||||||
|
super.setUp(Person.class, CLEAR_TABLES);
|
||||||
|
OpenJPAEntityManager em = emf.createEntityManager();
|
||||||
|
JDBCConfiguration conf = (JDBCConfiguration) em.getConfiguration();
|
||||||
|
if (conf.getConnectionUserName() != null || !conf.getConnectionUserName().equals("")) {
|
||||||
|
// Disable for non-Derby, due to connectionUserName to schema mapping failures
|
||||||
|
setTestsDisabled(true);
|
||||||
|
getLog().trace("TestOverrideNonJtaDataSource can only be executed against Derby w/o a schema");
|
||||||
|
} else {
|
||||||
// create an EMF for each database.
|
// create an EMF for each database.
|
||||||
init(defaultJndiName);
|
init(defaultJndiName);
|
||||||
init(jndiNames[0]);
|
init(jndiNames[0]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected EntityManagerFactory getEmf(String cfPropertyName, String cfPropertyValue) {
|
protected EntityManagerFactory getEmf(String cfPropertyName, String cfPropertyValue) {
|
||||||
return getEmf(cfPropertyName, cfPropertyValue, false);
|
return getEmf(cfPropertyName, cfPropertyValue, false);
|
||||||
|
@ -101,20 +112,13 @@ public class TestOverrideNonJtaDataSource extends AbstractPersistenceTestCase {
|
||||||
|
|
||||||
public void overridePropertyOnEM(String name, String value) {
|
public void overridePropertyOnEM(String name, String value) {
|
||||||
// use the default JndiName for the base EntityManagerFactory
|
// use the default JndiName for the base EntityManagerFactory
|
||||||
OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)getEmf(name, defaultJndiName);
|
OpenJPAEntityManagerFactorySPI emf1 = (OpenJPAEntityManagerFactorySPI)getEmf(name, defaultJndiName);
|
||||||
assertNotNull(emf);
|
assertNotNull(emf1);
|
||||||
|
try {
|
||||||
OpenJPAEntityManagerSPI em = emf.createEntityManager();
|
OpenJPAEntityManagerSPI em = emf1.createEntityManager();
|
||||||
assertNotNull(em);
|
assertNotNull(em);
|
||||||
|
|
||||||
JDBCConfiguration conf = (JDBCConfiguration) em.getConfiguration();
|
EntityManager em1 = getEm(emf1, name, value);
|
||||||
DBDictionary dict = conf.getDBDictionaryInstance();
|
|
||||||
if (!(dict instanceof DerbyDictionary)) {
|
|
||||||
// Disable for non-Derby.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityManager em1 = getEm(emf, name, value);
|
|
||||||
assertNotNull(em1);
|
assertNotNull(em1);
|
||||||
|
|
||||||
// 'prove' that we're using a different database by inserting the same row
|
// 'prove' that we're using a different database by inserting the same row
|
||||||
|
@ -145,7 +149,8 @@ public class TestOverrideNonJtaDataSource extends AbstractPersistenceTestCase {
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
fail("Should not be able to commit the same row a second time");
|
fail("Should not be able to commit the same row a second time");
|
||||||
} catch (RollbackException rbe) {
|
} catch (RollbackException rbe) {
|
||||||
assertTrue(rbe.getCause() instanceof EntityExistsException);
|
assertTrue("Expected EntityExistsException but found " + rbe.getCause(),
|
||||||
|
rbe.getCause() instanceof EntityExistsException);
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,15 +165,17 @@ public class TestOverrideNonJtaDataSource extends AbstractPersistenceTestCase {
|
||||||
}
|
}
|
||||||
em.close();
|
em.close();
|
||||||
em1.close();
|
em1.close();
|
||||||
closeEMF(emf);
|
} finally {
|
||||||
|
closeEMF(emf1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInvalidCfName() throws Exception {
|
public void testInvalidCfName() throws Exception {
|
||||||
// ensure EM creation fails - when provided an invalid JNDI name
|
// ensure EM creation fails - when provided an invalid JNDI name
|
||||||
EntityManagerFactory emf = null;
|
EntityManagerFactory emf1 = null;
|
||||||
try {
|
try {
|
||||||
emf = getEmf("openjpa.ConnectionFactory2Name", defaultJndiName);
|
emf1 = getEmf("openjpa.ConnectionFactory2Name", defaultJndiName);
|
||||||
getEm(emf, "openjpa.ConnectionFactory2Name", "jdbc/NotReal");
|
getEm(emf1, "openjpa.ConnectionFactory2Name", "jdbc/NotReal");
|
||||||
fail("Expected an excepton when creating an EM with a bogus JNDI name");
|
fail("Expected an excepton when creating an EM with a bogus JNDI name");
|
||||||
} catch (ArgumentException e) {
|
} catch (ArgumentException e) {
|
||||||
assertTrue(e.isFatal());
|
assertTrue(e.isFatal());
|
||||||
|
@ -176,55 +183,55 @@ public class TestOverrideNonJtaDataSource extends AbstractPersistenceTestCase {
|
||||||
assertTrue(e.getMessage().contains("jdbc/NotReal")); // ensure failing JNDI name is in the message
|
assertTrue(e.getMessage().contains("jdbc/NotReal")); // ensure failing JNDI name is in the message
|
||||||
assertTrue(e.getMessage().contains("EntityManager")); // ensure where the JNDI name came from is in message
|
assertTrue(e.getMessage().contains("EntityManager")); // ensure where the JNDI name came from is in message
|
||||||
} finally {
|
} finally {
|
||||||
closeEMF(emf);
|
closeEMF(emf1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDataCache() {
|
public void testDataCache() {
|
||||||
EntityManagerFactory emf = null;
|
EntityManagerFactory emf1 = null;
|
||||||
|
|
||||||
emf = getEmf("openjpa.DataCache", "true");
|
|
||||||
try {
|
try {
|
||||||
getEm(emf, "openjpa.ConnectionFactoryName", "jdbc/NotReal");
|
emf1 = getEmf("openjpa.DataCache", "true");
|
||||||
|
getEm(emf1, "openjpa.ConnectionFactoryName", "jdbc/NotReal");
|
||||||
fail("Expected an excepton when creating an EM with a bogus JNDI name");
|
fail("Expected an excepton when creating an EM with a bogus JNDI name");
|
||||||
} catch (ArgumentException e) {
|
} catch (ArgumentException e) {
|
||||||
assertTrue(e.isFatal());
|
assertTrue(e.isFatal());
|
||||||
assertTrue(e.getMessage().contains("jdbc/NotReal"));
|
assertTrue(e.getMessage().contains("jdbc/NotReal"));
|
||||||
assertTrue(e.getMessage().contains("L2 Cache"));
|
assertTrue(e.getMessage().contains("L2 Cache"));
|
||||||
} finally {
|
} finally {
|
||||||
closeEMF(emf);
|
closeEMF(emf1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testQueryCache() {
|
public void testQueryCache() {
|
||||||
EntityManagerFactory emf = null;
|
EntityManagerFactory emf1 = null;
|
||||||
|
|
||||||
emf = getEmf("openjpa.QueryCache", "true");
|
|
||||||
try {
|
try {
|
||||||
getEm(emf, "openjpa.ConnectionFactoryName", "jdbc/NotReal");
|
emf1 = getEmf("openjpa.QueryCache", "true");
|
||||||
|
getEm(emf1, "openjpa.ConnectionFactoryName", "jdbc/NotReal");
|
||||||
fail("Expected an excepton when creating an EM with a bogus JNDI name");
|
fail("Expected an excepton when creating an EM with a bogus JNDI name");
|
||||||
} catch (ArgumentException e) {
|
} catch (ArgumentException e) {
|
||||||
assertTrue(e.isFatal());
|
assertTrue(e.isFatal());
|
||||||
assertTrue(e.getMessage().contains("jdbc/NotReal"));
|
assertTrue(e.getMessage().contains("jdbc/NotReal"));
|
||||||
assertTrue(e.getMessage().contains("openjpa.QueryCache"));
|
assertTrue(e.getMessage().contains("openjpa.QueryCache"));
|
||||||
} finally {
|
} finally {
|
||||||
closeEMF(emf);
|
closeEMF(emf1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSyncMappings() {
|
public void testSyncMappings() {
|
||||||
EntityManagerFactory emf = null;
|
EntityManagerFactory emf1 = null;
|
||||||
|
|
||||||
emf = getEmf("openjpa.jdbc.SynchronizeMappings", "buildSchema");
|
|
||||||
try {
|
try {
|
||||||
getEm(emf, "openjpa.ConnectionFactoryName", "jdbc/NotReal");
|
emf1 = getEmf("openjpa.jdbc.SynchronizeMappings", "buildSchema");
|
||||||
|
getEm(emf1, "openjpa.ConnectionFactoryName", "jdbc/NotReal");
|
||||||
fail("Expected an excepton when creating an EM with a bogus JNDI name");
|
fail("Expected an excepton when creating an EM with a bogus JNDI name");
|
||||||
} catch (ArgumentException e) {
|
} catch (ArgumentException e) {
|
||||||
assertTrue(e.isFatal());
|
assertTrue(e.isFatal());
|
||||||
assertTrue(e.getMessage().contains("jdbc/NotReal"));
|
assertTrue(e.getMessage().contains("jdbc/NotReal"));
|
||||||
assertTrue(e.getMessage().contains("openjpa.jdbc.SynchronizeMappings"));
|
assertTrue(e.getMessage().contains("openjpa.jdbc.SynchronizeMappings"));
|
||||||
} finally {
|
} finally {
|
||||||
closeEMF(emf);
|
closeEMF(emf1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue