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 RefreshAll With Collection Containing Nulls
   32    *<BR>
   33    *<B>Keywords:</B> cache
   34    *<BR>
   35    *<B>Assertion IDs:</B> A12.5-12
   36    *<BR>
   37    *<B>Assertion Description: </B>
   38   Passing a non-null Object[] or Collection arguments to refreshAll that
   39   contain null elements will have the documented behavior for non-null elements, and the null
   40   elements will be ignored.
   41   
   42    */
   43   
   44   public class CallingRefreshAllWithCollectionContainingNulls extends PersistenceManagerTest {
   45   
   46       /** */
   47       private static final String ASSERTION_FAILED = 
   48           "Assertion A12.5-12 (CallingRefreshAllWithCollectionContainingNulls) 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(CallingRefreshAllWithCollectionContainingNulls.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 testCallingRefreshAllWithCollectionContainingNulls() {
   67       	pm = getPM();  
   68       	createObjects(pm);
   69       	runTestRefreshAll1(pm);
   70       	runTestRefreshAll2(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 (2,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 refreshAll (Collection col1) */
   99       private void runTestRefreshAll1(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.refreshAll(col1);
  111           	if (debug) logger.debug(" \nPASSED in testRefreshAll1()");
  112           	tx.rollback();
  113           }
  114           finally {
  115           	if (tx.isActive())
  116           		tx.rollback();
  117           }
  118       }
  119   
  120   
  121       /* test refreshAll (Object[] objArray) */
  122       private void runTestRefreshAll2(PersistenceManager pm) {
  123           Transaction tx = pm.currentTransaction();
  124           try {           	
  125           	tx.begin();
  126   
  127           	PCPoint p5 = null;
  128           	Collection col1 = new java.util.HashSet();
  129           	col1.add (p3);
  130           	col1.add (p4);
  131           	col1.add (p5);
  132             
  133           	pm.refreshAll(col1.toArray());
  134           	if (debug) logger.debug(" \nPASSED in testRefreshAll2()");
  135           	tx.rollback();
  136           } 
  137           finally {
  138           	if (tx.isActive())
  139           		tx.rollback();
  140           }
  141       }
  142   }

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