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


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

    /**
     * URL of the wsWarSample page
     */
    private static final String URL_WSWARSAMPLE = "/wswarsample/";

    /**
     * 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_WsWarSample(testtorun));
        }
    }

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

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

    /**
     * Constructor with a specified name
     * @param s name
     */
    public F_WsWarSample(String s) {
        super(s, URL_WSWARSAMPLE);
    }

    /**
     * Check if home page is accessible
     * @throws Exception if an error occurs
     */
    public void testDeploymentCompleted() throws Exception {
        // 3 links + 3 logo links on homepage
        checkDeploymentCompleted(3+3);
    }

    /**
     * Check if Axis is Running
     * @throws Exception if an error occurs
     */
    public void testAxisServicesAccessible() throws Exception {

        // links to /jaxrpcEndpoint1/* in first place (0)
        checkAxisServicesAccessible(3, "endpoints", "jaxrpc");
    }

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

        // for wsWarSample axis generated WSDL link is in second place (1)
        checkAxisWSDL("endpoints/jaxrpc?JWSDL");
    }

    /**
     * Check if deployed WebService is running
     * @throws Exception if an error occurs
     */
    public void testDeployedWebService() throws Exception {

        this.wc.setAuthorization("jonas", "jonas");
        checkDeployedWebService("jaxrpcTest.jsp",
                                url + "endpoints/jaxrpc",
                                "JOnAS",
                                "JOnAS JaxRpc WebService Test Page");
    }

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

        checkWSDLPublication("MyWebService" + File.separator + "jaxrpcEndpoint.wsdl",
                             "http://ws.servlets.wssample.objectweb.org",
                             "JaxRpcEndpointInterfaceService",
                             "JaxRpcEndpoint1",
                             url + "endpoints/jaxrpc");

    }


}
