Source Code Cross Referenced for DatabaseTestCase.java in  » Testing » DbUnit » org » dbunit » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » DbUnit » org.dbunit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * The DbUnit Database Testing Framework
004:         * Copyright (C)2002-2004, DbUnit.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         */
021:
022:        package org.dbunit;
023:
024:        import org.slf4j.Logger;
025:        import org.slf4j.LoggerFactory;
026:
027:        import junit.framework.TestCase;
028:        import org.dbunit.database.IDatabaseConnection;
029:        import org.dbunit.dataset.IDataSet;
030:        import org.dbunit.operation.DatabaseOperation;
031:
032:        /**
033:         * @author Manuel Laflamme
034:         * @version $Revision: 554 $
035:         * @since Feb 17, 2002
036:         * TODO: mark it as deprecated use #{DBTestCase} instead.
037:         */
038:        public abstract class DatabaseTestCase extends TestCase {
039:
040:            /**
041:             * Logger for this class
042:             */
043:            private static final Logger logger = LoggerFactory
044:                    .getLogger(DatabaseTestCase.class);
045:
046:            private IDatabaseTester tester;
047:
048:            public DatabaseTestCase() {
049:            }
050:
051:            public DatabaseTestCase(String name) {
052:                super (name);
053:            }
054:
055:            /**
056:             * Returns the test database connection.
057:             */
058:            protected abstract IDatabaseConnection getConnection()
059:                    throws Exception;
060:
061:            /**
062:             * Returns the test dataset.
063:             */
064:            protected abstract IDataSet getDataSet() throws Exception;
065:
066:            /**
067:             * Creates a IDatabaseTester for this testCase.<br>
068:             *
069:             * A {@link DefaultDatabaseTester} is used by default.
070:             * @throws Exception
071:             */
072:            protected IDatabaseTester newDatabaseTester() throws Exception {
073:                logger.debug("newDatabaseTester() - start");
074:
075:                final IDatabaseConnection connection = getConnection();
076:                final IDatabaseTester tester = new DefaultDatabaseTester(
077:                        connection);
078:                return tester;
079:            }
080:
081:            /**
082:             * Gets the IDatabaseTester for this testCase.<br>
083:             * If the IDatabaseTester is not set yet, this method calls
084:             * newDatabaseTester() to obtain a new instance.
085:             * @throws Exception
086:             */
087:            protected IDatabaseTester getDatabaseTester() throws Exception {
088:                logger.debug("getDatabaseTester() - start");
089:
090:                if (this .tester == null) {
091:                    this .tester = newDatabaseTester();
092:                }
093:                return this .tester;
094:            }
095:
096:            /**
097:             * Close the specified connection. Override this method of you want to
098:             * keep your connection alive between tests.
099:             */
100:            protected void closeConnection(IDatabaseConnection connection)
101:                    throws Exception {
102:                logger.debug("closeConnection(connection=" + connection
103:                        + ") - start");
104:
105:                assertNotNull("DatabaseTester is not set", getDatabaseTester());
106:                getDatabaseTester().closeConnection(connection);
107:            }
108:
109:            /**
110:             * Returns the database operation executed in test setup.
111:             */
112:            protected DatabaseOperation getSetUpOperation() throws Exception {
113:                logger.debug("getSetUpOperation() - start");
114:
115:                return DatabaseOperation.CLEAN_INSERT;
116:            }
117:
118:            /**
119:             * Returns the database operation executed in test cleanup.
120:             */
121:            protected DatabaseOperation getTearDownOperation() throws Exception {
122:                logger.debug("getTearDownOperation() - start");
123:
124:                return DatabaseOperation.NONE;
125:            }
126:
127:            ////////////////////////////////////////////////////////////////////////////
128:            // TestCase class
129:
130:            protected void setUp() throws Exception {
131:                logger.debug("setUp() - start");
132:
133:                super .setUp();
134:                final IDatabaseTester databaseTester = getDatabaseTester();
135:                assertNotNull("DatabaseTester is not set", databaseTester);
136:                databaseTester.setSetUpOperation(getSetUpOperation());
137:                databaseTester.setDataSet(getDataSet());
138:                databaseTester.onSetup();
139:            }
140:
141:            protected void tearDown() throws Exception {
142:                logger.debug("tearDown() - start");
143:
144:                try {
145:                    final IDatabaseTester databaseTester = getDatabaseTester();
146:                    assertNotNull("DatabaseTester is not set", databaseTester);
147:                    databaseTester.setTearDownOperation(getTearDownOperation());
148:                    databaseTester.setDataSet(getDataSet());
149:                    databaseTester.onTearDown();
150:                } finally {
151:                    super.tearDown();
152:                }
153:            }
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.