/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999-2005 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 1any 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.examples.clients.webservices;


import java.io.File;

import junit.framework.TestSuite;

import com.meterware.httpunit.WebResponse;

/**
 * Define a class to test the webServices examples
 * Test WebServices deployment OK and test Call on deployed WebService
 * @author Guillaume Sauthier
 */
public class F_WsEarSample extends A_WebServicesEndpoint {

    /**
     * URL of the wsEarSample page
     */
    private static final String URL_WSEARSAMPLE = "/axis-ws/";

    /**
     * The username to use for the webapp
     */
    private static final String USERNAME = "jonas";

    /**
     * The password to use for teh webapp
     */
    private static final String PASSWORD = "jonas";

    /**
     * Main method
     * @param args the arguments
     */
    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_WsEarSample(testtorun));
        }
    }

    /**
     * Get a new TestSuite for this class
     * @return a new TestSuite for this class
     */
    public static TestSuite suite() {
        return new TestSuite(F_WsEarSample.class);
    }

    /**
     * Setup need for these tests
     * earsample is required
     * @throws Exception if it fails
     */
    protected void setUp() throws Exception {
        super.setUp();
        useEar("ws");
    }

    /**
     * Constructor with a specified name
     * @param s name
     */
    public F_WsEarSample(String s) {
        super(s, URL_WSEARSAMPLE, USERNAME, PASSWORD);
    }

    /**
     * Check if services page is accessible
     * @throws Exception if an error occurs
     */
    public void testDeploymentCompleted() throws Exception {

        WebResponse wr = wc.getResponse(url + "services1/webservice");
        assertNotNull("no homepage", wr);
    }

    /**
     * Check if WSDL is generated
     * @throws Exception if an error occurs
     */
    public void testAxisWSDL() throws Exception {

        // for wsEarSample axis generated WSDL link is in second place (1)
        checkAxisWSDL("services1/webservice?JWSDL");
    }

    /**
     * Check if WSDL has been published
     * @throws Exception if an error occurs
     */
    public void testWSDLPublication() throws Exception {

        checkWSDLPublication("My Web Services" + File.separator + "ssbEndpoint.wsdl",
                             "http://ws.beans.wssample.objectweb.org",
                             "WSBeanEndpointLocalService",
                             "WSBeanEndpointLocal",
                             url + "services1/webservice");
    }


}
