<commit_before>/*
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 1998-2002 Kana Software, Inc.
// Copyright (C) 2001-2007 <NAME> and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
// jhyde, 21 January, 1999
*/

package mondrian.test;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Enumeration;
import java.util.regex.Pattern;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import mondrian.olap.MondrianProperties;
import mondrian.olap.ParserTest;
import mondrian.olap.Util;
import mondrian.olap.UtilTestCase;
import mondrian.olap.fun.FunctionTest;
import mondrian.olap.fun.SortTest;
import mondrian.olap.fun.CrossJoinTest;
import mondrian.olap.fun.MemberHelperTest;
import mondrian.olap.HierarchyBugTest;
import mondrian.olap.QueryTest;
import mondrian.olap.CellPropertyTest;
import mondrian.rolap.*;
import mondrian.rolap.aggmatcher.*;
import mondrian.test.comp.ResultComparatorTest;
import mondrian.udf.*;
import mondrian.util.*;
import mondrian.xmla.XmlaBasicTest;
import mondrian.xmla.XmlaExcel2000Test;
import mondrian.xmla.XmlaExcelXPTest;
import mondrian.xmla.XmlaErrorTest;
import mondrian.xmla.XmlaCognosTest;
import mondrian.xmla.impl.DynamicDatasourceXmlaServletTest;
import mondrian.xmla.test.XmlaTest;
import mondrian.test.clearview.*;
import mondrian.calc.impl.ConstantCalcTest;

import org.apache.log4j.Logger;

/**
 * Main test suite for Mondrian.
 *
 * <p>The {@link #suite()} method returns a suite which contains all other
 * Mondrian tests.
 *
 * @author jhyde
 * @version $Id$
 */
public class Main extends TestSuite {
    private static final Logger logger = Logger.getLogger(Main.class);

    /**
     * Entry point to run test suite from the command line.
     *
     * @param args Command-line parameters.
     */
    public static void main(String[] args) {
        new Main().runSafe(args);
    }

    /**
     * Runs the suite, catching any exceptions and printing their stack trace.
     *
     * @param args Command-line arguments
     */
    private void runSafe(String[] args) {
        try {
            run(args);
        } catch (Exception e) {
            PrintWriter pw = new PrintWriter(System.out);
            pw.println("mondrian.test.Main received exception:");
            String[] errors = Util.convertStackToString(e);
            for (int i = 0; i < errors.length; i++) {
                pw.println(errors[i]);
            }
            pw.flush();
            System.exit(1);
        }
    }

    /**
     * Creates and runs the root test suite.
     */
    void run(String[] args) throws Exception {
        final MondrianProperties properties = MondrianProperties.instance();
        Test test = suite();
        if (properties.Warmup.get()) {
            System.out.println("Starting warmup run...");
            MondrianTestRunner runner = new MondrianTestRunner();
            TestResult tres = runner.doRun(test);
            if (!tres.wasSuccessful()) {
                System.out.println("Warmup run failed. Regular tests will not be run.");
                System.exit(1);
            }
            System.out.println("Warmup run complete. Starting regular run...");
        }
        MondrianTestRunner runner = new MondrianTestRunner();
        runner.setIterations(properties.Iterations.get());
        System.out.println("Iterations=" + properties.Iterations.get());
        runner.setVUsers(properties.VUsers.get());
        runner.setTimeLimit(properties.TimeLimit.get());
        TestResult tres = runner.doRun(test);
        if (!tres.wasSuccessful())
            System.exit(1);
    }

