KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > identity > hibernate > UserDbTest


1 package org.jbpm.identity.hibernate;
2
3 import java.net.*;
4 import java.security.*;
5 import java.util.*;
6
7 import org.jbpm.identity.*;
8
9 public class UserDbTest extends IdentityDbTestCase {
10
11   public void testUser() {
12     User user = new User("johndoe");
13     user = saveAndReload(user);
14     assertEquals("johndoe", user.getName());
15   }
16   
17   public void testUserMemberships() {
18     User john = new User("johndoe");
19     Group qaTeam = new Group("qa team", "hierarchy");
20     Group marketingTeam = new Group("marketing team", "hierarchy");
21     Membership.create(john, "mgr", qaTeam);
22     Membership.create(john, "mgr", marketingTeam);
23     
24     john = saveAndReload(john);
25     
26     Set groups = john.getGroupsForGroupType("hierarchy");
27     
28     assertEquals(2, groups.size());
29     assertEquals(2, groups.size());
30     assertTrue(containsGroup(groups, "qa team"));
31     assertTrue(containsGroup(groups, "marketing team"));
32   }
33   
34   public void testUserPermissions() {
35     User user = new User("johndoe");
36     user.addPermission(new NetPermission("connect", "9001"));
37     user.addPermission(new AllPermission("all", "everything"));
38     
39     user = saveAndReload(user);
40     
41     Set permissions = user.getPermissions();
42     assertNotNull(permissions);
43     assertEquals(2, permissions.size());
44     
45   }
46   
47   public boolean containsGroup(Set groups, String JavaDoc groupName) {
48     Iterator iter = groups.iterator();
49     while (iter.hasNext()) {
50       if( groupName.equals(((Group)iter.next()).getName())) {
51         return true;
52       }
53     }
54     return false;
55   }
56 }
57
Popular Tags