PropertiesBasedJdbcDatabaseTester.java

  1. /*
  2.  *
  3.  * The DbUnit Database Testing Framework
  4.  * Copyright (C)2002-2004, DbUnit.org
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Lesser General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2.1 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public
  17.  * License along with this library; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  *
  20.  */

  21. package org.dbunit;

  22. /**
  23.  * DatabaseTester that configures a DriverManager from environment properties.<br>
  24.  * This class defines a set of keys for system properties that need to be
  25.  * present in the environment before using it. Example:
  26.  * <xmp>
  27.  * System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS,
  28.  *             "com.mycompany.myDriver" );
  29.  * System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL,
  30.  *             "jdbc:mydb://host/dbname" );
  31.  * System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME,
  32.  *             "myuser" );
  33.  * System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD,
  34.  *             "mypasswd" );
  35.  * System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_SCHEMA,
  36.  *             "myschema" );
  37.  * </xmp>
  38.  *
  39.  * @author Andres Almiray(aalmiray@users.sourceforge.net)
  40.  * @author Felipe Leme (dbunit@felipeal.net)
  41.  * @author Last changed by: $Author$
  42.  * @version $Revision$ $Date$
  43.  * @since 2.2.0
  44.  */
  45. public class PropertiesBasedJdbcDatabaseTester extends JdbcDatabaseTester
  46. {

  47.     /** A key for property that defines the connection url */
  48.     public static final String DBUNIT_CONNECTION_URL = "dbunit.connectionUrl";
  49.     /** A key for property that defines the driver classname */
  50.     public static final String DBUNIT_DRIVER_CLASS = "dbunit.driverClass";
  51.     /** A key for property that defines the user's password */
  52.     public static final String DBUNIT_PASSWORD = "dbunit.password";
  53.     /** A key for property that defines the username */
  54.     public static final String DBUNIT_USERNAME = "dbunit.username";
  55.     /** A key for property that defines the database schema */
  56.     public static final String DBUNIT_SCHEMA = "dbunit.schema";

  57.     /**
  58.      * Creates a new {@link JdbcDatabaseTester} using specific {@link System#getProperty(String)}
  59.      * values as initialization parameters
  60.      * @throws Exception
  61.      */
  62.     public PropertiesBasedJdbcDatabaseTester() throws Exception
  63.     {
  64.         super(  System.getProperty(DBUNIT_DRIVER_CLASS),
  65.                 System.getProperty(DBUNIT_CONNECTION_URL),
  66.                 System.getProperty(DBUNIT_USERNAME),
  67.                 System.getProperty(DBUNIT_PASSWORD),
  68.                 System.getProperty(DBUNIT_SCHEMA)
  69.             );
  70.     }

  71. }