diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs | 268 |
1 files changed, 268 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs new file mode 100644 index 0000000..e03e71d --- /dev/null +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs | |||
@@ -0,0 +1,268 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using NUnit.Framework; | ||
35 | using OpenMetaverse; | ||
36 | using OpenMetaverse.Messages.Linden; | ||
37 | using OpenMetaverse.Packets; | ||
38 | using OpenMetaverse.StructuredData; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Communications; | ||
41 | using OpenSim.Framework.Servers; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | using OpenSim.Region.ClientStack.Linden; | ||
44 | using OpenSim.Region.CoreModules.Avatar.InstantMessage; | ||
45 | using OpenSim.Region.CoreModules.Framework; | ||
46 | using OpenSim.Region.Framework.Scenes; | ||
47 | using OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups; | ||
48 | using OpenSim.Tests.Common; | ||
49 | |||
50 | namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups.Tests | ||
51 | { | ||
52 | /// <summary> | ||
53 | /// Basic groups module tests | ||
54 | /// </summary> | ||
55 | [TestFixture] | ||
56 | public class GroupsModuleTests : OpenSimTestCase | ||
57 | { | ||
58 | [SetUp] | ||
59 | public override void SetUp() | ||
60 | { | ||
61 | base.SetUp(); | ||
62 | |||
63 | uint port = 9999; | ||
64 | uint sslPort = 9998; | ||
65 | |||
66 | // This is an unfortunate bit of clean up we have to do because MainServer manages things through static | ||
67 | // variables and the VM is not restarted between tests. | ||
68 | MainServer.RemoveHttpServer(port); | ||
69 | |||
70 | BaseHttpServer server = new BaseHttpServer(port, false, sslPort, ""); | ||
71 | MainServer.AddHttpServer(server); | ||
72 | MainServer.Instance = server; | ||
73 | } | ||
74 | |||
75 | [Test] | ||
76 | public void TestSendAgentGroupDataUpdate() | ||
77 | { | ||
78 | TestHelpers.InMethod(); | ||
79 | // TestHelpers.EnableLogging(); | ||
80 | |||
81 | TestScene scene = new SceneHelpers().SetupScene(); | ||
82 | IConfigSource configSource = new IniConfigSource(); | ||
83 | IConfig config = configSource.AddConfig("Groups"); | ||
84 | config.Set("Enabled", true); | ||
85 | config.Set("Module", "GroupsModule"); | ||
86 | config.Set("DebugEnabled", true); | ||
87 | |||
88 | GroupsModule gm = new GroupsModule(); | ||
89 | EventQueueGetModule eqgm = new EventQueueGetModule(); | ||
90 | |||
91 | // We need a capabilities module active so that adding the scene presence creates an event queue in the | ||
92 | // EventQueueGetModule | ||
93 | SceneHelpers.SetupSceneModules( | ||
94 | scene, configSource, gm, new MockGroupsServicesConnector(), new CapabilitiesModule(), eqgm); | ||
95 | |||
96 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseStem("1")); | ||
97 | |||
98 | gm.SendAgentGroupDataUpdate(sp.ControllingClient); | ||
99 | |||
100 | Hashtable eventsResponse = eqgm.GetEvents(UUID.Zero, sp.UUID); | ||
101 | |||
102 | Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.OK)); | ||
103 | |||
104 | // Console.WriteLine("Response [{0}]", (string)eventsResponse["str_response_string"]); | ||
105 | |||
106 | OSDMap rawOsd = (OSDMap)OSDParser.DeserializeLLSDXml((string)eventsResponse["str_response_string"]); | ||
107 | OSDArray eventsOsd = (OSDArray)rawOsd["events"]; | ||
108 | |||
109 | bool foundUpdate = false; | ||
110 | foreach (OSD osd in eventsOsd) | ||
111 | { | ||
112 | OSDMap eventOsd = (OSDMap)osd; | ||
113 | |||
114 | if (eventOsd["message"] == "AgentGroupDataUpdate") | ||
115 | foundUpdate = true; | ||
116 | } | ||
117 | |||
118 | Assert.That(foundUpdate, Is.True, "Did not find AgentGroupDataUpdate in response"); | ||
119 | |||
120 | // TODO: More checking of more actual event data. | ||
121 | } | ||
122 | |||
123 | [Test] | ||
124 | public void TestSendGroupNotice() | ||
125 | { | ||
126 | TestHelpers.InMethod(); | ||
127 | // TestHelpers.EnableLogging(); | ||
128 | |||
129 | TestScene scene = new SceneHelpers().SetupScene(); | ||
130 | |||
131 | MessageTransferModule mtm = new MessageTransferModule(); | ||
132 | GroupsModule gm = new GroupsModule(); | ||
133 | GroupsMessagingModule gmm = new GroupsMessagingModule(); | ||
134 | MockGroupsServicesConnector mgsc = new MockGroupsServicesConnector(); | ||
135 | |||
136 | IConfigSource configSource = new IniConfigSource(); | ||
137 | |||
138 | { | ||
139 | IConfig config = configSource.AddConfig("Messaging"); | ||
140 | config.Set("MessageTransferModule", mtm.Name); | ||
141 | } | ||
142 | |||
143 | { | ||
144 | IConfig config = configSource.AddConfig("Groups"); | ||
145 | config.Set("Enabled", true); | ||
146 | config.Set("Module", gm.Name); | ||
147 | config.Set("DebugEnabled", true); | ||
148 | config.Set("MessagingModule", gmm.Name); | ||
149 | config.Set("MessagingEnabled", true); | ||
150 | } | ||
151 | |||
152 | SceneHelpers.SetupSceneModules(scene, configSource, mgsc, mtm, gm, gmm); | ||
153 | |||
154 | UUID userId = TestHelpers.ParseTail(0x1); | ||
155 | string subjectText = "newman"; | ||
156 | string messageText = "Hello"; | ||
157 | string combinedSubjectMessage = string.Format("{0}|{1}", subjectText, messageText); | ||
158 | |||
159 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); | ||
160 | TestClient tc = (TestClient)sp.ControllingClient; | ||
161 | |||
162 | UUID groupID = gm.CreateGroup(tc, "group1", null, true, UUID.Zero, 0, true, true, true); | ||
163 | gm.JoinGroupRequest(tc, groupID); | ||
164 | |||
165 | // Create a second user who doesn't want to receive notices | ||
166 | ScenePresence sp2 = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x2)); | ||
167 | TestClient tc2 = (TestClient)sp2.ControllingClient; | ||
168 | gm.JoinGroupRequest(tc2, groupID); | ||
169 | gm.SetGroupAcceptNotices(tc2, groupID, false, true); | ||
170 | |||
171 | List<GridInstantMessage> spReceivedMessages = new List<GridInstantMessage>(); | ||
172 | tc.OnReceivedInstantMessage += im => spReceivedMessages.Add(im); | ||
173 | |||
174 | List<GridInstantMessage> sp2ReceivedMessages = new List<GridInstantMessage>(); | ||
175 | tc2.OnReceivedInstantMessage += im => sp2ReceivedMessages.Add(im); | ||
176 | |||
177 | GridInstantMessage noticeIm = new GridInstantMessage(); | ||
178 | noticeIm.fromAgentID = userId.Guid; | ||
179 | noticeIm.toAgentID = groupID.Guid; | ||
180 | noticeIm.message = combinedSubjectMessage; | ||
181 | noticeIm.dialog = (byte)InstantMessageDialog.GroupNotice; | ||
182 | |||
183 | tc.HandleImprovedInstantMessage(noticeIm); | ||
184 | |||
185 | Assert.That(spReceivedMessages.Count, Is.EqualTo(1)); | ||
186 | Assert.That(spReceivedMessages[0].message, Is.EqualTo(combinedSubjectMessage)); | ||
187 | |||
188 | List<GroupNoticeData> notices = mgsc.GetGroupNotices(UUID.Zero, groupID); | ||
189 | Assert.AreEqual(1, notices.Count); | ||
190 | |||
191 | // OpenSimulator (possibly also SL) transport the notice ID as the session ID! | ||
192 | Assert.AreEqual(notices[0].NoticeID.Guid, spReceivedMessages[0].imSessionID); | ||
193 | |||
194 | Assert.That(sp2ReceivedMessages.Count, Is.EqualTo(0)); | ||
195 | } | ||
196 | |||
197 | /// <summary> | ||
198 | /// Run test with the MessageOnlineUsersOnly flag set. | ||
199 | /// </summary> | ||
200 | [Test] | ||
201 | public void TestSendGroupNoticeOnlineOnly() | ||
202 | { | ||
203 | TestHelpers.InMethod(); | ||
204 | // TestHelpers.EnableLogging(); | ||
205 | |||
206 | TestScene scene = new SceneHelpers().SetupScene(); | ||
207 | |||
208 | MessageTransferModule mtm = new MessageTransferModule(); | ||
209 | GroupsModule gm = new GroupsModule(); | ||
210 | GroupsMessagingModule gmm = new GroupsMessagingModule(); | ||
211 | |||
212 | IConfigSource configSource = new IniConfigSource(); | ||
213 | |||
214 | { | ||
215 | IConfig config = configSource.AddConfig("Messaging"); | ||
216 | config.Set("MessageTransferModule", mtm.Name); | ||
217 | } | ||
218 | |||
219 | { | ||
220 | IConfig config = configSource.AddConfig("Groups"); | ||
221 | config.Set("Enabled", true); | ||
222 | config.Set("Module", gm.Name); | ||
223 | config.Set("DebugEnabled", true); | ||
224 | config.Set("MessagingModule", gmm.Name); | ||
225 | config.Set("MessagingEnabled", true); | ||
226 | config.Set("MessageOnlineUsersOnly", true); | ||
227 | } | ||
228 | |||
229 | SceneHelpers.SetupSceneModules(scene, configSource, new MockGroupsServicesConnector(), mtm, gm, gmm); | ||
230 | |||
231 | UUID userId = TestHelpers.ParseTail(0x1); | ||
232 | string subjectText = "newman"; | ||
233 | string messageText = "Hello"; | ||
234 | string combinedSubjectMessage = string.Format("{0}|{1}", subjectText, messageText); | ||
235 | |||
236 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); | ||
237 | TestClient tc = (TestClient)sp.ControllingClient; | ||
238 | |||
239 | UUID groupID = gm.CreateGroup(tc, "group1", null, true, UUID.Zero, 0, true, true, true); | ||
240 | gm.JoinGroupRequest(tc, groupID); | ||
241 | |||
242 | // Create a second user who doesn't want to receive notices | ||
243 | ScenePresence sp2 = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x2)); | ||
244 | TestClient tc2 = (TestClient)sp2.ControllingClient; | ||
245 | gm.JoinGroupRequest(tc2, groupID); | ||
246 | gm.SetGroupAcceptNotices(tc2, groupID, false, true); | ||
247 | |||
248 | List<GridInstantMessage> spReceivedMessages = new List<GridInstantMessage>(); | ||
249 | tc.OnReceivedInstantMessage += im => spReceivedMessages.Add(im); | ||
250 | |||
251 | List<GridInstantMessage> sp2ReceivedMessages = new List<GridInstantMessage>(); | ||
252 | tc2.OnReceivedInstantMessage += im => sp2ReceivedMessages.Add(im); | ||
253 | |||
254 | GridInstantMessage noticeIm = new GridInstantMessage(); | ||
255 | noticeIm.fromAgentID = userId.Guid; | ||
256 | noticeIm.toAgentID = groupID.Guid; | ||
257 | noticeIm.message = combinedSubjectMessage; | ||
258 | noticeIm.dialog = (byte)InstantMessageDialog.GroupNotice; | ||
259 | |||
260 | tc.HandleImprovedInstantMessage(noticeIm); | ||
261 | |||
262 | Assert.That(spReceivedMessages.Count, Is.EqualTo(1)); | ||
263 | Assert.That(spReceivedMessages[0].message, Is.EqualTo(combinedSubjectMessage)); | ||
264 | |||
265 | Assert.That(sp2ReceivedMessages.Count, Is.EqualTo(0)); | ||
266 | } | ||
267 | } | ||
268 | } \ No newline at end of file | ||