TestReplayer.java :  » Testing » jacareto » jacareto » replay » Java Open Source

Java Open Source » Testing » jacareto 
jacareto » jacareto » replay » TestReplayer.java
/*
 * Jacareto Copyright (c) 2002-2005
 * Applied Computer Science Research Group, Darmstadt University of
 * Technology, Institute of Mathematics & Computer Science,
 * Ludwigsburg University of Education, and Computer Based
 * Learning Research Group, Aachen University. All rights reserved.
 *
 * Jacareto is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * Jacareto is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with Jacareto; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

package jacareto.replay;


import jacareto.struct.StructureElement;
import jacareto.system.Environment;
import jacareto.test.Test;
import jacareto.test.TestReport;
import jacareto.test.TestReportElement;

import org.apache.log4j.Level;

/**
 * A replayer which is responsible for tests.
 *
 * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
 * @version 1.01
 */
public class TestReplayer extends Replayer {
    /** The logger level. */
    private Level loggerLevel;

    /** The String for test failure. */
    private String testFailed;

    /** The String for test success. */
    private String testSucceeded;

    /**
     * Creates a new replayer.
     *
     * @param env the environment
     * @param replay the Replay object
     */
    public TestReplayer (Environment env, Replay replay) {
        super(env, replay);
        loggerLevel = Level.toLevel (customization.getString ("TestReplayer.LogLevel", "ERROR"));
        testFailed = language.getString ("Replayers.TestReplayer.TestFailed");
        testSucceeded = language.getString ("Replayers.TestReplayer.TestSucceeded");
    }

    /**
     * Returns whether this replayer is responsible for the given structure element or not. This is
     * true if the recordable is a {@link jacareto.test.Test}.
     *
     * @param element the structure element
     *
     * @return <code>true</code> if this replayer is responsible for the given element; otherwise
     *         <code>false</code>.
     */
    public boolean handlesElement (StructureElement element) {
        return (element != null) && (element instanceof Test);
    }

    /**
     * Loads the test specifier for the given test element, and starts the testing.
     *
     * @param element the structure element
     *
     * @return DOCUMENT ME!
     */
    public boolean replay (StructureElement element) {
        Test test = (Test) element;

        boolean testResult = test.evaluate (replay.getComponents ());

        if (! testResult) {
            logger.log (loggerLevel, testFailed);
            logger.log (loggerLevel, test.getComponentName () + ":\n");
            logger.log (loggerLevel, test.getEvaluationMessage ());
        } else {
            logger.log (loggerLevel, testSucceeded);
        }

        TestReport testReport = getReplay ().getTestReport ();

        if (testReport != null) {
            testReport.add (new TestReportElement(env, test));
        }

        return testResult || test.isIgnoring ();
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.