/*
 * 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.Enumeration;

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

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

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

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

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

  

    /**
     * test finder method outside a transaction.
     */
    public void testCreatesFindINfoForNumOutTx() throws Exception {
        int found2 = 0;
        int found3 = 0;
        int newval = 14;
        Simple s1 = null;
        Simple s2 = null;
        try {
            s1 = getHome().create("n3", 1001, newval);
            s2 = getHome().create("n4", 1002, 2);
            s2.setNumTest(newval);
            Enumeration list = getHome().findInfoForNum(newval);
            while (list.hasMoreElements()) {
                list.nextElement();
                found2++;
            }
            assertEquals("first try", 2, found2);
        } finally {
            // cleaning
            if (s1 != null) {
                s1.remove();
            }
            if (s2 != null) {
                s2.remove();
            }
        }
    }

  
}
