Source Code Cross Referenced for ViewTests.java in  » Database-ORM » beankeeper » hu » netmind » persistence » 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 ORM » beankeeper » hu.netmind.persistence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (C) 2006 NetMind Consulting Bt.
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 3 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */package hu.netmind.persistence;
018:
019:        import java.util.List;
020:        import java.util.Map;
021:
022:        /**
023:         * Class tests the view capability of library.
024:         * @author Brautigam Robert
025:         * @version Revision: $Revision$
026:         */
027:        public class ViewTests extends AbstractPersistenceTest {
028:            public ViewTests(String name) throws Exception {
029:                super (name);
030:            }
031:
032:            public void testNonExistentTable() throws Exception {
033:                // Test
034:                List result = store.find("view nonexist.self");
035:                assertEquals(0, result.size());
036:            }
037:
038:            public void testViewSimple1() throws Exception {
039:                // Drop table
040:                dropTables("book");
041:                // Insert two books
042:                store.save(new Book("Title1", ""));
043:                store.save(new Book("Title2", ""));
044:                // Get view of titles
045:                List result = store
046:                        .find("view book.title order by book.title asc");
047:                // Check
048:                assertEquals(2, result.size());
049:                for (int i = 0; i < 2; i++) {
050:                    Map value = (Map) result.get(i);
051:                    assertEquals("Title" + (i + 1), value.get("title")
052:                            .toString());
053:                }
054:            }
055:
056:            public void testViewSimple2() throws Exception {
057:                // Drop table
058:                dropTables("book");
059:                // Insert two books
060:                store.save(new Book("Title1", "12341"));
061:                store.save(new Book("Title2", "12342"));
062:                // Get view of titles
063:                List result = store
064:                        .find("view book.title,book.isbn order by book.title asc");
065:                // Check
066:                assertEquals(2, result.size());
067:                for (int i = 0; i < 2; i++) {
068:                    Map value = (Map) result.get(i);
069:                    assertEquals("Title" + (i + 1), value.get("title")
070:                            .toString());
071:                    assertEquals("1234" + (i + 1), value.get("isbn").toString());
072:                }
073:            }
074:
075:            public void testViewMoreTables() throws Exception {
076:                // Drop table
077:                dropTables("book");
078:                dropTables("author");
079:                // Insert two books
080:                Book book1 = new Book("Java For Dummies", "51966");
081:                book1.setMainAuthor(new Author("Ada", "Lovelace"));
082:                store.save(book1);
083:                store.save(new Author("Bjarne", "Stroustrup"));
084:                // Get view of titles
085:                List result = store
086:                        .find("view book.title,author.firstname where book.mainauthor=author");
087:                // Check
088:                assertEquals(1, result.size());
089:                Map value = (Map) result.get(0);
090:                assertEquals("Java For Dummies", value.get("title").toString());
091:                assertEquals("Ada", value.get("firstname").toString());
092:            }
093:
094:            public void testViewComplexAttribute() throws Exception {
095:                // Drop table
096:                dropTables("book");
097:                dropTables("author");
098:                // Insert two books
099:                Book book1 = new Book("Java For Dummies", "51966");
100:                book1.setMainAuthor(new Author("Ada", "Lovelace"));
101:                store.save(book1);
102:                store.save(new Author("Bjarne", "Stroustrup"));
103:                // Get view of titles
104:                List result = store
105:                        .find("view book.title,book.mainauthor.firstname");
106:                // Check
107:                assertEquals(1, result.size());
108:                Map value = (Map) result.get(0);
109:                assertEquals("Java For Dummies", value.get("title").toString());
110:                assertEquals("Ada", value.get("firstname").toString());
111:            }
112:
113:            public void testViewComplexAttributeWithAliases() throws Exception {
114:                // Drop table
115:                dropTables("book");
116:                dropTables("author");
117:                // Insert two books
118:                Book book1 = new Book("Java For Dummies", "51966");
119:                book1.setMainAuthor(new Author("Ada", "Lovelace"));
120:                store.save(book1);
121:                store.save(new Author("Bjarne", "Stroustrup"));
122:                // Get view of titles
123:                List result = store
124:                        .find("view book.title a,book.mainauthor.firstname b");
125:                // Check
126:                assertEquals(1, result.size());
127:                Map value = (Map) result.get(0);
128:                assertEquals("Java For Dummies", value.get("a").toString());
129:                assertEquals("Ada", value.get("b").toString());
130:            }
131:
132:            public void testTargetSubclass() throws Exception {
133:                // Drop tables
134:                dropTables("referrer");
135:                dropTables("referrersubclass");
136:                // Insert stuff
137:                store.save(new ReferrerSubclass(1, 1));
138:                store.save(new Referrer(2));
139:                // Select
140:                List result = store
141:                        .find("view referrersubclass.subidentity,referrersubclass.identity order by referrersubclass.identity");
142:                // Check
143:                assertEquals(1, result.size());
144:                Map map1 = (Map) result.get(0);
145:                assertEquals("" + 1, map1.get("identity").toString());
146:                assertEquals("" + 1, map1.get("subidentity").toString());
147:            }
148:
149:            public void testTargetSubclassSuperclassFirst() throws Exception {
150:                // Drop tables
151:                dropTables("referrer");
152:                dropTables("referrersubclass");
153:                // Insert stuff
154:                store.save(new ReferrerSubclass(1, 1));
155:                store.save(new Referrer(2));
156:                // Select
157:                List result = store
158:                        .find("view referrersubclass.identity,referrersubclass.subidentity order by referrersubclass.identity");
159:                // Check
160:                assertEquals(1, result.size());
161:                Map map1 = (Map) result.get(0);
162:                assertEquals("" + 1, map1.get("identity").toString());
163:                assertEquals("" + 1, map1.get("subidentity").toString());
164:            }
165:
166:            public void testOrderByNonExistentAttribute() throws Exception {
167:                // Drop table
168:                dropTables("book");
169:                // Insert two books
170:                store.save(new Book("Title1", ""));
171:                store.save(new Book("Title2", ""));
172:                // Get view of titles
173:                List result = store
174:                        .find("view book.isbn order by book.title asc");
175:                // Check
176:                assertEquals(2, result.size());
177:            }
178:
179:            public void testKeywordAttribute() throws Exception {
180:                // Drop table
181:                dropTables("nametester");
182:                // Create
183:                NameTester n = new NameTester();
184:                n.setSelect("OK");
185:                store.save(n);
186:                // Select
187:                List result = store.find("view nametester.select");
188:                assertEquals(1, result.size());
189:                assertEquals("OK", ((Map) result.get(0)).get("select"));
190:            }
191:
192:            public void testUnspecifiedAttribute() throws Exception {
193:                // Drop table
194:                dropTables("book");
195:                // Insert book
196:                store.save(new Book("Title", "Isbn"));
197:                // Get view
198:                List result = store.find("view book.title,isbn");
199:                // Check
200:                assertEquals(0, result.size());
201:            }
202:
203:            public void testSimilarNamedAttributes() throws Exception {
204:                // Drop table
205:                dropTables("book");
206:                // Insert books
207:                store.save(new Book("Title 1", "ISBN"));
208:                store.save(new Book("Title 2", "ISBN"));
209:                store.save(new Book("Title 3", "NONE"));
210:                // Get joined view of titles
211:                List result = store
212:                        .find("view book1(book).title a, book2(book).title b where book1.isbn=book2.isbn and book1.title<>book2.title order by book1.title asc");
213:                // Check
214:                assertEquals(2, result.size());
215:                Map value1 = (Map) result.get(0);
216:                assertEquals("Title 1", value1.get("a"));
217:                assertEquals("Title 2", value1.get("b"));
218:                Map value2 = (Map) result.get(1);
219:                assertEquals("Title 2", value2.get("a"));
220:                assertEquals("Title 1", value2.get("b"));
221:            }
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.