UserProfileCacheServiceTests.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 OpenSim 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. using System;
  28. using log4net;
  29. using NUnit.Framework;
  30. using NUnit.Framework.SyntaxHelpers;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications.Cache;
  34. using OpenSim.Region.Communications.Local;
  35. using OpenSim.Tests.Common.Mock;
  36. namespace OpenSim.Framework.Communications.Tests
  37. {
  38. /// <summary>
  39. /// User profile cache service tests
  40. /// </summary>
  41. [TestFixture]
  42. public class UserProfileCacheServiceTests
  43. {
  44. /// <summary>
  45. /// Test user details get.
  46. /// </summary>
  47. [Test]
  48. public void TestGetUserDetails()
  49. {
  50. UUID nonExistingUserId = UUID.Parse("00000000-0000-0000-0000-000000000001");
  51. UUID existingUserId = UUID.Parse("00000000-0000-0000-0000-000000000002");
  52. CommunicationsManager commsManager = UserProfileTestUtils.SetupServices();
  53. CachedUserInfo existingUserInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager, existingUserId);
  54. Assert.That(existingUserInfo, Is.Not.Null, "Existing user info unexpectedly not found");
  55. CachedUserInfo nonExistingUserInfo = commsManager.UserProfileCacheService.GetUserDetails(nonExistingUserId);
  56. Assert.That(nonExistingUserInfo, Is.Null, "Non existing user info unexpectedly found");
  57. }
  58. /// <summary>
  59. /// Test requesting inventory for a user
  60. /// </summary>
  61. [Test]
  62. public void TestRequestInventoryForUser()
  63. {
  64. CommunicationsManager commsManager = UserProfileTestUtils.SetupServices();
  65. CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
  66. Assert.That(userInfo.HasReceivedInventory, Is.True);
  67. }
  68. /// <summary>
  69. /// Test retrieving a child folder
  70. /// </summary>
  71. [Test]
  72. public void TestGetChildFolder()
  73. {
  74. CommunicationsManager commsManager = UserProfileTestUtils.SetupServices();
  75. CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
  76. UUID folderId = UUID.Parse("00000000-0000-0000-0000-000000000011");
  77. Assert.That(userInfo.RootFolder.GetChildFolder(folderId), Is.Null);
  78. userInfo.CreateFolder("testFolder", folderId, (ushort)AssetType.Animation, userInfo.RootFolder.ID);
  79. Assert.That(userInfo.RootFolder.GetChildFolder(folderId), Is.Not.Null);
  80. }
  81. /// <summary>
  82. /// Test creating an inventory folder
  83. /// </summary>
  84. [Test]
  85. public void TestCreateFolder()
  86. {
  87. IUserDataPlugin userDataPlugin = new TestUserDataPlugin();
  88. IInventoryDataPlugin inventoryDataPlugin = new TestInventoryDataPlugin();
  89. CommunicationsManager commsManager
  90. = UserProfileTestUtils.SetupServices(userDataPlugin, inventoryDataPlugin);
  91. CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
  92. UUID folderId = UUID.Parse("00000000-0000-0000-0000-000000000010");
  93. Assert.That(userInfo.RootFolder.ContainsChildFolder(folderId), Is.False);
  94. // 1: Try a folder create that should fail because the parent id given does not exist
  95. UUID missingFolderId = UUID.Random();
  96. Assert.That(
  97. userInfo.CreateFolder("testFolder1", folderId, (ushort)AssetType.Animation, missingFolderId), Is.False);
  98. Assert.That(inventoryDataPlugin.getInventoryFolder(folderId), Is.Null);
  99. Assert.That(userInfo.RootFolder.ContainsChildFolder(missingFolderId), Is.False);
  100. Assert.That(userInfo.RootFolder.FindFolder(folderId), Is.Null);
  101. // 2: Try a folder create that should work
  102. Assert.That(
  103. userInfo.CreateFolder("testFolder2", folderId, (ushort)AssetType.Animation, userInfo.RootFolder.ID), Is.True);
  104. Assert.That(inventoryDataPlugin.getInventoryFolder(folderId), Is.Not.Null);
  105. Assert.That(userInfo.RootFolder.ContainsChildFolder(folderId), Is.True);
  106. }
  107. /// <summary>
  108. /// Test updating a folder
  109. /// </summary>
  110. [Test]
  111. public void TestUpdateFolder()
  112. {
  113. IUserDataPlugin userDataPlugin = new TestUserDataPlugin();
  114. IInventoryDataPlugin inventoryDataPlugin = new TestInventoryDataPlugin();
  115. CommunicationsManager commsManager
  116. = UserProfileTestUtils.SetupServices(userDataPlugin, inventoryDataPlugin);
  117. CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
  118. UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
  119. InventoryFolderImpl rootFolder = userInfo.RootFolder;
  120. userInfo.CreateFolder("folder1", folder1Id, (ushort)AssetType.Animation, rootFolder.ID);
  121. // 1: Test updates that don't involve moving the folder
  122. {
  123. string newFolderName1 = "newFolderName1";
  124. ushort folderType1 = (ushort)AssetType.Texture;
  125. userInfo.UpdateFolder(newFolderName1, folder1Id, folderType1, rootFolder.ID);
  126. InventoryFolderImpl folder1 = rootFolder.GetChildFolder(folder1Id);
  127. Assert.That(newFolderName1, Is.EqualTo(folder1.Name));
  128. Assert.That(folderType1, Is.EqualTo((ushort)folder1.Type));
  129. InventoryFolderBase dataFolder1 = inventoryDataPlugin.getInventoryFolder(folder1Id);
  130. Assert.That(newFolderName1, Is.EqualTo(dataFolder1.Name));
  131. Assert.That(folderType1, Is.EqualTo((ushort)dataFolder1.Type));
  132. }
  133. // 2: Test an update that also involves moving the folder
  134. {
  135. UUID folder2Id = UUID.Parse("00000000-0000-0000-0000-000000000061");
  136. userInfo.CreateFolder("folder2", folder2Id, (ushort)AssetType.Animation, rootFolder.ID);
  137. InventoryFolderImpl folder2 = rootFolder.GetChildFolder(folder2Id);
  138. string newFolderName2 = "newFolderName2";
  139. ushort folderType2 = (ushort)AssetType.Bodypart;
  140. userInfo.UpdateFolder(newFolderName2, folder1Id, folderType2, folder2Id);
  141. InventoryFolderImpl folder1 = folder2.GetChildFolder(folder1Id);
  142. Assert.That(newFolderName2, Is.EqualTo(folder1.Name));
  143. Assert.That(folderType2, Is.EqualTo((ushort)folder1.Type));
  144. Assert.That(folder2Id, Is.EqualTo(folder1.ParentID));
  145. Assert.That(folder2.ContainsChildFolder(folder1Id), Is.True);
  146. Assert.That(rootFolder.ContainsChildFolder(folder1Id), Is.False);
  147. InventoryFolderBase dataFolder1 = inventoryDataPlugin.getInventoryFolder(folder1Id);
  148. Assert.That(newFolderName2, Is.EqualTo(dataFolder1.Name));
  149. Assert.That(folderType2, Is.EqualTo((ushort)dataFolder1.Type));
  150. Assert.That(folder2Id, Is.EqualTo(dataFolder1.ParentID));
  151. }
  152. }
  153. /// <summary>
  154. /// Test moving an inventory folder
  155. /// </summary>
  156. [Test]
  157. public void TestMoveFolder()
  158. {
  159. IUserDataPlugin userDataPlugin = new TestUserDataPlugin();
  160. IInventoryDataPlugin inventoryDataPlugin = new TestInventoryDataPlugin();
  161. CommunicationsManager commsManager
  162. = UserProfileTestUtils.SetupServices(userDataPlugin, inventoryDataPlugin);
  163. CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
  164. UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000020");
  165. UUID folder2Id = UUID.Parse("00000000-0000-0000-0000-000000000021");
  166. UUID folderToMoveId = UUID.Parse("00000000-0000-0000-0000-000000000030");
  167. InventoryFolderImpl rootFolder = userInfo.RootFolder;
  168. userInfo.CreateFolder("folder1", folder1Id, (ushort)AssetType.Animation, rootFolder.ID);
  169. InventoryFolderImpl folder1 = rootFolder.GetChildFolder(folder1Id);
  170. userInfo.CreateFolder("folder2", folder2Id, (ushort)AssetType.Animation, rootFolder.ID);
  171. InventoryFolderImpl folder2 = rootFolder.GetChildFolder(folder2Id);
  172. // Check folder is currently in folder1
  173. userInfo.CreateFolder("folderToMove", folderToMoveId, (ushort)AssetType.Animation, folder1Id);
  174. Assert.That(folder1.ContainsChildFolder(folderToMoveId), Is.True);
  175. userInfo.MoveFolder(folderToMoveId, folder2Id);
  176. // Check folder is now in folder2 and no trace remains in folder1
  177. Assert.That(folder2.ContainsChildFolder(folderToMoveId), Is.True);
  178. Assert.That(inventoryDataPlugin.getInventoryFolder(folderToMoveId).ParentID, Is.EqualTo(folder2Id));
  179. Assert.That(folder1.ContainsChildFolder(folderToMoveId), Is.False);
  180. }
  181. /// <summary>
  182. /// Test purging an inventory folder
  183. /// </summary>
  184. [Test]
  185. public void TestPurgeFolder()
  186. {
  187. //log4net.Config.XmlConfigurator.Configure();
  188. IUserDataPlugin userDataPlugin = new TestUserDataPlugin();
  189. IInventoryDataPlugin inventoryDataPlugin = new TestInventoryDataPlugin();
  190. CommunicationsManager commsManager
  191. = UserProfileTestUtils.SetupServices(userDataPlugin, inventoryDataPlugin);
  192. CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);
  193. UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000070");
  194. InventoryFolderImpl rootFolder = userInfo.RootFolder;
  195. userInfo.CreateFolder("folder1", folder1Id, (ushort)AssetType.Animation, rootFolder.ID);
  196. Assert.That(inventoryDataPlugin.getInventoryFolder(folder1Id), Is.Not.Null);
  197. // Test purge
  198. userInfo.PurgeFolder(rootFolder.ID);
  199. Assert.That(rootFolder.RequestListOfFolders(), Is.Empty);
  200. Assert.That(inventoryDataPlugin.getInventoryFolder(folder1Id), Is.Null);
  201. }
  202. }
  203. }