/*
 * 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 org.objectweb.jonas.jtests.beans.annuaire.Personne;
import org.objectweb.jonas.jtests.beans.annuaire.PersonneHome;
import org.objectweb.jonas.jtests.util.JTestCase;


/**
 * This is an advanced test suite for home interface on entity bean CMP.
 * Beans used: annuaire
 * @author Philippe Coq, Philippe Durieux, Helene Joanin (jonas team)
 */
public abstract class B_AdvancedHomeEC extends JTestCase {

    String mynum = "638";
    String myname = "Philippe Durieux";

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

    protected void setUp() {
        super.setUp();
        useBeans("annuaire", true);
    }

    /**
     * return PersonneHome, that can be either CMP v1 or CMP v2 bean.
     */
    abstract public PersonneHome getHome();


    /**
     * test a simple Remove
     * Find an instance already in database and remove it.
     */
    public void testFindbynomRemoveCreate() throws Exception {
        Personne p = getHome().findByNom("Adriana Danes");
        p.remove();
        getHome().create("Adriana Danes", "777"); // cleaning
      
    }

  

    /**
     * Test create + remove in transactions
     */
    public void testCreateRemoveInTx() throws Exception {
        for (int i = 0; i < 20; i++) {
            utx.begin();
            try {
                getHome().create("Eric Paire", "500");
                getHome().remove("Eric Paire");
               
            }
            catch (Exception e) {
                fail(e.getMessage());
            }
            finally {
                utx.commit();
            }
        }
    }
}

