db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r959037 - in /db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory: AfterCloseSetMethodsThrowException.java Close.java CloseFailsIfTransactionActive.java CloseWithoutPermissionThrowsSecurityException.java
Date Tue, 29 Jun 2010 17:11:45 GMT
Author: clr
Date: Tue Jun 29 17:11:45 2010
New Revision: 959037

URL: http://svn.apache.org/viewvc?rev=959037&view=rev
Log:
JDO-653 Thanks to Peter Dettman for the patch

Modified:
    db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/AfterCloseSetMethodsThrowException.java
    db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/Close.java
    db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/CloseFailsIfTransactionActive.java
    db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/CloseWithoutPermissionThrowsSecurityException.java

Modified: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/AfterCloseSetMethodsThrowException.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/AfterCloseSetMethodsThrowException.java?rev=959037&r1=959036&r2=959037&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/AfterCloseSetMethodsThrowException.java
(original)
+++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/AfterCloseSetMethodsThrowException.java
Tue Jun 29 17:11:45 2010
@@ -21,7 +21,6 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 
-import javax.jdo.JDOException;
 import javax.jdo.JDOFatalInternalException;
 import javax.jdo.JDOUserException;
 import javax.jdo.PersistenceManagerFactory;
@@ -67,40 +66,69 @@ public class AfterCloseSetMethodsThrowEx
     public void test() {
         Class[] stringParameters = new Class[]{String.class};
         Class[] booleanParameters = new Class[]{boolean.class};
+        Class[] objectParameters = new Class[]{Object.class};
+        Class[] integerParameters = new Class[]{Integer.class};
         Object[] stringParameter = new Object[]{"Nobody knows the trouble"};
         Object[] booleanParameter = new Object[]{new Boolean(false)};
+        Object[] objectParameter = new Object[]{null};
+        Object[] integerParameter = new Object[]{new Integer(0)};
         
         SetProperty[] setMethods = new SetProperty[] {
             new SetProperty("setConnectionDriverName", stringParameters, stringParameter),
+            new SetProperty("setConnectionFactory", objectParameters, objectParameter),
+            new SetProperty("setConnectionFactory2", objectParameters, objectParameter),
             new SetProperty("setConnectionFactoryName", stringParameters, stringParameter),
             new SetProperty("setConnectionFactory2Name", stringParameters, stringParameter),
+            new SetProperty("setConnectionPassword", stringParameters, stringParameter),
             new SetProperty("setConnectionURL", stringParameters, stringParameter),
             new SetProperty("setConnectionUserName", stringParameters, stringParameter),
-            new SetProperty("setConnectionPassword", stringParameters, stringParameter),
+            new SetProperty("setCopyOnAttach", booleanParameters, booleanParameter),
+            new SetProperty("setDetachAllOnCommit", booleanParameters, booleanParameter),
             new SetProperty("setIgnoreCache", booleanParameters, booleanParameter),
+            new SetProperty("setMapping", stringParameters, stringParameter),
             new SetProperty("setMultithreaded", booleanParameters, booleanParameter),
+            new SetProperty("setName", stringParameters, stringParameter),
             new SetProperty("setNontransactionalRead", booleanParameters, booleanParameter),
             new SetProperty("setNontransactionalWrite", booleanParameters, booleanParameter),
             new SetProperty("setOptimistic", booleanParameters, booleanParameter),
+            new SetProperty("setPersistenceUnitName", stringParameters, stringParameter),
+            new SetProperty("setReadOnly", booleanParameters, booleanParameter),
             new SetProperty("setRestoreValues", booleanParameters, booleanParameter),
-            new SetProperty("setRetainValues", booleanParameters, booleanParameter)
+            new SetProperty("setRetainValues", booleanParameters, booleanParameter),
+            new SetProperty("setServerTimeZoneID", stringParameters, stringParameter),
+            new SetProperty("setTransactionIsolationLevel", stringParameters, stringParameter),
+            new SetProperty("setTransactionType", stringParameters, stringParameter)
         };
-       
+
         GetProperty[] getMethods = new GetProperty[] {
             new GetProperty("getConnectionDriverName"),
+            new GetProperty("getConnectionFactory"),
+            new GetProperty("getConnectionFactory2"),
             new GetProperty("getConnectionFactoryName"),
             new GetProperty("getConnectionFactory2Name"),
             new GetProperty("getConnectionURL"),
             new GetProperty("getConnectionUserName"),
+            new GetProperty("getCopyOnAttach"),
+            new GetProperty("getDataStoreCache"),
+            new GetProperty("getDetachAllOnCommit"),
+            new GetProperty("getFetchGroups"),
             new GetProperty("getIgnoreCache"),
+            new GetProperty("getMapping"),
             new GetProperty("getMultithreaded"),
+            new GetProperty("getName"),
             new GetProperty("getNontransactionalRead"),
             new GetProperty("getNontransactionalWrite"),
             new GetProperty("getOptimistic"),
+            new GetProperty("getPersistenceUnitName"),
+            new GetProperty("getProperties"),
+            new GetProperty("getReadOnly"),
             new GetProperty("getRestoreValues"),
-            new GetProperty("getRetainValues")
+            new GetProperty("getRetainValues"),
+            new GetProperty("getServerTimeZoneID"),
+            new GetProperty("getTransactionIsolationLevel"),
+            new GetProperty("getTransactionType")
         };
-       
+
         pmf = getPMF();
         closePMF(pmf); // don't use closePMF() because that sets pmf to null
         // each set method should throw an exception
@@ -111,11 +139,14 @@ public class AfterCloseSetMethodsThrowEx
             try {
                 sp.execute(pmf);
                 fail(ASSERTION_FAILED,
-                     "pmf method " + where + " shoudl throw JDOUserException when called
for closed pmf");
+                    "pmf method " + where + " should throw JDOUserException when called for
closed pmf");
             } catch (JDOUserException ex) {
                 if (debug)
                     logger.debug("Caught expected exception " + ex.toString() +
                                  " from " + where);
+            } catch (Exception ex) {
+                fail(ASSERTION_FAILED,
+                     "Caught unexpected exception " + ex.toString() + " from " + where);
             }
         }
         // each get method should succeed
@@ -125,7 +156,7 @@ public class AfterCloseSetMethodsThrowEx
             String where = gp.getMethodName();
             try {
                 gp.execute(pmf);
-            } catch (JDOUserException ex) {
+            } catch (Exception ex) {
                 fail(ASSERTION_FAILED,
                      "Caught unexpected exception " + ex.toString() + " from " +
                      where);
@@ -157,7 +188,7 @@ public class AfterCloseSetMethodsThrowEx
             } catch (IllegalAccessException ex) {
                 throw new JDOFatalInternalException("IllegalAccessException", ex);
             } catch (java.lang.reflect.InvocationTargetException ex) {
-                throw (JDOException)ex.getTargetException();
+                throw (RuntimeException)ex.getTargetException();
             }
         }
        
