diff options
author | Diva Canto | 2015-05-10 08:44:21 -0700 |
---|---|---|
committer | Diva Canto | 2015-05-10 08:44:21 -0700 |
commit | f992ed0f400573a54cca0dc919284f88ae83540f (patch) | |
tree | 43f380e7f3d907afb4a5571927e2936891b95ed7 /OpenSim | |
parent | Fix mantis #7054: AO in Firestorm and Kokua stopped loading after new invento... (diff) | |
download | opensim-SC-f992ed0f400573a54cca0dc919284f88ae83540f.zip opensim-SC-f992ed0f400573a54cca0dc919284f88ae83540f.tar.gz opensim-SC-f992ed0f400573a54cca0dc919284f88ae83540f.tar.bz2 opensim-SC-f992ed0f400573a54cca0dc919284f88ae83540f.tar.xz |
Added unit tests for FetchInventoryDescendents http://wiki.secondlife.com/wiki/Linden_Lab_Official:Inventory_API#Fetch_Inventory_Descendents
Also, consolidated the location of the files that handle inventory capabilities.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs (renamed from OpenSim/Capabilities/Handlers/FetchInventoryDescendents/FetchInvDescHandler.cs) | 0 | ||||
-rw-r--r-- | OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescServerConnector.cs (renamed from OpenSim/Capabilities/Handlers/FetchInventoryDescendents/FetchInvDescServerConnector.cs) | 0 | ||||
-rw-r--r-- | OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs (renamed from OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2Handler.cs) | 0 | ||||
-rw-r--r-- | OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs | 217 |
4 files changed, 217 insertions, 0 deletions
diff --git a/OpenSim/Capabilities/Handlers/FetchInventoryDescendents/FetchInvDescHandler.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs index 810096f..810096f 100644 --- a/OpenSim/Capabilities/Handlers/FetchInventoryDescendents/FetchInvDescHandler.cs +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs | |||
diff --git a/OpenSim/Capabilities/Handlers/FetchInventoryDescendents/FetchInvDescServerConnector.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescServerConnector.cs index 6fbe173..6fbe173 100644 --- a/OpenSim/Capabilities/Handlers/FetchInventoryDescendents/FetchInvDescServerConnector.cs +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescServerConnector.cs | |||
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2Handler.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs index b67b326..b67b326 100644 --- a/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2Handler.cs +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs | |||
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs b/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs new file mode 100644 index 0000000..1064c7b --- /dev/null +++ b/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs | |||
@@ -0,0 +1,217 @@ | |||
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.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Net; | ||
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 | |||
43 | namespace OpenSim.Capabilities.Handlers.FetchInventory.Tests | ||
44 | { | ||
45 | [TestFixture] | ||
46 | public class FetchInventoryDescendents2HandlerTests : OpenSimTestCase | ||
47 | { | ||
48 | private UUID m_userID = UUID.Zero; | ||
49 | private Scene m_scene; | ||
50 | private UUID m_rootFolderID; | ||
51 | private int m_rootDescendents; | ||
52 | private UUID m_notecardsFolder; | ||
53 | private UUID m_objectsFolder; | ||
54 | |||
55 | private void Init() | ||
56 | { | ||
57 | // CreateInventoryFolder an inventory | ||
58 | |||
59 | m_scene = new SceneHelpers().SetupScene(); | ||
60 | |||
61 | m_scene.InventoryService.CreateUserInventory(m_userID); | ||
62 | |||
63 | m_rootFolderID = m_scene.InventoryService.GetRootFolder(m_userID).ID; | ||
64 | |||
65 | InventoryFolderBase of = m_scene.InventoryService.GetFolderForType(m_userID, AssetType.Object); | ||
66 | m_objectsFolder = of.ID; | ||
67 | |||
68 | // Add an object | ||
69 | InventoryItemBase item = new InventoryItemBase(new UUID("b0000000-0000-0000-0000-00000000000b"), m_userID); | ||
70 | item.AssetID = UUID.Random(); | ||
71 | item.AssetType = (int)AssetType.Object; | ||
72 | item.Folder = m_objectsFolder; | ||
73 | item.Name = "Some Object"; | ||
74 | m_scene.InventoryService.AddItem(item); | ||
75 | |||
76 | InventoryFolderBase ncf = m_scene.InventoryService.GetFolderForType(m_userID, AssetType.Notecard); | ||
77 | m_notecardsFolder = ncf.ID; | ||
78 | |||
79 | // Add a notecard | ||
80 | item = new InventoryItemBase(new UUID("10000000-0000-0000-0000-000000000001"), m_userID); | ||
81 | item.AssetID = UUID.Random(); | ||
82 | item.AssetType = (int)AssetType.Notecard; | ||
83 | item.Folder = m_notecardsFolder; | ||
84 | item.Name = "Test Notecard 1"; | ||
85 | m_scene.InventoryService.AddItem(item); | ||
86 | // Add another notecard | ||
87 | item.ID = new UUID("20000000-0000-0000-0000-000000000002"); | ||
88 | item.AssetID = new UUID("a0000000-0000-0000-0000-00000000000a"); | ||
89 | item.Name = "Test Notecard 2"; | ||
90 | m_scene.InventoryService.AddItem(item); | ||
91 | |||
92 | // Add a folder | ||
93 | InventoryFolderBase folder = new InventoryFolderBase(new UUID("f0000000-0000-0000-0000-00000000000f"), "Test Folder", m_userID, m_rootFolderID); | ||
94 | m_scene.InventoryService.AddFolder(folder); | ||
95 | |||
96 | // Add a link to notecard 2 in Test Folder | ||
97 | item.AssetID = item.ID; // use item ID of notecard 2 | ||
98 | item.ID = new UUID("40000000-0000-0000-0000-000000000004"); | ||
99 | item.AssetType = (int)AssetType.Link; | ||
100 | item.Folder = folder.ID; | ||
101 | item.Name = "Link to notecard"; | ||
102 | m_scene.InventoryService.AddItem(item); | ||
103 | |||
104 | // Add a link to the Objects folder in Test Folder | ||
105 | item.AssetID = m_scene.InventoryService.GetFolderForType(m_userID, AssetType.Object).ID; // use item ID of Objects folder | ||
106 | item.ID = new UUID("50000000-0000-0000-0000-000000000005"); | ||
107 | item.AssetType = (int)AssetType.LinkFolder; | ||
108 | item.Folder = folder.ID; | ||
109 | item.Name = "Link to Objects folder"; | ||
110 | m_scene.InventoryService.AddItem(item); | ||
111 | |||
112 | InventoryCollection coll = m_scene.InventoryService.GetFolderContent(m_userID, m_rootFolderID); | ||
113 | m_rootDescendents = coll.Items.Count + coll.Folders.Count; | ||
114 | Console.WriteLine("Number of descendents: " + m_rootDescendents); | ||
115 | } | ||
116 | |||
117 | [Test] | ||
118 | public void Test_001_SimpleFolder() | ||
119 | { | ||
120 | TestHelpers.InMethod(); | ||
121 | |||
122 | Init(); | ||
123 | |||
124 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null); | ||
125 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
126 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
127 | |||
128 | string request = "<llsd><map><key>folders</key><array><map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
129 | request += m_rootFolderID; | ||
130 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map></array></map></llsd>"; | ||
131 | |||
132 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
133 | |||
134 | Assert.That(llsdresponse != null, Is.True, "Incorrect null response"); | ||
135 | Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response"); | ||
136 | Assert.That(llsdresponse.Contains("00000000-0000-0000-0000-000000000000"), Is.True, "Response should contain userID"); | ||
137 | |||
138 | string descendents = "descendents</key><integer>" + m_rootDescendents + "</integer>"; | ||
139 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents"); | ||
140 | Console.WriteLine(llsdresponse); | ||
141 | } | ||
142 | |||
143 | [Test] | ||
144 | public void Test_002_MultipleFolders() | ||
145 | { | ||
146 | TestHelpers.InMethod(); | ||
147 | |||
148 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null); | ||
149 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
150 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
151 | |||
152 | string request = "<llsd><map><key>folders</key><array>"; | ||
153 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
154 | request += m_rootFolderID; | ||
155 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
156 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
157 | request += m_notecardsFolder; | ||
158 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
159 | request += "</array></map></llsd>"; | ||
160 | |||
161 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
162 | Console.WriteLine(llsdresponse); | ||
163 | |||
164 | string descendents = "descendents</key><integer>" + m_rootDescendents + "</integer>"; | ||
165 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for root folder"); | ||
166 | descendents = "descendents</key><integer>2</integer>"; | ||
167 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for Notecard folder"); | ||
168 | |||
169 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000001"), Is.True, "Notecard 1 is missing from response"); | ||
170 | Assert.That(llsdresponse.Contains("20000000-0000-0000-0000-000000000002"), Is.True, "Notecard 2 is missing from response"); | ||
171 | } | ||
172 | |||
173 | [Test] | ||
174 | public void Test_003_Links() | ||
175 | { | ||
176 | TestHelpers.InMethod(); | ||
177 | |||
178 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null); | ||
179 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
180 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
181 | |||
182 | string request = "<llsd><map><key>folders</key><array><map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
183 | request += "f0000000-0000-0000-0000-00000000000f"; | ||
184 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map></array></map></llsd>"; | ||
185 | |||
186 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
187 | Console.WriteLine(llsdresponse); | ||
188 | |||
189 | string descendents = "descendents</key><integer>2</integer>"; | ||
190 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for Test Folder"); | ||
191 | |||
192 | // Make sure that the note card link is included | ||
193 | Assert.That(llsdresponse.Contains("Link to notecard"), Is.True, "Link to notecard is missing"); | ||
194 | |||
195 | //Make sure the notecard item itself is included | ||
196 | Assert.That(llsdresponse.Contains("Test Notecard 2"), Is.True, "Notecard 2 item (the source) is missing"); | ||
197 | |||
198 | // Make sure that the source item is before the link item | ||
199 | int pos1 = llsdresponse.IndexOf("Test Notecard 2"); | ||
200 | int pos2 = llsdresponse.IndexOf("Link to notecard"); | ||
201 | Assert.Less(pos1, pos2, "Source of link is after link"); | ||
202 | |||
203 | // Make sure the folder link is included | ||
204 | Assert.That(llsdresponse.Contains("Link to Objects folder"), Is.True, "Link to Objects folder is missing"); | ||
205 | |||
206 | // Make sure the objects inside the Objects folder are included | ||
207 | // Note: I'm not entirely sure this is needed, but that's what I found in the implementation | ||
208 | Assert.That(llsdresponse.Contains("Some Object"), Is.True, "Some Object item (contents of the source) is missing"); | ||
209 | |||
210 | // Make sure that the source item is before the link item | ||
211 | pos1 = llsdresponse.IndexOf("Some Object"); | ||
212 | pos2 = llsdresponse.IndexOf("Link to Objects folder"); | ||
213 | Assert.Less(pos1, pos2, "Contents of source of folder link is after folder link"); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | } \ No newline at end of file | ||