XInventoryServiceTests.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 Nini.Config;
  29. using NUnit.Framework;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Server.Base;
  33. using OpenSim.Services.Interfaces;
  34. using OpenSim.Tests.Common;
  35. namespace OpenSim.Services.InventoryService.Tests
  36. {
  37. /// <summary>
  38. /// Tests for the XInventoryService
  39. /// </summary>
  40. /// <remarks>
  41. /// TODO: Fill out more tests.
  42. /// </remarks>
  43. [TestFixture]
  44. public class XInventoryServiceTests : OpenSimTestCase
  45. {
  46. private IInventoryService CreateXInventoryService()
  47. {
  48. IConfigSource config = new IniConfigSource();
  49. config.AddConfig("InventoryService");
  50. config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
  51. return ServerUtils.LoadPlugin<IInventoryService>(
  52. "OpenSim.Services.InventoryService.dll:XInventoryService", new Object[] { config });
  53. }
  54. /// <summary>
  55. /// Tests add item operation.
  56. /// </summary>
  57. /// <remarks>
  58. /// TODO: Test all operations.
  59. /// </remarks>
  60. [Test]
  61. public void TestAddItem()
  62. {
  63. TestHelpers.InMethod();
  64. string creatorId = TestHelpers.ParseTail(0x1).ToString();
  65. UUID ownerId = TestHelpers.ParseTail(0x2);
  66. UUID itemId = TestHelpers.ParseTail(0x10);
  67. UUID assetId = TestHelpers.ParseTail(0x20);
  68. UUID folderId = TestHelpers.ParseTail(0x30);
  69. int invType = (int)InventoryType.Animation;
  70. int assetType = (int)AssetType.Animation;
  71. string itemName = "item1";
  72. IInventoryService xis = CreateXInventoryService();
  73. InventoryItemBase itemToStore
  74. = new InventoryItemBase(itemId, ownerId)
  75. {
  76. CreatorIdentification = creatorId.ToString(),
  77. AssetID = assetId,
  78. Name = itemName,
  79. Folder = folderId,
  80. InvType = invType,
  81. AssetType = assetType
  82. };
  83. Assert.That(xis.AddItem(itemToStore), Is.True);
  84. InventoryItemBase itemRetrieved = new InventoryItemBase(itemId);
  85. itemRetrieved = xis.GetItem(itemRetrieved);
  86. Assert.That(itemRetrieved, Is.Not.Null);
  87. Assert.That(itemRetrieved.CreatorId, Is.EqualTo(creatorId));
  88. Assert.That(itemRetrieved.Owner, Is.EqualTo(ownerId));
  89. Assert.That(itemRetrieved.AssetID, Is.EqualTo(assetId));
  90. Assert.That(itemRetrieved.Folder, Is.EqualTo(folderId));
  91. Assert.That(itemRetrieved.InvType, Is.EqualTo(invType));
  92. Assert.That(itemRetrieved.AssetType, Is.EqualTo(assetType));
  93. Assert.That(itemRetrieved.Name, Is.EqualTo(itemName));
  94. }
  95. [Test]
  96. public void TestUpdateItem()
  97. {
  98. TestHelpers.InMethod();
  99. // TestHelpers.EnableLogging();
  100. string creatorId = TestHelpers.ParseTail(0x1).ToString();
  101. UUID ownerId = TestHelpers.ParseTail(0x2);
  102. UUID itemId = TestHelpers.ParseTail(0x10);
  103. UUID assetId = TestHelpers.ParseTail(0x20);
  104. UUID folderId = TestHelpers.ParseTail(0x30);
  105. int invType = (int)InventoryType.Animation;
  106. int assetType = (int)AssetType.Animation;
  107. string itemName = "item1";
  108. string itemName2 = "item2";
  109. IInventoryService xis = CreateXInventoryService();
  110. InventoryItemBase itemToStore
  111. = new InventoryItemBase(itemId, ownerId)
  112. {
  113. CreatorIdentification = creatorId.ToString(),
  114. AssetID = assetId,
  115. Name = itemName,
  116. Folder = folderId,
  117. InvType = invType,
  118. AssetType = assetType
  119. };
  120. Assert.That(xis.AddItem(itemToStore), Is.True);
  121. // Normal update
  122. itemToStore.Name = itemName2;
  123. Assert.That(xis.UpdateItem(itemToStore), Is.True);
  124. InventoryItemBase itemRetrieved = new InventoryItemBase(itemId);
  125. itemRetrieved = xis.GetItem(itemRetrieved);
  126. Assert.That(itemRetrieved, Is.Not.Null);
  127. Assert.That(itemRetrieved.Name, Is.EqualTo(itemName2));
  128. // Attempt to update properties that should never change
  129. string creatorId2 = TestHelpers.ParseTail(0x7).ToString();
  130. UUID ownerId2 = TestHelpers.ParseTail(0x8);
  131. UUID folderId2 = TestHelpers.ParseTail(0x70);
  132. int invType2 = (int)InventoryType.CallingCard;
  133. int assetType2 = (int)AssetType.CallingCard;
  134. string itemName3 = "item3";
  135. itemToStore.CreatorIdentification = creatorId2.ToString();
  136. itemToStore.Owner = ownerId2;
  137. itemToStore.Folder = folderId2;
  138. itemToStore.InvType = invType2;
  139. itemToStore.AssetType = assetType2;
  140. itemToStore.Name = itemName3;
  141. Assert.That(xis.UpdateItem(itemToStore), Is.True);
  142. itemRetrieved = xis.GetItem(itemRetrieved);
  143. Assert.That(itemRetrieved, Is.Not.Null);
  144. Assert.That(itemRetrieved.CreatorId, Is.EqualTo(creatorId));
  145. Assert.That(itemRetrieved.Owner, Is.EqualTo(ownerId));
  146. Assert.That(itemRetrieved.AssetID, Is.EqualTo(assetId));
  147. Assert.That(itemRetrieved.Folder, Is.EqualTo(folderId));
  148. Assert.That(itemRetrieved.InvType, Is.EqualTo(invType));
  149. Assert.That(itemRetrieved.AssetType, Is.EqualTo(assetType));
  150. Assert.That(itemRetrieved.Name, Is.EqualTo(itemName3));
  151. }
  152. }
  153. }