TestInventoryDataPlugin.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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.Reflection;
  30. using log4net;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Data;
  34. namespace OpenSim.Tests.Common
  35. {
  36. /// <summary>
  37. /// In memory inventory data plugin for test purposes. Could be another dll when properly filled out and when the
  38. /// mono addin plugin system starts co-operating with the unit test system. Currently no locking since unit
  39. /// tests are single threaded.
  40. /// </summary>
  41. public class TestInventoryDataPlugin : IInventoryDataPlugin
  42. {
  43. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. /// <value>
  45. /// Inventory folders
  46. /// </value>
  47. private Dictionary<UUID, InventoryFolderBase> m_folders = new Dictionary<UUID, InventoryFolderBase>();
  48. //// <value>
  49. /// Inventory items
  50. /// </value>
  51. private Dictionary<UUID, InventoryItemBase> m_items = new Dictionary<UUID, InventoryItemBase>();
  52. /// <value>
  53. /// User root folders
  54. /// </value>
  55. private Dictionary<UUID, InventoryFolderBase> m_rootFolders = new Dictionary<UUID, InventoryFolderBase>();
  56. public string Version { get { return "0"; } }
  57. public string Name { get { return "TestInventoryDataPlugin"; } }
  58. public void Initialise() {}
  59. public void Initialise(string connect) {}
  60. public void Dispose() {}
  61. public List<InventoryFolderBase> getFolderHierarchy(UUID parentID)
  62. {
  63. List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
  64. foreach (InventoryFolderBase folder in m_folders.Values)
  65. {
  66. if (folder.ParentID == parentID)
  67. {
  68. folders.AddRange(getFolderHierarchy(folder.ID));
  69. folders.Add(folder);
  70. }
  71. }
  72. return folders;
  73. }
  74. public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
  75. {
  76. // InventoryFolderBase folder = m_folders[folderID];
  77. // m_log.DebugFormat("[MOCK INV DB]: Getting items in folder {0} {1}", folder.Name, folder.ID);
  78. List<InventoryItemBase> items = new List<InventoryItemBase>();
  79. foreach (InventoryItemBase item in m_items.Values)
  80. {
  81. if (item.Folder == folderID)
  82. {
  83. // m_log.DebugFormat("[MOCK INV DB]: getInventoryInFolder() adding item {0}", item.Name);
  84. items.Add(item);
  85. }
  86. }
  87. return items;
  88. }
  89. public List<InventoryFolderBase> getUserRootFolders(UUID user) { return null; }
  90. public InventoryFolderBase getUserRootFolder(UUID user)
  91. {
  92. // m_log.DebugFormat("[MOCK INV DB]: Looking for root folder for {0}", user);
  93. InventoryFolderBase folder = null;
  94. m_rootFolders.TryGetValue(user, out folder);
  95. return folder;
  96. }
  97. public List<InventoryFolderBase> getInventoryFolders(UUID parentID)
  98. {
  99. // InventoryFolderBase parentFolder = m_folders[parentID];
  100. // m_log.DebugFormat("[MOCK INV DB]: Getting folders in folder {0} {1}", parentFolder.Name, parentFolder.ID);
  101. List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
  102. foreach (InventoryFolderBase folder in m_folders.Values)
  103. {
  104. if (folder.ParentID == parentID)
  105. {
  106. // m_log.DebugFormat(
  107. // "[MOCK INV DB]: Found folder {0} {1} in {2} {3}",
  108. // folder.Name, folder.ID, parentFolder.Name, parentFolder.ID);
  109. folders.Add(folder);
  110. }
  111. }
  112. return folders;
  113. }
  114. public InventoryFolderBase getInventoryFolder(UUID folderId)
  115. {
  116. InventoryFolderBase folder = null;
  117. m_folders.TryGetValue(folderId, out folder);
  118. return folder;
  119. }
  120. public InventoryFolderBase queryInventoryFolder(UUID folderID)
  121. {
  122. return getInventoryFolder(folderID);
  123. }
  124. public void addInventoryFolder(InventoryFolderBase folder)
  125. {
  126. // m_log.DebugFormat(
  127. // "[MOCK INV DB]: Adding inventory folder {0} {1} type {2}",
  128. // folder.Name, folder.ID, (AssetType)folder.Type);
  129. m_folders[folder.ID] = folder;
  130. if (folder.ParentID == UUID.Zero)
  131. {
  132. // m_log.DebugFormat(
  133. // "[MOCK INV DB]: Adding root folder {0} {1} for {2}", folder.Name, folder.ID, folder.Owner);
  134. m_rootFolders[folder.Owner] = folder;
  135. }
  136. }
  137. public void updateInventoryFolder(InventoryFolderBase folder)
  138. {
  139. m_folders[folder.ID] = folder;
  140. }
  141. public void moveInventoryFolder(InventoryFolderBase folder)
  142. {
  143. // Simple replace
  144. updateInventoryFolder(folder);
  145. }
  146. public void deleteInventoryFolder(UUID folderId)
  147. {
  148. if (m_folders.ContainsKey(folderId))
  149. m_folders.Remove(folderId);
  150. }
  151. public void addInventoryItem(InventoryItemBase item)
  152. {
  153. InventoryFolderBase folder = m_folders[item.Folder];
  154. // m_log.DebugFormat(
  155. // "[MOCK INV DB]: Adding inventory item {0} {1} in {2} {3}", item.Name, item.ID, folder.Name, folder.ID);
  156. m_items[item.ID] = item;
  157. }
  158. public void updateInventoryItem(InventoryItemBase item) { addInventoryItem(item); }
  159. public void deleteInventoryItem(UUID itemId)
  160. {
  161. if (m_items.ContainsKey(itemId))
  162. m_items.Remove(itemId);
  163. }
  164. public InventoryItemBase getInventoryItem(UUID itemId)
  165. {
  166. if (m_items.ContainsKey(itemId))
  167. return m_items[itemId];
  168. else
  169. return null;
  170. }
  171. public InventoryItemBase queryInventoryItem(UUID item)
  172. {
  173. return null;
  174. }
  175. public List<InventoryItemBase> fetchActiveGestures(UUID avatarID) { return null; }
  176. }
  177. }