Save This Page
Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.api.persistencemanager.cache » [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   
   19   package org.apache.jdo.tck.api.persistencemanager.cache;
   20   
   21   import java.util.Collection;
   22   
   23   import javax.jdo.PersistenceManager;
   24   import javax.jdo.Transaction;
   25   
   26   import org.apache.jdo.tck.api.persistencemanager.PersistenceManagerTest;
   27   import org.apache.jdo.tck.pc.mylib.PCPoint;
   28   import org.apache.jdo.tck.util.BatchTestRunner;
   29   
   30   /**
   31    *<B>Title:</B> Calling EvictAll With Collection Containing Nulls
   32    *<BR>
   33    *<B>Keywords:</B> cache
   34    *<BR>
   35    *<B>Assertion IDs:</B> A12.5-11
   36    *<BR>
   37    *<B>Assertion Description: </B>
   38   Passing a non-null Object[] or Collection arguments to evictAll that
   39   contain null elements will have the documented behavior for non-null elements, and the null elements
   40   will be ignored.
   41   
   42    */
   43   
   44   public class CallingEvictAllWithCollectionContainingNulls extends PersistenceManagerTest {
   45   
   46       /** */
   47       private static final String ASSERTION_FAILED = 
   48           "Assertion A12.5-11 (CallingEvictAllWithCollectionContainingNulls) failed: ";
   49       
   50       /**
   51        * The <code>main</code> is called when the class
   52        * is directly executed from the command line.
   53        * @param args The arguments passed to the program.
   54        */
   55       public static void main(String[] args) {
   56           BatchTestRunner.run(CallingEvictAllWithCollectionContainingNulls.class);
   57       }
   58       
   59       private PCPoint p1;
   60       private PCPoint p2;
   61       private PCPoint p3;
   62       private PCPoint p4;
   63       private PCPoint p5;
   64   
   65       /** */
   66       public void testCallingEvictAllWithCollectionContainingNulls() {
   67           pm = getPM();
   68           createObjects(pm);
   69           runTestEvictAll1(pm);
   70           runTestEvictAll2(pm);
   71           pm.close();
   72           pm = null;
   73       }
   74       
   75       /** */
   76       private void createObjects(PersistenceManager pm) {
   77           Transaction tx = pm.currentTransaction();
   78           try {
   79               tx.begin();
   80               p1 = new PCPoint (1,3);
   81               p2 = new PCPoint (4,3);
   82               p3 = new PCPoint (4,2);
   83               p4 = new PCPoint (3,3);
   84               
   85               pm.makePersistent(p1);
   86               pm.makePersistent(p2);
   87               pm.makePersistent(p3);
   88               pm.makePersistent(p4);
   89            
   90               tx.commit();
   91           }
   92           finally {
   93               if (tx.isActive())
   94                   tx.rollback();
   95           }
   96       }
   97       
   98       /* test evictAll (Collection col1) */
   99       private void runTestEvictAll1(PersistenceManager pm) {
  100           Transaction tx = pm.currentTransaction();
  101           try {
  102               tx.begin();
  103               
  104               PCPoint p5 = null;
  105               Collection col1 = new java.util.HashSet();
  106               col1.add (p1);
  107               col1.add (p5);
  108               col1.add (p2);
  109               
  110               pm.evictAll(col1);
  111               if (debug) logger.debug(" \nPASSED in testEvictAll1()");
  112           }
  113           finally {
  114               if (tx.isActive())
  115                   tx.rollback();
  116           }
  117       }
  118       
  119       /** test evictAll (Object[] objArray) */
  120       private void runTestEvictAll2(PersistenceManager pm) {
  121           Transaction tx = pm.currentTransaction();
  122           try {
  123               tx.begin();
  124               
  125               PCPoint p5 = null;
  126               Collection col1 = new java.util.HashSet();
  127               col1.add (p3);
  128               col1.add (p4);
  129               col1.add (p5);
  130               
  131               pm.evictAll(col1.toArray());
  132               if (debug) logger.debug(" \nPASSED in testEvictAll2()");
  133           }
  134           finally {
  135               if (tx.isActive())
  136                   tx.rollback();
  137           }
  138       }
  139   }

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