/*
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2004 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 javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.objectweb.jonas.jtests.beans.relation.tier.TestFacade;
import org.objectweb.jonas.jtests.beans.relation.tier.TestFacadeHome;
import org.objectweb.jonas.jtests.util.JTestCase;



/**
 * This is a test suite on CMP 2 and EJBQL.
 * @author Helene Joanin
 */
public class F_TierEC2 extends JTestCase {

    private static TestFacadeHome facadeHome = null;

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

    protected boolean isInit = false;

    protected void setUp() {
        super.setUp();
        if (!isInit) {
            useBeans("tier", true);
            try {
                facadeHome = (TestFacadeHome)
                    PortableRemoteObject.narrow(ictx.lookup("Rel_Tier_TestFacadeHomeRemote"),
                                                TestFacadeHome.class);
            } catch (NamingException e) {
                fail("Cannot get bean home: " + e.getMessage());
            }
            isInit = true;
        }
    }

    /**
     * Test the findByTiemorOrTiephy method.
     * @throws Exception
     */
    public void testFindByTiemorOrTiephy() throws Exception {
        Collection c;
        TestFacade facade = facadeHome.create();
        c = facade.tierfindByTiemorOrTiephy("none");
        assertEquals("Number of 'none' Tier: ", 0, c.size());
        c = facade.tierfindByTiemorOrTiephy("helene joanin");
        assertEquals("Number of 'helene joanin' Tier: ", 1, c.size());
    }
    
    protected boolean initStateOK() throws Exception {
        return true;
    }

    public static Test suite() {
        return new TestSuite(F_TierEC2.class);
    }

    public static void main (String args[]) {
        String testtorun = null;
        // Get args
        for (int argn = 0; argn < args.length; argn++) {
            String sarg = args[argn];
            if (sarg.equals("-n")) {
                testtorun = args[++argn];
            }
        }
        if (testtorun == null) {
            junit.textui.TestRunner.run(suite());
        } else {
            junit.textui.TestRunner.run(new F_TierEC2(testtorun));
        }
    }
}
