TestInventoryDataPlugin.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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.Mock
  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. // m_log.DebugFormat("[MOCK INV DB]: Getting items in folder {0}", folderID);
  77. List<InventoryItemBase> items = new List<InventoryItemBase>();
  78. foreach (InventoryItemBase item in m_items.Values)
  79. {
  80. if (item.Folder == folderID)
  81. items.Add(item);
  82. }
  83. return items;
  84. }
  85. public List<InventoryFolderBase> getUserRootFolders(UUID user) { return null; }
  86. public InventoryFolderBase getUserRootFolder(UUID user)
  87. {
  88. // m_log.DebugFormat("[MOCK INV DB]: Looking for root folder for {0}", user);
  89. InventoryFolderBase folder = null;
  90. m_rootFolders.TryGetValue(user, out folder);
  91. return folder;
  92. }
  93. public List<InventoryFolderBase> getInventoryFolders(UUID parentID)
  94. {
  95. List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
  96. foreach (InventoryFolderBase folder in m_folders.Values)
  97. {
  98. if (folder.ParentID == parentID)
  99. folders.Add(folder);
  100. }
  101. return folders;
  102. }
  103. public InventoryFolderBase getInventoryFolder(UUID folderId)
  104. {
  105. InventoryFolderBase folder = null;
  106. m_folders.TryGetValue(folderId, out folder);
  107. return folder;
  108. }
  109. public InventoryFolderBase queryInventoryFolder(UUID folderID)
  110. {
  111. return getInventoryFolder(folderID);
  112. }
  113. public void addInventoryFolder(InventoryFolderBase folder)
  114. {
  115. m_folders[folder.ID] = folder;
  116. if (folder.ParentID == UUID.Zero)
  117. {
  118. // m_log.DebugFormat(
  119. // "[MOCK INV DB]: Adding root folder {0} {1} for {2}", folder.Name, folder.ID, folder.Owner);
  120. m_rootFolders[folder.Owner] = folder;
  121. }
  122. }
  123. public void updateInventoryFolder(InventoryFolderBase folder)
  124. {
  125. m_folders[folder.ID] = folder;
  126. }
  127. public void moveInventoryFolder(InventoryFolderBase folder)
  128. {
  129. // Simple replace
  130. updateInventoryFolder(folder);
  131. }
  132. public void deleteInventoryFolder(UUID folderId)
  133. {
  134. if (m_folders.ContainsKey(folderId))
  135. m_folders.Remove(folderId);
  136. }
  137. public void addInventoryItem(InventoryItemBase item)
  138. {
  139. // m_log.DebugFormat(
  140. // "[MOCK INV DB]: Adding inventory item {0} {1} in {2}", item.Name, item.ID, item.Folder);
  141. m_items[item.ID] = item;
  142. }
  143. public void updateInventoryItem(InventoryItemBase item) { addInventoryItem(item); }
  144. public void deleteInventoryItem(UUID itemId)
  145. {
  146. if (m_items.ContainsKey(itemId))
  147. m_items.Remove(itemId);
  148. }
  149. public InventoryItemBase getInventoryItem(UUID itemId)
  150. {
  151. if (m_items.ContainsKey(itemId))
  152. return m_items[itemId];
  153. else
  154. return null;
  155. }
  156. public InventoryItemBase queryInventoryItem(UUID item)
  157. {
  158. return null;
  159. }
  160. public List<InventoryItemBase> fetchActiveGestures(UUID avatarID) { return null; }
  161. }
  162. }