WebFetchInvDescModuleTests.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Net;
  32. using System.Text;
  33. using HttpServer;
  34. using log4net.Config;
  35. using Nini.Config;
  36. using NUnit.Framework;
  37. using OpenMetaverse;
  38. using OpenMetaverse.Packets;
  39. using OpenMetaverse.StructuredData;
  40. using OpenSim.Framework;
  41. using OpenSim.Framework.Capabilities;
  42. using OpenSim.Framework.Servers;
  43. using OpenSim.Framework.Servers.HttpServer;
  44. using OpenSim.Region.ClientStack.Linden;
  45. using OpenSim.Region.CoreModules.Framework;
  46. using OpenSim.Region.Framework.Scenes;
  47. using OpenSim.Services.Interfaces;
  48. using OpenSim.Tests.Common;
  49. using OSDArray = OpenMetaverse.StructuredData.OSDArray;
  50. using OSDMap = OpenMetaverse.StructuredData.OSDMap;
  51. namespace OpenSim.Region.ClientStack.Linden.Caps.Tests
  52. {
  53. [TestFixture]
  54. public class WebFetchInvDescModuleTests : OpenSimTestCase
  55. {
  56. [TestFixtureSetUp]
  57. public void TestFixtureSetUp()
  58. {
  59. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  60. Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
  61. }
  62. [TestFixtureTearDown]
  63. public void TestFixureTearDown()
  64. {
  65. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  66. // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
  67. // tests really shouldn't).
  68. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  69. }
  70. [SetUp]
  71. public override void SetUp()
  72. {
  73. base.SetUp();
  74. // This is an unfortunate bit of clean up we have to do because MainServer manages things through static
  75. // variables and the VM is not restarted between tests.
  76. uint port = 9999;
  77. MainServer.RemoveHttpServer(port);
  78. BaseHttpServer server = new BaseHttpServer(port, false, 0, "");
  79. MainServer.AddHttpServer(server);
  80. MainServer.Instance = server;
  81. server.Start(false);
  82. }
  83. [Test]
  84. public void TestInventoryDescendentsFetch()
  85. {
  86. TestHelpers.InMethod();
  87. TestHelpers.EnableLogging();
  88. BaseHttpServer httpServer = MainServer.Instance;
  89. Scene scene = new SceneHelpers().SetupScene();
  90. CapabilitiesModule capsModule = new CapabilitiesModule();
  91. WebFetchInvDescModule wfidModule = new WebFetchInvDescModule(false);
  92. IConfigSource config = new IniConfigSource();
  93. config.AddConfig("ClientStack.LindenCaps");
  94. config.Configs["ClientStack.LindenCaps"].Set("Cap_FetchInventoryDescendents2", "localhost");
  95. SceneHelpers.SetupSceneModules(scene, config, capsModule, wfidModule);
  96. UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1));
  97. // We need a user present to have any capabilities set up
  98. SceneHelpers.AddScenePresence(scene, ua.PrincipalID);
  99. TestHttpRequest req = new TestHttpRequest();
  100. OpenSim.Framework.Capabilities.Caps userCaps = capsModule.GetCapsForUser(ua.PrincipalID);
  101. PollServiceEventArgs pseArgs;
  102. userCaps.TryGetPollHandler("FetchInventoryDescendents2", out pseArgs);
  103. req.UriPath = pseArgs.Url;
  104. req.Uri = new Uri(req.UriPath);
  105. // Retrieve root folder details directly so that we can request
  106. InventoryFolderBase folder = scene.InventoryService.GetRootFolder(ua.PrincipalID);
  107. OSDMap osdFolder = new OSDMap();
  108. osdFolder["folder_id"] = folder.ID;
  109. osdFolder["owner_id"] = ua.PrincipalID;
  110. osdFolder["fetch_folders"] = true;
  111. osdFolder["fetch_items"] = true;
  112. osdFolder["sort_order"] = 0;
  113. OSDArray osdFoldersArray = new OSDArray();
  114. osdFoldersArray.Add(osdFolder);
  115. OSDMap osdReqMap = new OSDMap();
  116. osdReqMap["folders"] = osdFoldersArray;
  117. req.Body = new MemoryStream(OSDParser.SerializeLLSDXmlBytes(osdReqMap));
  118. TestHttpClientContext context = new TestHttpClientContext(false);
  119. MainServer.Instance.OnRequest(context, new RequestEventArgs(req));
  120. // Drive processing of the queued inventory request synchronously.
  121. wfidModule.WaitProcessQueuedInventoryRequest();
  122. MainServer.Instance.PollServiceRequestManager.WaitPerformResponse();
  123. // System.Threading.Thread.Sleep(10000);
  124. OSDMap responseOsd = (OSDMap)OSDParser.DeserializeLLSDXml(context.ResponseBody);
  125. OSDArray foldersOsd = (OSDArray)responseOsd["folders"];
  126. OSDMap folderOsd = (OSDMap)foldersOsd[0];
  127. // A sanity check that the response has the expected number of descendents for a default inventory
  128. // TODO: Need a more thorough check.
  129. Assert.That((int)folderOsd["descendents"], Is.EqualTo(16));
  130. }
  131. }
  132. }