InventoryClient.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Text;
  30. using System.Reflection;
  31. using OpenMetaverse;
  32. using NUnit.Framework;
  33. using OpenSim.Framework;
  34. using OpenSim.Services.Interfaces;
  35. using OpenSim.Services.Connectors;
  36. using OpenSim.Tests.Common;
  37. namespace Robust.Tests
  38. {
  39. [TestFixture]
  40. public class InventoryClient
  41. {
  42. // private static readonly ILog m_log =
  43. // LogManager.GetLogger(
  44. // MethodBase.GetCurrentMethod().DeclaringType);
  45. private UUID m_userID = new UUID("00000000-0000-0000-0000-333333333333");
  46. private UUID m_rootFolderID;
  47. private UUID m_notecardsFolder;
  48. private UUID m_objectsFolder;
  49. [Test]
  50. public void Inventory_001_CreateInventory()
  51. {
  52. TestHelpers.InMethod();
  53. XInventoryServicesConnector m_Connector = new XInventoryServicesConnector(DemonServer.Address);
  54. // Create an inventory that looks like this:
  55. //
  56. // /My Inventory
  57. // <other system folders>
  58. // /Objects
  59. // Some Object
  60. // /Notecards
  61. // Notecard 1
  62. // Notecard 2
  63. // /Test Folder
  64. // Link to notecard -> /Notecards/Notecard 2
  65. // Link to Objects folder -> /Objects
  66. bool success = m_Connector.CreateUserInventory(m_userID);
  67. Assert.IsTrue(success, "Failed to create user inventory");
  68. m_rootFolderID = m_Connector.GetRootFolder(m_userID).ID;
  69. Assert.AreNotEqual(m_rootFolderID, UUID.Zero, "Root folder ID must not be UUID.Zero");
  70. InventoryFolderBase of = m_Connector.GetFolderForType(m_userID, FolderType.Object);
  71. Assert.IsNotNull(of, "Failed to retrieve Objects folder");
  72. m_objectsFolder = of.ID;
  73. Assert.AreNotEqual(m_objectsFolder, UUID.Zero, "Objects folder ID must not be UUID.Zero");
  74. // Add an object
  75. InventoryItemBase item = new InventoryItemBase(new UUID("b0000000-0000-0000-0000-00000000000b"), m_userID);
  76. item.AssetID = UUID.Random();
  77. item.AssetType = (int)AssetType.Object;
  78. item.Folder = m_objectsFolder;
  79. item.Name = "Some Object";
  80. item.Description = string.Empty;
  81. success = m_Connector.AddItem(item);
  82. Assert.IsTrue(success, "Failed to add object to inventory");
  83. InventoryFolderBase ncf = m_Connector.GetFolderForType(m_userID, FolderType.Notecard);
  84. Assert.IsNotNull(of, "Failed to retrieve Notecards folder");
  85. m_notecardsFolder = ncf.ID;
  86. Assert.AreNotEqual(m_notecardsFolder, UUID.Zero, "Notecards folder ID must not be UUID.Zero");
  87. m_notecardsFolder = ncf.ID;
  88. // Add a notecard
  89. item = new InventoryItemBase(new UUID("10000000-0000-0000-0000-000000000001"), m_userID);
  90. item.AssetID = UUID.Random();
  91. item.AssetType = (int)AssetType.Notecard;
  92. item.Folder = m_notecardsFolder;
  93. item.Name = "Test Notecard 1";
  94. item.Description = string.Empty;
  95. success = m_Connector.AddItem(item);
  96. Assert.IsTrue(success, "Failed to add Notecard 1 to inventory");
  97. // Add another notecard
  98. item.ID = new UUID("20000000-0000-0000-0000-000000000002");
  99. item.AssetID = new UUID("a0000000-0000-0000-0000-00000000000a");
  100. item.Name = "Test Notecard 2";
  101. item.Description = string.Empty;
  102. success = m_Connector.AddItem(item);
  103. Assert.IsTrue(success, "Failed to add Notecard 2 to inventory");
  104. // Add a folder
  105. InventoryFolderBase folder = new InventoryFolderBase(new UUID("f0000000-0000-0000-0000-00000000000f"), "Test Folder", m_userID, m_rootFolderID);
  106. folder.Type = (int)FolderType.None;
  107. success = m_Connector.AddFolder(folder);
  108. Assert.IsTrue(success, "Failed to add Test Folder to inventory");
  109. // Add a link to notecard 2 in Test Folder
  110. item.AssetID = item.ID; // use item ID of notecard 2
  111. item.ID = new UUID("40000000-0000-0000-0000-000000000004");
  112. item.AssetType = (int)AssetType.Link;
  113. item.Folder = folder.ID;
  114. item.Name = "Link to notecard";
  115. item.Description = string.Empty;
  116. success = m_Connector.AddItem(item);
  117. Assert.IsTrue(success, "Failed to add link to notecard to inventory");
  118. // Add a link to the Objects folder in Test Folder
  119. item.AssetID = m_Connector.GetFolderForType(m_userID, FolderType.Object).ID; // use item ID of Objects folder
  120. item.ID = new UUID("50000000-0000-0000-0000-000000000005");
  121. item.AssetType = (int)AssetType.LinkFolder;
  122. item.Folder = folder.ID;
  123. item.Name = "Link to Objects folder";
  124. item.Description = string.Empty;
  125. success = m_Connector.AddItem(item);
  126. Assert.IsTrue(success, "Failed to add link to objects folder to inventory");
  127. InventoryCollection coll = m_Connector.GetFolderContent(m_userID, m_rootFolderID);
  128. Assert.IsNotNull(coll, "Failed to retrieve contents of root folder");
  129. Assert.Greater(coll.Folders.Count, 0, "Root folder does not have any subfolders");
  130. coll = m_Connector.GetFolderContent(m_userID, folder.ID);
  131. Assert.IsNotNull(coll, "Failed to retrieve contents of Test Folder");
  132. Assert.AreEqual(coll.Items.Count + coll.Folders.Count, 2, "Test Folder is expected to have exactly 2 things inside");
  133. }
  134. [Test]
  135. public void Inventory_002_MultipleItemsRequest()
  136. {
  137. TestHelpers.InMethod();
  138. XInventoryServicesConnector m_Connector = new XInventoryServicesConnector(DemonServer.Address);
  139. // Prefetch Notecard 1, will be cached from here on
  140. InventoryItemBase item = new InventoryItemBase(new UUID("10000000-0000-0000-0000-000000000001"), m_userID);
  141. item = m_Connector.GetItem(item);
  142. Assert.NotNull(item, "Failed to get Notecard 1");
  143. Assert.AreEqual("Test Notecard 1", item.Name, "Wrong name for Notecard 1");
  144. UUID[] uuids = new UUID[2];
  145. uuids[0] = item.ID;
  146. uuids[1] = new UUID("20000000-0000-0000-0000-000000000002");
  147. InventoryItemBase[] items = m_Connector.GetMultipleItems(m_userID, uuids);
  148. Assert.NotNull(items, "Failed to get multiple items");
  149. Assert.IsTrue(items.Length == 2, "Requested 2 items, but didn't receive 2 items");
  150. // Now they should both be cached
  151. items = m_Connector.GetMultipleItems(m_userID, uuids);
  152. Assert.NotNull(items, "(Repeat) Failed to get multiple items");
  153. Assert.IsTrue(items.Length == 2, "(Repeat) Requested 2 items, but didn't receive 2 items");
  154. // This item doesn't exist, but [0] does, and it's cached.
  155. uuids[1] = new UUID("bb000000-0000-0000-0000-0000000000bb");
  156. // Fetching should return 2 items, but [1] should be null
  157. items = m_Connector.GetMultipleItems(m_userID, uuids);
  158. Assert.NotNull(items, "(Three times) Failed to get multiple items");
  159. Assert.IsTrue(items.Length == 2, "(Three times) Requested 2 items, but didn't receive 2 items");
  160. Assert.AreEqual("Test Notecard 1", items[0].Name, "(Three times) Wrong name for Notecard 1");
  161. Assert.IsNull(items[1], "(Three times) Expecting 2nd item to be null");
  162. // Now both don't exist
  163. uuids[0] = new UUID("aa000000-0000-0000-0000-0000000000aa");
  164. items = m_Connector.GetMultipleItems(m_userID, uuids);
  165. Assert.Null(items[0], "Request to multiple non-existent items is supposed to return null [0]");
  166. Assert.Null(items[1], "Request to multiple non-existent items is supposed to return null [1]");
  167. // This item exists, and it's not cached
  168. uuids[1] = new UUID("b0000000-0000-0000-0000-00000000000b");
  169. // Fetching should return 2 items, but [0] should be null
  170. items = m_Connector.GetMultipleItems(m_userID, uuids);
  171. Assert.NotNull(items, "(Four times) Failed to get multiple items");
  172. Assert.IsTrue(items.Length == 2, "(Four times) Requested 2 items, but didn't receive 2 items");
  173. Assert.AreEqual("Some Object", items[1].Name, "(Four times) Wrong name for Some Object");
  174. Assert.IsNull(items[0], "(Four times) Expecting 1st item to be null");
  175. }
  176. }
  177. }