Source Code Cross Referenced for InsertStatementTest.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.Database;
004:        import liquibase.database.FirebirdDatabase;
005:        import liquibase.database.structure.DatabaseSnapshot;
006:        import liquibase.database.template.JdbcTemplate;
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 InsertStatementTest extends AbstractSqlStatementTest {
014:            private static final String TABLE_NAME = "InsertTest";
015:            private static final String VARCHAR_COL_NAME = "colName_vc";
016:            private static final String DATE_COL_NAME = "colName_dt";
017:            private static final String BOOLEAN_COL_NAME = "colName_b";
018:            private static final String INT_COL_NAME = "colName_i";
019:            private static final String FLOAT_COL_NAME = "colName_f";
020:
021:            protected void setupDatabase(Database database) throws Exception {
022:                dropAndCreateTable(new CreateTableStatement(null, TABLE_NAME)
023:                        .addColumn(VARCHAR_COL_NAME, "varchar(50)").addColumn(
024:                                DATE_COL_NAME, "varchar(50)").addColumn(
025:                                BOOLEAN_COL_NAME, database.getBooleanType())
026:                        .addColumn(INT_COL_NAME, "int").addColumn(
027:                                FLOAT_COL_NAME, "float"), database);
028:
029:                dropAndCreateTable(
030:                        new CreateTableStatement(TestContext.ALT_SCHEMA,
031:                                TABLE_NAME).addColumn(VARCHAR_COL_NAME,
032:                                "varchar(50)").addColumn(DATE_COL_NAME,
033:                                "varchar(50)").addColumn(BOOLEAN_COL_NAME,
034:                                database.getBooleanType()).addColumn(
035:                                INT_COL_NAME, "int").addColumn(FLOAT_COL_NAME,
036:                                "float"), database);
037:            }
038:
039:            protected SqlStatement generateTestStatement() {
040:                return new InsertStatement(null, null);
041:            }
042:
043:            @Test
044:            public void execute_defaultSchema() throws Exception {
045:                new DatabaseTestTemplate()
046:                        .testOnAvailableDatabases(new SqlStatementDatabaseTest(
047:                                null, new InsertStatement(null, TABLE_NAME)
048:                                        .addColumnValue(VARCHAR_COL_NAME,
049:                                                "new value")) {
050:
051:                            private int oldCount;
052:
053:                            protected void preExecuteAssert(
054:                                    DatabaseSnapshot snapshot) throws Exception {
055:                                oldCount = new JdbcTemplate(snapshot
056:                                        .getDatabase())
057:                                        .queryForInt(new RawSqlStatement(
058:                                                "select count(*) from "
059:                                                        + TABLE_NAME));
060:                            }
061:
062:                            protected void postExecuteAssert(
063:                                    DatabaseSnapshot snapshot) throws Exception {
064:                                int newCount = new JdbcTemplate(snapshot
065:                                        .getDatabase())
066:                                        .queryForInt(new RawSqlStatement(
067:                                                "select count(*) from "
068:                                                        + TABLE_NAME));
069:                                assertEquals(oldCount + 1, newCount);
070:                            }
071:
072:                        });
073:            }
074:
075:            @Test
076:            public void execute_altSchema() throws Exception {
077:                new DatabaseTestTemplate()
078:                        .testOnAvailableDatabases(new SqlStatementDatabaseTest(
079:                                TestContext.ALT_SCHEMA, new InsertStatement(
080:                                        TestContext.ALT_SCHEMA, TABLE_NAME)
081:                                        .addColumnValue(VARCHAR_COL_NAME,
082:                                                "new value")) {
083:
084:                            private int oldCount;
085:
086:                            protected boolean supportsTest(Database database) {
087:                                return !(database instanceof  FirebirdDatabase);
088:                            }
089:
090:                            protected void preExecuteAssert(
091:                                    DatabaseSnapshot snapshot) throws Exception {
092:                                oldCount = new JdbcTemplate(snapshot
093:                                        .getDatabase())
094:                                        .queryForInt(new RawSqlStatement(
095:                                                "select count(*) from "
096:                                                        + TestContext.ALT_SCHEMA
097:                                                        + "." + TABLE_NAME));
098:                            }
099:
100:                            protected void postExecuteAssert(
101:                                    DatabaseSnapshot snapshot) throws Exception {
102:                                int newCount = new JdbcTemplate(snapshot
103:                                        .getDatabase())
104:                                        .queryForInt(new RawSqlStatement(
105:                                                "select count(*) from "
106:                                                        + TestContext.ALT_SCHEMA
107:                                                        + "." + TABLE_NAME));
108:                                assertEquals(oldCount + 1, newCount);
109:                            }
110:
111:                        });
112:            }
113:
114:            @Test
115:            public void execute_multiColumns() throws Exception {
116:                new DatabaseTestTemplate()
117:                        .testOnAvailableDatabases(new SqlStatementDatabaseTest(
118:                                null,
119:                                new InsertStatement(null, TABLE_NAME)
120:                                        .addColumnValue(VARCHAR_COL_NAME,
121:                                                "new value")
122:                                        .addColumnValue(
123:                                                DATE_COL_NAME,
124:                                                new java.sql.Date(
125:                                                        new java.util.Date()
126:                                                                .getTime()))
127:                                        .addColumnValue(INT_COL_NAME, 42)
128:                                        .addColumnValue(FLOAT_COL_NAME, 123.456)) {
129:
130:                            private int oldCount;
131:
132:                            protected void preExecuteAssert(
133:                                    DatabaseSnapshot snapshot) throws Exception {
134:                                oldCount = new JdbcTemplate(snapshot
135:                                        .getDatabase())
136:                                        .queryForInt(new RawSqlStatement(
137:                                                "select count(*) from "
138:                                                        + TABLE_NAME));
139:                            }
140:
141:                            protected void postExecuteAssert(
142:                                    DatabaseSnapshot snapshot) throws Exception {
143:                                int newCount = new JdbcTemplate(snapshot
144:                                        .getDatabase())
145:                                        .queryForInt(new RawSqlStatement(
146:                                                "select count(*) from "
147:                                                        + TABLE_NAME));
148:                                assertEquals(oldCount + 1, newCount);
149:                            }
150:
151:                        });
152:            }
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.