/*
 * Created on Nov 17, 2004
 * Copyright (C) Andrea Schweer, 2004
 *
 * This file is part of the Greenstone Alerting Service.
 * Refer to the COPYING file in the base directory of this package
 * for licensing information.
 */
package org.greenstone.gsdlas;

import java.net.URL;
import java.util.Set;

import junit.framework.TestCase;

/**
 * @author schweer
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class GreenstoneCommunicatorTest extends TestCase {

    private GreenstoneCommunicator gsComm;
    
    public static void main(String[] args) {
        junit.textui.TestRunner.run(GreenstoneCommunicatorTest.class);
    }
    
    protected void setUp() throws Exception {
        URL host;
        try {
            host = new URL("http://localhost:8080/soap/servlet/rpcrouter");
            gsComm = new GreenstoneCommunicator(host);
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }
    
    public final void testGetSiteList() {
        String[] sites;
        try {
            sites = gsComm.getCollectionNames();
            for (int i = 0; i < sites.length; i++) {
                System.out.println(sites[i]);
                
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }
    
    public final void testSupportsFullTextSearch() {
        try {
            assertTrue(gsComm.supportsTextSearch("gs2mgppdemo"));
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }
    
    public final void testFullTextSearch() {
        try {
            Set result = gsComm.fullTextSearch("gs2mgppdemo", "Burundi");
            assertEquals(14, result.size());
            assertTrue(result.contains("HASH4632a8a51d33c47a75c559.7.1"));
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }

}
