package org.treesched.regression;

import java.io.File;

import junit.framework.Test;
import junit.framework.TestResult;
import junit.framework.TestSuite;

import org.oddjob.arooa.AbstractArooaComponent;
import org.oddjob.arooa.SimpleObjectFactory;
import org.oddjob.arooa.XMLDefinitionHelper;

/**
 * 
 */
public class ScheduleTester extends AbstractArooaComponent
implements Test {

	protected TestSuite suite;
	protected int count = 0;

	public void addConfiguredTest(SingleTestSchedule test )  {
		suite.addTest(test);
		++count;	    
	}
	
	public ScheduleTester(String configFile) throws Exception {
		
		suite = new TestSuite("Test for " + configFile);
		
        File buildFile = new File(configFile);
                
        XMLDefinitionHelper xmlHelper = new XMLDefinitionHelper();
        SimpleObjectFactory objectFactory = new SimpleObjectFactory();        
        xmlHelper.parse(buildFile, "schedule-tester", this);
        getRuntimeConfigurable().maybeConfigure(true);
	}

	public int countTestCases() {
		return count;
	}
	
	public void run(TestResult result) {
		suite.run(result);
	}
	
	protected TestSuite getSuite() {
		return suite;
	}

	public static Test suite() throws Exception {
		try {
		    ScheduleTester test = new ScheduleTester("./test/conf/daily_schedule_test.xml");		
			return test.getSuite();
		} catch (Exception e) {
		    e.printStackTrace();
		    throw e;
		}
	}	
}
