TestInventoryDataPlugin.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 OpenMetaverse;
  30. using OpenSim.Framework;
  31. using OpenSim.Data;
  32. namespace OpenSim.Tests.Common.Mock
  33. {
  34. /// <summary>
  35. /// In memory inventory data plugin for test purposes. Could be another dll when properly filled out and when the
  36. /// mono addin plugin system starts co-operating with the unit test system. Currently no locking since unit
  37. /// tests are single threaded.
  38. /// </summary>
  39. public class TestInventoryDataPlugin : IInventoryDataPlugin
  40. {
  41. /// <value>
  42. /// Inventory folders
  43. /// </value>
  44. private Dictionary<UUID, InventoryFolderBase> m_folders = new Dictionary<UUID, InventoryFolderBase>();
  45. //// <value>
  46. /// Inventory items
  47. /// </value>
  48. private Dictionary<UUID, InventoryItemBase> m_items = new Dictionary<UUID, InventoryItemBase>();
  49. /// <value>
  50. /// User root folders
  51. /// </value>
  52. private Dictionary<UUID, InventoryFolderBase> m_rootFolders = new Dictionary<UUID, InventoryFolderBase>();
  53. public string Version { get { return "0"; } }
  54. public string Name { get { return "TestInventoryDataPlugin"; } }
  55. public void Initialise() {}
  56. public void Initialise(string connect) {}
  57. public void Dispose() {}
  58. public List<InventoryFolderBase> getFolderHierarchy(UUID parentID)
  59. {
  60. List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
  61. foreach (InventoryFolderBase folder in m_folders.Values)
  62. {
  63. if (folder.ParentID == parentID)
  64. {
  65. folders.AddRange(getFolderHierarchy(folder.ID));
  66. folders.Add(folder);
  67. }
  68. }
  69. return folders;
  70. }
  71. public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
  72. {
  73. return new List<InventoryItemBase>();
  74. }
  75. public List<InventoryFolderBase> getUserRootFolders(UUID user) { return null; }
  76. public InventoryFolderBase getUserRootFolder(UUID user)
  77. {
  78. InventoryFolderBase folder = null;
  79. m_rootFolders.TryGetValue(user, out folder);
  80. return folder;
  81. }
  82. public List<InventoryFolderBase> getInventoryFolders(UUID parentID)
  83. {
  84. List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
  85. foreach (InventoryFolderBase folder in m_folders.Values)
  86. {
  87. if (folder.ParentID == parentID)
  88. folders.Add(folder);
  89. }
  90. return folders;
  91. }
  92. public InventoryFolderBase getInventoryFolder(UUID folderId)
  93. {
  94. InventoryFolderBase folder = null;
  95. m_folders.TryGetValue(folderId, out folder);
  96. return folder;
  97. }
  98. public InventoryFolderBase queryInventoryFolder(UUID folderID)
  99. {
  100. return getInventoryFolder(folderID);
  101. }
  102. public void addInventoryFolder(InventoryFolderBase folder)
  103. {
  104. m_folders[folder.ID] = folder;
  105. if (folder.ParentID == UUID.Zero)
  106. m_rootFolders[folder.Owner] = folder;
  107. }
  108. public void updateInventoryFolder(InventoryFolderBase folder)
  109. {
  110. m_folders[folder.ID] = folder;
  111. }
  112. public void moveInventoryFolder(InventoryFolderBase folder)
  113. {
  114. // Simple replace
  115. updateInventoryFolder(folder);
  116. }
  117. public void deleteInventoryFolder(UUID folderId)
  118. {
  119. if (m_folders.ContainsKey(folderId))
  120. m_folders.Remove(folderId);
  121. }
  122. public void addInventoryItem(InventoryItemBase item) { m_items[item.ID] = item; }
  123. public void updateInventoryItem(InventoryItemBase item) { addInventoryItem(item); }
  124. public void deleteInventoryItem(UUID itemId)
  125. {
  126. if (m_items.ContainsKey(itemId))
  127. m_items.Remove(itemId);
  128. }
  129. public InventoryItemBase getInventoryItem(UUID itemId)
  130. {
  131. if (m_items.ContainsKey(itemId))
  132. return m_items[itemId];
  133. else
  134. return null;
  135. }
  136. public InventoryItemBase queryInventoryItem(UUID item)
  137. {
  138. return null;
  139. }
  140. public List<InventoryItemBase> fetchActiveGestures(UUID avatarID) { return null; }
  141. }
  142. }