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.JDONullIdentityException;
   21   import javax.jdo.identity.SingleFieldIdentity;
   22   import javax.jdo.spi.PersistenceCapable;
   23   
   24   import org.apache.jdo.tck.pc.singlefieldidentity.AbstractPCPointSingleField;
   25   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldByte;
   26   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldCharacter;
   27   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldDate;
   28   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldInteger;
   29   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldLong;
   30   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldPrimitivebyte;
   31   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldPrimitivechar;
   32   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldPrimitiveint;
   33   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldPrimitivelong;
   34   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldPrimitiveshort;
   35   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldShort;
   36   import org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldString;
   37   import org.apache.jdo.tck.util.BatchTestRunner;
   38   
   39   /**
   40    *<B>Title:</B>NewObjectIdInstance of PersistenceCapable
   41    *<BR>
   42    *<B>Keywords:</B> persistencecapable
   43    *<BR>
   44    *<B>Assertion IDs:</B> A7.12-38, A7.12-39
   45    *<BR>
   46    *<B>Assertion Description: </B>
   47    *<p>
   48    * A7.12-38:<br>
   49    * For classes using single field identity method 
   50    * <code>PersistenceCapable.newObjectIdInstance()</code> must be called 
   51    * on a persistent instance with its primary key field initialized, 
   52    * or a JDONullIdentityException is thrown.<p>
   53    * 
   54    * A7.12-39:<br>
   55    * The instance returned is initialized with the value of the primary key 
   56    * field of the instance on which the method is called.
   57    * 
   58    * @author Michael Watzek
   59    */
   60   public class NewObjectIdInstance extends AbstractPersistenceCapableTest {
   61   
   62       /** */
   63       private static final String FAILED = 
   64           " (jdoNewObjectIdInstance) failed: ";
   65   
   66       /** */
   67       private static final String ASSERTION_A7_12_38_FAILED = 
   68           "Assertion A7.12-38" + FAILED;
   69   
   70       /** */
   71       private static final String ASSERTION_A7_12_39_FAILED = 
   72           "Assertion A7.12-39" + FAILED;
   73   
   74       /**
   75        * The <code>main</code> is called when the class
   76        * is directly executed from the command line.
   77        * @param args The arguments passed to the program.
   78        */
   79       public static void main(String[] args) {
   80           BatchTestRunner.run(NewObjectIdInstance.class);
   81       }
   82   
   83       public void testSingleFieldIdentityNotInitializedByte() {
   84           if (isTestToBePerformed()) {
   85               singleFieldIdentityNotInitialized(new PCPointSingleFieldByte());
   86           }
   87       }
   88       
   89       public void testSingleFieldIdentityNotInitializedCharacter() {
   90           if (isTestToBePerformed()) {
   91               singleFieldIdentityNotInitialized(new PCPointSingleFieldCharacter());
   92           }
   93       }
   94       
   95       public void testSingleFieldIdentityNotInitializedInteger() {
   96           if (isTestToBePerformed()) {
   97               singleFieldIdentityNotInitialized(new PCPointSingleFieldInteger());
   98           }
   99       }
  100       
  101       public void testSingleFieldIdentityNotInitializedLong() {
  102           if (isTestToBePerformed()) {
  103               singleFieldIdentityNotInitialized(new PCPointSingleFieldLong());
  104           }
  105       }
  106       
  107       public void testSingleFieldIdentityNotInitializedShort() {
  108           if (isTestToBePerformed()) {
  109               singleFieldIdentityNotInitialized(new PCPointSingleFieldShort());
  110           }
  111       }
  112       
  113       public void testSingleFieldIdentityNotInitializedString() {
  114           if (isTestToBePerformed()) {
  115               singleFieldIdentityNotInitialized(new PCPointSingleFieldString());
  116           }
  117       }
  118   
  119       public void testSingleFieldIdentityNotInitializedDate() {
  120           if (isTestToBePerformed()) {
  121               singleFieldIdentityNotInitialized(new PCPointSingleFieldDate());
  122           }
  123       }
  124   
  125       public void testSingleFieldIdentityInitializedbyte() {
  126           if (isTestToBePerformed()) {
  127               singleFieldIdentityInitialized(new PCPointSingleFieldPrimitivebyte(1, 2));
  128           }
  129       }
  130       
  131       public void testSingleFieldIdentityInitializedByte() {
  132           if (isTestToBePerformed()) {
  133               singleFieldIdentityInitialized(new PCPointSingleFieldByte(1, 2));
  134           }
  135       }
  136       
  137       public void testSingleFieldIdentityInitializedchar() {
  138           if (isTestToBePerformed()) {
  139               singleFieldIdentityInitialized(new PCPointSingleFieldPrimitivechar(1, 2));
  140           }
  141       }
  142       
  143       public void testSingleFieldIdentityInitializedCharacter() {
  144           if (isTestToBePerformed()) {
  145               singleFieldIdentityInitialized(new PCPointSingleFieldCharacter(1, 2));
  146           }
  147       }
  148       
  149       public void testSingleFieldIdentityInitializedint() {
  150           if (isTestToBePerformed()) {
  151               singleFieldIdentityInitialized(new PCPointSingleFieldPrimitiveint(1, 2));
  152           }
  153       }
  154       
  155       public void testSingleFieldIdentityInitializedInteger() {
  156           if (isTestToBePerformed()) {
  157               singleFieldIdentityInitialized(new PCPointSingleFieldInteger(1, 2));
  158           }
  159       }
  160       
  161       public void testSingleFieldIdentityInitializedlong() {
  162           if (isTestToBePerformed()) {
  163               singleFieldIdentityInitialized(new PCPointSingleFieldPrimitivelong(1, 2));
  164           }
  165       }
  166       
  167       public void testSingleFieldIdentityInitializedLong() {
  168           if (isTestToBePerformed()) {
  169               singleFieldIdentityInitialized(new PCPointSingleFieldLong(1, 2));
  170           }
  171       }
  172       
  173       public void testSingleFieldIdentityInitializedshort() {
  174           if (isTestToBePerformed()) {
  175               singleFieldIdentityInitialized(new PCPointSingleFieldPrimitiveshort(1, 2));
  176           }
  177       }
  178       
  179       public void testSingleFieldIdentityInitializedShort() {
  180           if (isTestToBePerformed()) {
  181               singleFieldIdentityInitialized(new PCPointSingleFieldShort(1, 2));
  182           }
  183       }
  184       
  185       public void testSingleFieldIdentityInitializedString() {
  186           if (isTestToBePerformed()) {
  187               singleFieldIdentityInitialized(new PCPointSingleFieldString(1, 2));
  188           }
  189       }
  190   
  191       public void testSingleFieldIdentityInitializedDate() {
  192           if (isTestToBePerformed()) {
  193               singleFieldIdentityInitialized(new PCPointSingleFieldDate(1, 2));
  194           }
  195       }
  196   
  197       /**
  198        * The common method for test cases checking for assertion A7.12-38:<br>
  199        * For classes using single field identity method 
  200        * <code>PersistenceCapable.newObjectIdInstance()</code> must be called 
  201        * on a persistent instance with its primary key field initialized, 
  202        * @param o the object to check
  203        */
  204       private void singleFieldIdentityNotInitialized(AbstractPCPointSingleField o) {
  205           assertPersistenceCapable(o);
  206           PersistenceCapable pc = (PersistenceCapable) o;
  207           try {
  208               Object sfi = pc.jdoNewObjectIdInstance();
  209               String message = ASSERTION_A7_12_38_FAILED + 
  210               "pc.jdoNewObjectIdInstance should throw " +
  211               "JDONullIdentityException if PK field is null, but it returned "+sfi;
  212               fail(message);
  213           } catch (JDONullIdentityException e) {
  214               // expected exception
  215               if (debug)
  216                   logger.debug("caught expected exception " + e.toString());
  217           } 
  218       }
  219       
  220       /**
  221        * The common method for test cases checking for assertion A7.12-39:<br>
  222        * The instance returned is initialized with the value of the primary key 
  223        * field of the instance on which the method is called.
  224        * @param o the persistent instance to check
  225        */
  226       private void singleFieldIdentityInitialized(AbstractPCPointSingleField o) {
  227           assertPersistenceCapable(o);
  228           makePersistent(o);
  229           PersistenceCapable pc = (PersistenceCapable) o;
  230           SingleFieldIdentity sfi = 
  231               (SingleFieldIdentity) pc.jdoNewObjectIdInstance();
  232           if (!o.equalsPKField(sfi)) {
  233               fail(ASSERTION_A7_12_39_FAILED + 
  234                       "pc.jdoNewObjectIdInstance() returned unexpected " +
  235                       "single field identity object id.");
  236           }
  237       }
  238   }

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