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

import junit.framework.Test;
import junit.framework.TestSuite;
import javax.rmi.PortableRemoteObject;

/**
 * This TestCase is a set of multithreaded clients accessing concurrently
 * the set of accounts.
 */
public class F_multi extends A_multi {

    protected static ManagerHome home = null;
    protected static Manager manager = null;
    protected static boolean initialized = false;

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

    public Manager getManager(){
        return manager;
    }

    public String getManagerHomeName() {
        return "manacManagerHome";
    }

    protected void setUp() throws Exception {
        super.setUp();
        if (home == null) {
            useBeans("manac");
            home = (ManagerHome) PortableRemoteObject.narrow(ictx.lookup(getManagerHomeName()),
                                                             ManagerHome.class);
        }
        if (manager == null) {
            manager = home.create(initialValue);
        }
        if (!initialized) {
            // Initializes the test by creating 20 accounts
            System.out.println("creating "+accounts+" accounts");
            getManager().createAll(accounts);
            initialized = true;
        } 
        threadfail = false;
    }

    protected void tearDown() throws Exception {
        super.tearDown();
        if (threadfail) {
            initialized = false;
        }
        if (manager != null) {
            manager.reinitAll();
            manager.remove();
            manager = null;
        }
    }

    public static Test suite() {
        return new TestSuite(F_multi.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_multi(testtorun));
        }
    }
}
