/*
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.jtests.clients.entity;

import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.transaction.UserTransaction;

import org.objectweb.jonas.jtests.beans.fbasic.Simple;
import org.objectweb.jonas.jtests.beans.fbasic.SimpleHome;
import org.objectweb.jonas.jtests.util.JTestCase;


/**
 * test cases common to both suites CMP and BMP.
 */
public abstract class B_BasicHomeInterface extends JTestCase {

    protected static SimpleHome home = null;

    public B_BasicHomeInterface(String name) {
        super(name);
    }

    /**
     * init environment:
     * - load beans
     * - create/init database for entities.
     */
    protected void setUp() {
        super.setUp();
        useBeans("fbasic", true);
    }

    /**
     * return SimpleHome, that can be either BMP or CMP bean.
     */
    abstract public SimpleHome getHome();

    /**
     *  testFindByPK verify that findByPrimaryKey find an existing entityBean
     *  pre condition: an element with "pk1" as primary key must exist in the database
     *
     *  findByPrimaryKey("testFindByPK") must pass.
      */
   
 
    public void testFindByPK() throws Exception {
        getHome().findByPrimaryKey("pk1");
      
    }

 
    
    /**
     * testCreateNewEntity verify that we can create a new entityBean 
     * We create a new entity testCreateNewEntity, 20, 6
     * the findByTestName("testCreateNewEntity") must pass and the resulting must be equals to 20
     * pre condition the testCreateNewEntity element must not exist
     * 
      */
    public void testCreateNewEntityFindByNameRemove() throws Exception {
        getHome().create("pk100", 20, 6);
        Simple entity2 = getHome().findByTestName("pk100");
        assertEquals(20, entity2.getInfo());
        // cleaning
        entity2.remove();
      
    }

}
