All Downloads are FREE. Search and download functionalities are using the official Maven repository.

msv.msv.test.batch.model.TestReader Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package batch.model;

import java.io.File;
import java.io.FilenameFilter;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.SAXParserFactory;

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

/**
 * Parses a directory into the test suite.
 * 
 * This object will enumerate test files, and TestBuilder will create
 * actual test cases.
 * 
 * @author
 *    Kohsuke KAWAGUCHI
 */
public class TestReader
{
    public TestReader( TestBuilder _builder ) {
        this.builder = _builder;
    }

    private final TestBuilder builder;
    

    
    /**
     * Obtains a test object from a schema file (e.g., abc.rng) and
     * its instance documents.
     */
    public Test parseSchema( File schema ) throws Exception {

        String schemaName = schema.getName();
        File parent = new File(schema.getParent());
        
        final String prefix = schemaName.substring(0, schemaName.lastIndexOf('.')+1);
        final boolean isCorrect = schemaName.indexOf(".e.")==-1;
        
        if(isCorrect) {
            TestSuite suite = new TestSuite();
            
            suite.addTest( builder.createCorrectSchemaTest(schema) );
                
            // collects test instances.            
            String[] instances = parent.list( new FilenameFilter(){ 
                public boolean accept( File dir, String name ) {
                    return name.startsWith(prefix) && name.endsWith(".xml");
                }
            } );
            
            if( instances!=null ) {
                for( int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy