Hi,

I'm trying to come up with a simple test template for a JDO TCK test. I need your feedback. I've attached a draft, half-cooked. (I have done nothing yet with the test method and helper method.)

Up to the point where the test method begins, I've put in replaceable kewords:
PACKAGE
TEST_SUPERCLASS
TITLE
KEYWORDS
ASSERTION_ID
ASSERTION_TEXT
TEST_NAME
PC_CLASS
I plan to provide instructions on replacing these items with appropriate test.

**Is this useful?

**Should we attempt to include any sample code in the test method? Or should we leave it empty and provide an external text description with some pointers on writing test code?

I thought of providing more documentation in template.java, but I decided against it for two reasons: -. I want the template to be easily editable, without a lot of extra stuff that needs to be deleted. -. People inevitably leave boilerplate comments in the document they are editing and I want to avoid that by not putting any in.

I welcome your comments and suggestions.

-- Michelle
/*
 * Copyright 2005 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
 
package org.apache.jdo.tck.PACKAGE;

import org.apache.jdo.tck.TEST_SUPERCLASS;

/**
 *<B>Title:</B> Test TITLE
 *<BR>
 *<B>Keywords:</B> KEWORDS
 *<BR>
 *<B>Assertion IDs:</B> ASSERTION_ID
 *<BR>
 *<B>Assertion Description: </B>
 ASSERTION_TEXT
 */

public class TEST_NAME extends TEST_SUPERCLASS {

    /** */
    private static final String ASSERTION_FAILED = 
        "Assertion ASSERTION_ID (TEST_NAME) failed: ";
    
    /**
     * The <code>main</code> is called when the class
     * is directly executed from the command line.
     * @param args The arguments passed to the program.
     */
    public static void main(String[] args) {
        BatchTestRunner.run(TEST_NAME.class);
    }

    /**
     * @see JDO_Test#localSetUp()
     */
    protected void localSetUp() {
        addTearDownClass(PC_CLASS.class);
    }
    
    /** */
    public void test() {
        if (!isApplicationIdentitySupported()) {
            printUnsupportedOptionalFeatureNotTested(
                    "HollowInstanceMaintainsPK", 
                    "javax.jdo.option.ApplicationIdentity");
        } else if (!runsWithApplicationIdentity()) {
            printNonApplicableIdentityType(
                    "HollowInstanceMaintainsPK", 
                    "javax.jdo.option.ApplicationIdentity");
        }
        else {
            pm = getPM();
            pm.currentTransaction().begin();

            PCRect obj = getPersistentNewInstance();
            long beforeValue=obj.getId();
            pm.currentTransaction().commit(); // obj should transition to HOLLOW
            //The next call obj.getId() is a primary key access.
            //The method must not be called inside a transaction,
            //because a JDO implementation must allow primary key accesses
            //outside of transactions.
            long afterValue=obj.getId();
            if (beforeValue!=afterValue) {
                fail(ASSERTION_FAILED,
                     "Key field value incorrect after commit. Expected: " + 
                     beforeValue + " Found: " + afterValue);
            }
        }
    }

    /** */
    private PCRect getPersistentNewInstance() {
        PCRect obj = new PCRect(0, new PCPoint(1,5), new PCPoint(7,3));
        pm.makePersistent(obj); // obj should transition to persistent-new
        int curr = currentState(obj);
        if( curr != PERSISTENT_NEW ){
            fail(ASSERTION_FAILED,
                 "StateTransitions: Unable to create persistent-new instance " +
                 "from transient instance via makePersistent(), state is " +
                 states[curr]);
        }
        return obj;
    }

}

Reply via email to