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


001:        package liquibase.database.sql;
002:
003:        import liquibase.database.*;
004:        import liquibase.database.structure.Column;
005:        import liquibase.database.structure.DatabaseSnapshot;
006:        import liquibase.exception.JDBCException;
007:        import liquibase.test.DatabaseTestTemplate;
008:        import liquibase.test.SqlStatementDatabaseTest;
009:        import liquibase.test.TestContext;
010:        import static org.junit.Assert.*;
011:        import org.junit.Test;
012:
013:        public class AddColumnStatementTest extends AbstractSqlStatementTest {
014:
015:            private static final String TABLE_NAME = "AddColTest";
016:            private static final String NEW_COLUMN_NAME = "NewCol";
017:
018:            protected void setupDatabase(Database database) throws Exception {
019:                dropAndCreateTable(new CreateTableStatement(null, TABLE_NAME)
020:                        .addColumn("existingCol", "int"), database);
021:                dropAndCreateTable(new CreateTableStatement(
022:                        TestContext.ALT_SCHEMA, TABLE_NAME).addColumn(
023:                        "existingCol", "int"), database);
024:            }
025:
026:            protected AddColumnStatement generateTestStatement() {
027:                return new AddColumnStatement(null, null, null, null, null);
028:            }
029:
030:            @Test
031:            public void execute_stringDefault() throws Exception {
032:                new DatabaseTestTemplate()
033:                        .testOnAvailableDatabases(new SqlStatementDatabaseTest(
034:                                null, new AddColumnStatement(null, TABLE_NAME,
035:                                        NEW_COLUMN_NAME, "varchar(50)",
036:                                        "new default")) {
037:                            protected void preExecuteAssert(
038:                                    DatabaseSnapshot snapshot) {
039:                                assertNull(snapshot.getTable(TABLE_NAME)
040:                                        .getColumn(NEW_COLUMN_NAME));
041:                            }
042:
043:                            protected void postExecuteAssert(
044:                                    DatabaseSnapshot snapshot) {
045:                                Column columnSnapshot = snapshot.getTable(
046:                                        TABLE_NAME).getColumn(NEW_COLUMN_NAME);
047:                                assertNotNull(columnSnapshot);
048:                                assertEquals(NEW_COLUMN_NAME.toUpperCase(),
049:                                        columnSnapshot.getName().toUpperCase());
050:                                assertEquals("varchar".toUpperCase(),
051:                                        columnSnapshot.getTypeName()
052:                                                .toUpperCase());
053:                                assertEquals(50, columnSnapshot.getColumnSize());
054:                                assertEquals("new default", columnSnapshot
055:                                        .getDefaultValue());
056:
057:                                assertEquals(true, columnSnapshot.isNullable());
058:                            }
059:                        });
060:            }
061:
062:            @Test
063:            public void execute_intDefault() throws Exception {
064:                new DatabaseTestTemplate()
065:                        .testOnAvailableDatabases(new SqlStatementDatabaseTest(
066:                                null, new AddColumnStatement(null, TABLE_NAME,
067:                                        NEW_COLUMN_NAME, "int", 42)) {
068:                            protected void preExecuteAssert(
069:                                    DatabaseSnapshot snapshot) {
070:                                assertNull(snapshot.getTable(TABLE_NAME)
071:                                        .getColumn(NEW_COLUMN_NAME));
072:                            }
073:
074:                            protected void postExecuteAssert(
075:                                    DatabaseSnapshot snapshot) {
076:                                Column columnSnapshot = snapshot.getTable(
077:                                        TABLE_NAME).getColumn(NEW_COLUMN_NAME);
078:                                assertNotNull(columnSnapshot);
079:                                assertEquals(NEW_COLUMN_NAME.toUpperCase(),
080:                                        columnSnapshot.getName().toUpperCase());
081:                                if (snapshot.getDatabase() instanceof  OracleDatabase) {
082:                                    assertEquals("NUMBER", columnSnapshot
083:                                            .getTypeName().toUpperCase());
084:                                } else {
085:                                    assertTrue(columnSnapshot.getTypeName()
086:                                            .toUpperCase().startsWith("INT"));
087:                                }
088:                                assertEquals(42, ((Number) columnSnapshot
089:                                        .getDefaultValue()).intValue());
090:
091:                                assertEquals(true, columnSnapshot.isNullable());
092:                            }
093:
094:                        }
095:
096:                        );
097:            }
098:
099:            @Test
100:            public void execute_floatDefault() throws Exception {
101:                new DatabaseTestTemplate()
102:                        .testOnAvailableDatabases(new SqlStatementDatabaseTest(
103:                                null, new AddColumnStatement(null, TABLE_NAME,
104:                                        NEW_COLUMN_NAME, "float", 42.5)) {
105:                            protected void preExecuteAssert(
106:                                    DatabaseSnapshot snapshot) {
107:                                assertNull(snapshot.getTable(TABLE_NAME)
108:                                        .getColumn(NEW_COLUMN_NAME));
109:                            }
110:
111:                            protected void postExecuteAssert(
112:                                    DatabaseSnapshot snapshot) {
113:                                Column columnSnapshot = snapshot.getTable(
114:                                        TABLE_NAME).getColumn(NEW_COLUMN_NAME);
115:                                assertNotNull(columnSnapshot);
116:                                assertEquals(NEW_COLUMN_NAME.toUpperCase(),
117:                                        columnSnapshot.getName().toUpperCase());
118:                                assertEquals(42.5, ((Number) columnSnapshot
119:                                        .getDefaultValue()).doubleValue());
120:
121:                                assertEquals(true, columnSnapshot.isNullable());
122:                            }
123:                        });
124:            }
125:
126:            @Test
127:            public void execute_notNull() throws Exception {
128:                new DatabaseTestTemplate()
129:                        .testOnAvailableDatabases(new SqlStatementDatabaseTest(
130:                                null, new AddColumnStatement(null, TABLE_NAME,
131:                                        NEW_COLUMN_NAME, "int", 42,
132:                                        new NotNullConstraint())) {
133:                            protected void preExecuteAssert(
134:                                    DatabaseSnapshot snapshot) {
135:                                assertNull(snapshot.getTable(TABLE_NAME)
136:                                        .getColumn(NEW_COLUMN_NAME));
137:                            }
138:
139:                            protected void postExecuteAssert(
140:                                    DatabaseSnapshot snapshot) {
141:                                Column columnSnapshot = snapshot.getTable(
142:                                        TABLE_NAME).getColumn(NEW_COLUMN_NAME);
143:                                assertNotNull(columnSnapshot);
144:                                assertEquals(false, columnSnapshot.isNullable());
145:                            }
146:                        }
147:
148:                        );
149:            }
150:
151:            @Test
152:            public void execute_primaryKey_nonAutoIncrement() throws Exception {
153:                new DatabaseTestTemplate()
154:                        .testOnAvailableDatabases(new SqlStatementDatabaseTest(
155:                                null, new AddColumnStatement(null, TABLE_NAME,
156:                                        NEW_COLUMN_NAME, "int", null,
157:                                        new PrimaryKeyConstraint())) {
158:
159:                            protected boolean expectedException(
160:                                    Database database, JDBCException exception) {
161:                                return (database instanceof  DB2Database
162:                                        || database instanceof  DerbyDatabase
163:                                        || database instanceof  H2Database || database instanceof  CacheDatabase);
164:                            }
165:
166:                            protected void preExecuteAssert(
167:                                    DatabaseSnapshot snapshot) {
168:                                assertNull(snapshot.getTable(TABLE_NAME)
169:                                        .getColumn(NEW_COLUMN_NAME));
170:                            }
171:
172:                            protected void postExecuteAssert(
173:                                    DatabaseSnapshot snapshot) {
174:                                Column columnSnapshot = snapshot.getTable(
175:                                        TABLE_NAME).getColumn(NEW_COLUMN_NAME);
176:                                assertNotNull(columnSnapshot);
177:                                assertEquals(false, columnSnapshot.isNullable());
178:                                assertTrue(columnSnapshot.isPrimaryKey());
179:                                assertEquals(false, columnSnapshot
180:                                        .isAutoIncrement());
181:                            }
182:                        });
183:            }
184:
185:            @Test
186:            public void execute_altSchema() throws Exception {
187:                new DatabaseTestTemplate()
188:                        .testOnAvailableDatabases(new SqlStatementDatabaseTest(
189:                                TestContext.ALT_SCHEMA, new AddColumnStatement(
190:                                        TestContext.ALT_SCHEMA, TABLE_NAME,
191:                                        NEW_COLUMN_NAME, "varchar(50)",
192:                                        "new default")) {
193:                            protected void preExecuteAssert(
194:                                    DatabaseSnapshot snapshot) {
195:                                assertNull(snapshot.getTable(TABLE_NAME)
196:                                        .getColumn(NEW_COLUMN_NAME));
197:                            }
198:
199:                            protected void postExecuteAssert(
200:                                    DatabaseSnapshot snapshot) {
201:                                Column columnSnapshot = snapshot.getTable(
202:                                        TABLE_NAME).getColumn(NEW_COLUMN_NAME);
203:                                assertNotNull(columnSnapshot);
204:                                assertEquals(NEW_COLUMN_NAME.toUpperCase(),
205:                                        columnSnapshot.getName().toUpperCase());
206:                                assertEquals("new default", columnSnapshot
207:                                        .getDefaultValue());
208:
209:                                assertEquals(true, columnSnapshot.isNullable());
210:                            }
211:
212:                        });
213:            }
214:
215:            @Test
216:            public void execute_primaryKeyAutoIncrement() throws Exception {
217:                new DatabaseTestTemplate()
218:                        .testOnAvailableDatabases(new SqlStatementDatabaseTest(
219:                                null, new AddColumnStatement(null, TABLE_NAME,
220:                                        NEW_COLUMN_NAME, "int", null,
221:                                        new PrimaryKeyConstraint(),
222:                                        new AutoIncrementConstraint())) {
223:
224:                            protected boolean expectedException(
225:                                    Database database, JDBCException exception) {
226:                                return (database instanceof  DB2Database
227:                                        || database instanceof  DerbyDatabase
228:                                        || database instanceof  H2Database
229:                                        || database instanceof  CacheDatabase || !database
230:                                        .supportsAutoIncrement());
231:                            }
232:
233:                            protected void preExecuteAssert(
234:                                    DatabaseSnapshot snapshot) {
235:                                assertNull(snapshot.getTable(TABLE_NAME)
236:                                        .getColumn(NEW_COLUMN_NAME));
237:                            }
238:
239:                            protected void postExecuteAssert(
240:                                    DatabaseSnapshot snapshot) {
241:                                Column columnSnapshot = snapshot.getTable(
242:                                        TABLE_NAME).getColumn(NEW_COLUMN_NAME);
243:                                assertNotNull(columnSnapshot);
244:                                assertEquals(false, columnSnapshot.isNullable());
245:                                assertTrue(columnSnapshot.isPrimaryKey());
246:                                assertEquals(true, columnSnapshot
247:                                        .isAutoIncrement());
248:                            }
249:                        });
250:            }
251:
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.