<commit_before>/*
  Copyright (C) 2003 EBI, GRL
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Publicpr
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
 
  This library 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
  Lesser General Public License for more details.
 
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.ensembl.healthcheck;

import java.util.*;
import java.util.logging.*;
import java.sql.*;
import java.io.*;
import java.util.zip.*;

import org.ensembl.healthcheck.testcase.*;

import org.ensembl.healthcheck.util.*;

/**
 * <p>TestRunner is a base class that provides utilities for running tests -
 * logging, the ability to find and run tests from certain locations, etc.</p>
 */

public class TestRunner {
  
  /** List that holds an instance of each test. */
  protected List allTests;
  /** The List of group names (as Strings) that will be run. */
  protected List groupsToRun;
  /** If set, database names are filtered with this regular expression before the regexp built into the tests. */
  protected String preFilterRegexp;
  /** The logger to use for this class */
  protected static Logger logger = Logger.getLogger("HealthCheckLogger");
  /** Output level used by ReportManager */
  protected int outputLevel = ReportLine.ALL;
  /** The name of the file where configuration is stored */
  protected String propertiesFileName = "database.properties";
  /** Flag to determine whether repairs will be shown if appropriate */
  protected boolean showRepair = false;
  /** Flag to determine whether repairs will be carried out if appropriate */
  protected boolean doRepair = false;
  
  private static final String SCHEMA_INFO_FILENAME = "schemas.ser";
  private static final boolean GZIP_SCHEMA_INFO = true;

  // -------------------------------------------------------------------------
  /** Creates a new instance of TestRunner */
  
  public TestRunner() {
    
    groupsToRun = new ArrayList();
    
  } // TestRunner
  
  // -------------------------------------------------------------------------
  /**
   * Read the <code>database.properties</code> file into the System properties
   * so that it can be overridden with -D.
   */
  protected void readPropertiesFile() {
    
    String propsFile = System.getProperty("user.dir") + System.getProperty("file.separator") + propertiesFileName;
    Properties dbProps = Utils.readPropertiesFile(propsFile);
    logger.fine("Read database properties from " + propsFile);
    Enumeration e = dbProps.propertyNames();
    String name, value;
    while (e.hasMoreElements()) {
      name = (String)e.nextElement();
      value = dbProps.getProperty(name);
      // add to System
      System.setProperty(name, value);
      logger.finer("\t" + name + " = " + value);
    }
    
  } // readPropertiesFile
  
  // -------------------------------------------------------------------------
  /**
   * Get a list of all the schema names .
   * @return An array of the schema names.
   */
  public String[] getAllSchemaNames() {
    
    Connection conn;
    
    String[] schemaNames = null;
    
    // open connection
    try {<commit_msg>Validate databaseURL property to make sure it starts with jdbc:<commit_after>/*
  Copyright (C) 2003 EBI, GRL
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Publicpr
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
 
  This library 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
  Lesser General Public License for more details.
 
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.ensembl.healthcheck;

import java.util.*;
import java.util.logging.*;
import java.sql.*;
import java.io.*;
import java.util.zip.*;

import org.ensembl.healthcheck.testcase.*;

import org.ensembl.healthcheck.util.*;

/**
 * <p>TestRunner is a base class that provides utilities for running tests -
 * logging, the ability to find and run tests from certain locations, etc.</p>
 */

public class TestRunner {
  
  /** List that holds an instance of each test. */
  protected List allTests;
  /** The List of group names (as Strings) that will be run. */
  protected List groupsToRun;
  /** If set, database names are filtered with this regular expression before the regexp built into the tests. */
  protected String preFilterRegexp;
  /** The logger to use for this class */
  protected static Logger logger = Logger.getLogger("HealthCheckLogger");
  /** Output level used by ReportManager */
  protected int outputLevel = ReportLine.ALL;
  /** The name of the file where configuration is stored */
  protected String propertiesFileName = "database.properties";
  /** Flag to determine whether repairs will be shown if appropriate */
  protected boolean showRepair = false;
  /** Flag to determine whether repairs will be carried out if appropriate */
  protected boolean doRepair = false;
  
  private static final String SCHEMA_INFO_FILENAME = "schemas.ser";
  private static final boolean GZIP_SCHEMA_INFO = true;

  // -------------------------------------------------------------------------
  /** Creates a new instance of TestRunner */
  
  public TestRunner() {
    
    groupsToRun = new ArrayList();
    
  } // TestRunner
  
  // -------------------------------------------------------------------------
  /**
   * Read the <code>database.properties</code> file into the System properties
   * so that it can be overridden with -D.
   */
  protected void readPropertiesFile() {
    
    String propsFile = System.getProperty("user.dir") + System.getProperty("file.separator") + propertiesFileName;
    Properties dbProps = Utils.readPropertiesFile(propsFile);
    logger.fine("Read database properties from " + propsFile);
    Enumeration e = dbProps.propertyNames();
    String name, value;
    while (e.hasMoreElements()) {
      name = (String)e.nextElement();
      value = dbProps.getProperty(name);
      // add to System
      System.setProperty(name, value);
      logger.finer("\t" + name + " = " + value);
    }
    
    // validate database URL - if it doesn't start with jdbc: this can cause confusion
    String databaseURL = System.getProperty("databaseURL");
    if (databaseURL == null || databaseURL.equals("")) {
    	System.err.println("Error: databaseURL not specified in " + propsFile);	
    } else {
    	String prefix = databaseURL.substring(0, 5);
    	if (!prefix.equalsIgnoreCase("jdbc:")) {
    		System.err.println("WARNING - databaseURL property should start with jdbc: but it does not seem to. Check this if you experience problems loading the database driver");
    	}	
    }
    
  } // readPropertiesFile
  
  // -------------------------------------------------------------------------
  /**
   * Get a list of all the schema names .
   * @return An array of the schema names.
   */
  public String[] getAllSchemaNames() {
    
    Connection conn;
    
    String[] schemaNames = null;
    
    // open connection
    try {
{'fraction_non_alphanumeric': 0.14086310667178897, 'fraction_numerical': 0.005378409527468306, 'mean_word_length': 2.5875057418465777, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6805251', 'n_tokens_mistral': 2015, 'n_tokens_neox': 1967, 'n_words': 815}