OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
GroupsModuleTests.cs
Go to the documentation of this file.
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.Servers;
41 using OpenSim.Framework.Servers.HttpServer;
42 using OpenSim.Region.ClientStack.Linden;
43 using OpenSim.Region.CoreModules.Avatar.InstantMessage;
44 using OpenSim.Region.CoreModules.Framework;
45 using OpenSim.Region.Framework.Scenes;
46 using OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups;
47 using OpenSim.Tests.Common;
48 
49 namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups.Tests
50 {
54  [TestFixture]
56  {
57  [SetUp]
58  public override void SetUp()
59  {
60  base.SetUp();
61 
62  uint port = 9999;
63  uint sslPort = 9998;
64 
65  // This is an unfortunate bit of clean up we have to do because MainServer manages things through static
66  // variables and the VM is not restarted between tests.
67  MainServer.RemoveHttpServer(port);
68 
69  BaseHttpServer server = new BaseHttpServer(port, false, sslPort, "");
70  MainServer.AddHttpServer(server);
71  MainServer.Instance = server;
72  }
73 
74  [Test]
76  {
77 /* AgentGroupDataUpdate is udp
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  if((int)eventsResponse["int_response_code"] != (int)HttpStatusCode.OK)
103  {
104  eventsResponse = eqgm.GetEvents(UUID.Zero, sp.UUID);
105  if((int)eventsResponse["int_response_code"] != (int)HttpStatusCode.OK)
106  eventsResponse = eqgm.GetEvents(UUID.Zero, sp.UUID);
107  }
108 
109  Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.OK));
110 
111 // Console.WriteLine("Response [{0}]", (string)eventsResponse["str_response_string"]);
112 
113  OSDMap rawOsd = (OSDMap)OSDParser.DeserializeLLSDXml((string)eventsResponse["str_response_string"]);
114  OSDArray eventsOsd = (OSDArray)rawOsd["events"];
115 
116  bool foundUpdate = false;
117  foreach (OSD osd in eventsOsd)
118  {
119  OSDMap eventOsd = (OSDMap)osd;
120 
121  if (eventOsd["message"] == "AgentGroupDataUpdate")
122  foundUpdate = true;
123  }
124 
125  Assert.That(foundUpdate, Is.True, "Did not find AgentGroupDataUpdate in response");
126 
127  // TODO: More checking of more actual event data.
128 */
129  }
130 
131  [Test]
132  public void TestSendGroupNotice()
133  {
134  TestHelpers.InMethod();
135 // TestHelpers.EnableLogging();
136 
137  TestScene scene = new SceneHelpers().SetupScene();
138 
140  GroupsModule gm = new GroupsModule();
143 
144  IConfigSource configSource = new IniConfigSource();
145 
146  {
147  IConfig config = configSource.AddConfig("Messaging");
148  config.Set("MessageTransferModule", mtm.Name);
149  }
150 
151  {
152  IConfig config = configSource.AddConfig("Groups");
153  config.Set("Enabled", true);
154  config.Set("Module", gm.Name);
155  config.Set("DebugEnabled", true);
156  config.Set("MessagingModule", gmm.Name);
157  config.Set("MessagingEnabled", true);
158  }
159 
160  SceneHelpers.SetupSceneModules(scene, configSource, mgsc, mtm, gm, gmm);
161 
162  UUID userId = TestHelpers.ParseTail(0x1);
163  string subjectText = "newman";
164  string messageText = "Hello";
165  string combinedSubjectMessage = string.Format("{0}|{1}", subjectText, messageText);
166 
167  ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
168  TestClient tc = (TestClient)sp.ControllingClient;
169 
170  UUID groupID = gm.CreateGroup(tc, "group1", null, true, UUID.Zero, 0, true, true, true);
171  gm.JoinGroupRequest(tc, groupID);
172 
173  // Create a second user who doesn't want to receive notices
174  ScenePresence sp2 = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x2));
175  TestClient tc2 = (TestClient)sp2.ControllingClient;
176  gm.JoinGroupRequest(tc2, groupID);
177  gm.SetGroupAcceptNotices(tc2, groupID, false, true);
178 
179  List<GridInstantMessage> spReceivedMessages = new List<GridInstantMessage>();
180  tc.OnReceivedInstantMessage += im => spReceivedMessages.Add(im);
181 
182  List<GridInstantMessage> sp2ReceivedMessages = new List<GridInstantMessage>();
183  tc2.OnReceivedInstantMessage += im => sp2ReceivedMessages.Add(im);
184 
185  GridInstantMessage noticeIm = new GridInstantMessage();
186  noticeIm.fromAgentID = userId.Guid;
187  noticeIm.toAgentID = groupID.Guid;
188  noticeIm.message = combinedSubjectMessage;
189  noticeIm.dialog = (byte)InstantMessageDialog.GroupNotice;
190 
191  tc.HandleImprovedInstantMessage(noticeIm);
192 
193  Assert.That(spReceivedMessages.Count, Is.EqualTo(1));
194  Assert.That(spReceivedMessages[0].message, Is.EqualTo(combinedSubjectMessage));
195 
196  List<GroupNoticeData> notices = mgsc.GetGroupNotices(UUID.Zero, groupID);
197  Assert.AreEqual(1, notices.Count);
198 
199  // OpenSimulator (possibly also SL) transport the notice ID as the session ID!
200  Assert.AreEqual(notices[0].NoticeID.Guid, spReceivedMessages[0].imSessionID);
201 
202  Assert.That(sp2ReceivedMessages.Count, Is.EqualTo(0));
203  }
204 
208  [Test]
210  {
211  TestHelpers.InMethod();
212  // TestHelpers.EnableLogging();
213 
214  TestScene scene = new SceneHelpers().SetupScene();
215 
217  GroupsModule gm = new GroupsModule();
219 
220  IConfigSource configSource = new IniConfigSource();
221 
222  {
223  IConfig config = configSource.AddConfig("Messaging");
224  config.Set("MessageTransferModule", mtm.Name);
225  }
226 
227  {
228  IConfig config = configSource.AddConfig("Groups");
229  config.Set("Enabled", true);
230  config.Set("Module", gm.Name);
231  config.Set("DebugEnabled", true);
232  config.Set("MessagingModule", gmm.Name);
233  config.Set("MessagingEnabled", true);
234  config.Set("MessageOnlineUsersOnly", true);
235  }
236 
237  SceneHelpers.SetupSceneModules(scene, configSource, new MockGroupsServicesConnector(), mtm, gm, gmm);
238 
239  UUID userId = TestHelpers.ParseTail(0x1);
240  string subjectText = "newman";
241  string messageText = "Hello";
242  string combinedSubjectMessage = string.Format("{0}|{1}", subjectText, messageText);
243 
244  ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
245  TestClient tc = (TestClient)sp.ControllingClient;
246 
247  UUID groupID = gm.CreateGroup(tc, "group1", null, true, UUID.Zero, 0, true, true, true);
248  gm.JoinGroupRequest(tc, groupID);
249 
250  // Create a second user who doesn't want to receive notices
251  ScenePresence sp2 = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x2));
252  TestClient tc2 = (TestClient)sp2.ControllingClient;
253  gm.JoinGroupRequest(tc2, groupID);
254  gm.SetGroupAcceptNotices(tc2, groupID, false, true);
255 
256  List<GridInstantMessage> spReceivedMessages = new List<GridInstantMessage>();
257  tc.OnReceivedInstantMessage += im => spReceivedMessages.Add(im);
258 
259  List<GridInstantMessage> sp2ReceivedMessages = new List<GridInstantMessage>();
260  tc2.OnReceivedInstantMessage += im => sp2ReceivedMessages.Add(im);
261 
262  GridInstantMessage noticeIm = new GridInstantMessage();
263  noticeIm.fromAgentID = userId.Guid;
264  noticeIm.toAgentID = groupID.Guid;
265  noticeIm.message = combinedSubjectMessage;
266  noticeIm.dialog = (byte)InstantMessageDialog.GroupNotice;
267 
268  tc.HandleImprovedInstantMessage(noticeIm);
269 
270  Assert.That(spReceivedMessages.Count, Is.EqualTo(1));
271  Assert.That(spReceivedMessages[0].message, Is.EqualTo(combinedSubjectMessage));
272 
273  Assert.That(sp2ReceivedMessages.Count, Is.EqualTo(0));
274  }
275  }
276 }
void TestSendGroupNoticeOnlineOnly()
Run test with the MessageOnlineUsersOnly flag set.
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
Interactive OpenSim region server
Definition: OpenSim.cs:55