Source Code Cross Referenced for RoleServiceTest.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » workflow » role » 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 » ERP CRM Financial » Kuali Financial System » org.kuali.workflow.role 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 The Kuali Foundation.
003:         *
004:         *
005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         * http://www.opensource.org/licenses/ecl1.php
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.kuali.workflow.role;
018:
019:        import java.sql.Timestamp;
020:
021:        import org.junit.Ignore;
022:        import org.junit.Test;
023:        import org.kuali.workflow.identity.IdentityType;
024:        import org.kuali.workflow.test.WorkflowTestCase;
025:
026:        import edu.iu.uis.eden.KEWServiceLocator;
027:        import edu.iu.uis.eden.routetemplate.RuleAttribute;
028:
029:        /**
030:         *
031:         * @author ewestfal
032:         */
033:        public class RoleServiceTest extends WorkflowTestCase {
034:
035:            private RoleService roleService;
036:
037:            @Override
038:            protected void setUpTransaction() throws Exception {
039:                super .setUpTransaction();
040:                roleService = KEWServiceLocator.getRoleService();
041:            }
042:
043:            @Ignore
044:            @Test
045:            public void testSaveRole() throws Exception {
046:                Role role = new Role();
047:                role.setDescription("My Description");
048:                role.setName("RoleServiceTestRole");
049:                assertNull(role.getRoleId());
050:                roleService.save(role);
051:                assertNotNull(role.getRoleId());
052:
053:                // refetch the Role
054:                Role roleRefetched = roleService.findRoleByName(role.getName());
055:                assertEquals("Role IDs should be the same.", role.getRoleId(),
056:                        roleRefetched.getRoleId());
057:                roleRefetched = roleService.findRoleById(role.getRoleId());
058:                assertEquals("Role names should be the same.", role.getName(),
059:                        roleRefetched.getName());
060:
061:                // add some attributes
062:                RuleAttribute ruleAttribute = KEWServiceLocator
063:                        .getRuleAttributeService().findByName(
064:                                "TestRuleAttribute");
065:                assertNotNull("TestRuleAttribute should exist", ruleAttribute);
066:                RoleAttribute roleAttribute = new RoleAttribute();
067:                roleAttribute.setRole(roleRefetched);
068:                roleAttribute.setRuleAttribute(ruleAttribute);
069:                roleRefetched.getAttributes().add(roleAttribute);
070:                roleService.save(roleRefetched);
071:
072:                assertEquals("Role IDs should be the same.", roleRefetched
073:                        .getRoleId(), roleAttribute.getRoleId());
074:                assertEquals("Rule Attribute IDs should be the same.",
075:                        ruleAttribute.getRuleAttributeId(), roleAttribute
076:                                .getRuleAttributeId());
077:                assertNotNull("Role Attribute should have an ID.",
078:                        roleAttribute.getRoleAttributeId());
079:
080:                // refetch the Role
081:                roleRefetched = roleService.findRoleByName(role.getName());
082:                assertEquals("Should have 1 attribute", 1, roleRefetched
083:                        .getAttributes().size());
084:
085:                // save a Role without a description, should be legal
086:                role = new Role();
087:                role.setName("RoleServiceTestRole2");
088:                roleService.save(role);
089:                role = roleService.findRoleByName("RoleServiceTestRole2");
090:                assertNull(role.getDescription());
091:                role.setDescription("");
092:                roleService.save(role);
093:                role = roleService.findRoleByName("RoleServiceTestRole2");
094:                // the database doesn't store an empty string but rather NULL (could this be Oracle-specific?)
095:                assertNull(role.getDescription());
096:            }
097:
098:            @Ignore
099:            @Test
100:            public void testRoleNameUnique() throws Exception {
101:                Role role = new Role();
102:                role.setDescription("desc1");
103:                role.setName("RoleServiceTestRole");
104:                assertNull(role.getRoleId());
105:                roleService.save(role);
106:
107:                // try saving a role with the same name, we should encounter an error
108:                Role role2 = new Role();
109:                role2.setDescription("desc2");
110:                role2.setName("RoleServiceTestRole");
111:                try {
112:                    roleService.save(role2);
113:                    fail("An error should have been thrown when attempting to save a Role with a duplicate name.");
114:                } catch (Exception e) {
115:                }
116:
117:                // while we're at it, check that we can't enter an empty role name
118:                role2.setName(null);
119:                try {
120:                    roleService.save(role2);
121:                    fail("An error should have been thrown when attempting to save a Role with a null name.");
122:                } catch (Exception e) {
123:                }
124:
125:                role2.setName("");
126:                try {
127:                    roleService.save(role2);
128:                    fail("An error should have been thrown when attempting to save a Role with an empty name.");
129:                } catch (Exception e) {
130:                }
131:            }
132:
133:            @Ignore
134:            @Test
135:            public void testSaveQualifiedRole() throws Exception {
136:                // create and save the Role
137:                Role role = new Role();
138:                role.setName("RoleServiceTestRole-testSaveQualifiedRole");
139:                RoleAttribute roleAttribute = new RoleAttribute();
140:                roleAttribute.setRole(role);
141:                roleAttribute.setRuleAttribute(KEWServiceLocator
142:                        .getRuleAttributeService().findByName(
143:                                "TestRuleAttribute"));
144:                role.getAttributes().add(roleAttribute);
145:                roleService.save(role);
146:
147:                // create qualified role
148:                QualifiedRole qRole = new QualifiedRole();
149:                Timestamp now = new Timestamp(System.currentTimeMillis());
150:                qRole.setActivationDate(now);
151:                qRole.setActive(true);
152:                qRole.setCurrent(true);
153:                qRole.setDescription("My First Qualified Role");
154:                qRole.setRole(role);
155:                qRole.setVersionNumber(new Integer(0));
156:
157:                // add members
158:                QualifiedRoleMember member1 = new QualifiedRoleMember();
159:                member1.setMemberId("ewestfal");
160:                member1.setMemberType(IdentityType.USER);
161:                member1.setQualifiedRole(qRole);
162:                qRole.getMembers().add(member1);
163:
164:                QualifiedRoleMember member2 = new QualifiedRoleMember();
165:                member2.setMemberId("MyWorkgroup");
166:                member2.setMemberType(IdentityType.GROUP);
167:                member2.setQualifiedRole(qRole);
168:                qRole.getMembers().add(member2);
169:
170:                // add extension 1
171:                QualifiedRoleExtension extension1 = new QualifiedRoleExtension();
172:                extension1.setQualifiedRole(qRole);
173:                extension1.setRoleAttribute(roleAttribute);
174:
175:                QualifiedRoleExtensionValue extension1Value1 = new QualifiedRoleExtensionValue();
176:                extension1Value1.setExtension(extension1);
177:                extension1Value1.setKey("chart");
178:                extension1Value1.setValue("BL");
179:
180:                QualifiedRoleExtensionValue extension1Value2 = new QualifiedRoleExtensionValue();
181:                extension1Value2.setExtension(extension1);
182:                extension1Value2.setKey("org");
183:                extension1Value2.setValue("PSY");
184:
185:                extension1.getExtensionValues().add(extension1Value1);
186:                extension1.getExtensionValues().add(extension1Value2);
187:
188:                qRole.getExtensions().add(extension1);
189:
190:                // add extension 2
191:                QualifiedRoleExtension extension2 = new QualifiedRoleExtension();
192:                extension2.setQualifiedRole(qRole);
193:                extension2.setRoleAttribute(roleAttribute);
194:
195:                QualifiedRoleExtensionValue extension2Value1 = new QualifiedRoleExtensionValue();
196:                extension2Value1.setExtension(extension2);
197:                extension2Value1.setKey("totalAmount");
198:                extension2Value1.setValue("1234");
199:                extension2.getExtensionValues().add(extension2Value1);
200:
201:                qRole.getExtensions().add(extension2);
202:
203:                // save the qualified role
204:                roleService.save(qRole);
205:
206:                // reload it and make sure all of the data was sucessfully saved
207:                QualifiedRole qRole2 = roleService.findQualifiedRoleById(qRole
208:                        .getQualifiedRoleId());
209:                assertNotNull(qRole2);
210:                assertNotNull(qRole2.getQualifiedRoleId());
211:                assertTrue(qRole2.isActive());
212:                assertTrue(qRole2.isCurrent());
213:                assertNotNull(qRole2.getRole());
214:                assertEquals(role.getName(), qRole2.getRole().getName());
215:
216:                // check the members
217:                assertEquals(2, qRole2.getMembers().size());
218:                member1 = qRole2.getMembers().get(0);
219:                member2 = qRole2.getMembers().get(1);
220:                assertEquals("ewestfal", member1.getMemberId());
221:                assertEquals(IdentityType.USER, member1.getMemberType());
222:                assertEquals(member1.getQualifiedRoleMemberId(), member1
223:                        .getResponsibilityId());
224:                assertEquals("MyWorkgroup", member2.getMemberId());
225:                assertEquals(IdentityType.GROUP, member2.getMemberType());
226:                assertEquals(member2.getQualifiedRoleMemberId(), member2
227:                        .getResponsibilityId());
228:
229:                // remove a member
230:                qRole2.getMembers().remove(1);
231:                roleService.save(qRole2);
232:
233:                // now check that it got removed
234:                qRole2 = roleService.findQualifiedRoleById(qRole2
235:                        .getQualifiedRoleId());
236:                assertEquals(1, qRole2.getMembers().size());
237:                assertEquals("ewestfal", qRole2.getMembers().get(0)
238:                        .getMemberId());
239:
240:                // check the extensions
241:                assertEquals(2, qRole2.getExtensions().size());
242:                extension1 = qRole2.getExtensions().get(0);
243:                extension2 = qRole2.getExtensions().get(1);
244:
245:                assertEquals("TestRuleAttribute", extension1.getRoleAttribute()
246:                        .getRuleAttribute().getName());
247:                assertEquals(2, extension1.getExtensionValues().size());
248:                extension1Value1 = extension1.getExtensionValues().get(0);
249:                extension1Value2 = extension1.getExtensionValues().get(1);
250:                assertEquals("chart", extension1Value1.getKey());
251:                assertEquals("BL", extension1Value1.getValue());
252:                assertEquals("org", extension1Value2.getKey());
253:                assertEquals("PSY", extension1Value2.getValue());
254:
255:                // remove a value and an extension
256:                extension1.getExtensionValues().remove(extension1Value1);
257:                qRole2.getExtensions().remove(extension2);
258:                roleService.save(qRole2);
259:
260:                // verify that there is only 1 extension left with 1 value
261:                qRole2 = roleService.findQualifiedRoleById(qRole2
262:                        .getQualifiedRoleId());
263:                assertEquals(1, qRole2.getExtensions().size());
264:                extension1 = qRole2.getExtensions().get(0);
265:                assertEquals(1, extension1.getExtensionValues().size());
266:                assertEquals("org", extension1.getExtensionValues().get(0)
267:                        .getKey());
268:            }
269:
270:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.