Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.api.persistencecapable » [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.persistencecapable;
   19   
   20   import javax.jdo.JDOHelper;
   21   import javax.jdo.PersistenceManager;
   22   import javax.jdo.spi.PersistenceCapable;
   23   
   24   import org.apache.jdo.tck.JDO_Test;
   25   
   26   /**
   27    * This class is the super class for all persistence-capable tests. 
   28    * @author Michael Watzek
   29    */
   30   abstract class AbstractPersistenceCapableTest extends JDO_Test {
   31   
   32       /**
   33        * Makes the given object persistent, 
   34        * adds it as tear down instance,
   35        * and returns its object id.
   36        * @param pc the transient instance to be made persistent 
   37        * @return the object id of the persistent instance
   38        */
   39       protected Object makePersistent(Object pc) {
   40           addTearDownClass(pc.getClass());
   41           PersistenceManager pm = getPM();
   42           pm.currentTransaction().begin();
   43           pm.makePersistent(pc);
   44           Object result = JDOHelper.getObjectId(pc);
   45           pm.currentTransaction().commit();
   46           return result;
   47       }
   48       
   49       protected boolean isTestToBePerformed() {
   50           String testName = getClass().getName();
   51           if (!isBinaryCompatibilitySupported()) {
   52               printUnsupportedOptionalFeatureNotTested(
   53                       testName, "javax.jdo.option.BinaryCompatibility");
   54           } else if (!isApplicationIdentitySupported()) {
   55               printUnsupportedOptionalFeatureNotTested(
   56                       testName, "javax.jdo.option.ApplicationIdentity");
   57           }
   58           return isBinaryCompatibilitySupported() &&
   59                  isApplicationIdentitySupported() &&
   60                  runsWithApplicationIdentity();
   61       }
   62       
   63       protected void assertPersistenceCapable(Object o) {
   64           if (!(o instanceof PersistenceCapable)) {
   65               throw new IllegalArgumentException
   66                   ("Argument o must be instance of PersistenceCapable.");
   67           }
   68       }
   69   }

Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.api.persistencecapable » [javadoc | source]