Save This Page
Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.api.persistencemanagerfactory » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    * 
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    * Unless required by applicable law or agreed to in writing, software 
   12    * distributed under the License is distributed on an "AS IS" BASIS, 
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
   14    * See the License for the specific language governing permissions and 
   15    * limitations under the License.
   16    */
   17    
   18   package org.apache.jdo.tck.api.persistencemanagerfactory;
   19   
   20   import java.security.Permission;
   21   
   22   import javax.jdo.spi.JDOPermission;
   23   import org.apache.jdo.tck.JDO_Test;
   24   import org.apache.jdo.tck.util.BatchTestRunner;
   25   
   26   /**
   27    *<B>Title:</B>Close of PersistenceManagerFactory Throws SecurityException if
   28    * JDOPermission("closePersistenceManagerFactory") Is Not Set
   29    *<BR>
   30    *<B>Keywords:</B> persistencemanagerfactory SecurityException
   31    *<BR>
   32    *<B>Assertion IDs:</B> A11.4-3
   33    *<BR>
   34    *<B>Assertion Description: </B>
   35    * PersistenceManagerFactory.close() closes this PersistenceManagerFactory.
   36    * If JDOPermission("closePersistenceManagerFactory") is not set, then
   37    * SecurityException in thrown. 
   38    */
   39   
   40   
   41   public class CloseWithoutPermissionThrowsSecurityException extends JDO_Test {
   42       
   43       /** */
   44       private static final String ASSERTION_FAILED = 
   45           "Assertions A11.4-3 (CloseWithoutPermissionThrowsSecurityException) failed: ";
   46       
   47       /**
   48        * The <code>main</code> is called when the class
   49        * is directly executed from the command line.
   50        * @param args The arguments passed to the program.
   51        */
   52       public static void main(String[] args) {
   53           BatchTestRunner.run(CloseWithoutPermissionThrowsSecurityException.class);
   54       }
   55   
   56       /** */
   57       public void test() {
   58   	    pmf = getPMF();
   59   
   60           SecurityManager oldSecMgr = System.getSecurityManager();
   61           try {
   62               System.setSecurityManager(new MySecurityManager());
   63           } catch (SecurityException se) {
   64               // running with the TCK SecurityManager; don't run this test
   65               return;
   66           }
   67   
   68           try {
   69               pmf.close();
   70           } catch (SecurityException ex) {
   71               // expected exception if JDOPermission("closePersistenceManagerFactory") is not set
   72               if (debug)
   73                   logger.debug("caught expected exception " + ex.toString());
   74           }
   75           finally {
   76               System.setSecurityManager(oldSecMgr);
   77           }
   78       }
   79   
   80       public class MySecurityManager extends SecurityManager {
   81           public void checkPermission(Permission perm) {
   82               if (perm==JDOPermission.CLOSE_PERSISTENCE_MANAGER_FACTORY)
   83                   throw new SecurityException(
   84                       "JDOPermission.CLOSE_PERSISTENCE_MANAGER_FACTORY not set");
   85           }
   86       }
   87   }

Save This Page
Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.api.persistencemanagerfactory » [javadoc | source]