aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Common/Mock/TestGroupsDataPlugin.cs
diff options
context:
space:
mode:
authorDiva Canto2017-05-04 20:17:54 -0700
committerDiva Canto2017-05-04 20:17:54 -0700
commit3f641d98bd4c9fa1ce5b98c8d071f53596d06a7a (patch)
treed0c85c9026d8272b891fac21e1c83703b9d14c0a /OpenSim/Tests/Common/Mock/TestGroupsDataPlugin.cs
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-3f641d98bd4c9fa1ce5b98c8d071f53596d06a7a.zip
opensim-SC_OLD-3f641d98bd4c9fa1ce5b98c8d071f53596d06a7a.tar.gz
opensim-SC_OLD-3f641d98bd4c9fa1ce5b98c8d071f53596d06a7a.tar.bz2
opensim-SC_OLD-3f641d98bd4c9fa1ce5b98c8d071f53596d06a7a.tar.xz
Added a fully functional groups data layer for testing.
Diffstat (limited to '')
-rw-r--r--OpenSim/Tests/Common/Mock/TestGroupsDataPlugin.cs339
1 files changed, 339 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/Mock/TestGroupsDataPlugin.cs b/OpenSim/Tests/Common/Mock/TestGroupsDataPlugin.cs
new file mode 100644
index 0000000..8e2d8e6
--- /dev/null
+++ b/OpenSim/Tests/Common/Mock/TestGroupsDataPlugin.cs
@@ -0,0 +1,339 @@
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6using OpenMetaverse;
7using OpenSim.Data;
8
9namespace OpenSim.Tests.Common.Mock
10{
11 public class TestGroupsDataPlugin : IGroupsData
12 {
13 class CompositeKey
14 {
15 private readonly string _key;
16 public string Key
17 {
18 get { return _key; }
19 }
20
21 public CompositeKey(UUID _k1, string _k2)
22 {
23 _key = _k1.ToString() + _k2;
24 }
25
26 public CompositeKey(UUID _k1, string _k2, string _k3)
27 {
28 _key = _k1.ToString() + _k2 + _k3;
29 }
30
31 public override bool Equals(object obj)
32 {
33 if (obj is CompositeKey)
34 {
35 return Key == ((CompositeKey)obj).Key;
36 }
37 return false;
38 }
39
40 public override int GetHashCode()
41 {
42 return base.GetHashCode();
43 }
44
45 public override string ToString()
46 {
47 return Key;
48 }
49 }
50
51 private Dictionary<UUID, GroupData> m_Groups;
52 private Dictionary<CompositeKey, MembershipData> m_Membership;
53 private Dictionary<CompositeKey, RoleData> m_Roles;
54 private Dictionary<CompositeKey, RoleMembershipData> m_RoleMembership;
55 private Dictionary<UUID, InvitationData> m_Invites;
56 private Dictionary<UUID, NoticeData> m_Notices;
57 private Dictionary<string, PrincipalData> m_Principals;
58
59 public TestGroupsDataPlugin(string connectionString, string realm)
60 {
61 m_Groups = new Dictionary<UUID, GroupData>();
62 m_Membership = new Dictionary<CompositeKey, MembershipData>();
63 m_Roles = new Dictionary<CompositeKey, RoleData>();
64 m_RoleMembership = new Dictionary<CompositeKey, RoleMembershipData>();
65 m_Invites = new Dictionary<UUID, InvitationData>();
66 m_Notices = new Dictionary<UUID, NoticeData>();
67 m_Principals = new Dictionary<string, PrincipalData>();
68 }
69
70 #region groups table
71 public bool StoreGroup(GroupData data)
72 {
73 return false;
74 }
75
76 public GroupData RetrieveGroup(UUID groupID)
77 {
78 if (m_Groups.ContainsKey(groupID))
79 return m_Groups[groupID];
80
81 return null;
82 }
83
84 public GroupData RetrieveGroup(string name)
85 {
86 return m_Groups.Values.First(g => g.Data.ContainsKey("Name") && g.Data["Name"] == name);
87 }
88
89 public GroupData[] RetrieveGroups(string pattern)
90 {
91 if (string.IsNullOrEmpty(pattern))
92 pattern = "1";
93
94 IEnumerable<GroupData> groups = m_Groups.Values.Where(g => g.Data.ContainsKey("Name") && (g.Data["Name"].StartsWith(pattern) || g.Data["Name"].EndsWith(pattern)));
95
96 return (groups != null) ? groups.ToArray() : new GroupData[0];
97 }
98
99 public bool DeleteGroup(UUID groupID)
100 {
101 return m_Groups.Remove(groupID);
102 }
103
104 public int GroupsCount()
105 {
106 return m_Groups.Count;
107 }
108 #endregion
109
110 #region membership table
111 public MembershipData RetrieveMember(UUID groupID, string pricipalID)
112 {
113 CompositeKey dkey = new CompositeKey(groupID, pricipalID);
114 if (m_Membership.ContainsKey(dkey))
115 return m_Membership[dkey];
116
117 return null;
118 }
119
120 public MembershipData[] RetrieveMembers(UUID groupID)
121 {
122 IEnumerable<CompositeKey> keys = m_Membership.Keys.Where(k => k.Key.StartsWith(groupID.ToString()));
123 return keys.Where(m_Membership.ContainsKey).Select(x => m_Membership[x]).ToArray();
124 }
125
126 public MembershipData[] RetrieveMemberships(string principalID)
127 {
128 IEnumerable<CompositeKey> keys = m_Membership.Keys.Where(k => k.Key.EndsWith(principalID.ToString()));
129 return keys.Where(m_Membership.ContainsKey).Select(x => m_Membership[x]).ToArray();
130 }
131
132 public MembershipData[] RetrievePrincipalGroupMemberships(string principalID)
133 {
134 return RetrieveMemberships(principalID);
135 }
136
137 public MembershipData RetrievePrincipalGroupMembership(string principalID, UUID groupID)
138 {
139 CompositeKey dkey = new CompositeKey(groupID, principalID);
140 if (m_Membership.ContainsKey(dkey))
141 return m_Membership[dkey];
142 return null;
143 }
144
145 public bool StoreMember(MembershipData data)
146 {
147 CompositeKey dkey = new CompositeKey(data.GroupID, data.PrincipalID);
148 m_Membership[dkey] = data;
149 return true;
150 }
151
152 public bool DeleteMember(UUID groupID, string principalID)
153 {
154 CompositeKey dkey = new CompositeKey(groupID, principalID);
155 if (m_Membership.ContainsKey(dkey))
156 return m_Membership.Remove(dkey);
157
158 return false;
159 }
160
161 public int MemberCount(UUID groupID)
162 {
163 return m_Membership.Count;
164 }
165 #endregion
166
167 #region roles table
168 public bool StoreRole(RoleData data)
169 {
170 CompositeKey dkey = new CompositeKey(data.GroupID, data.RoleID.ToString());
171 m_Roles[dkey] = data;
172 return true;
173 }
174
175 public RoleData RetrieveRole(UUID groupID, UUID roleID)
176 {
177 CompositeKey dkey = new CompositeKey(groupID, roleID.ToString());
178 if (m_Roles.ContainsKey(dkey))
179 return m_Roles[dkey];
180
181 return null;
182 }
183
184 public RoleData[] RetrieveRoles(UUID groupID)
185 {
186 IEnumerable<CompositeKey> keys = m_Roles.Keys.Where(k => k.Key.StartsWith(groupID.ToString()));
187 return keys.Where(m_Roles.ContainsKey).Select(x => m_Roles[x]).ToArray();
188 }
189
190 public bool DeleteRole(UUID groupID, UUID roleID)
191 {
192 CompositeKey dkey = new CompositeKey(groupID, roleID.ToString());
193 if (m_Roles.ContainsKey(dkey))
194 return m_Roles.Remove(dkey);
195
196 return false;
197 }
198
199 public int RoleCount(UUID groupID)
200 {
201 return m_Roles.Count;
202 }
203 #endregion
204
205 #region rolememberhip table
206 public RoleMembershipData[] RetrieveRolesMembers(UUID groupID)
207 {
208 IEnumerable<CompositeKey> keys = m_Roles.Keys.Where(k => k.Key.StartsWith(groupID.ToString()));
209 return keys.Where(m_RoleMembership.ContainsKey).Select(x => m_RoleMembership[x]).ToArray();
210 }
211
212 public RoleMembershipData[] RetrieveRoleMembers(UUID groupID, UUID roleID)
213 {
214 IEnumerable<CompositeKey> keys = m_Roles.Keys.Where(k => k.Key.StartsWith(groupID.ToString() + roleID.ToString()));
215 return keys.Where(m_RoleMembership.ContainsKey).Select(x => m_RoleMembership[x]).ToArray();
216 }
217
218 public RoleMembershipData[] RetrieveMemberRoles(UUID groupID, string principalID)
219 {
220 IEnumerable<CompositeKey> keys = m_Roles.Keys.Where(k => k.Key.StartsWith(groupID.ToString()) && k.Key.EndsWith(principalID));
221 return keys.Where(m_RoleMembership.ContainsKey).Select(x => m_RoleMembership[x]).ToArray();
222 }
223
224 public RoleMembershipData RetrieveRoleMember(UUID groupID, UUID roleID, string principalID)
225 {
226 CompositeKey dkey = new CompositeKey(groupID, roleID.ToString(), principalID);
227 if (m_RoleMembership.ContainsKey(dkey))
228 return m_RoleMembership[dkey];
229
230 return null;
231 }
232
233 public int RoleMemberCount(UUID groupID, UUID roleID)
234 {
235 return m_RoleMembership.Count;
236 }
237
238 public bool StoreRoleMember(RoleMembershipData data)
239 {
240 CompositeKey dkey = new CompositeKey(data.GroupID, data.RoleID.ToString(), data.PrincipalID);
241 m_RoleMembership[dkey] = data;
242 return true;
243 }
244
245 public bool DeleteRoleMember(RoleMembershipData data)
246 {
247 CompositeKey dkey = new CompositeKey(data.GroupID, data.RoleID.ToString(), data.PrincipalID);
248 if (m_RoleMembership.ContainsKey(dkey))
249 return m_RoleMembership.Remove(dkey);
250
251 return false;
252 }
253
254 public bool DeleteMemberAllRoles(UUID groupID, string principalID)
255 {
256 List<CompositeKey> keys = m_RoleMembership.Keys.Where(k => k.Key.StartsWith(groupID.ToString()) && k.Key.EndsWith(principalID)).ToList();
257 foreach (CompositeKey k in keys)
258 m_RoleMembership.Remove(k);
259 return true;
260 }
261 #endregion
262
263 #region principals table
264 public bool StorePrincipal(PrincipalData data)
265 {
266 m_Principals[data.PrincipalID] = data;
267 return true;
268 }
269
270 public PrincipalData RetrievePrincipal(string principalID)
271 {
272 if (m_Principals.ContainsKey(principalID))
273 return m_Principals[principalID];
274
275 return null;
276 }
277
278 public bool DeletePrincipal(string principalID)
279 {
280 if (m_Principals.ContainsKey(principalID))
281 return m_Principals.Remove(principalID);
282 return false;
283 }
284 #endregion
285
286 #region invites table
287 public bool StoreInvitation(InvitationData data)
288 {
289 return false;
290 }
291
292 public InvitationData RetrieveInvitation(UUID inviteID)
293 {
294 return null;
295 }
296
297 public InvitationData RetrieveInvitation(UUID groupID, string principalID)
298 {
299 return null;
300 }
301
302 public bool DeleteInvite(UUID inviteID)
303 {
304 return false;
305 }
306
307 public void DeleteOldInvites()
308 {
309 }
310 #endregion
311
312 #region notices table
313 public bool StoreNotice(NoticeData data)
314 {
315 return false;
316 }
317
318 public NoticeData RetrieveNotice(UUID noticeID)
319 {
320 return null;
321 }
322
323 public NoticeData[] RetrieveNotices(UUID groupID)
324 {
325 return new NoticeData[0];
326 }
327
328 public bool DeleteNotice(UUID noticeID)
329 {
330 return false;
331 }
332
333 public void DeleteOldNotices()
334 {
335 }
336 #endregion
337
338 }
339}