1
0

FetchInventory2HandlerTests.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.Linq;
  30. using System.Net;
  31. using System.Text.RegularExpressions;
  32. using log4net;
  33. using log4net.Config;
  34. using NUnit.Framework;
  35. using OpenMetaverse;
  36. using OpenSim.Capabilities.Handlers;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Services.Interfaces;
  41. using OpenSim.Tests.Common;
  42. namespace OpenSim.Capabilities.Handlers.FetchInventory.Tests
  43. {
  44. [TestFixture]
  45. public class FetchInventory2HandlerTests : OpenSimTestCase
  46. {
  47. private UUID m_userID = UUID.Random();
  48. private Scene m_scene;
  49. private UUID m_rootFolderID;
  50. private UUID m_notecardsFolder;
  51. private UUID m_objectsFolder;
  52. private void Init()
  53. {
  54. // Create an inventory that looks like this:
  55. //
  56. // /My Inventory
  57. // <other system folders>
  58. // /Objects
  59. // Object 1
  60. // Object 2
  61. // Object 3
  62. // /Notecards
  63. // Notecard 1
  64. // Notecard 2
  65. // Notecard 3
  66. // Notecard 4
  67. // Notecard 5
  68. m_scene = new SceneHelpers().SetupScene();
  69. m_scene.InventoryService.CreateUserInventory(m_userID);
  70. m_rootFolderID = m_scene.InventoryService.GetRootFolder(m_userID).ID;
  71. InventoryFolderBase of = m_scene.InventoryService.GetFolderForType(m_userID, FolderType.Object);
  72. m_objectsFolder = of.ID;
  73. // Add 3 objects
  74. InventoryItemBase item;
  75. for (int i = 1; i <= 3; i++)
  76. {
  77. item = new InventoryItemBase(new UUID("b0000000-0000-0000-0000-0000000000b" + i), m_userID);
  78. item.AssetID = UUID.Random();
  79. item.AssetType = (int)AssetType.Object;
  80. item.Folder = m_objectsFolder;
  81. item.Name = "Object " + i;
  82. m_scene.InventoryService.AddItem(item);
  83. }
  84. InventoryFolderBase ncf = m_scene.InventoryService.GetFolderForType(m_userID, FolderType.Notecard);
  85. m_notecardsFolder = ncf.ID;
  86. // Add 5 notecards
  87. for (int i = 1; i <= 5; i++)
  88. {
  89. item = new InventoryItemBase(new UUID("10000000-0000-0000-0000-00000000000" + i), m_userID);
  90. item.AssetID = UUID.Random();
  91. item.AssetType = (int)AssetType.Notecard;
  92. item.Folder = m_notecardsFolder;
  93. item.Name = "Notecard " + i;
  94. m_scene.InventoryService.AddItem(item);
  95. }
  96. }
  97. [Test]
  98. public void Test_001_RequestOne()
  99. {
  100. TestHelpers.InMethod();
  101. Init();
  102. FetchInventory2Handler handler = new FetchInventory2Handler(m_scene.InventoryService, m_userID);
  103. TestOSHttpRequest req = new TestOSHttpRequest();
  104. TestOSHttpResponse resp = new TestOSHttpResponse();
  105. string request = "<llsd><map><key>items</key><array><map><key>item_id</key><uuid>";
  106. request += "10000000-0000-0000-0000-000000000001"; // Notecard 1
  107. request += "</uuid></map></array></map></llsd>";
  108. string llsdresponse = handler.FetchInventoryRequest(request, "/FETCH", string.Empty, req, resp);
  109. Assert.That(llsdresponse != null, Is.True, "Incorrect null response");
  110. Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response");
  111. Assert.That(llsdresponse.Contains(m_userID.ToString()), Is.True, "Response should contain userID");
  112. Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000001"), Is.True, "Response does not contain item uuid");
  113. Assert.That(llsdresponse.Contains("Notecard 1"), Is.True, "Response does not contain item Name");
  114. Console.WriteLine(llsdresponse);
  115. }
  116. [Test]
  117. public void Test_002_RequestMany()
  118. {
  119. TestHelpers.InMethod();
  120. Init();
  121. FetchInventory2Handler handler = new FetchInventory2Handler(m_scene.InventoryService, m_userID);
  122. TestOSHttpRequest req = new TestOSHttpRequest();
  123. TestOSHttpResponse resp = new TestOSHttpResponse();
  124. string request = "<llsd><map><key>items</key><array>";
  125. request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000001</uuid></map>"; // Notecard 1
  126. request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000002</uuid></map>"; // Notecard 2
  127. request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000003</uuid></map>"; // Notecard 3
  128. request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000004</uuid></map>"; // Notecard 4
  129. request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000005</uuid></map>"; // Notecard 5
  130. request += "</array></map></llsd>";
  131. string llsdresponse = handler.FetchInventoryRequest(request, "/FETCH", string.Empty, req, resp);
  132. Assert.That(llsdresponse != null, Is.True, "Incorrect null response");
  133. Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response");
  134. Assert.That(llsdresponse.Contains(m_userID.ToString()), Is.True, "Response should contain userID");
  135. Console.WriteLine(llsdresponse);
  136. Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000001"), Is.True, "Response does not contain notecard 1");
  137. Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000002"), Is.True, "Response does not contain notecard 2");
  138. Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000003"), Is.True, "Response does not contain notecard 3");
  139. Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000004"), Is.True, "Response does not contain notecard 4");
  140. Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000005"), Is.True, "Response does not contain notecard 5");
  141. }
  142. }
  143. }