/*
 * 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 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
 *
 * Initial developer: Florent BENOIT
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.examples.clients.webservices;


import org.objectweb.jonas.examples.util.JExampleTestCase;

import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebLink;
import com.meterware.httpunit.WebResponse;

/**
 * Define an abstract class to test the webServices examples
 * @author Guillaume Sauthier
 */
public abstract class A_WebServices extends JExampleTestCase {

    public A_WebServices(String s, String urlPrefix) {
        super(s, urlPrefix);
    }

    public A_WebServices(String s, String urlPrefix, String username, String password){
    	super(s, urlPrefix, username, password);
    }
    
    /**
     * Check if home page is accessible
     * @throws Exception if an error occurs
     */
    public void checkDeploymentCompleted(int nbHomePageLinks) throws Exception {
        WebResponse wr = wc.getResponse(url + "index.html");
        WebLink[] links = wr.getLinks();
        assertEquals("deployment OK", nbHomePageLinks, links.length);
    }

    public WebResponse executeGoogleWebService(String page, String query) throws Exception {

        WebResponse wr = wc.getResponse(url + page);

        WebForm form = wr.getForms()[0];
        // set Search Query
        form.setParameter("search", query);
        return form.submit();
    }
}
