/**
 * Tests all of the major functionality of MobyServlet, and calls ACDServlet's
 * main method to ensure classes that only it uses are tested too.
 */

package ca.ucalgary.services.test;

import ca.ucalgary.services.CGIService;
import ca.ucalgary.seahawk.services.MobyClient;
import ca.ucalgary.seahawk.services.test.MobyClientTestCase;

import org.biomoby.service.test.MobyServletTestCase;
import org.biomoby.service.test.ServletTester;
import org.biomoby.shared.MobyDataType;
import org.biomoby.shared.data.*;

import junit.framework.*;

import java.io.*;
import java.net.URL;
import java.util.*;

/**
 * For the testMain cases to be actually successful, the WEB-INF/web.xml 
 * file must be one with all the CGI parameters...
 */
public class CGIServiceTestCase extends MobyServletTestCase{
    private final static String CGITEST_CLASS_NAME = "ca.ucalgary.services.CGIService";
    //private final static String CGITEST_MOBY_XML = "ca/ucalgary/services/test/mobyDNASeq.xml";
    private final static String CGITEST_MOBY_XML = "ca/ucalgary/services/test/mobyKeyword.xml";

    public CGIServiceTestCase(String name){
	super(name);
    }
    
    // Next two methods used by testMain in MobyServlet
    protected URL getExampleURL(){
	URL testDataURL = getClass().getClassLoader().getResource(CGITEST_MOBY_XML);
	if(testDataURL == null){
	    fail("Could not find test data resource (" + CGITEST_MOBY_XML + 
		 "), please make sure your class path is specified correctly");
	}
	return testDataURL;
    }

    protected String getExampleClass(){
	return CGITEST_CLASS_NAME;
    }

    /**
     * @return a test suite for all the test methods of this test case.
     * We do a bunch of tests, not just of this class, but ones it depends on, so that
     * we can use Minnow create a self-contained WAR of only the classes 
     * required to run CGI services.
     */
    public static Test suite() {

	TestSuite suite = new TestSuite();
 	suite.addTest(new CGIServiceTestCase("testMain"));  // for network access test in Moby Servlet

 	suite.addTest(new LegacyServiceTestCase("testBinaryRegex"));
	suite.addTest(new MobyClientTestCase("testMemberInheritance"));

 	suite.addTest(new MobyServletTestCase("testRDF"));
 	suite.addTest(new MobyServletTestCase("testRequestChain")); 
 	suite.addTest(new MobyServletTestCase("testSecondaryParams"));
 	suite.addTest(new MobyServletTestCase("testServletTester"));
        return suite;
    }

    public static void main(String[] args){
	junit.textui.TestRunner.run(suite());
    }
}
