OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
FriendModuleTests.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.Generic;
30 using Nini.Config;
31 using NUnit.Framework;
32 using OpenMetaverse;
33 using OpenSim.Data.Null;
34 using OpenSim.Framework;
35 using OpenSim.Region.CoreModules.Avatar.Friends;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Tests.Common;
38 
39 namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests
40 {
41  [TestFixture]
43  {
44  private FriendsModule m_fm;
45  private TestScene m_scene;
46 
47  [TestFixtureSetUp]
48  public void FixtureInit()
49  {
50  // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
51  Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
52  }
53 
54  [TestFixtureTearDown]
55  public void TearDown()
56  {
57  // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
58  // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
59  // tests really shouldn't).
60  Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
61  }
62 
63  [SetUp]
64  public void Init()
65  {
66  // We must clear friends data between tests since Data.Null holds it in static properties. This is necessary
67  // so that different services and simulator can share the data in standalone mode. This is pretty horrible
68  // effectively the statics are global variables.
69  NullFriendsData.Clear();
70 
71  IConfigSource config = new IniConfigSource();
72  config.AddConfig("Modules");
73  // Not strictly necessary since FriendsModule assumes it is the default (!)
74  config.Configs["Modules"].Set("FriendsModule", "FriendsModule");
75  config.AddConfig("Friends");
76  config.Configs["Friends"].Set("Connector", "OpenSim.Services.FriendsService.dll");
77  config.AddConfig("FriendsService");
78  config.Configs["FriendsService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
79 
80  m_scene = new SceneHelpers().SetupScene();
81  m_fm = new FriendsModule();
82  SceneHelpers.SetupSceneModules(m_scene, config, m_fm);
83  }
84 
85  [Test]
86  public void TestLoginWithNoFriends()
87  {
88  TestHelpers.InMethod();
89 // log4net.Config.XmlConfigurator.Configure();
90 
91  UUID userId = TestHelpers.ParseTail(0x1);
92 
93  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
94 
95  Assert.That(((TestClient)sp.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0));
96  Assert.That(((TestClient)sp.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(0));
97  }
98 
99  [Test]
101  {
102  TestHelpers.InMethod();
103 // log4net.Config.XmlConfigurator.Configure();
104 
105  UUID user1Id = TestHelpers.ParseTail(0x1);
106  UUID user2Id = TestHelpers.ParseTail(0x2);
107 
108 // UserAccountHelpers.CreateUserWithInventory(m_scene, user1Id);
109 // UserAccountHelpers.CreateUserWithInventory(m_scene, user2Id);
110 //
111 // m_fm.AddFriendship(user1Id, user2Id);
112 
113  ScenePresence sp1 = SceneHelpers.AddScenePresence(m_scene, user1Id);
114  ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, user2Id);
115 
116  m_fm.AddFriendship(sp1.ControllingClient, user2Id);
117 
118  // Not necessary for this test. CanSeeOnline is automatically granted.
119 // m_fm.GrantRights(sp1.ControllingClient, user2Id, (int)FriendRights.CanSeeOnline);
120 
121  // We must logout from the client end so that the presence service is correctly updated by the presence
122  // detector. This is listening to the OnConnectionClosed event on the client.
123  ((TestClient)sp1.ControllingClient).Logout();
124  ((TestClient)sp2.ControllingClient).Logout();
125 // m_scene.RemoveClient(sp1.UUID, true);
126 // m_scene.RemoveClient(sp2.UUID, true);
127 
128  ScenePresence sp1Redux = SceneHelpers.AddScenePresence(m_scene, user1Id);
129 
130  // We don't expect to receive notifications of offline friends on login, just online.
131  Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0));
132  Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(0));
133  }
134 
135  [Test]
137  {
138  TestHelpers.InMethod();
139 // log4net.Config.XmlConfigurator.Configure();
140 
141  UUID user1Id = TestHelpers.ParseTail(0x1);
142  UUID user2Id = TestHelpers.ParseTail(0x2);
143 
144 // UserAccountHelpers.CreateUserWithInventory(m_scene, user1Id);
145 // UserAccountHelpers.CreateUserWithInventory(m_scene, user2Id);
146 //
147 // m_fm.AddFriendship(user1Id, user2Id);
148 
149  ScenePresence sp1 = SceneHelpers.AddScenePresence(m_scene, user1Id);
150  ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, user2Id);
151 
152  m_fm.AddFriendship(sp1.ControllingClient, user2Id);
153 
154  // Not necessary for this test. CanSeeOnline is automatically granted.
155 // m_fm.GrantRights(sp1.ControllingClient, user2Id, (int)FriendRights.CanSeeOnline);
156 
157  // We must logout from the client end so that the presence service is correctly updated by the presence
158  // detector. This is listening to the OnConnectionClosed event on the client.
159 // ((TestClient)sp1.ControllingClient).Logout();
160  ((TestClient)sp2.ControllingClient).Logout();
161 // m_scene.RemoveClient(user2Id, true);
162 
163  ScenePresence sp2Redux = SceneHelpers.AddScenePresence(m_scene, user2Id);
164 
165  Assert.That(((TestClient)sp2Redux.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0));
166  Assert.That(((TestClient)sp2Redux.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(1));
167  }
168 
169  [Test]
171  {
172  TestHelpers.InMethod();
173 // log4net.Config.XmlConfigurator.Configure();
174 
175  UUID userId = TestHelpers.ParseTail(0x1);
176  UUID user2Id = TestHelpers.ParseTail(0x2);
177 
178  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
179  SceneHelpers.AddScenePresence(m_scene, user2Id);
180 
181  // This fiendship is two-way but without a connector, only the first user will receive the online
182  // notification.
183  m_fm.AddFriendship(sp.ControllingClient, user2Id);
184 
185  Assert.That(((TestClient)sp.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0));
186  Assert.That(((TestClient)sp.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(1));
187  }
188 
189  [Test]
191  {
192  TestHelpers.InMethod();
193 // log4net.Config.XmlConfigurator.Configure();
194 
195  UUID user1Id = TestHelpers.ParseTail(0x1);
196  UUID user2Id = TestHelpers.ParseTail(0x2);
197 
198  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, user1Id);
199  SceneHelpers.AddScenePresence(m_scene, user2Id);
200 
201  m_fm.AddFriendship(sp.ControllingClient, user2Id);
202  m_fm.RemoveFriendship(sp.ControllingClient, user2Id);
203 
204  TestClient user1Client = sp.ControllingClient as TestClient;
205  Assert.That(user1Client.ReceivedFriendshipTerminations.Count, Is.EqualTo(1));
206  Assert.That(user1Client.ReceivedFriendshipTerminations[0], Is.EqualTo(user2Id));
207  }
208  }
209 }
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
Interactive OpenSim region server
Definition: OpenSim.cs:55