clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 using OpenSim.Tests.Common.Mock;
50  
51 namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups.Tests
52 {
53 /// <summary>
54 /// Basic groups module tests
55 /// </summary>
56 [TestFixture]
57 public class GroupsModuleTests : OpenSimTestCase
58 {
59 [SetUp]
60 public override void SetUp()
61 {
62 base.SetUp();
63  
64 uint port = 9999;
65 uint sslPort = 9998;
66  
67 // This is an unfortunate bit of clean up we have to do because MainServer manages things through static
68 // variables and the VM is not restarted between tests.
69 MainServer.RemoveHttpServer(port);
70  
71 BaseHttpServer server = new BaseHttpServer(port, false, sslPort, "");
72 MainServer.AddHttpServer(server);
73 MainServer.Instance = server;
74 }
75  
76 [Test]
77 public void TestSendAgentGroupDataUpdate()
78 {
79 TestHelpers.InMethod();
80 // TestHelpers.EnableLogging();
81  
82 TestScene scene = new SceneHelpers().SetupScene();
83 IConfigSource configSource = new IniConfigSource();
84 IConfig config = configSource.AddConfig("Groups");
85 config.Set("Enabled", true);
86 config.Set("Module", "GroupsModule");
87 config.Set("DebugEnabled", true);
88  
89 GroupsModule gm = new GroupsModule();
90 EventQueueGetModule eqgm = new EventQueueGetModule();
91  
92 // We need a capabilities module active so that adding the scene presence creates an event queue in the
93 // EventQueueGetModule
94 SceneHelpers.SetupSceneModules(
95 scene, configSource, gm, new MockGroupsServicesConnector(), new CapabilitiesModule(), eqgm);
96  
97 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseStem("1"));
98  
99 gm.SendAgentGroupDataUpdate(sp.ControllingClient);
100  
101 Hashtable eventsResponse = eqgm.GetEvents(UUID.Zero, sp.UUID);
102  
103 Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.OK));
104  
105 // Console.WriteLine("Response [{0}]", (string)eventsResponse["str_response_string"]);
106  
107 OSDMap rawOsd = (OSDMap)OSDParser.DeserializeLLSDXml((string)eventsResponse["str_response_string"]);
108 OSDArray eventsOsd = (OSDArray)rawOsd["events"];
109  
110 bool foundUpdate = false;
111 foreach (OSD osd in eventsOsd)
112 {
113 OSDMap eventOsd = (OSDMap)osd;
114  
115 if (eventOsd["message"] == "AgentGroupDataUpdate")
116 foundUpdate = true;
117 }
118  
119 Assert.That(foundUpdate, Is.True, "Did not find AgentGroupDataUpdate in response");
120  
121 // TODO: More checking of more actual event data.
122 }
123  
124 [Test]
125 public void TestSendGroupNotice()
126 {
127 TestHelpers.InMethod();
128 // TestHelpers.EnableLogging();
129  
130 TestScene scene = new SceneHelpers().SetupScene();
131  
132 MessageTransferModule mtm = new MessageTransferModule();
133 GroupsModule gm = new GroupsModule();
134 GroupsMessagingModule gmm = new GroupsMessagingModule();
135 MockGroupsServicesConnector mgsc = new MockGroupsServicesConnector();
136  
137 IConfigSource configSource = new IniConfigSource();
138  
139 {
140 IConfig config = configSource.AddConfig("Messaging");
141 config.Set("MessageTransferModule", mtm.Name);
142 }
143  
144 {
145 IConfig config = configSource.AddConfig("Groups");
146 config.Set("Enabled", true);
147 config.Set("Module", gm.Name);
148 config.Set("DebugEnabled", true);
149 config.Set("MessagingModule", gmm.Name);
150 config.Set("MessagingEnabled", true);
151 }
152  
153 SceneHelpers.SetupSceneModules(scene, configSource, mgsc, mtm, gm, gmm);
154  
155 UUID userId = TestHelpers.ParseTail(0x1);
156 string subjectText = "newman";
157 string messageText = "Hello";
158 string combinedSubjectMessage = string.Format("{0}|{1}", subjectText, messageText);
159  
160 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
161 TestClient tc = (TestClient)sp.ControllingClient;
162  
163 UUID groupID = gm.CreateGroup(tc, "group1", null, true, UUID.Zero, 0, true, true, true);
164 gm.JoinGroupRequest(tc, groupID);
165  
166 // Create a second user who doesn't want to receive notices
167 ScenePresence sp2 = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x2));
168 TestClient tc2 = (TestClient)sp2.ControllingClient;
169 gm.JoinGroupRequest(tc2, groupID);
170 gm.SetGroupAcceptNotices(tc2, groupID, false, true);
171  
172 List<GridInstantMessage> spReceivedMessages = new List<GridInstantMessage>();
173 tc.OnReceivedInstantMessage += im => spReceivedMessages.Add(im);
174  
175 List<GridInstantMessage> sp2ReceivedMessages = new List<GridInstantMessage>();
176 tc2.OnReceivedInstantMessage += im => sp2ReceivedMessages.Add(im);
177  
178 GridInstantMessage noticeIm = new GridInstantMessage();
179 noticeIm.fromAgentID = userId.Guid;
180 noticeIm.toAgentID = groupID.Guid;
181 noticeIm.message = combinedSubjectMessage;
182 noticeIm.dialog = (byte)InstantMessageDialog.GroupNotice;
183  
184 tc.HandleImprovedInstantMessage(noticeIm);
185  
186 Assert.That(spReceivedMessages.Count, Is.EqualTo(1));
187 Assert.That(spReceivedMessages[0].message, Is.EqualTo(combinedSubjectMessage));
188  
189 List<GroupNoticeData> notices = mgsc.GetGroupNotices(UUID.Zero, groupID);
190 Assert.AreEqual(1, notices.Count);
191  
192 // OpenSimulator (possibly also SL) transport the notice ID as the session ID!
193 Assert.AreEqual(notices[0].NoticeID.Guid, spReceivedMessages[0].imSessionID);
194  
195 Assert.That(sp2ReceivedMessages.Count, Is.EqualTo(0));
196 }
197  
198 /// <summary>
199 /// Run test with the MessageOnlineUsersOnly flag set.
200 /// </summary>
201 [Test]
202 public void TestSendGroupNoticeOnlineOnly()
203 {
204 TestHelpers.InMethod();
205 // TestHelpers.EnableLogging();
206  
207 TestScene scene = new SceneHelpers().SetupScene();
208  
209 MessageTransferModule mtm = new MessageTransferModule();
210 GroupsModule gm = new GroupsModule();
211 GroupsMessagingModule gmm = new GroupsMessagingModule();
212  
213 IConfigSource configSource = new IniConfigSource();
214  
215 {
216 IConfig config = configSource.AddConfig("Messaging");
217 config.Set("MessageTransferModule", mtm.Name);
218 }
219  
220 {
221 IConfig config = configSource.AddConfig("Groups");
222 config.Set("Enabled", true);
223 config.Set("Module", gm.Name);
224 config.Set("DebugEnabled", true);
225 config.Set("MessagingModule", gmm.Name);
226 config.Set("MessagingEnabled", true);
227 config.Set("MessageOnlineUsersOnly", true);
228 }
229  
230 SceneHelpers.SetupSceneModules(scene, configSource, new MockGroupsServicesConnector(), mtm, gm, gmm);
231  
232 UUID userId = TestHelpers.ParseTail(0x1);
233 string subjectText = "newman";
234 string messageText = "Hello";
235 string combinedSubjectMessage = string.Format("{0}|{1}", subjectText, messageText);
236  
237 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
238 TestClient tc = (TestClient)sp.ControllingClient;
239  
240 UUID groupID = gm.CreateGroup(tc, "group1", null, true, UUID.Zero, 0, true, true, true);
241 gm.JoinGroupRequest(tc, groupID);
242  
243 // Create a second user who doesn't want to receive notices
244 ScenePresence sp2 = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x2));
245 TestClient tc2 = (TestClient)sp2.ControllingClient;
246 gm.JoinGroupRequest(tc2, groupID);
247 gm.SetGroupAcceptNotices(tc2, groupID, false, true);
248  
249 List<GridInstantMessage> spReceivedMessages = new List<GridInstantMessage>();
250 tc.OnReceivedInstantMessage += im => spReceivedMessages.Add(im);
251  
252 List<GridInstantMessage> sp2ReceivedMessages = new List<GridInstantMessage>();
253 tc2.OnReceivedInstantMessage += im => sp2ReceivedMessages.Add(im);
254  
255 GridInstantMessage noticeIm = new GridInstantMessage();
256 noticeIm.fromAgentID = userId.Guid;
257 noticeIm.toAgentID = groupID.Guid;
258 noticeIm.message = combinedSubjectMessage;
259 noticeIm.dialog = (byte)InstantMessageDialog.GroupNotice;
260  
261 tc.HandleImprovedInstantMessage(noticeIm);
262  
263 Assert.That(spReceivedMessages.Count, Is.EqualTo(1));
264 Assert.That(spReceivedMessages[0].message, Is.EqualTo(combinedSubjectMessage));
265  
266 Assert.That(sp2ReceivedMessages.Count, Is.EqualTo(0));
267 }
268 }
269 }