/*
 * 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 javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.objectweb.jonas.jtests.beans.fbasic.SimpleHome;
import org.objectweb.jonas.jtests.beans.fbasic.Simple;
import java.util.Enumeration;

/**
 * This set of test are basic tests on CMP entity home interface.
 * Only specific tests to CMP are here, all tests common to CMP and BMP
 * are in the inherited class A_BasicHomeInterface.
 * @author Philippe Coq, Philippe Durieux, Helene Joanin. (jonas team)
 */
public abstract class B_BasicHomeInterfaceEC extends B_BasicHomeInterface {

    public B_BasicHomeInterfaceEC(String name) {
        super(name);
    }
   
  
    // --------------------------------------------------------------------
    // tests on clause where for CMP finder methods
    // These tests are specific to CMP 
    // ---------------------------------------------------------------------

    /**
     * testFinderBetween  verify a finder method that return a Enumeration
     * whith a where clause :
     *  where ?1 <= c_info and c_info <= ?2 and ?1 <= c_numtest and c_numtest <= ?2
     * the purpose of this test is to verify the correct interpretation of parameters
     * ?1 ?2
     */
    public void testFinderBetween() throws Exception {
        int value = 991959;
        getHome().create("991959_1", value, value);
        getHome().create("991959_2", value, value);
        Simple entity = null;
        Enumeration eList = null;
        eList = getHome().findInfo_beetwen(value, value);
        int nb = 0;
        while (eList.hasMoreElements()) {
            entity = (Simple) javax.rmi.PortableRemoteObject.narrow(eList.nextElement(), Simple.class);
            nb++;
            assertEquals("Wrong Info value", entity.getInfo(), value);
            assertEquals("Wrong NumTest value", entity.getNumTest(), value);
        }
        assertEquals("Wrong number of entities found", 2, nb);
        getHome().remove("991959_1");
        getHome().remove("991959_2");
    }

  public void testFinderBetweenSansVerif() throws Exception {
        int value = 991959;
        getHome().create("991959_1", value, value);
        getHome().create("991959_2", value, value);
        Simple entity = null;
        Enumeration eList = null;
        eList = getHome().findInfo_beetwen(value, value);
        
        getHome().remove("991959_1");
        getHome().remove("991959_2");
    }


   // juste pour voir

    public void testCreateRemoveFinderBetween() throws Exception {
        int value = 991959;
        getHome().create("991959_1", value, value);
        getHome().create("991959_2", value, value);
        Simple entity = null;
        Enumeration eList = null;
        
        getHome().remove("991959_1");
        getHome().remove("991959_2");
    }
    /**
     * testFinderEqualOne  verify a finder method that return a Enumeration
     * whith a where clause :
     *   where c_info = ?1 and c_numtest = ?1
     * the object of this test is to verify the correct interpretation of parameters
     * ?1 ?2
     */
    public void testFinderEqualOne() throws Exception {
        Simple entity = null;
        Enumeration eList = null;
        eList = getHome().findEqualOne(80);
        int nb = 0;
        while (eList.hasMoreElements()) {
            entity = (Simple) javax.rmi.PortableRemoteObject.narrow(eList.nextElement(), Simple.class);
            nb++;
            assertEquals(80, entity.getInfo());
            assertEquals(80, entity.getNumTest());
        }
        assertEquals(2, nb);
    }

    /**
     * testFinderEqualTwo  verify a finder method that return a Enumeration
     * whith a where clause :
     *   where c_info = ? and c_numtest = ?
     * the object of this test is to verify the correct interpretation of parameters
     * ?1 ?2
     */
    public void testFinderEqualTwo() throws Exception {
        Simple entity = null;
        Enumeration eList = null;
        eList = getHome().findEqualTwo(100, 90);
        int nb = 0;
        while (eList.hasMoreElements()) {
            entity = (Simple) javax.rmi.PortableRemoteObject.narrow(eList.nextElement(), Simple.class);
            nb++;
            assertEquals(100, entity.getInfo());
            assertEquals(90, entity.getNumTest());
        }
        assertEquals(1, nb);
    }

}