    /**
     * Creates a TestSuite to test the whole of mondrian. Methods with the
     * signature <code>public static Test suite()</code> are recognized
     * automatically by JUnit test-harnesses; see {@link TestSuite}.
     */
    public static Test suite() throws Exception {
        RolapUtil.checkTracing();
        MondrianProperties properties = MondrianProperties.instance();
        String testName = properties.TestName.get();
        String testClass = properties.TestClass.get();

        System.out.println("testName: " + testName);
        System.out.println("testClass: " + testClass);
        System.out.println("java.version: " + System.getProperty("java.version"));

        TestSuite suite = new TestSuite();
        if (testClass != null && !testClass.equals("")) {
            Class clazz = Class.forName(testClass);

            // use addTestSuite only if the class has test methods
            // Allows you to run individual queries with ResultComparatorTest

            boolean matchTestMethods = false;
            if (Test.class.isAssignableFrom(clazz)) {
                Method[] methods = clazz.getMethods();
                for (int i = 0; i < methods.length && !matchTestMethods; i++) {
                    matchTestMethods = methods[i].getName().startsWith("test");
                }
            }

            if (matchTestMethods) {
                // e.g. testClass = "mondrian.test.FoodMartTestCase",
                // the name of a class which extends TestCase. We will invoke
                // every method which starts with 'test'. (If "testName" is set,
                // we'll filter this list later.)
                suite.addTestSuite(clazz);
            } else {
                // e.g. testClass = "mondrian.olap.fun.BuiltinFunTable". Class
                // does not implement Test, so look for a 'public [static]
                // Test suite()' method.
                Method method = clazz.getMethod("suite", new Class[0]);
                Object target;
                if (Modifier.isStatic(method.getModifiers())) {
                    target = null;
                } else {
                    target = clazz.newInstance();
                }
                Object o = method.invoke(target);
                suite.addTest((Test) o);
            }
        } else {
            suite.addTestSuite(DialectTest.class);
            suite.addTestSuite(MemoryMonitorTest.class);
            suite.addTestSuite(ObjectPoolTest.class);
            suite.addTestSuite(RolapConnectionTest.class);
            suite.addTest(ResultComparatorTest.suite());
            suite.addTestSuite(DrillThroughTest.class);
            suite.addTestSuite(BasicQueryTest.class);
            suite.addTest(CVBasicTest.suite());
            suite.addTest(GrandTotalTest.suite());
            suite.addTest(MetricFilterTest.suite());<commit_msg>MONDRIAN: Moved DialectTest to run after RolapConnectionTest. This is a temporary fix for ResultComparatorTest failure<commit_after>/*
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 1998-2002 Kana Software, Inc.
// Copyright (C) 2001-2007 <NAME> and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
// jhyde, 21 January, 1999
*/

package mondrian.test;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Enumeration;
import java.util.regex.Pattern;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import mondrian.olap.MondrianProperties;
import mondrian.olap.ParserTest;
import mondrian.olap.Util;
import mondrian.olap.UtilTestCase;
import mondrian.olap.fun.FunctionTest;
import mondrian.olap.fun.SortTest;
import mondrian.olap.fun.CrossJoinTest;
import mondrian.olap.fun.MemberHelperTest;
import mondrian.olap.HierarchyBugTest;
import mondrian.olap.QueryTest;
import mondrian.olap.CellPropertyTest;
import mondrian.rolap.*;
import mondrian.rolap.aggmatcher.*;
import mondrian.test.comp.ResultComparatorTest;
import mondrian.udf.*;
import mondrian.util.*;
import mondrian.xmla.XmlaBasicTest;
import mondrian.xmla.XmlaExcel2000Test;
import mondrian.xmla.XmlaExcelXPTest;
import mondrian.xmla.XmlaErrorTest;
import mondrian.xmla.XmlaCognosTest;
import mondrian.xmla.impl.DynamicDatasourceXmlaServletTest;
import mondrian.xmla.test.XmlaTest;
import mondrian.test.clearview.*;
import mondrian.calc.impl.ConstantCalcTest;

import org.apache.log4j.Logger;

/**
 * Main test suite for Mondrian.
 *
 * <p>The {@link #suite()} method returns a suite which contains all other
 * Mondrian tests.
 *
 * @author jhyde
 * @version $Id$
 */
public class Main extends TestSuite {
    private static final Logger logger = Logger.getLogger(Main.class);

    /**
     * Entry point to run test suite from the command line.
     *
     * @param args Command-line parameters.
     */
    public static void main(String[] args) {
        new Main().runSafe(args);
    }

    /**
     * Runs the suite, catching any exceptions and printing their stack trace.
     *
     * @param args Command-line arguments
     */
    private void runSafe(String[] args) {
        try {
            run(args);
        } catch (Exception e) {
            PrintWriter pw = new PrintWriter(System.out);
            pw.println("mondrian.test.Main received exception:");
            String[] errors = Util.convertStackToString(e);
            for (int i = 0; i < errors.length; i++) {
                pw.println(errors[i]);
            }
            pw.flush();
            System.exit(1);
        }
    }

    /**
     * Creates and runs the root test suite.
     */
    void run(String[] args) throws Exception {
        final MondrianProperties properties = MondrianProperties.instance();
        Test test = suite();
        if (properties.Warmup.get()) {
            System.out.println("Starting warmup run...");
            MondrianTestRunner runner = new MondrianTestRunner();
            TestResult tres = runner.doRun(test);
            if (!tres.wasSuccessful()) {
                System.out.println("Warmup run failed. Regular tests will not be run.");
                System.exit(1);
            }
            System.out.println("Warmup run complete. Starting regular run...");
        }
        MondrianTestRunner runner = new MondrianTestRunner();
        runner.setIterations(properties.Iterations.get());
        System.out.println("Iterations=" + properties.Iterations.get());
        runner.setVUsers(properties.VUsers.get());
        runner.setTimeLimit(properties.TimeLimit.get());
        TestResult tres = runner.doRun(test);
        if (!tres.wasSuccessful())
            System.exit(1);
    }

    /**
     * Creates a TestSuite to test the whole of mondrian. Methods with the
     * signature <code>public static Test suite()</code> are recognized
     * automatically by JUnit test-harnesses; see {@link TestSuite}.
     */
    public static Test suite() throws Exception {
        RolapUtil.checkTracing();
        MondrianProperties properties = MondrianProperties.instance();
        String testName = properties.TestName.get();
        String testClass = properties.TestClass.get();

        System.out.println("testName: " + testName);
        System.out.println("testClass: " + testClass);
        System.out.println("java.version: " + System.getProperty("java.version"));

        TestSuite suite = new TestSuite();
        if (testClass != null && !testClass.equals("")) {
            Class clazz = Class.forName(testClass);

            // use addTestSuite only if the class has test methods
            // Allows you to run individual queries with ResultComparatorTest

            boolean matchTestMethods = false;
            if (Test.class.isAssignableFrom(clazz)) {
                Method[] methods = clazz.getMethods();
                for (int i = 0; i < methods.length && !matchTestMethods; i++) {
                    matchTestMethods = methods[i].getName().startsWith("test");
                }
            }

            if (matchTestMethods) {
                // e.g. testClass = "mondrian.test.FoodMartTestCase",
                // the name of a class which extends TestCase. We will invoke
                // every method which starts with 'test'. (If "testName" is set,
                // we'll filter this list later.)
                suite.addTestSuite(clazz);
            } else {
                // e.g. testClass = "mondrian.olap.fun.BuiltinFunTable". Class
                // does not implement Test, so look for a 'public [static]
                // Test suite()' method.
                Method method = clazz.getMethod("suite", new Class[0]);
                Object target;
                if (Modifier.isStatic(method.getModifiers())) {
                    target = null;
                } else {
                    target = clazz.newInstance();
                }
                Object o = method.invoke(target);
                suite.addTest((Test) o);
            }
        } else {
            suite.addTestSuite(MemoryMonitorTest.class);
            suite.addTestSuite(ObjectPoolTest.class);
            suite.addTestSuite(RolapConnectionTest.class);
            suite.addTestSuite(DialectTest.class);
            suite.addTest(ResultComparatorTest.suite());
            suite.addTestSuite(DrillThroughTest.class);
            suite.addTestSuite(BasicQueryTest.class);
            suite.addTest(CVBasicTest.suite());
            suite.addTest(GrandTotalTest.suite());
            suite.addTest(MetricFilterTest.suite());
{'fraction_non_alphanumeric': 0.1109728423980675, 'fraction_numerical': 0.004831271502818242, 'mean_word_length': 2.4155, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3295177', 'n_tokens_mistral': 3819, 'n_tokens_neox': 3753, 'n_words': 933}