Source Code Cross Referenced for AbstractDatabaseTest.java in  » Database-Client » LiquiBase » liquibase » database » 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 » Database Client » LiquiBase » liquibase.database 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package liquibase.database;
002:
003:        import liquibase.change.ColumnConfig;
004:        import liquibase.test.TestContext;
005:        import static org.easymock.EasyMock.*;
006:        import static org.junit.Assert.*;
007:        import org.junit.Test;
008:
009:        import java.sql.Connection;
010:        import java.sql.DatabaseMetaData;
011:        import java.sql.SQLException;
012:
013:        /**
014:         * Base test class for database-specific tests
015:         */
016:        public abstract class AbstractDatabaseTest {
017:
018:            protected AbstractDatabase database;
019:
020:            protected AbstractDatabaseTest(AbstractDatabase database)
021:                    throws Exception {
022:                this .database = database;
023:                TestContext context = TestContext.getInstance();
024:                DatabaseConnection connection = context.getConnection(context
025:                        .getTestUrl(database));
026:                if (connection != null) {
027:                    database.setConnection(connection);
028:                }
029:            }
030:
031:            public AbstractDatabase getDatabase() {
032:                return database;
033:            }
034:
035:            protected abstract String getProductNameString();
036:
037:            public abstract void getBlobType();
038:
039:            public abstract void supportsInitiallyDeferrableColumns();
040:
041:            public abstract void getBooleanType();
042:
043:            public abstract void getCurrencyType();
044:
045:            public abstract void getUUIDType();
046:
047:            public abstract void getClobType();
048:
049:            public abstract void getDateType();
050:
051:            public abstract void getDateTimeType();
052:
053:            public abstract void getCurrentDateTimeFunction();
054:
055:            @Test
056:            public void getColumnType() {
057:                ColumnConfig column = new ColumnConfig();
058:
059:                column.setType("boolean");
060:                assertEquals(database.getBooleanType(), database
061:                        .getColumnType(column));
062:                column.setType("BooLean");
063:                assertEquals(database.getBooleanType(), database
064:                        .getColumnType(column));
065:
066:                column.setType("currency");
067:                assertEquals(database.getCurrencyType(), database
068:                        .getColumnType(column));
069:                column.setType("currEncy");
070:                assertEquals(database.getCurrencyType(), database
071:                        .getColumnType(column));
072:
073:                column.setType("uuid");
074:                assertEquals(database.getUUIDType(), database
075:                        .getColumnType(column));
076:                column.setType("UUID");
077:                assertEquals(database.getUUIDType(), database
078:                        .getColumnType(column));
079:
080:                column.setType("blob");
081:                assertEquals(database.getBlobType(), database
082:                        .getColumnType(column));
083:                column.setType("BLOB");
084:                assertEquals(database.getBlobType(), database
085:                        .getColumnType(column));
086:
087:                column.setType("clob");
088:                assertEquals(database.getClobType(), database
089:                        .getColumnType(column));
090:                column.setType("CLOB");
091:                assertEquals(database.getClobType(), database
092:                        .getColumnType(column));
093:
094:                column.setType("SomethingElse");
095:                assertEquals("SomethingElse", database.getColumnType(column));
096:            }
097:
098:            @Test
099:            public void getDriverName() throws Exception {
100:                Connection connection = createMock(Connection.class);
101:                DatabaseMetaData metaData = createMock(DatabaseMetaData.class);
102:
103:                connection.setAutoCommit(false);
104:                expect(connection.getMetaData()).andReturn(metaData);
105:                expect(metaData.getDriverName()).andReturn("DriverNameHere");
106:                replay(connection);
107:                replay(metaData);
108:
109:                Database database = getDatabase();
110:                database.setConnection(connection);
111:
112:                assertEquals("DriverNameHere", database.getDriverName());
113:            }
114:
115:            @Test
116:            public void getConnectionURL() throws Exception {
117:                Connection connection = createMock(Connection.class);
118:                DatabaseMetaData metaData = createMock(DatabaseMetaData.class);
119:                connection.setAutoCommit(false);
120:                expect(connection.getMetaData()).andReturn(metaData);
121:                expect(metaData.getURL()).andReturn("URLHere");
122:                replay(connection);
123:                replay(metaData);
124:
125:                Database database = getDatabase();
126:                database.setConnection(connection);
127:
128:                assertEquals("URLHere", database.getConnectionURL());
129:            }
130:
131:            @Test
132:            public void testGetConnectionUsername() throws Exception {
133:                Connection connection = createMock(Connection.class);
134:                DatabaseMetaData metaData = createMock(DatabaseMetaData.class);
135:
136:                connection.setAutoCommit(false);
137:                expect(connection.getMetaData()).andReturn(metaData);
138:                expect(metaData.getUserName()).andReturn("usernameHere");
139:                replay(connection);
140:                replay(metaData);
141:
142:                Database database = getDatabase();
143:                database.setConnection(connection);
144:
145:                assertEquals("usernameHere", database.getConnectionUsername());
146:            }
147:
148:            @Test
149:            public void isCorrectDatabaseImplementation() throws Exception {
150:                assertTrue(getDatabase().isCorrectDatabaseImplementation(
151:                        getMockConnection()));
152:            }
153:
154:            protected Connection getMockConnection() throws SQLException {
155:                Connection conn = createMock(Connection.class);
156:                DatabaseMetaData metaData = createMock(DatabaseMetaData.class);
157:                conn.setAutoCommit(false);
158:
159:                expectLastCall().anyTimes();
160:                expect(conn.getMetaData()).andReturn(metaData).anyTimes();
161:                expect(metaData.getDatabaseProductName()).andReturn(
162:                        getProductNameString()).anyTimes();
163:                replay(conn);
164:                replay(metaData);
165:                return conn;
166:            }
167:
168:            @Test
169:            public void escapeTableName_noSchema() {
170:                Database database = getDatabase();
171:                assertEquals("tableName", database.escapeTableName(null,
172:                        "tableName"));
173:            }
174:
175:            @Test
176:            public void escapeTableName_withSchema() {
177:                Database database = getDatabase();
178:                assertEquals("schemaName.tableName", database.escapeTableName(
179:                        "schemaName", "tableName"));
180:            }
181:
182:            @Test
183:            public void getColumnType_javaTypes() throws SQLException {
184:                Database database = getDatabase();
185:                DatabaseConnection connection = database.getConnection();
186:                if (connection != null) {
187:                    connection.rollback();
188:                    assertEquals(database.getDateType().toUpperCase(), database
189:                            .getColumnType("java.sql.Types.DATE", false)
190:                            .toUpperCase());
191:                    assertEquals(database.getBooleanType().toUpperCase(),
192:                            database.getColumnType("java.sql.Types.BOOLEAN",
193:                                    false).toUpperCase());
194:                    assertEquals("VARCHAR(255)", database.getColumnType(
195:                            "java.sql.Types.VARCHAR(255)", false).toUpperCase());
196:                }
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.