Source Code Cross Referenced for DBVersionSourceTest.java in  » Testing » unitils » org » unitils » dbmaintainer » version » impl » 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 » unitils » org.unitils.dbmaintainer.version.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007,  Unitils.org
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.unitils.dbmaintainer.version.impl;
017:
018:        import static org.apache.commons.lang.time.DateUtils.parseDate;
019:        import static org.junit.Assert.assertFalse;
020:        import static org.junit.Assert.assertTrue;
021:        import static org.unitils.database.SQLUnitils.executeUpdate;
022:        import static org.unitils.database.SQLUnitils.executeUpdateQuietly;
023:        import static org.unitils.reflectionassert.ReflectionAssert.assertRefEquals;
024:
025:        import java.sql.SQLException;
026:        import java.util.Properties;
027:
028:        import javax.sql.DataSource;
029:
030:        import org.junit.After;
031:        import org.junit.Before;
032:        import org.junit.Test;
033:        import org.unitils.UnitilsJUnit4;
034:        import org.unitils.core.ConfigurationLoader;
035:        import org.unitils.core.UnitilsException;
036:        import org.unitils.core.dbsupport.SQLHandler;
037:        import org.unitils.database.annotations.TestDataSource;
038:        import org.unitils.dbmaintainer.version.Version;
039:        import static org.unitils.dbmaintainer.version.impl.DBVersionSource.PROPKEY_AUTO_CREATE_VERSION_TABLE;
040:
041:        /**
042:         * Test class for {@link org.unitils.dbmaintainer.version.impl.DBVersionSource}. The implementation is tested using a
043:         * test database. The dbms that is used depends on the database configuration in test/resources/unitils.properties
044:         * 
045:         * @author Filip Neven
046:         * @author Tim Ducheyne
047:         */
048:        public class DBVersionSourceTest extends UnitilsJUnit4 {
049:
050:            /* The tested instance */
051:            private DBVersionSource dbVersionSource;
052:
053:            /* The tested instance with auto-create configured */
054:            private DBVersionSource dbVersionSourceAutoCreate;
055:
056:            /* The dataSource */
057:            @TestDataSource
058:            private DataSource dataSource = null;
059:
060:            /**
061:             * Initialize test fixture and creates a test version table.
062:             */
063:            @Before
064:            public void setUp() throws Exception {
065:                Properties configuration = new ConfigurationLoader()
066:                        .loadConfiguration();
067:                SQLHandler sqlHandler = new SQLHandler(dataSource);
068:                dbVersionSource = new DBVersionSource();
069:                dbVersionSource.init(configuration, sqlHandler);
070:
071:                configuration.setProperty(PROPKEY_AUTO_CREATE_VERSION_TABLE,
072:                        "true");
073:                dbVersionSourceAutoCreate = new DBVersionSource();
074:                dbVersionSourceAutoCreate.init(configuration, sqlHandler);
075:
076:                dropVersionTable();
077:                createVersionTable();
078:            }
079:
080:            /**
081:             * Cleanup by dropping the test version table.
082:             */
083:            @After
084:            public void tearDown() throws Exception {
085:                dropVersionTable();
086:            }
087:
088:            /**
089:             * Test setting and getting version
090:             */
091:            @Test
092:            public void testGetAndSetDBVersion() throws Exception {
093:                Version version = new Version(3L, parseDate("2006-10-08 12:00",
094:                        new String[] { "yyyy-MM-dd hh:mm" }).getTime());
095:
096:                dbVersionSource.setDbVersion(version);
097:                Version result = dbVersionSource.getDbVersion();
098:                assertRefEquals(version, result);
099:            }
100:
101:            /**
102:             * Tests getting the version, but no version table yet (e.g. first use)
103:             */
104:            @Test(expected=UnitilsException.class)
105:            public void testGetDBVersion_noVersionTable() throws Exception {
106:                dropVersionTable();
107:                dbVersionSource.getDbVersion();
108:            }
109:
110:            /**
111:             * Tests getting the version, but no version table yet and auto-create is true.
112:             */
113:            @Test
114:            public void testGetDBVersion_noVersionTableAutoCreate()
115:                    throws Exception {
116:                dropVersionTable();
117:
118:                Version result = dbVersionSourceAutoCreate.getDbVersion();
119:                assertRefEquals(0L, result.getIndex());
120:            }
121:
122:            /**
123:             * Tests getting the version but table is empty.
124:             */
125:            @Test
126:            public void testGetAndSetDBVersion_emptyVersionTable()
127:                    throws Exception {
128:                clearVersionTable();
129:                Version version = new Version(3L, parseDate("2006-10-08 12:00",
130:                        new String[] { "yyyy-MM-dd hh:mm" }).getTime());
131:
132:                dbVersionSource.setDbVersion(version);
133:                Version result = dbVersionSource.getDbVersion();
134:                assertRefEquals(version, result);
135:            }
136:
137:            /**
138:             * Test whether the update succeeded value can be correclty set and retrieved, when succeeded is true
139:             */
140:            @Test
141:            public void testRegisterUpdateSucceeded_succeeded()
142:                    throws Exception {
143:                dbVersionSource.registerUpdateSucceeded(true);
144:                boolean result = dbVersionSource.isLastUpdateSucceeded();
145:
146:                assertTrue(result);
147:            }
148:
149:            /**
150:             * Test whether the update succeeded value can be correclty set and retrieved, when succeeded is false
151:             */
152:            @Test
153:            public void testRegisterUpdateSucceeded_notSucceeded()
154:                    throws Exception {
155:                dbVersionSource.registerUpdateSucceeded(false);
156:                boolean result = dbVersionSource.isLastUpdateSucceeded();
157:
158:                assertFalse(result);
159:            }
160:
161:            /**
162:             * Utility method to create the test version table.
163:             */
164:            private void createVersionTable() throws SQLException {
165:                executeUpdate(dbVersionSource.getCreateVersionTableStatement(),
166:                        dataSource);
167:            }
168:
169:            /**
170:             * Utility method to drop the test version table.
171:             */
172:            private void dropVersionTable() throws SQLException {
173:                executeUpdateQuietly("drop table db_version", dataSource);
174:            }
175:
176:            /**
177:             * Utility method to clear the test version table.
178:             */
179:            private void clearVersionTable() throws SQLException {
180:                executeUpdate("delete from db_version", dataSource);
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.