01: /*
02: *
03: * The DbUnit Database Testing Framework
04: * Copyright (C)2002-2004, DbUnit.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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:
22: package org.dbunit;
23:
24: import org.slf4j.Logger;
25: import org.slf4j.LoggerFactory;
26:
27: /**
28: * DatabaseTester that configures a DriverManager from environment properties.<br>
29: * This class defines a set of keys for system properties that need to be
30: * present in the environment before using it. Example:
31: * <xmp>
32: * System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS,
33: * "com.mycompany.myDriver" );
34: * System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL,
35: * "jdbc:mydb://host/dbname" );
36: * System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME,
37: * "myuser" );
38: * System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD,
39: * "mypasswd" );
40: * System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_SCHEMA,
41: * "myschema" );
42: * </xmp>
43: *
44: * @author Andres Almiray <aalmiray@users.sourceforge.net>
45: * @author Felipe Leme <dbunit@felipeal.net>
46: */
47: public class PropertiesBasedJdbcDatabaseTester extends
48: JdbcDatabaseTester {
49:
50: /**
51: * Logger for this class
52: */
53: private static final Logger logger = LoggerFactory
54: .getLogger(PropertiesBasedJdbcDatabaseTester.class);
55:
56: /** A key for property that defines the connection url */
57: public static final String DBUNIT_CONNECTION_URL = "dbunit.connectionUrl";
58: /** A key for property that defines the driver classname */
59: public static final String DBUNIT_DRIVER_CLASS = "dbunit.driverClass";
60: /** A key for property that defines the user's password */
61: public static final String DBUNIT_PASSWORD = "dbunit.password";
62: /** A key for property that defines the username */
63: public static final String DBUNIT_USERNAME = "dbunit.username";
64: /** A key for property that defines the database schema */
65: public static final String DBUNIT_SCHEMA = "dbunit.schema";
66:
67: /** A key for property that defines the connection url */
68:
69: public PropertiesBasedJdbcDatabaseTester() {
70: super (null, null, null, null);
71: }
72:
73: protected void initialize() throws Exception {
74: logger.debug("initialize() - start");
75:
76: setDriverClass(System.getProperty(DBUNIT_DRIVER_CLASS));
77: setConnectionUrl(System.getProperty(DBUNIT_CONNECTION_URL));
78: setUsername(System.getProperty(DBUNIT_USERNAME));
79: setPassword(System.getProperty(DBUNIT_PASSWORD));
80: setSchema(System.getProperty(DBUNIT_SCHEMA));
81: super.initialize();
82: }
83: }
|