commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henn...@apache.org
Subject cvs commit: jakarta-commons/configuration/conf testdb.script
Date Mon, 11 Oct 2004 09:17:09 GMT
henning     2004/10/11 02:17:09

  Modified:    configuration/src/test/org/apache/commons/configuration
                        TestDatabaseConfiguration.java
               configuration/conf testdb.script
  Added:       configuration/src/test/org/apache/commons/configuration/test
                        HsqlDB.java
  Log:
  Make the Database Configuration Test actually _work_ on a freshly checked out
  commons-configuration tree (Pre-1.0 release fix).
  
  Revision  Changes    Path
  1.9       +18 -5     jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestDatabaseConfiguration.java
  
  Index: TestDatabaseConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestDatabaseConfiguration.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestDatabaseConfiguration.java	20 Aug 2004 13:55:42 -0000	1.8
  +++ TestDatabaseConfiguration.java	11 Oct 2004 09:17:09 -0000	1.9
  @@ -25,7 +25,10 @@
   import javax.sql.DataSource;
   
   import junit.framework.TestCase;
  +
  +import org.apache.commons.configuration.test.HsqlDB;
   import org.apache.commons.dbcp.BasicDataSource;
  +
   import org.dbunit.database.DatabaseConnection;
   import org.dbunit.database.IDatabaseConnection;
   import org.dbunit.dataset.IDataSet;
  @@ -41,8 +44,12 @@
    */
   public class TestDatabaseConfiguration extends TestCase
   {
  +    public final String DATABASE_DRIVER = "org.hsqldb.jdbcDriver";
  +    public final String DATABASE_URL = "jdbc:hsqldb:target/test-classes/testdb";
  +
  +    private static HsqlDB hsqlDB = null;
  +
       private DataSource datasource;
  -    private IDataSet dataSet;	
   
       protected void setUp() throws Exception
       {
  @@ -53,9 +60,15 @@
       	//Thread.sleep(1000);
       	
           // set up the datasource
  +        
  +        if (hsqlDB == null)
  +        {
  +            hsqlDB = new HsqlDB(DATABASE_URL, DATABASE_DRIVER, "conf/testdb.script");
  +        }
  +
           BasicDataSource datasource = new BasicDataSource();
  -        datasource.setDriverClassName("org.hsqldb.jdbcDriver");
  -        datasource.setUrl("jdbc:hsqldb:target/test-classes/testdb");
  +        datasource.setDriverClassName(DATABASE_DRIVER);
  +        datasource.setUrl(DATABASE_URL);
           datasource.setUsername("sa");
           datasource.setPassword("");
   
  @@ -64,7 +77,7 @@
   
           // prepare the database
           IDatabaseConnection connection = new DatabaseConnection(datasource.getConnection());
  -        dataSet = new XmlDataSet(new FileInputStream("conf/dataset.xml"));
  +        IDataSet dataSet = new XmlDataSet(new FileInputStream("conf/dataset.xml"));
   
           try
           {
  
  
  
  1.1                  jakarta-commons/configuration/src/test/org/apache/commons/configuration/test/HsqlDB.java
  
  Index: HsqlDB.java
  ===================================================================
  package org.apache.commons.configuration.test;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import java.io.FileReader;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  import org.apache.commons.lang.StringUtils;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Stolen from Turbine
   *
   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
   * @version $Id: HsqlDB.java,v 1.1 2004/10/11 09:17:09 henning Exp $
   */
  
  public class HsqlDB
  {
      private Connection connection = null;
      private static Log log = LogFactory.getLog(HsqlDB.class);
  
      public HsqlDB(String uri, String databaseDriver, String loadFile)
              throws Exception
      {
          Class.forName(databaseDriver);
  
          this.connection = DriverManager.getConnection(uri, "sa", "");
  
              if (StringUtils.isNotEmpty(loadFile))
              {
                  loadSqlFile(loadFile);
              }
          this.connection.commit();
      }
  
      public Connection getConnection()
      {
          return connection;
      }
  
      public void close()
      {
          try
          {
              connection.close();
          }
          catch (Exception e)
          {
          }
      }
  
      private void loadSqlFile(String fileName)
              throws Exception
      {
          Statement statement = null;
          try
          {
              statement = connection.createStatement();
              String commands = getFileContents(fileName);
  
              for (int targetPos = commands.indexOf(';'); targetPos > -1; targetPos = commands.indexOf(';'))
              {
                  String cmd = commands.substring(0, targetPos + 1);
                  try
                  {
                      statement.execute(cmd);
                  }
                  catch (SQLException sqle)
                  {
                      log.warn("Statement: " + cmd + ": " + sqle.getMessage());
                  }
                  
                  commands = commands.substring(targetPos + 2);
              }
          }
          finally
          {
              if (statement != null)
              {
                  statement.close();
              }
          }
      }
  
      private String getFileContents(String fileName)
              throws Exception
      {
          FileReader fr = new FileReader(fileName);
  
          char fileBuf[]  = new char[1024];
          StringBuffer sb = new StringBuffer(1000);
          int res = -1;
  
          while ((res = fr.read(fileBuf, 0, 1024)) > -1)
          {
              sb.append(fileBuf, 0, res);
          }
          fr.close();
          return sb.toString();
      }
  }
  
  
  
  
  1.4       +80 -75    jakarta-commons/configuration/conf/testdb.script
  
  Index: testdb.script
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/testdb.script,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- testdb.script	23 Sep 2004 12:05:31 -0000	1.3
  +++ testdb.script	11 Oct 2004 09:17:09 -0000	1.4
  @@ -1,75 +1,80 @@
  -CREATE TABLE CONFIGURATION(KEY VARCHAR NOT NULL PRIMARY KEY,VALUE VARCHAR)
  -CREATE TABLE CONFIGURATIONS(NAME VARCHAR NOT NULL,KEY VARCHAR NOT NULL,VALUE VARCHAR,CONSTRAINT
SYS_PK_CONFIGURATIONS PRIMARY KEY(NAME,KEY))
  -CREATE TABLE CONFIGURATIONLIST(ID VARCHAR NOT NULL PRIMARY KEY, KEY VARCHAR NOT NULL,VALUE
VARCHAR)
  -
  -GRANT ALL ON CLASS "java.lang.Math" TO PUBLIC
  -GRANT ALL ON CLASS "org.hsqldb.Library" TO PUBLIC
  -CREATE USER SA PASSWORD "" ADMIN
  -CREATE ALIAS DAYNAME FOR "org.hsqldb.Library.dayname"
  -CREATE ALIAS SPACE FOR "org.hsqldb.Library.space"
  -CREATE ALIAS SUBSTRING FOR "org.hsqldb.Library.substring"
  -CREATE ALIAS HEXTORAW FOR "org.hsqldb.Library.hexToRaw"
  -CREATE ALIAS SQRT FOR "java.lang.Math.sqrt"
  -CREATE ALIAS ABS FOR "org.hsqldb.Library.abs"
  -CREATE ALIAS POWER FOR "java.lang.Math.pow"
  -CREATE ALIAS CHAR FOR "org.hsqldb.Library.character"
  -CREATE ALIAS CONCAT FOR "org.hsqldb.Library.concat"
  -CREATE ALIAS PI FOR "org.hsqldb.Library.pi"
  -CREATE ALIAS RAWTOHEX FOR "org.hsqldb.Library.rawToHex"
  -CREATE ALIAS SECOND FOR "org.hsqldb.Library.second"
  -CREATE ALIAS TRUNCATE FOR "org.hsqldb.Library.truncate"
  -CREATE ALIAS MONTH FOR "org.hsqldb.Library.month"
  -CREATE ALIAS LOWER FOR "org.hsqldb.Library.lcase"
  -CREATE ALIAS ATAN2 FOR "java.lang.Math.atan2"
  -CREATE ALIAS REPEAT FOR "org.hsqldb.Library.repeat"
  -CREATE ALIAS DAYOFMONTH FOR "org.hsqldb.Library.dayofmonth"
  -CREATE ALIAS TAN FOR "java.lang.Math.tan"
  -CREATE ALIAS RADIANS FOR "java.lang.Math.toRadians"
  -CREATE ALIAS FLOOR FOR "java.lang.Math.floor"
  -CREATE ALIAS NOW FOR "org.hsqldb.Library.now"
  -CREATE ALIAS ACOS FOR "java.lang.Math.acos"
  -CREATE ALIAS DAYOFWEEK FOR "org.hsqldb.Library.dayofweek"
  -CREATE ALIAS CEILING FOR "java.lang.Math.ceil"
  -CREATE ALIAS DAYOFYEAR FOR "org.hsqldb.Library.dayofyear"
  -CREATE ALIAS LCASE FOR "org.hsqldb.Library.lcase"
  -CREATE ALIAS WEEK FOR "org.hsqldb.Library.week"
  -CREATE ALIAS SOUNDEX FOR "org.hsqldb.Library.soundex"
  -CREATE ALIAS ASIN FOR "java.lang.Math.asin"
  -CREATE ALIAS LOCATE FOR "org.hsqldb.Library.locate"
  -CREATE ALIAS EXP FOR "java.lang.Math.exp"
  -CREATE ALIAS MONTHNAME FOR "org.hsqldb.Library.monthname"
  -CREATE ALIAS YEAR FOR "org.hsqldb.Library.year"
  -CREATE ALIAS LEFT FOR "org.hsqldb.Library.left"
  -CREATE ALIAS ROUNDMAGIC FOR "org.hsqldb.Library.roundMagic"
  -CREATE ALIAS BITOR FOR "org.hsqldb.Library.bitor"
  -CREATE ALIAS LTRIM FOR "org.hsqldb.Library.ltrim"
  -CREATE ALIAS COT FOR "org.hsqldb.Library.cot"
  -CREATE ALIAS COS FOR "java.lang.Math.cos"
  -CREATE ALIAS MOD FOR "org.hsqldb.Library.mod"
  -CREATE ALIAS SIGN FOR "org.hsqldb.Library.sign"
  -CREATE ALIAS DEGREES FOR "java.lang.Math.toDegrees"
  -CREATE ALIAS LOG FOR "java.lang.Math.log"
  -CREATE ALIAS SIN FOR "java.lang.Math.sin"
  -CREATE ALIAS CURTIME FOR "org.hsqldb.Library.curtime"
  -CREATE ALIAS DIFFERENCE FOR "org.hsqldb.Library.difference"
  -CREATE ALIAS INSERT FOR "org.hsqldb.Library.insert"
  -CREATE ALIAS SUBSTR FOR "org.hsqldb.Library.substring"
  -CREATE ALIAS DATABASE FOR "org.hsqldb.Library.database"
  -CREATE ALIAS MINUTE FOR "org.hsqldb.Library.minute"
  -CREATE ALIAS HOUR FOR "org.hsqldb.Library.hour"
  -CREATE ALIAS IDENTITY FOR "org.hsqldb.Library.identity"
  -CREATE ALIAS QUARTER FOR "org.hsqldb.Library.quarter"
  -CREATE ALIAS CURDATE FOR "org.hsqldb.Library.curdate"
  -CREATE ALIAS BITAND FOR "org.hsqldb.Library.bitand"
  -CREATE ALIAS USER FOR "org.hsqldb.Library.user"
  -CREATE ALIAS UCASE FOR "org.hsqldb.Library.ucase"
  -CREATE ALIAS RTRIM FOR "org.hsqldb.Library.rtrim"
  -CREATE ALIAS LOG10 FOR "org.hsqldb.Library.log10"
  -CREATE ALIAS RIGHT FOR "org.hsqldb.Library.right"
  -CREATE ALIAS ATAN FOR "java.lang.Math.atan"
  -CREATE ALIAS UPPER FOR "org.hsqldb.Library.ucase"
  -CREATE ALIAS ASCII FOR "org.hsqldb.Library.ascii"
  -CREATE ALIAS RAND FOR "java.lang.Math.random"
  -CREATE ALIAS LENGTH FOR "org.hsqldb.Library.length"
  -CREATE ALIAS ROUND FOR "org.hsqldb.Library.round"
  -CREATE ALIAS REPLACE FOR "org.hsqldb.Library.replace"
  +DROP TABLE CONFIGURATION IF EXISTS;
  +CREATE TABLE CONFIGURATION(KEY VARCHAR NOT NULL PRIMARY KEY,VALUE VARCHAR);
  +
  +DROP TABLE CONFIGURATIONS IF EXISTS;
  +CREATE TABLE CONFIGURATIONS(NAME VARCHAR NOT NULL,KEY VARCHAR NOT NULL,VALUE VARCHAR,CONSTRAINT
SYS_PK_CONFIGURATIONS PRIMARY KEY(NAME,KEY));
  +
  +DROP TABLE CONFIGURATIONLIST IF EXISTS;
  +CREATE TABLE CONFIGURATIONLIST(ID VARCHAR NOT NULL PRIMARY KEY, KEY VARCHAR NOT NULL,VALUE
VARCHAR);;
  +;
  +GRANT ALL ON CLASS "java.lang.Math" TO PUBLIC;
  +GRANT ALL ON CLASS "org.hsqldb.Library" TO PUBLIC;
  +CREATE USER SA PASSWORD "" ADMIN;
  +CREATE ALIAS DAYNAME FOR "org.hsqldb.Library.dayname";
  +CREATE ALIAS SPACE FOR "org.hsqldb.Library.space";
  +CREATE ALIAS SUBSTRING FOR "org.hsqldb.Library.substring";
  +CREATE ALIAS HEXTORAW FOR "org.hsqldb.Library.hexToRaw";
  +CREATE ALIAS SQRT FOR "java.lang.Math.sqrt";
  +CREATE ALIAS ABS FOR "org.hsqldb.Library.abs";
  +CREATE ALIAS POWER FOR "java.lang.Math.pow";
  +CREATE ALIAS CHAR FOR "org.hsqldb.Library.character";
  +CREATE ALIAS CONCAT FOR "org.hsqldb.Library.concat";
  +CREATE ALIAS PI FOR "org.hsqldb.Library.pi";
  +CREATE ALIAS RAWTOHEX FOR "org.hsqldb.Library.rawToHex";
  +CREATE ALIAS SECOND FOR "org.hsqldb.Library.second";
  +CREATE ALIAS TRUNCATE FOR "org.hsqldb.Library.truncate";
  +CREATE ALIAS MONTH FOR "org.hsqldb.Library.month";
  +CREATE ALIAS LOWER FOR "org.hsqldb.Library.lcase";
  +CREATE ALIAS ATAN2 FOR "java.lang.Math.atan2";
  +CREATE ALIAS REPEAT FOR "org.hsqldb.Library.repeat";
  +CREATE ALIAS DAYOFMONTH FOR "org.hsqldb.Library.dayofmonth";
  +CREATE ALIAS TAN FOR "java.lang.Math.tan";
  +CREATE ALIAS RADIANS FOR "java.lang.Math.toRadians";
  +CREATE ALIAS FLOOR FOR "java.lang.Math.floor";
  +CREATE ALIAS NOW FOR "org.hsqldb.Library.now";
  +CREATE ALIAS ACOS FOR "java.lang.Math.acos";
  +CREATE ALIAS DAYOFWEEK FOR "org.hsqldb.Library.dayofweek";
  +CREATE ALIAS CEILING FOR "java.lang.Math.ceil";
  +CREATE ALIAS DAYOFYEAR FOR "org.hsqldb.Library.dayofyear";
  +CREATE ALIAS LCASE FOR "org.hsqldb.Library.lcase";
  +CREATE ALIAS WEEK FOR "org.hsqldb.Library.week";
  +CREATE ALIAS SOUNDEX FOR "org.hsqldb.Library.soundex";
  +CREATE ALIAS ASIN FOR "java.lang.Math.asin";
  +CREATE ALIAS LOCATE FOR "org.hsqldb.Library.locate";
  +CREATE ALIAS EXP FOR "java.lang.Math.exp";
  +CREATE ALIAS MONTHNAME FOR "org.hsqldb.Library.monthname";
  +CREATE ALIAS YEAR FOR "org.hsqldb.Library.year";
  +CREATE ALIAS LEFT FOR "org.hsqldb.Library.left";
  +CREATE ALIAS ROUNDMAGIC FOR "org.hsqldb.Library.roundMagic";
  +CREATE ALIAS BITOR FOR "org.hsqldb.Library.bitor";
  +CREATE ALIAS LTRIM FOR "org.hsqldb.Library.ltrim";
  +CREATE ALIAS COT FOR "org.hsqldb.Library.cot";
  +CREATE ALIAS COS FOR "java.lang.Math.cos";
  +CREATE ALIAS MOD FOR "org.hsqldb.Library.mod";
  +CREATE ALIAS SIGN FOR "org.hsqldb.Library.sign";
  +CREATE ALIAS DEGREES FOR "java.lang.Math.toDegrees";
  +CREATE ALIAS LOG FOR "java.lang.Math.log";
  +CREATE ALIAS SIN FOR "java.lang.Math.sin";
  +CREATE ALIAS CURTIME FOR "org.hsqldb.Library.curtime";
  +CREATE ALIAS DIFFERENCE FOR "org.hsqldb.Library.difference";
  +CREATE ALIAS INSERT FOR "org.hsqldb.Library.insert";
  +CREATE ALIAS SUBSTR FOR "org.hsqldb.Library.substring";
  +CREATE ALIAS DATABASE FOR "org.hsqldb.Library.database";
  +CREATE ALIAS MINUTE FOR "org.hsqldb.Library.minute";
  +CREATE ALIAS HOUR FOR "org.hsqldb.Library.hour";
  +CREATE ALIAS IDENTITY FOR "org.hsqldb.Library.identity";
  +CREATE ALIAS QUARTER FOR "org.hsqldb.Library.quarter";
  +CREATE ALIAS CURDATE FOR "org.hsqldb.Library.curdate";
  +CREATE ALIAS BITAND FOR "org.hsqldb.Library.bitand";
  +CREATE ALIAS USER FOR "org.hsqldb.Library.user";
  +CREATE ALIAS UCASE FOR "org.hsqldb.Library.ucase";
  +CREATE ALIAS RTRIM FOR "org.hsqldb.Library.rtrim";
  +CREATE ALIAS LOG10 FOR "org.hsqldb.Library.log10";
  +CREATE ALIAS RIGHT FOR "org.hsqldb.Library.right";
  +CREATE ALIAS ATAN FOR "java.lang.Math.atan";
  +CREATE ALIAS UPPER FOR "org.hsqldb.Library.ucase";
  +CREATE ALIAS ASCII FOR "org.hsqldb.Library.ascii";
  +CREATE ALIAS RAND FOR "java.lang.Math.random";
  +CREATE ALIAS LENGTH FOR "org.hsqldb.Library.length";
  +CREATE ALIAS ROUND FOR "org.hsqldb.Library.round";
  +CREATE ALIAS REPLACE FOR "org.hsqldb.Library.replace";
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message