WebFetchInvDescModuleTests.cs 6.7 KB

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