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