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  package org.dbunit;
22  
23  import org.dbunit.database.DatabaseConfig;
24  import org.dbunit.database.IDatabaseConnection;
25  import org.dbunit.dataset.IDataSet;
26  import org.dbunit.operation.DatabaseOperation;
27  
28  import junit.framework.TestCase;
29  
30  /**
31   * @author gommma
32   * @author Last changed by: $Author$
33   * @version $Revision$ $Date$
34   * @since 2.3.0
35   */
36  public class DatabaseTestCaseIT extends TestCase
37  {
38  
39  	public void testTearDownExceptionDoesNotObscureTestException() 
40  	{
41  		//TODO implement #1087040  	  tearDownOperation Exception obscures underlying problem
42  	}
43  	
44  	/**
45  	 * Tests whether the user can simply change the {@link DatabaseConfig} by
46  	 * overriding the method {@link DatabaseTestCase#setUpDatabaseConfig(DatabaseConfig)}.
47  	 * @throws Exception
48  	 */
49  	public void testConfigureConnection() throws Exception
50  	{
51  	    DatabaseEnvironment dbEnv = DatabaseEnvironment.getInstance();
52  	    final IDatabaseConnection conn = dbEnv.getConnection();
53  	    
54  	    DatabaseTestCase testSubject = new DatabaseTestCase() {
55  
56              /**
57               * method under test
58               */
59              protected void setUpDatabaseConfig(DatabaseConfig config) {
60                  config.setProperty(DatabaseConfig.PROPERTY_BATCH_SIZE, new Integer(97));
61              }
62  
63              protected IDatabaseConnection getConnection() throws Exception {
64                  return conn;
65              }
66  
67              protected IDataSet getDataSet() throws Exception {
68                  return null;
69              }
70  
71              protected DatabaseOperation getSetUpOperation() throws Exception {
72                  return DatabaseOperation.NONE;
73              }
74  
75              protected DatabaseOperation getTearDownOperation() throws Exception {
76                  return DatabaseOperation.NONE;
77              }
78          };
79          
80          // Simulate JUnit which first of all calls the "setUp" method
81          testSubject.setUp();
82          
83          IDatabaseConnection actualConn = testSubject.getConnection();
84          assertEquals(new Integer(97), actualConn.getConfig().getProperty(DatabaseConfig.PROPERTY_BATCH_SIZE));
85          
86          IDatabaseConnection actualConn2 = testSubject.getDatabaseTester().getConnection();
87          assertEquals(new Integer(97), actualConn2.getConfig().getProperty(DatabaseConfig.PROPERTY_BATCH_SIZE));
88  	}
89  }