From 71918eeab4beee076d53469e8d19addab49135b7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 7 Mar 2014 01:04:40 +0000 Subject: Add regression test for sending group notices via xmlrpc groups connector. --- OpenSim/Data/IXGroupData.cs | 59 +++++++- OpenSim/Data/Null/NullXGroupData.cs | 34 ++--- .../Avatar/XmlRpcGroups/GroupsModule.cs | 1 + .../Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs | 55 ++++++++ .../Common/Mock/MockGroupsServicesConnector.cs | 152 +++++++++++++++++---- prebuild.xml | 3 +- 6 files changed, 255 insertions(+), 49 deletions(-) diff --git a/OpenSim/Data/IXGroupData.cs b/OpenSim/Data/IXGroupData.cs index 2965e8c..e5821ef 100644 --- a/OpenSim/Data/IXGroupData.cs +++ b/OpenSim/Data/IXGroupData.cs @@ -48,9 +48,57 @@ namespace OpenSim.Data public ulong everyonePowers; public ulong ownersPowers; + public Dictionary members = new Dictionary(); + public Dictionary notices = new Dictionary(); + public XGroup Clone() { - return (XGroup)MemberwiseClone(); + XGroup clone = (XGroup)MemberwiseClone(); + clone.members = new Dictionary(); + clone.notices = new Dictionary(); + + foreach (KeyValuePair kvp in members) + clone.members[kvp.Key] = kvp.Value.Clone(); + + foreach (KeyValuePair kvp in notices) + clone.notices[kvp.Key] = kvp.Value.Clone(); + + return clone; + } + } + + public class XGroupMember + { + public UUID agentID; + public UUID groupID; + public UUID roleID; + public bool acceptNotices = true; + public bool listInProfile = true; + + public XGroupMember Clone() + { + return (XGroupMember)MemberwiseClone(); + } + } + + public class XGroupNotice + { + public UUID groupID; + public UUID noticeID; + public uint timestamp; + public string fromName; + public string subject; + public string message; + public byte[] binaryBucket; + public bool hasAttachment; + public int assetType; + + public XGroupNotice Clone() + { + XGroupNotice clone = (XGroupNotice)MemberwiseClone(); + clone.binaryBucket = (byte[])binaryBucket.Clone(); + + return clone; } } @@ -58,14 +106,13 @@ namespace OpenSim.Data /// Early stub interface for groups data, not final. /// /// - /// Currently in-use only for regression test purposes. Needs to be filled out over time. + /// Currently in-use only for regression test purposes. /// public interface IXGroupData { bool StoreGroup(XGroup group); - XGroup[] GetGroups(string field, string val); - XGroup[] GetGroups(string[] fields, string[] vals); - bool DeleteGroups(string field, string val); - bool DeleteGroups(string[] fields, string[] vals); + XGroup GetGroup(UUID groupID); + Dictionary GetGroups(); + bool DeleteGroup(UUID groupID); } } \ No newline at end of file diff --git a/OpenSim/Data/Null/NullXGroupData.cs b/OpenSim/Data/Null/NullXGroupData.cs index 7a86b9f..3fa9451 100644 --- a/OpenSim/Data/Null/NullXGroupData.cs +++ b/OpenSim/Data/Null/NullXGroupData.cs @@ -38,7 +38,7 @@ using OpenSim.Data; namespace OpenSim.Data.Null { - public class NullXGroupData : NullGenericDataHandler, IXGroupData + public class NullXGroupData : IXGroupData { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -56,35 +56,31 @@ namespace OpenSim.Data.Null return true; } - public XGroup[] GetGroups(string field, string val) + public XGroup GetGroup(UUID groupID) { - return GetGroups(new string[] { field }, new string[] { val }); - } + XGroup group = null; - public XGroup[] GetGroups(string[] fields, string[] vals) - { lock (m_groups) - { - List origGroups = Get(fields, vals, m_groups.Values.ToList()); + m_groups.TryGetValue(groupID, out group); - return origGroups.Select(g => g.Clone()).ToArray(); - } + return group; } - public bool DeleteGroups(string field, string val) + public Dictionary GetGroups() { - return DeleteGroups(new string[] { field }, new string[] { val }); + Dictionary groupsClone = new Dictionary(); + + lock (m_groups) + foreach (XGroup group in m_groups.Values) + groupsClone[group.groupID] = group.Clone(); + + return groupsClone; } - public bool DeleteGroups(string[] fields, string[] vals) + public bool DeleteGroup(UUID groupID) { lock (m_groups) - { - XGroup[] groupsToDelete = GetGroups(fields, vals); - Array.ForEach(groupsToDelete, g => m_groups.Remove(g.groupID)); - } - - return true; + return m_groups.Remove(groupID); } } } \ No newline at end of file diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs index d09d3ad..62020ee 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs @@ -497,6 +497,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups OnNewGroupNotice(GroupID, NoticeID); } + /*** We would insert call code here ***/ // Send notice out to everyone that wants notices foreach (GroupMembersData member in m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), GroupID)) { diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs index 26d2597..08a93b8 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs @@ -27,6 +27,7 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Net; using System.Reflection; using Nini.Config; @@ -118,5 +119,59 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups.Tests // TODO: More checking of more actual event data. } + + [Test] + public void TestSendGroupNotice() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + TestScene scene = new SceneHelpers().SetupScene(); + IConfigSource configSource = new IniConfigSource(); + IConfig config = configSource.AddConfig("Groups"); + config.Set("Enabled", true); + config.Set("Module", "GroupsModule"); + config.Set("DebugEnabled", true); + + GroupsModule gm = new GroupsModule(); + + SceneHelpers.SetupSceneModules(scene, configSource, gm, new MockGroupsServicesConnector()); + + UUID userId = TestHelpers.ParseTail(0x1); + string subjectText = "newman"; + string messageText = "Hello"; + string combinedSubjectMessage = string.Format("{0}|{1}", subjectText, messageText); + + ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); + TestClient tc = (TestClient)sp.ControllingClient; + + UUID groupID = gm.CreateGroup(tc, "group1", null, true, UUID.Zero, 0, true, true, true); + gm.JoinGroupRequest(tc, groupID); + + // Create a second user who doesn't want to receive notices + ScenePresence sp2 = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x2)); + TestClient tc2 = (TestClient)sp2.ControllingClient; + gm.JoinGroupRequest(tc2, groupID); + gm.SetGroupAcceptNotices(tc2, groupID, false, true); + + List spReceivedMessages = new List(); + tc.OnReceivedInstantMessage += im => spReceivedMessages.Add(im); + + List sp2ReceivedMessages = new List(); + tc2.OnReceivedInstantMessage += im => sp2ReceivedMessages.Add(im); + + GridInstantMessage noticeIm = new GridInstantMessage(); + noticeIm.fromAgentID = userId.Guid; + noticeIm.toAgentID = groupID.Guid; + noticeIm.message = combinedSubjectMessage; + noticeIm.dialog = (byte)InstantMessageDialog.GroupNotice; + + tc.HandleImprovedInstantMessage(noticeIm); + + Assert.That(spReceivedMessages.Count, Is.EqualTo(1)); + Assert.That(spReceivedMessages[0].message, Is.EqualTo(combinedSubjectMessage)); + + Assert.That(sp2ReceivedMessages.Count, Is.EqualTo(0)); + } } } \ No newline at end of file diff --git a/OpenSim/Tests/Common/Mock/MockGroupsServicesConnector.cs b/OpenSim/Tests/Common/Mock/MockGroupsServicesConnector.cs index 3035cea..b3f8c36 100644 --- a/OpenSim/Tests/Common/Mock/MockGroupsServicesConnector.cs +++ b/OpenSim/Tests/Common/Mock/MockGroupsServicesConnector.cs @@ -138,33 +138,28 @@ namespace OpenSim.Tests.Common.Mock { } + private XGroup GetXGroup(UUID groupID, string name) + { + XGroup group = m_data.GetGroup(groupID); + + + if (group == null) + m_log.DebugFormat("[MOCK GROUPS SERVICES CONNECTOR]: No group found with ID {0}", groupID); + + return group; + } + public GroupRecord GetGroupRecord(UUID requestingAgentID, UUID groupID, string groupName) { m_log.DebugFormat( "[MOCK GROUPS SERVICES CONNECTOR]: Processing GetGroupRecord() for groupID {0}, name {1}", groupID, groupName); - XGroup[] groups; - string field, val; - - if (groupID != UUID.Zero) - { - field = "groupID"; - val = groupID.ToString(); - } - else - { - field = "name"; - val = groupName; - } - - groups = m_data.GetGroups(field, val); + XGroup xg = GetXGroup(groupID, groupName); - if (groups.Length == 0) + if (xg == null) return null; - XGroup xg = groups[0]; - GroupRecord gr = new GroupRecord() { GroupID = xg.groupID, @@ -196,8 +191,25 @@ namespace OpenSim.Tests.Common.Mock { } - public void SetAgentGroupInfo(UUID requestingAgentID, UUID AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile) + public void SetAgentGroupInfo(UUID requestingAgentID, UUID agentID, UUID groupID, bool acceptNotices, bool listInProfile) { + m_log.DebugFormat( + "[MOCK GROUPS SERVICES CONNECTOR]: SetAgentGroupInfo, requestingAgentID {0}, agentID {1}, groupID {2}, acceptNotices {3}, listInProfile {4}", + requestingAgentID, agentID, groupID, acceptNotices, listInProfile); + + XGroup group = GetXGroup(groupID, null); + + if (group == null) + return; + + XGroupMember xgm = null; + if (!group.members.TryGetValue(agentID, out xgm)) + return; + + xgm.acceptNotices = acceptNotices; + xgm.listInProfile = listInProfile; + + m_data.StoreGroup(group); } public void AddAgentToGroupInvite(UUID requestingAgentID, UUID inviteID, UUID groupID, UUID roleID, UUID agentID) @@ -213,8 +225,27 @@ namespace OpenSim.Tests.Common.Mock { } - public void AddAgentToGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID) + public void AddAgentToGroup(UUID requestingAgentID, UUID agentID, UUID groupID, UUID roleID) { + m_log.DebugFormat( + "[MOCK GROUPS SERVICES CONNECTOR]: AddAgentToGroup, requestingAgentID {0}, agentID {1}, groupID {2}, roleID {3}", + requestingAgentID, agentID, groupID, roleID); + + XGroup group = GetXGroup(groupID, null); + + if (group == null) + return; + + XGroupMember groupMember = new XGroupMember() + { + agentID = agentID, + groupID = groupID, + roleID = roleID + }; + + group.members[agentID] = groupMember; + + m_data.StoreGroup(group); } public void RemoveAgentFromGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID) @@ -259,9 +290,31 @@ namespace OpenSim.Tests.Common.Mock return null; } - public List GetGroupMembers(UUID requestingAgentID, UUID GroupID) + public List GetGroupMembers(UUID requestingAgentID, UUID groupID) { - return null; + m_log.DebugFormat( + "[MOCK GROUPS SERVICES CONNECTOR]: GetGroupMembers, requestingAgentID {0}, groupID {1}", + requestingAgentID, groupID); + + List groupMembers = new List(); + + XGroup group = GetXGroup(groupID, null); + + if (group == null) + return groupMembers; + + foreach (XGroupMember xgm in group.members.Values) + { + GroupMembersData gmd = new GroupMembersData(); + gmd.AgentID = xgm.agentID; + gmd.IsOwner = group.founderID == gmd.AgentID; + gmd.AcceptNotices = xgm.acceptNotices; + gmd.ListInProfile = xgm.listInProfile; + + groupMembers.Add(gmd); + } + + return groupMembers; } public List GetGroupRoleMembers(UUID requestingAgentID, UUID GroupID) @@ -269,18 +322,71 @@ namespace OpenSim.Tests.Common.Mock return null; } - public List GetGroupNotices(UUID requestingAgentID, UUID GroupID) + public List GetGroupNotices(UUID requestingAgentID, UUID groupID) { return null; } public GroupNoticeInfo GetGroupNotice(UUID requestingAgentID, UUID noticeID) { + m_log.DebugFormat( + "[MOCK GROUPS SERVICES CONNECTOR]: GetGroupNotices, requestingAgentID {0}, noticeID {1}", + requestingAgentID, noticeID); + + // Yes, not an efficient way to do it. + Dictionary groups = m_data.GetGroups(); + + foreach (XGroup group in groups.Values) + { + if (group.notices.ContainsKey(noticeID)) + { + XGroupNotice n = group.notices[noticeID]; + + GroupNoticeInfo gni = new GroupNoticeInfo(); + gni.GroupID = n.groupID; + gni.Message = n.message; + gni.BinaryBucket = n.binaryBucket; + gni.noticeData.NoticeID = n.noticeID; + gni.noticeData.Timestamp = n.timestamp; + gni.noticeData.FromName = n.fromName; + gni.noticeData.Subject = n.subject; + gni.noticeData.HasAttachment = n.hasAttachment; + gni.noticeData.AssetType = (byte)n.assetType; + + return gni; + } + } + return null; } public void AddGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket) { + m_log.DebugFormat( + "[MOCK GROUPS SERVICES CONNECTOR]: AddGroupNotice, requestingAgentID {0}, groupID {1}, noticeID {2}, fromName {3}, subject {4}, message {5}, binaryBucket.Length {6}", + requestingAgentID, groupID, noticeID, fromName, subject, message, binaryBucket.Length); + + XGroup group = GetXGroup(groupID, null); + + if (group == null) + return; + + XGroupNotice groupNotice = new XGroupNotice() + { + groupID = groupID, + noticeID = noticeID, + fromName = fromName, + subject = subject, + message = message, + timestamp = (uint)Util.UnixTimeSinceEpoch(), + hasAttachment = false, + assetType = 0, + binaryBucket = binaryBucket + }; + + group.notices[noticeID] = groupNotice; + + m_data.StoreGroup(group); } public void ResetAgentGroupChatSessions(UUID agentID) diff --git a/prebuild.xml b/prebuild.xml index dfb30dc..356110a 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -279,8 +279,9 @@ ../../bin/ - + + -- cgit v1.1