Source Code Cross Referenced for TableDependencySorterTest.java in  » Database-Client » SQL-Workbench » workbench » db » importer » 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 » SQL Workbench » workbench.db.importer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * TableDependencySorterTest.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.db.importer;
013:
014:        import java.sql.Statement;
015:        import java.util.ArrayList;
016:        import java.util.List;
017:        import junit.framework.TestCase;
018:        import workbench.TestUtil;
019:        import workbench.db.ConnectionMgr;
020:        import workbench.db.TableIdentifier;
021:        import workbench.db.WbConnection;
022:
023:        /**
024:         *
025:         * @author support@sql-workbench.net
026:         */
027:        public class TableDependencySorterTest extends TestCase {
028:            private WbConnection dbConn;
029:
030:            public TableDependencySorterTest(String testName) {
031:                super (testName);
032:            }
033:
034:            @Override
035:            protected void setUp() throws Exception {
036:                super .setUp();
037:                TestUtil util = new TestUtil("dependencyTest");
038:                dbConn = util.getConnection();
039:                Statement stmt = dbConn.createStatement();
040:                String baseSql = "CREATE TABLE base  \n" + "( \n"
041:                        + "   id1  INTEGER NOT NULL, \n"
042:                        + "   id2  INTEGER NOT NULL, \n"
043:                        + "   primary key (id1, id2) \n" + ")";
044:                stmt.execute(baseSql);
045:
046:                String child1Sql = "CREATE TABLE child1 \n"
047:                        + "( \n"
048:                        + "   id          INTEGER NOT NULL PRIMARY KEY, \n"
049:                        + "   base_id1    INTEGER NOT NULL, \n"
050:                        + "   base_id2    INTEGER NOT NULL, \n"
051:                        + "   FOREIGN KEY (base_id1, base_id2) REFERENCES base (id1,id2) \n"
052:                        + ")";
053:                stmt.executeUpdate(child1Sql);
054:
055:                String child2Sql = "CREATE TABLE child2 \n"
056:                        + "( \n"
057:                        + "   id          INTEGER NOT NULL PRIMARY KEY, \n"
058:                        + "   base_id1    INTEGER NOT NULL, \n"
059:                        + "   base_id2    INTEGER NOT NULL, \n"
060:                        + "   FOREIGN KEY (base_id1, base_id2) REFERENCES base (id1,id2) \n"
061:                        + ")";
062:                stmt.executeUpdate(child2Sql);
063:
064:                String child3Sql = "CREATE TABLE child2_detail \n" + "( \n"
065:                        + "   id          INTEGER NOT NULL PRIMARY KEY, \n"
066:                        + "   child_id    INTEGER NOT NULL, \n"
067:                        + "   FOREIGN KEY (child_id) REFERENCES child2 (id) \n"
068:                        + ")";
069:                stmt.executeUpdate(child3Sql);
070:
071:                String sql = "CREATE TABLE child1_detail \n"
072:                        + "( \n"
073:                        + "   id          INTEGER NOT NULL PRIMARY KEY, \n"
074:                        + "   child1_id    INTEGER NOT NULL, \n"
075:                        + "   FOREIGN KEY (child1_id) REFERENCES child1 (id) \n"
076:                        + ")";
077:                stmt.executeUpdate(sql);
078:
079:                sql = "CREATE TABLE child1_detail2 \n"
080:                        + "( \n"
081:                        + "   id          INTEGER NOT NULL PRIMARY KEY, \n"
082:                        + "   detail_id    INTEGER NOT NULL, \n"
083:                        + "   FOREIGN KEY (detail_id) REFERENCES child1_detail (id) \n"
084:                        + ")";
085:                stmt.executeUpdate(sql);
086:
087:                sql = "CREATE TABLE tbl1 \n" + "( \n"
088:                        + "   id          INTEGER NOT NULL PRIMARY KEY" + ")";
089:                stmt.executeUpdate(sql);
090:
091:                sql = "CREATE TABLE tbl2 \n" + "( \n"
092:                        + "   id          INTEGER NOT NULL PRIMARY KEY" + ")";
093:                stmt.executeUpdate(sql);
094:
095:                sql = "CREATE TABLE tbl3 \n" + "( \n"
096:                        + "   id          INTEGER NOT NULL PRIMARY KEY" + ")";
097:                stmt.executeUpdate(sql);
098:            }
099:
100:            @Override
101:            protected void tearDown() throws Exception {
102:                ConnectionMgr.getInstance().disconnectAll();
103:                super .tearDown();
104:            }
105:
106:            public void testPlainTables() {
107:                ArrayList<TableIdentifier> tables = new ArrayList<TableIdentifier>();
108:                for (int i = 0; i < 3; i++) {
109:                    tables.add(new TableIdentifier("tbl" + (i + 1)));
110:                }
111:
112:                TableDependencySorter sorter = new TableDependencySorter(
113:                        this .dbConn);
114:                List<TableIdentifier> result = sorter.sortForInsert(tables);
115:                assertEquals("Not enough entries", tables.size(), result.size());
116:            }
117:
118:            public void testCheckDependencies() {
119:                TableIdentifier base = new TableIdentifier("base");
120:                TableIdentifier child1 = new TableIdentifier("child1");
121:                TableIdentifier child2 = new TableIdentifier("child2");
122:                TableIdentifier child1_detail = new TableIdentifier(
123:                        "child1_detail");
124:                TableIdentifier child1_detail2 = new TableIdentifier(
125:                        "child1_detail2");
126:                TableIdentifier child2_detail = new TableIdentifier(
127:                        "child2_detail");
128:                ArrayList<TableIdentifier> tbl = new ArrayList<TableIdentifier>();
129:                tbl.add(child1);
130:                tbl.add(base);
131:                tbl.add(child2);
132:                tbl.add(child1_detail);
133:                tbl.add(child2_detail);
134:                tbl.add(child1_detail2);
135:                TableDependencySorter sorter = new TableDependencySorter(
136:                        this .dbConn);
137:                List<TableIdentifier> result = sorter.sortForDelete(tbl, false);
138:                //		for (TableIdentifier t : result)
139:                //		{
140:                //			System.out.println(t.toString());
141:                //		}
142:                //		System.out.println("--------------------");
143:                assertEquals("Not enough entries", tbl.size(), result.size());
144:                assertEquals("Wrong first table", result.get(0), child1_detail2);
145:
146:                // the second entry is either child1_detail or child2_detail
147:                TableIdentifier second = result.get(1);
148:                assertEquals(true, second.equals(child1_detail)
149:                        || second.equals(child2_detail));
150:
151:                TableIdentifier last = result.get(result.size() - 1);
152:                assertEquals("Wrong last table", true, last.equals(base));
153:
154:                TableIdentifier lastButOne = result.get(result.size() - 2);
155:                assertEquals(true, lastButOne.equals(child1)
156:                        || lastButOne.equals(child2));
157:
158:                List<TableIdentifier> insertList = sorter.sortForInsert(tbl);
159:                //		for (TableIdentifier t : insertList)
160:                //		{
161:                //			System.out.println(t.toString());
162:                //		}
163:                assertEquals("Not enough entries", tbl.size(), insertList
164:                        .size());
165:                assertEquals("Wrong first table for insert", base, insertList
166:                        .get(0));
167:            }
168:
169:            public void testCheckAddMissing() {
170:                TableIdentifier child1 = new TableIdentifier("child1");
171:                ArrayList<TableIdentifier> tbl = new ArrayList<TableIdentifier>();
172:                tbl.add(child1);
173:
174:                TableDependencySorter sorter = new TableDependencySorter(
175:                        this .dbConn);
176:                List<TableIdentifier> result = sorter.sortForDelete(tbl, true);
177:                //		for (TableIdentifier t : result)
178:                //		{
179:                //			System.out.println(t.toString());
180:                //		}
181:                //		System.out.println("--------------------");
182:
183:                // Should have added child1_detail and child1_detail2
184:                assertEquals("Not enough entries", 3, result.size());
185:                String first = result.get(0).getTableName().toLowerCase();
186:                String second = result.get(1).getTableName().toLowerCase();
187:                assertEquals("Wrong first table", true, first
188:                        .equals("child1_detail")
189:                        || first.equals("child1_detail2"));
190:                assertEquals("Wrong second table", true, second
191:                        .equals("child1_detail")
192:                        || second.equals("child1_detail2"));
193:                assertEquals("Wrong third table", "child1", result.get(2)
194:                        .getTableName().toLowerCase());
195:            }
196:
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.