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


001:        package liquibase.change;
002:
003:        import liquibase.ClassLoaderFileOpener;
004:        import liquibase.database.MSSQLDatabase;
005:        import liquibase.database.OracleDatabase;
006:        import liquibase.database.sql.SqlStatement;
007:        import liquibase.exception.SetupException;
008:        import liquibase.util.MD5Util;
009:        import liquibase.util.StreamUtil;
010:        import static org.junit.Assert.*;
011:        import org.junit.Before;
012:        import org.junit.Test;
013:        import org.w3c.dom.Element;
014:
015:        import javax.xml.parsers.DocumentBuilderFactory;
016:
017:        /**
018:         * Tests the SQL File with a simple text file. No real SQL is used with the
019:         * tests.
020:         * 
021:         * @author <a href="mailto:csuml@yahoo.co.uk">Paul Keeble</a>
022:         *
023:         */
024:        public class SQLFileChangeTest extends AbstractChangeTest {
025:
026:            SQLFileChange change;
027:            String fileName;
028:
029:            @Before
030:            public void setUp() throws Exception {
031:                //file contains contents "TESTDATA"
032:                fileName = "liquibase/change/SQLFileTestData.sql";
033:                change = new SQLFileChange();
034:                ClassLoaderFileOpener opener = new ClassLoaderFileOpener();
035:                change.setFileOpener(opener);
036:                change.setPath(fileName);
037:                change.setUp();
038:            }
039:
040:            @Test
041:            public void setFileOpener() {
042:                assertNotNull(change.getFileOpener());
043:            }
044:
045:            @Test
046:            public void createNode() throws Exception {
047:
048:                Element element = change.createNode(DocumentBuilderFactory
049:                        .newInstance().newDocumentBuilder().newDocument());
050:                assertEquals("sqlFile", element.getTagName());
051:
052:                assertEquals(fileName, element.getAttribute("path"));
053:            }
054:
055:            @Test
056:            public void generateStatement() throws Exception {
057:                assertEquals(fileName, change.getPath());
058:
059:                OracleDatabase database = new OracleDatabase();
060:                assertEquals("TESTDATA", change.generateStatements(database)[0]
061:                        .getSqlStatement(database));
062:
063:                assertEquals(MD5Util.computeMD5(change.getSql()), change
064:                        .getMD5Sum());
065:            }
066:
067:            @Test
068:            public void generateStatementFileNotFound() throws Exception {
069:                try {
070:                    change.setPath("doesnotexist.sql");
071:                    change.setUp();
072:                    change.generateStatements(new OracleDatabase());
073:
074:                    fail("The file does not exist so should not be found");
075:                } catch (SetupException fnfe) {
076:                    //expected
077:                }
078:            }
079:
080:            @Test
081:            public void multiLineSQLFileSemiColon() throws Exception {
082:                SQLFileChange change2 = new SQLFileChange();
083:                change2.setSql("SELECT * FROM customer;"
084:                        + StreamUtil.getLineSeparator()
085:                        + "SELECT * from table;"
086:                        + StreamUtil.getLineSeparator()
087:                        + "SELECT * from table2;"
088:                        + StreamUtil.getLineSeparator());
089:                OracleDatabase database = new OracleDatabase();
090:                SqlStatement[] statements = change2
091:                        .generateStatements(database);
092:
093:                assertEquals(3, statements.length);
094:                assertEquals("SELECT * FROM customer", statements[0]
095:                        .getSqlStatement(database));
096:                assertEquals("SELECT * from table", statements[1]
097:                        .getSqlStatement(database));
098:                assertEquals("SELECT * from table2", statements[2]
099:                        .getSqlStatement(database));
100:            }
101:
102:            @Test
103:            public void singleLineEndInSemiColon() throws Exception {
104:                SQLFileChange change2 = new SQLFileChange();
105:                change2.setSql("SELECT * FROM customer;");
106:                OracleDatabase database = new OracleDatabase();
107:                SqlStatement[] statements = change2
108:                        .generateStatements(database);
109:                assertEquals(1, statements.length);
110:                assertEquals("SELECT * FROM customer", statements[0]
111:                        .getSqlStatement(database));
112:            }
113:
114:            @Test
115:            public void singleLineEndGo() throws Exception {
116:                SQLFileChange change2 = new SQLFileChange();
117:                change2.setSql("SELECT * FROM customer\ngo");
118:                MSSQLDatabase database = new MSSQLDatabase();
119:                SqlStatement[] statements = change2
120:                        .generateStatements(database);
121:                assertEquals(1, statements.length);
122:                assertEquals("SELECT * FROM customer", statements[0]
123:                        .getSqlStatement(database));
124:            }
125:
126:            @Test
127:            public void singleLineBeginGo() throws Exception {
128:                SQLFileChange change2 = new SQLFileChange();
129:                change2.setSql("goSELECT * FROM customer\ngo");
130:                MSSQLDatabase database = new MSSQLDatabase();
131:                SqlStatement[] statements = change2
132:                        .generateStatements(database);
133:                assertEquals(1, statements.length);
134:                assertEquals("goSELECT * FROM customer", statements[0]
135:                        .getSqlStatement(database));
136:            }
137:
138:            @Test
139:            public void multiLineSQLFileGoShouldFind() throws Exception {
140:                SQLFileChange change2 = new SQLFileChange();
141:                change2.setSql("SELECT * FROM customer\ngo\n"
142:                        + "SELECT * from table\ngo");
143:                MSSQLDatabase database = new MSSQLDatabase();
144:                SqlStatement[] statements = change2
145:                        .generateStatements(database);
146:                assertEquals(2, statements.length);
147:                assertEquals("SELECT * FROM customer", statements[0]
148:                        .getSqlStatement(database));
149:                assertEquals("SELECT * from table", statements[1]
150:                        .getSqlStatement(database));
151:            }
152:
153:            @Test
154:            public void multiLineSQLFileGoShouldNotFind() throws Exception {
155:                SQLFileChange change2 = new SQLFileChange();
156:                change2.setSql("SELECT * FROM go\ngo\n"
157:                        + "SELECT * from gogo\ngo\n");
158:                MSSQLDatabase database = new MSSQLDatabase();
159:                SqlStatement[] statements = change2
160:                        .generateStatements(database);
161:
162:                assertEquals(2, statements.length);
163:                assertEquals("SELECT * FROM go", statements[0]
164:                        .getSqlStatement(database));
165:                assertEquals("SELECT * from gogo", statements[1]
166:                        .getSqlStatement(database));
167:            }
168:
169:            @Test
170:            public void getConfirmationMessage() throws Exception {
171:                change.setPath(fileName);
172:                assertEquals("SQL in file " + fileName + " executed", change
173:                        .getConfirmationMessage());
174:            }
175:
176:            @Test
177:            public void getRefactoringName() throws Exception {
178:                assertEquals("SQL From File", change.getChangeName());
179:
180:            }
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.