protected boolean runOneTest()

in java/src/org/apache/qetest/xsl/XSLTestHarness.java [364:467]


    protected boolean runOneTest(String testName, Properties hProps)
    {
        // Report on what we're about to do
        reporter.testCaseInit("runOneTest:" + testName);

        // Validate our basic arguments
        if ((testName == null) || (testName.length() == 0) || (hProps == null))
        {
            reporter.checkErr("runOneTest called with bad arguments!");
            reporter.testCaseClose();
            return false;
        }

        // Calculate just the ClassName of the test for later use as the logFile name
        String bareClassName = null;
        StringTokenizer st = new StringTokenizer(testName, ".");
        for (bareClassName = st.nextToken(); st.hasMoreTokens(); bareClassName = st.nextToken())
        { /* empty loop body */
        }
        st = null; // no longer needed

        // Validate that the output directory exists for the test to put it's results in
        String testOutDir = hProps.getProperty(FileBasedTest.OPT_OUTPUTDIR);
        if ((testOutDir == null) || (testOutDir.length() == 0))
        {
            // Default to current dir plus the bareClassName if not set
            testOutDir = new String("." + File.separator + bareClassName);
        }
        else
        {
            // Append the bareClassName so different tests don't clobber each other
            testOutDir += File.separator + bareClassName;
        }
        File oDir = new File(testOutDir);
        if (!oDir.exists())
        {
            if (!oDir.mkdirs())
            {
                // Report this but keep going anyway
                reporter.logErrorMsg("Could not create testOutDir: " + testOutDir);
            }
        }
        // no longer needed
        oDir = null;

        // Validate we can instantiate the test object itself
        reporter.logTraceMsg("About to newInstance(" + testName + ")");
        FileBasedTest test = null;
        try
        {
            Class testClass = Class.forName(testName);
            test = (FileBasedTest)testClass.newInstance();
        }
        catch (Exception e1)
        {
            reporter.checkErr("Could not create test, threw: " + e1.toString());
            reporter.logThrowable(reporter.ERRORMSG, e1, "Could not create test, threw");
            reporter.testCaseClose();
            return false;
        }

        // Create a properties block for the test and pre-fill it with custom info
        //      Start with the harness' properties, and then replace certain values
        Properties testProps = (Properties)hProps.clone();
        testProps.put(FileBasedTest.OPT_OUTPUTDIR, testOutDir);
        testProps.put(Logger.OPT_LOGFILE, testOutDir + LOG_EXTENSION);

        // Disable the ConsoleReporter for the *individual* tests, it's too confusing
        testProps.put("noDefaultReporter", "true");
        reporter.logHashtable(reporter.INFOMSG, testProps, "testProps before test creation");

        // Initialize the test with the properties we created
        test.setProperties(testProps);
        boolean testInit = test.initializeFromProperties(testProps);
        reporter.logInfoMsg("Test(" + testName + ").initializeFromProperties() = " + testInit);

        // -----------------
        // Execute the test!
        // -----------------
        boolean runTestStat = test.runTest(testProps);

        // Report where the test stored it's results - future use 
        //  by multiViewResults.xsl or some other rolledup report
        // Note we should really handle the filenames here better, 
        //  especially for relative vs. absolute issues
        Hashtable h = new Hashtable(2);
        h.put("result", reporter.resultToString(test.getReporter().getCurrentFileResult()));
        h.put("fileRef", (String)testProps.get(Logger.OPT_LOGFILE));
        reporter.logElement(reporter.WARNINGMSG, "resultsfile", h, test.getTestDescription());
        h = null; // no longer needed

        // Call worker method to actually calculate the result and call check*()        
        logTestResult(bareClassName, test.getReporter().getCurrentFileResult(), 
                      runTestStat, test.getAbortTest());

        // Cleanup local variables and garbage collect, in case tests don't
        //      release all resources or something
        testProps = null;
        test = null;
        logMemory();    // Side effect: System.gc()
        
        reporter.testCaseClose();
        return runTestStat;
    }