Source Code Cross Referenced for ManyToManyTest.java in  » Database-ORM » jaxor-3.5 » net » sourceforge » jaxor » example » users » tests » 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 » jaxor 3.5 » net.sourceforge.jaxor.example.users.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.jaxor.example.users.tests;
002:
003:        import net.sourceforge.jaxor.QueryParams;
004:        import net.sourceforge.jaxor.api.JaxorContext;
005:        import net.sourceforge.jaxor.example.tests.MultiTableTestCase;
006:        import net.sourceforge.jaxor.example.users.*;
007:
008:        import java.util.ArrayList;
009:        import java.util.List;
010:
011:        /**
012:         * Created By:   Mike
013:         * Date:         Nov 22, 2003
014:         * Time:         10:17:32 PM
015:         *
016:         * Last Checkin: $Author: mrettig $
017:         * Date:         $Date: 2004/02/14 16:29:11 $
018:         * Revision:     $Revision: 1.17 $
019:         */
020:        public class ManyToManyTest extends MultiTableTestCase {
021:
022:            private static final UserMetaRow userMeta = new UserMetaRow();
023:
024:            protected List getRows() {
025:                // the test case will setup these tables in the DB.
026:                List list = new ArrayList();
027:                list.add(new GroupMetaRow());
028:                list.add(userMeta);
029:                list.add(new GroupMemberMetaRow());
030:                return list;
031:            }
032:
033:            /**
034:             * Create a users and a group, then tests various queries to ensure that they resolve the right entities.
035:             */
036:            public void testCreatingMembers() {
037:                UserEntity user = UserFinder.newInstance("user");
038:                GroupEntity group = GroupFinder.newInstance("myGroup");
039:                group.setAdminUser(user);
040:                GroupMemberFinder.newInstance("myGroup", "user");
041:                commit();
042:                assertEquals(1, user.getGroupList().size());
043:                assertEquals(1, group.getUserList().size());
044:                assertEquals(user, group.getUserList().get(0));
045:                assertEquals(group, user.getGroupList().get(0));
046:                assertEquals(user, group.getAdminUser());
047:                assertEquals(group.getAdminUser(), group
048:                        .getAdminUserWithQuery());
049:                assertEquals(group.getAdminUser(), UserFinder
050:                        .selectAdmin("myGroup"));
051:                assertEquals(group.getAdminUserWithQuery(), group
052:                        .getAdminUserWithFind());
053:
054:                UserList userListWithFind = group.getUserListWithFind();
055:                userListWithFind.size();
056:                assertEquals(userListWithFind, group.getUserList());
057:                assertEquals(0, group.getNonAdminUsers().size());
058:
059:                UserFinder.newInstance("non-admin-user");
060:                //add the user to the group.
061:                GroupMemberFinder.newInstance("myGroup", "non-admin-user");
062:                commit();
063:                assertEquals(2, GroupMemberFinder.selectByGroupNameList(
064:                        "myGroup").size());
065:                // We need to refetch the group since we've inserted into the DB. The prior group instance
066:                // caches the results of references.
067:                group = GroupFinder.selectByGroupName("myGroup");
068:                assertEquals(2, group.getUserList().size());
069:                assertEquals(1, group.getNonAdminUsers().size());
070:                assertEquals(user, group.getAdminUser());
071:
072:                UserList genUserList = UserFinder.selectAdminsOfGroupsList();
073:                assertEquals(1, genUserList.size());
074:                //This is the equivalent query if written by hand.
075:                UserList userList = UserFinder
076:                        .query("select * from user_table u, groups g where u.user_name=g.admin_user_name");
077:                assertEquals(1, userList.size());
078:                assertEquals(genUserList, userList);
079:            }
080:
081:            public void testSelectingUsersOrderedByGroup() {
082:                UserEntity user = UserFinder.newInstance("user");
083:                GroupEntity group = GroupFinder.newInstance("myGroup");
084:                GroupMemberFinder.newInstance("myGroup", "user");
085:                group.setAdminUser(user);
086:                UserEntity user2 = UserFinder.newInstance("andrew");
087:                GroupEntity group2 = GroupFinder.newInstance("admin");
088:                GroupMemberFinder.newInstance("admin", "andrew");
089:                group2.setAdminUser(user2);
090:                commit();
091:
092:                UserList usersByGroup = UserFinder.selectByGroupList();
093:                assertEquals(2, usersByGroup.size());
094:                assertEquals(user2, usersByGroup.get(0));
095:                assertEquals(user, usersByGroup.get(1));
096:            }
097:
098:            public void testFinderExamples() {
099:                UserFinder.newInstance("mike");
100:                commit();
101:                JaxorContext jaxorContext = getJaxor();
102:                UserFinderBase finder = new UserFinderBase(jaxorContext);
103:                UserEntity user = finder.selectByUserName("mike");
104:
105:                user = finder.findUnique("where user_name='mike'", false);
106:
107:                QueryParams params = new QueryParams();
108:                params.addString("mike");
109:                user = finder.findUnique("where user_name=?", params, false);
110:
111:                user = finder.queryUnique("select * from "
112:                        + userMeta.getTableName() + " where user_name='mike'",
113:                        false);
114:
115:                UserQuery userQuery = finder
116:                        .asFindQuery("where user_name='mike'");
117:                userQuery.entity();
118:
119:                userQuery = finder.asQuery("select * from "
120:                        + userMeta.getTableName() + " where user_name='mike'");
121:                userQuery.entity();
122:                user = userQuery.entityProxy();
123:                user.getUserName();
124:                UserList list = userQuery.list();
125:                assertEquals(1, list.size());
126:                UserResultSet userRS = userQuery.resultSet();
127:                try {
128:                    assertTrue(userRS.hasNext());
129:                    userRS.next();
130:                } finally {
131:                    userRS.close();
132:                }
133:            }
134:
135:            public void testSettingEntityRefToNull() {
136:                GroupEntity group = new GroupBase();
137:                group.setAdminUser(null);
138:                assertNull(group.getAdminUser());
139:            }
140:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.