View Javadoc
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  
22  package org.dbunit;
23  
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  /**
28   * TestCase that uses a JdbcDatabaseTester.
29   *
30   * @author Andres Almiray (aalmiray@users.sourceforge.net)
31   * @author Felipe Leme (dbunit@felipeal.net)
32   * @author Last changed by: $Author$
33   * @version $Revision$ $Date$
34   * @since 2.2.0
35   */
36  public abstract class JdbcBasedDBTestCase extends DBTestCase
37  {
38  
39      /**
40       * Logger for this class
41       */
42      private static final Logger logger = LoggerFactory.getLogger(JdbcBasedDBTestCase.class);
43  
44      public JdbcBasedDBTestCase()
45      {
46          super();
47      }
48  
49      public JdbcBasedDBTestCase( String name )
50      {
51          super( name );
52      }
53  
54      /**
55       * Creates a new IDatabaseTester.<br>
56       * Default implementation returns a {@link JdbcDatabaseTester} configured
57       * with the values returned from {@link #getDriverClass},
58       * {@link #getConnectionUrl}, {@link #getUsername} and {@link #getPassword()}.
59       * @throws ClassNotFoundException when the driverClass was not found
60       */
61      protected IDatabaseTester newDatabaseTester() throws ClassNotFoundException
62      {
63          logger.debug("newDatabaseTester() - start");
64  
65          JdbcDatabaseTester databaseTester = new JdbcDatabaseTester( 
66                  getDriverClass(),
67                  getConnectionUrl(),
68                  getUsername(),
69                  getPassword() );
70          return databaseTester;
71      }
72  
73      /**
74       * Returns the test connection url.
75       */
76      protected abstract String getConnectionUrl();
77  
78      /**
79       * Returns the JDBC driver classname.
80       */
81      protected abstract String getDriverClass();
82  
83      /**
84       * Returns the password for the connection.<br>
85       * Subclasses may override this method to provide a custom password.<br>
86       * Default implementations returns null.
87       */
88      protected String getPassword()
89      {
90          return null;
91      }
92  
93      /**
94       * Returns the username for the connection.<br>
95       * Subclasses may override this method to provide a custom username.<br>
96       * Default implementations returns null.
97       */
98      protected String getUsername()
99      {
100         return null;
101     }
102 }