diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java index b431a081a..d56305a61 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java @@ -23,13 +23,16 @@ import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory; import org.apache.openjpa.persistence.OpenJPAPersistence; import org.apache.openjpa.persistence.query.SimpleEntity; +import org.apache.openjpa.persistence.test.AllowFailure; import org.apache.openjpa.persistence.test.SingleEMFTestCase; /** * Tests the new Bean Validation Factory support in the JPA 2.0 spec. * Basic (no provider) Validation scenarios being tested: * 1) By default, ValidationFactory is null - * 2) ValidationFactory can be provided by createEMF(Map props) + * 2) An invalid ValidationFactory with mode of NONE will not cause exception + * 3) An invalid ValidationFactory with mode of AUTO will not cause exception + * 4) An invalid ValidationFactory with mode of CALLBACK will cause exception * * @version $Rev$ $Date$ */ @@ -58,15 +61,16 @@ public class TestValidationFactory extends SingleEMFTestCase { assertNotNull(conf); assertEquals("Default ValidationFactory", null, - conf.getValidationFactory()); + conf.getValidationFactoryInstance()); } /** * Scenario being tested: - * 2) ValidationFactory can be provided by createEMF(Map props) + * 2) An invalid ValidationFactory with a mode of NONE will not + * cause an exception */ public void testValidationFactory2() { - getLog().trace("testValidationFactory2() - createEMF(Map props)"); + getLog().trace("testValidationFactory2() - ignored invalid factory"); OpenJPAEntityManagerFactory emf = null; // create the Map to test overrides @@ -81,12 +85,81 @@ public class TestValidationFactory extends SingleEMFTestCase { "org/apache/openjpa/persistence/validation/persistence.xml", props); assertNotNull(emf); - // verify validation mode + // verify same "validation factory" object is returned OpenJPAConfiguration conf = emf.getConfiguration(); assertNotNull(conf); assertEquals("ValidationFactory", this.getClass(), - conf.getValidationFactory()); + conf.getValidationFactoryInstance()); + } + + /** + * Scenario being tested: + * 3) An invalid ValidationFactory with a mode of AUTO will not + * cause an exception + */ + public void testValidationFactory3() { + getLog().trace("testValidationFactory3() - optional invalid factory"); + OpenJPAEntityManagerFactory emf = null; + + // create the Map to test overrides + // Just use current class object, as we have no provider to test with + Map props = new HashMap(); + props.put("javax.persistence.validation.factory", + this.getClass()); + + // create our EMF + emf = OpenJPAPersistence.createEntityManagerFactory( + "simple-auto-mode", + "org/apache/openjpa/persistence/validation/persistence.xml", + props); + assertNotNull(emf); + // verify same "validation factory" object is returned + OpenJPAConfiguration conf = emf.getConfiguration(); + assertNotNull(conf); + assertEquals("ValidationFactory", + this.getClass(), + conf.getValidationFactoryInstance()); + } + + /** + * Scenario being tested: + * 4) An invalid ValidationFactory with a mode of CALLBACK will + * cause an exception + */ + @AllowFailure(message="This will fail until OPENJPA-1111 is resolved.") + public void testValidationFactory4() { + getLog().trace("testValidationFactory4() - required invalid factory"); + OpenJPAEntityManagerFactory emf = null; + + // create the Map to test overrides + // Just use current class object, as we have no provider to test with + Map props = new HashMap(); + props.put("javax.persistence.validation.factory", + this.getClass()); + props.put("javax.persistence.validation.mode", + String.valueOf(ValidationMode.CALLBACK)); + + try { + // create our EMF + emf = OpenJPAPersistence.createEntityManagerFactory( + "simple-callback-mode", + "org/apache/openjpa/persistence/validation/persistence.xml", + props); + assertNotNull(emf); + // verify validation mode + OpenJPAConfiguration conf = emf.getConfiguration(); + assertNotNull(conf); + assertEquals("Validation mode", + String.valueOf(ValidationMode.CALLBACK), + conf.getValidationMode()); + fail("Expected an exception when ValidationMode=CALLBACK and " + + "an invalid ValidatorFactory is provided."); + } catch (Exception e) { + // expected + getLog().trace("testValidationFactory4() - caught expected " + + "exception", e); + } }