mirror of https://github.com/apache/openjpa.git
cleanup imports and add proper EMF cleanup
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@793990 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b40e3a425e
commit
c155c9ee2f
|
@ -20,7 +20,7 @@ import javax.persistence.ValidationMode;
|
||||||
|
|
||||||
import org.apache.openjpa.conf.OpenJPAConfiguration;
|
import org.apache.openjpa.conf.OpenJPAConfiguration;
|
||||||
import org.apache.openjpa.lib.log.Log;
|
import org.apache.openjpa.lib.log.Log;
|
||||||
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
|
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
|
||||||
import org.apache.openjpa.persistence.OpenJPAPersistence;
|
import org.apache.openjpa.persistence.OpenJPAPersistence;
|
||||||
import org.apache.openjpa.persistence.PersistenceException;
|
import org.apache.openjpa.persistence.PersistenceException;
|
||||||
import org.apache.openjpa.persistence.query.SimpleEntity;
|
import org.apache.openjpa.persistence.query.SimpleEntity;
|
||||||
|
@ -52,19 +52,22 @@ public class TestValidationMode extends SingleEMFTestCase {
|
||||||
*/
|
*/
|
||||||
public void testValidationMode1() {
|
public void testValidationMode1() {
|
||||||
getLog().trace("testValidationMode1() - Default mode is AUTO");
|
getLog().trace("testValidationMode1() - Default mode is AUTO");
|
||||||
OpenJPAEntityManagerFactory emf = null;
|
|
||||||
|
|
||||||
// create our EMF
|
// create our EMF
|
||||||
emf = OpenJPAPersistence.createEntityManagerFactory(
|
OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
|
||||||
"simple",
|
OpenJPAPersistence.createEntityManagerFactory(
|
||||||
"org/apache/openjpa/persistence/validation/persistence.xml");
|
"simple",
|
||||||
|
"org/apache/openjpa/persistence/validation/persistence.xml");
|
||||||
assertNotNull(emf);
|
assertNotNull(emf);
|
||||||
// verify default validation mode
|
try {
|
||||||
OpenJPAConfiguration conf = emf.getConfiguration();
|
// verify default validation mode
|
||||||
assertNotNull(conf);
|
OpenJPAConfiguration conf = emf.getConfiguration();
|
||||||
assertEquals("Default validation mode",
|
assertNotNull(conf);
|
||||||
String.valueOf(ValidationMode.AUTO),
|
assertEquals("Default validation mode",
|
||||||
conf.getValidationMode());
|
String.valueOf(ValidationMode.AUTO),
|
||||||
|
conf.getValidationMode());
|
||||||
|
} finally {
|
||||||
|
cleanup(emf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,19 +76,22 @@ public class TestValidationMode extends SingleEMFTestCase {
|
||||||
*/
|
*/
|
||||||
public void testValidationMode2() {
|
public void testValidationMode2() {
|
||||||
getLog().trace("testValidationMode1() - AUTO in persistence.xml");
|
getLog().trace("testValidationMode1() - AUTO in persistence.xml");
|
||||||
OpenJPAEntityManagerFactory emf = null;
|
|
||||||
|
|
||||||
// create our EMF
|
// create our EMF
|
||||||
emf = OpenJPAPersistence.createEntityManagerFactory(
|
OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
|
||||||
"simple-auto-mode",
|
OpenJPAPersistence.createEntityManagerFactory(
|
||||||
"org/apache/openjpa/persistence/validation/persistence.xml");
|
"simple-auto-mode",
|
||||||
|
"org/apache/openjpa/persistence/validation/persistence.xml");
|
||||||
assertNotNull(emf);
|
assertNotNull(emf);
|
||||||
// verify expected validation mode
|
try {
|
||||||
OpenJPAConfiguration conf = emf.getConfiguration();
|
// verify expected validation mode
|
||||||
assertNotNull(conf);
|
OpenJPAConfiguration conf = emf.getConfiguration();
|
||||||
assertEquals("Validation mode",
|
assertNotNull(conf);
|
||||||
String.valueOf(ValidationMode.AUTO),
|
assertEquals("Validation mode",
|
||||||
conf.getValidationMode());
|
String.valueOf(ValidationMode.AUTO),
|
||||||
|
conf.getValidationMode());
|
||||||
|
} finally {
|
||||||
|
cleanup(emf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,19 +101,22 @@ public class TestValidationMode extends SingleEMFTestCase {
|
||||||
public void testValidationMode3() {
|
public void testValidationMode3() {
|
||||||
getLog().trace("testValidationMode3() - persistence.xml overrides " +
|
getLog().trace("testValidationMode3() - persistence.xml overrides " +
|
||||||
"Default");
|
"Default");
|
||||||
OpenJPAEntityManagerFactory emf = null;
|
|
||||||
|
|
||||||
// create our EMF
|
// create our EMF
|
||||||
emf = OpenJPAPersistence.createEntityManagerFactory(
|
OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
|
||||||
"simple-none-mode",
|
OpenJPAPersistence.createEntityManagerFactory(
|
||||||
"org/apache/openjpa/persistence/validation/persistence.xml");
|
"simple-none-mode",
|
||||||
|
"org/apache/openjpa/persistence/validation/persistence.xml");
|
||||||
assertNotNull(emf);
|
assertNotNull(emf);
|
||||||
// verify validation mode
|
try {
|
||||||
OpenJPAConfiguration conf = emf.getConfiguration();
|
// verify validation mode
|
||||||
assertNotNull(conf);
|
OpenJPAConfiguration conf = emf.getConfiguration();
|
||||||
assertEquals("Validation mode",
|
assertNotNull(conf);
|
||||||
String.valueOf(ValidationMode.NONE),
|
assertEquals("Validation mode",
|
||||||
conf.getValidationMode());
|
String.valueOf(ValidationMode.NONE),
|
||||||
|
conf.getValidationMode());
|
||||||
|
} finally {
|
||||||
|
cleanup(emf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,13 +128,13 @@ public class TestValidationMode extends SingleEMFTestCase {
|
||||||
public void testValidationMode4() {
|
public void testValidationMode4() {
|
||||||
getLog().trace("testValidationMode4() - persistence.xml overrides " +
|
getLog().trace("testValidationMode4() - persistence.xml overrides " +
|
||||||
"Default");
|
"Default");
|
||||||
OpenJPAEntityManagerFactory emf = null;
|
OpenJPAEntityManagerFactorySPI emf = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// create our EMF
|
// create our EMF
|
||||||
emf = OpenJPAPersistence.createEntityManagerFactory(
|
emf = (OpenJPAEntityManagerFactorySPI)
|
||||||
"simple-callback-mode",
|
OpenJPAPersistence.createEntityManagerFactory(
|
||||||
"org/apache/openjpa/persistence/validation/persistence.xml");
|
"simple-callback-mode",
|
||||||
|
"org/apache/openjpa/persistence/validation/persistence.xml");
|
||||||
assertNotNull(emf);
|
assertNotNull(emf);
|
||||||
// verify validation mode
|
// verify validation mode
|
||||||
OpenJPAConfiguration conf = emf.getConfiguration();
|
OpenJPAConfiguration conf = emf.getConfiguration();
|
||||||
|
@ -137,6 +146,8 @@ public class TestValidationMode extends SingleEMFTestCase {
|
||||||
// expected when no Validation APIs or provider are available
|
// expected when no Validation APIs or provider are available
|
||||||
getLog().trace("testValidationMode4() - caught expected " +
|
getLog().trace("testValidationMode4() - caught expected " +
|
||||||
"exception", e);
|
"exception", e);
|
||||||
|
} finally {
|
||||||
|
cleanup(emf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +157,6 @@ public class TestValidationMode extends SingleEMFTestCase {
|
||||||
*/
|
*/
|
||||||
public void testValidationMode5() {
|
public void testValidationMode5() {
|
||||||
getLog().trace("testValidationMode5() - Map(NONE) overrides default");
|
getLog().trace("testValidationMode5() - Map(NONE) overrides default");
|
||||||
OpenJPAEntityManagerFactory emf = null;
|
|
||||||
|
|
||||||
// create the Map to test overrides
|
// create the Map to test overrides
|
||||||
Map<String,String> props = new HashMap<String,String>();
|
Map<String,String> props = new HashMap<String,String>();
|
||||||
|
@ -154,17 +164,22 @@ public class TestValidationMode extends SingleEMFTestCase {
|
||||||
String.valueOf(ValidationMode.NONE));
|
String.valueOf(ValidationMode.NONE));
|
||||||
|
|
||||||
// create our EMF
|
// create our EMF
|
||||||
emf = OpenJPAPersistence.createEntityManagerFactory(
|
OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
|
||||||
"simple",
|
OpenJPAPersistence.createEntityManagerFactory(
|
||||||
"org/apache/openjpa/persistence/validation/persistence.xml",
|
"simple",
|
||||||
|
"org/apache/openjpa/persistence/validation/persistence.xml",
|
||||||
props);
|
props);
|
||||||
assertNotNull(emf);
|
assertNotNull(emf);
|
||||||
// verify validation mode
|
try {
|
||||||
OpenJPAConfiguration conf = emf.getConfiguration();
|
// verify validation mode
|
||||||
assertNotNull(conf);
|
OpenJPAConfiguration conf = emf.getConfiguration();
|
||||||
assertEquals("Validation mode",
|
assertNotNull(conf);
|
||||||
String.valueOf(ValidationMode.NONE),
|
assertEquals("Validation mode",
|
||||||
conf.getValidationMode());
|
String.valueOf(ValidationMode.NONE),
|
||||||
|
conf.getValidationMode());
|
||||||
|
} finally {
|
||||||
|
cleanup(emf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -174,7 +189,6 @@ public class TestValidationMode extends SingleEMFTestCase {
|
||||||
public void testValidationMode6() {
|
public void testValidationMode6() {
|
||||||
getLog().trace("testValidationMode6() - Map(NONE) overrides PU " +
|
getLog().trace("testValidationMode6() - Map(NONE) overrides PU " +
|
||||||
"provided mode=callback");
|
"provided mode=callback");
|
||||||
OpenJPAEntityManagerFactory emf = null;
|
|
||||||
|
|
||||||
// create the Map to test overrides
|
// create the Map to test overrides
|
||||||
Map<String,String> props = new HashMap<String,String>();
|
Map<String,String> props = new HashMap<String,String>();
|
||||||
|
@ -182,17 +196,22 @@ public class TestValidationMode extends SingleEMFTestCase {
|
||||||
String.valueOf(ValidationMode.NONE));
|
String.valueOf(ValidationMode.NONE));
|
||||||
|
|
||||||
// create our EMF
|
// create our EMF
|
||||||
emf = OpenJPAPersistence.createEntityManagerFactory(
|
OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
|
||||||
"simple-callback-mode",
|
OpenJPAPersistence.createEntityManagerFactory(
|
||||||
"org/apache/openjpa/persistence/validation/persistence.xml",
|
"simple-callback-mode",
|
||||||
|
"org/apache/openjpa/persistence/validation/persistence.xml",
|
||||||
props);
|
props);
|
||||||
assertNotNull(emf);
|
assertNotNull(emf);
|
||||||
// verify validation mode
|
try {
|
||||||
OpenJPAConfiguration conf = emf.getConfiguration();
|
// verify validation mode
|
||||||
assertNotNull(conf);
|
OpenJPAConfiguration conf = emf.getConfiguration();
|
||||||
assertEquals("Validation mode",
|
assertNotNull(conf);
|
||||||
String.valueOf(ValidationMode.NONE),
|
assertEquals("Validation mode",
|
||||||
conf.getValidationMode());
|
String.valueOf(ValidationMode.NONE),
|
||||||
|
conf.getValidationMode());
|
||||||
|
} finally {
|
||||||
|
cleanup(emf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,7 +221,6 @@ public class TestValidationMode extends SingleEMFTestCase {
|
||||||
public void testValidationMode7() {
|
public void testValidationMode7() {
|
||||||
getLog().trace("testValidationMode7() - Map(ValidationMode.NONE) " +
|
getLog().trace("testValidationMode7() - Map(ValidationMode.NONE) " +
|
||||||
"overrides PU provided mode=callback");
|
"overrides PU provided mode=callback");
|
||||||
OpenJPAEntityManagerFactory emf = null;
|
|
||||||
|
|
||||||
// create the Map to test overrides
|
// create the Map to test overrides
|
||||||
Map<String,Object> props = new HashMap<String,Object>();
|
Map<String,Object> props = new HashMap<String,Object>();
|
||||||
|
@ -210,19 +228,33 @@ public class TestValidationMode extends SingleEMFTestCase {
|
||||||
ValidationMode.NONE);
|
ValidationMode.NONE);
|
||||||
|
|
||||||
// create our EMF
|
// create our EMF
|
||||||
emf = OpenJPAPersistence.createEntityManagerFactory(
|
OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
|
||||||
"simple-callback-mode",
|
OpenJPAPersistence.createEntityManagerFactory(
|
||||||
"org/apache/openjpa/persistence/validation/persistence.xml",
|
"simple-callback-mode",
|
||||||
|
"org/apache/openjpa/persistence/validation/persistence.xml",
|
||||||
props);
|
props);
|
||||||
assertNotNull(emf);
|
assertNotNull(emf);
|
||||||
// verify validation mode
|
try {
|
||||||
OpenJPAConfiguration conf = emf.getConfiguration();
|
// verify validation mode
|
||||||
assertNotNull(conf);
|
OpenJPAConfiguration conf = emf.getConfiguration();
|
||||||
assertEquals("Validation mode",
|
assertNotNull(conf);
|
||||||
String.valueOf(ValidationMode.NONE),
|
assertEquals("Validation mode",
|
||||||
conf.getValidationMode());
|
String.valueOf(ValidationMode.NONE),
|
||||||
|
conf.getValidationMode());
|
||||||
|
} finally {
|
||||||
|
cleanup(emf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to remove entities and close the emf an any open em's.
|
||||||
|
* @param emf
|
||||||
|
*/
|
||||||
|
private void cleanup(OpenJPAEntityManagerFactorySPI emf) {
|
||||||
|
clear(emf);
|
||||||
|
closeEMF(emf);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal convenience method for getting the OpenJPA logger
|
* Internal convenience method for getting the OpenJPA logger
|
||||||
|
|
Loading…
Reference in New Issue