1 package com.atlassian.user.impl.osuser;
2
3 import com.atlassian.user.*;
4 import com.atlassian.user.generic.AbstractTestGroupManager;
5
6 import java.util.Iterator;
7
8 public class TestOSUserGroupManager extends AbstractTestGroupManager
9 {
10 private OSUAccessor accessor;
11 protected OSUUserManager osuUserManager;
12 protected OSUGroupManager osuGroupManager;
13
14 protected String[] getConfigLocations()
15 {
16 return new String[]{
17 "classpath:com/atlassian/user/impl/osuser/osuserTestContext.xml",
18 "classpath:com/atlassian/user/dataSourceTestContext.xml",
19 };
20 }
21
22 protected void onTearDown() throws Exception
23 {
24 deleteUsersAndGroups();
25 super.onTearDown();
26 deleteUsersAndGroups();
27 }
28
29 private void deleteUsersAndGroups()
30 throws EntityException
31 {
32 for(Iterator i = osuGroupManager.getGroups().iterator(); i.hasNext(); ) {
33 Group group = (Group) i.next();
34 osuGroupManager.removeGroup(group);
35 }
36 for(Iterator i = osuUserManager.getUsers().iterator(); i.hasNext(); ) {
37 User user = (User) i.next();
38 osuUserManager.removeUser(user);
39 }
40 }
41
42 public void testGetGroupReturnsOSUGroup() throws EntityException
43 {
44 boolean created = accessor.getAccessProvider().create("group");
45 assertTrue("Could not create group through provider", created);
46
47 Group groupA = getGroupManager().getGroup("group");
48 assertNotNull(groupA);
49
50 Group groupB = new OSUGroup(new com.opensymphony.user.Group("group", accessor));
51 assertEquals("The osuserGroupManager is not returning groups equivalent to the opensymphony osuser construct",
52 groupA, groupB);
53 }
54
55 public void testCreateGroupCreatesOSUGroup() throws EntityException
56 {
57 Group groupA = getGroupManager().createGroup("group");
58 Group groupB = new OSUGroup(new com.opensymphony.user.Group("group", accessor));
59 assertEquals("The osuserUserManager is not creating users equivalent to the opensymphony osuser construct",
60 groupA, groupB);
61 }
62
63 protected UserManager getUserManager()
64 {
65 return osuUserManager;
66 }
67
68 protected GroupManager getGroupManager()
69 {
70 return osuGroupManager;
71 }
72
73 public void setAccessor(OSUAccessor accessor)
74 {
75 this.accessor = accessor;
76 }
77
78 public void setOsuUserManager(OSUUserManager osuUserManager)
79 {
80 this.osuUserManager = osuUserManager;
81 }
82
83 public void setOsuGroupManager(OSUGroupManager osuGroupManager)
84 {
85 this.osuGroupManager = osuGroupManager;
86 }
87 }