1 package org.jbpm.identity; 2 3 import java.util.*; 4 5 import junit.framework.*; 6 7 public class MembershipTest extends TestCase { 8 9 public void testGroupsForGroupType() { 10 User john = new User("johndoe"); 11 Group qaTeam = new Group("qa team", "hierarchy"); 12 Group marketingTeam = new Group("marketing team", "hierarchy"); 13 Membership.create(john, "mgr", qaTeam); 14 Membership.create(john, "mgr", marketingTeam); 15 16 Set groups = john.getGroupsForGroupType("hierarchy"); 17 assertEquals(2, groups.size()); 18 assertEquals(2, groups.size()); 19 assertTrue(containsGroup(groups, "qa team")); 20 assertTrue(containsGroup(groups, "marketing team")); 21 } 22 23 public void testEmptyGroupsForGroupType() { 24 User john = new User("johndoe"); 25 Group qaTeam = new Group("qa team", "hierarchy"); 26 Group marketingTeam = new Group("marketing team", "hierarchy"); 27 Membership.create(john, "mgr", qaTeam); 28 Membership.create(john, "mgr", marketingTeam); 29 30 Set groups = john.getGroupsForGroupType("non-existing-group-type"); 31 assertNotNull(groups); 32 assertEquals(0, groups.size()); 33 } 34 35 public void testGetGroupsForRole() { 36 User john = new User("johndoe"); 37 Group qaTeam = new Group("qa team", "hierarchy"); 38 Group marketingTeam = new Group("marketing team", "hierarchy"); 39 Group nozems = new Group("nozems"); 40 Membership.create(john, "mgr", qaTeam); 41 Membership.create(john, "mgr", marketingTeam); 42 Membership.create(john, "member", nozems); 43 44 Set groups = john.getGroupsForMembershipName("mgr"); 45 assertEquals(2, groups.size()); 46 } 47 48 public void testGetUsersInRole() { 49 User john = new User("johndoe"); 50 Group qaTeam = new Group("qa team", "hierarchy"); 51 Group marketingTeam = new Group("marketing team", "hierarchy"); 52 Membership.create(john, "mgr", qaTeam); 53 Membership.create(john, "mgr", marketingTeam); 54 55 assertEquals(1, qaTeam.getUsersForMembershipName("mgr").size()); 56 assertSame(john, qaTeam.getUsersForMembershipName("mgr").iterator().next()); 57 assertEquals(1, marketingTeam.getUsersForMembershipName("mgr").size()); 58 assertSame(john, marketingTeam.getUsersForMembershipName("mgr").iterator().next()); 59 } 60 61 public void testGetNoUsersInRole() { 62 Set users = new Group().getUsersForMembershipName("buzz"); 63 assertNotNull(users); 64 assertEquals(0, users.size()); 65 } 66 67 public boolean containsGroup(Set groups, String groupName) { 68 Iterator iter = groups.iterator(); 69 while (iter.hasNext()) { 70 if( groupName.equals(((Group)iter.next()).getName())) { 71 return true; 72 } 73 } 74 return false; 75 } 76 } 77
| Popular Tags
|