1
0

XInventoryServiceTests.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 = xis.GetItem(UUID.Zero, itemId);
  85. Assert.That(itemRetrieved, Is.Not.Null);
  86. Assert.That(itemRetrieved.CreatorId, Is.EqualTo(creatorId));
  87. Assert.That(itemRetrieved.Owner, Is.EqualTo(ownerId));
  88. Assert.That(itemRetrieved.AssetID, Is.EqualTo(assetId));
  89. Assert.That(itemRetrieved.Folder, Is.EqualTo(folderId));
  90. Assert.That(itemRetrieved.InvType, Is.EqualTo(invType));
  91. Assert.That(itemRetrieved.AssetType, Is.EqualTo(assetType));
  92. Assert.That(itemRetrieved.Name, Is.EqualTo(itemName));
  93. }
  94. [Test]
  95. public void TestUpdateItem()
  96. {
  97. TestHelpers.InMethod();
  98. // TestHelpers.EnableLogging();
  99. string creatorId = TestHelpers.ParseTail(0x1).ToString();
  100. UUID ownerId = TestHelpers.ParseTail(0x2);
  101. UUID itemId = TestHelpers.ParseTail(0x10);
  102. UUID assetId = TestHelpers.ParseTail(0x20);
  103. UUID folderId = TestHelpers.ParseTail(0x30);
  104. int invType = (int)InventoryType.Animation;
  105. int assetType = (int)AssetType.Animation;
  106. string itemName = "item1";
  107. string itemName2 = "item2";
  108. IInventoryService xis = CreateXInventoryService();
  109. InventoryItemBase itemToStore
  110. = new InventoryItemBase(itemId, ownerId)
  111. {
  112. CreatorIdentification = creatorId.ToString(),
  113. AssetID = assetId,
  114. Name = itemName,
  115. Folder = folderId,
  116. InvType = invType,
  117. AssetType = assetType
  118. };
  119. Assert.That(xis.AddItem(itemToStore), Is.True);
  120. // Normal update
  121. itemToStore.Name = itemName2;
  122. Assert.That(xis.UpdateItem(itemToStore), Is.True);
  123. InventoryItemBase itemRetrieved = xis.GetItem(UUID.Zero, itemId);
  124. Assert.That(itemRetrieved, Is.Not.Null);
  125. Assert.That(itemRetrieved.Name, Is.EqualTo(itemName2));
  126. // Attempt to update properties that should never change
  127. string creatorId2 = TestHelpers.ParseTail(0x7).ToString();
  128. UUID ownerId2 = TestHelpers.ParseTail(0x8);
  129. UUID folderId2 = TestHelpers.ParseTail(0x70);
  130. int invType2 = (int)InventoryType.CallingCard;
  131. int assetType2 = (int)AssetType.CallingCard;
  132. string itemName3 = "item3";
  133. itemToStore.CreatorIdentification = creatorId2.ToString();
  134. itemToStore.Owner = ownerId2;
  135. itemToStore.Folder = folderId2;
  136. itemToStore.InvType = invType2;
  137. itemToStore.AssetType = assetType2;
  138. itemToStore.Name = itemName3;
  139. Assert.That(xis.UpdateItem(itemToStore), Is.True);
  140. itemRetrieved = xis.GetItem(itemRetrieved.Owner, itemRetrieved.ID);
  141. Assert.That(itemRetrieved, Is.Not.Null);
  142. Assert.That(itemRetrieved.CreatorId, Is.EqualTo(creatorId));
  143. Assert.That(itemRetrieved.Owner, Is.EqualTo(ownerId));
  144. Assert.That(itemRetrieved.AssetID, Is.EqualTo(assetId));
  145. Assert.That(itemRetrieved.Folder, Is.EqualTo(folderId));
  146. Assert.That(itemRetrieved.InvType, Is.EqualTo(invType));
  147. Assert.That(itemRetrieved.AssetType, Is.EqualTo(assetType));
  148. Assert.That(itemRetrieved.Name, Is.EqualTo(itemName3));
  149. }
  150. }
  151. }