openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r780704 - /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java
Date Mon, 01 Jun 2009 16:18:16 GMT
Author: dwoods
Date: Mon Jun  1 16:18:16 2009
New Revision: 780704

URL: http://svn.apache.org/viewvc?rev=780704&view=rev
Log:
OPENJPA-1102 additional validation factory tests.  test scenario #4 will be addressed in OPENJPA-1111.

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java?rev=780704&r1=780703&r2=780704&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/validation/TestValidationFactory.java
Mon Jun  1 16:18:16 2009
@@ -23,13 +23,16 @@
 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 @@
         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 @@
             "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<String,Object> props = new HashMap<String,Object>();
+        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<String,Object> props = new HashMap<String,Object>();
+        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);
+        }
     }
 
 



Mime
View raw message