@@ -187,7 +218,7 @@ public class AfterCloseSetMethodsThrowEx
             } catch (IllegalAccessException ex) {
                 throw new JDOFatalInternalException("IllegalAccessException", ex);
             } catch (java.lang.reflect.InvocationTargetException ex) {
-                throw (JDOException)ex.getTargetException();
+                throw (RuntimeException)ex.getTargetException();
             }
         }
        

Modified: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/Close.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/Close.java?rev=959037&r1=959036&r2=959037&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/Close.java
(original)
+++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/Close.java
Tue Jun 29 17:11:45 2010
@@ -17,6 +17,9 @@
  
 package org.apache.jdo.tck.api.persistencemanagerfactory;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
 import javax.jdo.JDOFatalUserException;
 import javax.jdo.JDOUserException;
 
@@ -78,7 +81,28 @@ public class Close extends JDO_Test {
             fail(ASSERTION_FAILED, 
                  "Unexpected exception at pmf.close()/isClosed(): " + ex);
         }
-        
+
+        // pmf.close() on already-closed pmf should not throw an exception
+        try {
+            // don't use closePMF methods because they check isClosed before calling
+            AccessController.doPrivileged(
+                new PrivilegedAction () {
+                    public Object run () {
+                        pmf.close();
+                        return null;
+                    }
+                }
+            );
+        } catch (JDOUserException ex) {
+            // unexpected exception
+            fail(ASSERTION_FAILED, 
+                 "Unexpected exception at repeated pmf.close(): " + ex);
+        } catch (JDOFatalUserException ex) {
+            // unexpected exception
+            fail(ASSERTION_FAILED, 
+                 "Unexpected exception at repeated pmf.close(): " + ex);
+        }
+
         // trying to get a getPersistenceManager should result in a exception
         try {
             pm = pmf.getPersistenceManager();

Modified: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/CloseFailsIfTransactionActive.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/CloseFailsIfTransactionActive.java?rev=959037&r1=959036&r2=959037&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/CloseFailsIfTransactionActive.java
(original)
+++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/CloseFailsIfTransactionActive.java
Tue Jun 29 17:11:45 2010
@@ -111,6 +111,12 @@ public class CloseFailsIfTransactionActi
                              failed.toString());
                     }
                 }
+                if (pm1.isClosed()){
+                    fail(ASSERTION_FAILED, "Unexpected pm1 is closed.");
+                }
+                if (pm2.isClosed()){
+                    fail(ASSERTION_FAILED, "Unexpected pm2 is closed.");
+                }
             } 
             catch (Exception uex) {
                 setAborted();

Modified: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/CloseWithoutPermissionThrowsSecurityException.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/CloseWithoutPermissionThrowsSecurityException.java?rev=959037&r1=959036&r2=959037&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/CloseWithoutPermissionThrowsSecurityException.java
(original)
+++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/CloseWithoutPermissionThrowsSecurityException.java
Tue Jun 29 17:11:45 2010
@@ -19,7 +19,10 @@ package org.apache.jdo.tck.api.persisten
 
 import java.security.Permission;
 
+import javax.jdo.JDOException;
+import javax.jdo.PersistenceManagerFactory;
 import javax.jdo.spi.JDOPermission;
+
 import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -57,6 +60,14 @@ public class CloseWithoutPermissionThrow
     public void test() {
 	    pmf = getPMF();
 
+        closeWithMySecurityManager(pmf);
+
+        closePMF(pmf);
+
+        closeWithMySecurityManager(pmf);
+    }
+
+    private void closeWithMySecurityManager(PersistenceManagerFactory pmf) {
         SecurityManager oldSecMgr = System.getSecurityManager();
         try {
             System.setSecurityManager(new MySecurityManager());
@@ -67,10 +78,15 @@ public class CloseWithoutPermissionThrow
 
         try {
             pmf.close();
+            fail(ASSERTION_FAILED,
+                "SecurityException was not thrown when calling pmf.close() " +
+                "without JDOPermission.CLOSE_PERSISTENCE_MANAGER_FACTORY");
         } catch (SecurityException ex) {
             // expected exception if JDOPermission("closePersistenceManagerFactory") is not
set
             if (debug)
                 logger.debug("caught expected exception " + ex.toString());
+        } catch (JDOException e) {
+            fail(ASSERTION_FAILED, "Unexpected exception at pmf.close(): " + e);
         }
         finally {
             System.setSecurityManager(oldSecMgr);



Mime
View raw message