diff options
Diffstat (limited to 'OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs')
-rw-r--r-- | OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs | 292 |
1 files changed, 0 insertions, 292 deletions
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs b/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs deleted file mode 100644 index 2d5531a..0000000 --- a/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs +++ /dev/null | |||
@@ -1,292 +0,0 @@ | |||
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 System.Text.RegularExpressions; | ||
33 | using log4net; | ||
34 | using log4net.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Capabilities.Handlers; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using OpenSim.Tests.Common; | ||
43 | |||
44 | namespace OpenSim.Capabilities.Handlers.FetchInventory.Tests | ||
45 | { | ||
46 | [TestFixture] | ||
47 | public class FetchInventoryDescendents2HandlerTests : OpenSimTestCase | ||
48 | { | ||
49 | private UUID m_userID = UUID.Zero; | ||
50 | private Scene m_scene; | ||
51 | private UUID m_rootFolderID; | ||
52 | private int m_rootDescendents; | ||
53 | private UUID m_notecardsFolder; | ||
54 | private UUID m_objectsFolder; | ||
55 | |||
56 | private void Init() | ||
57 | { | ||
58 | // Create an inventory that looks like this: | ||
59 | // | ||
60 | // /My Inventory | ||
61 | // <other system folders> | ||
62 | // /Objects | ||
63 | // Some Object | ||
64 | // /Notecards | ||
65 | // Notecard 1 | ||
66 | // Notecard 2 | ||
67 | // /Test Folder | ||
68 | // Link to notecard -> /Notecards/Notecard 2 | ||
69 | // Link to Objects folder -> /Objects | ||
70 | |||
71 | m_scene = new SceneHelpers().SetupScene(); | ||
72 | |||
73 | m_scene.InventoryService.CreateUserInventory(m_userID); | ||
74 | |||
75 | m_rootFolderID = m_scene.InventoryService.GetRootFolder(m_userID).ID; | ||
76 | |||
77 | InventoryFolderBase of = m_scene.InventoryService.GetFolderForType(m_userID, FolderType.Object); | ||
78 | m_objectsFolder = of.ID; | ||
79 | |||
80 | // Add an object | ||
81 | InventoryItemBase item = new InventoryItemBase(new UUID("b0000000-0000-0000-0000-00000000000b"), m_userID); | ||
82 | item.AssetID = UUID.Random(); | ||
83 | item.AssetType = (int)AssetType.Object; | ||
84 | item.Folder = m_objectsFolder; | ||
85 | item.Name = "Some Object"; | ||
86 | m_scene.InventoryService.AddItem(item); | ||
87 | |||
88 | InventoryFolderBase ncf = m_scene.InventoryService.GetFolderForType(m_userID, FolderType.Notecard); | ||
89 | m_notecardsFolder = ncf.ID; | ||
90 | |||
91 | // Add a notecard | ||
92 | item = new InventoryItemBase(new UUID("10000000-0000-0000-0000-000000000001"), m_userID); | ||
93 | item.AssetID = UUID.Random(); | ||
94 | item.AssetType = (int)AssetType.Notecard; | ||
95 | item.Folder = m_notecardsFolder; | ||
96 | item.Name = "Test Notecard 1"; | ||
97 | m_scene.InventoryService.AddItem(item); | ||
98 | // Add another notecard | ||
99 | item.ID = new UUID("20000000-0000-0000-0000-000000000002"); | ||
100 | item.AssetID = new UUID("a0000000-0000-0000-0000-00000000000a"); | ||
101 | item.Name = "Test Notecard 2"; | ||
102 | m_scene.InventoryService.AddItem(item); | ||
103 | |||
104 | // Add a folder | ||
105 | InventoryFolderBase folder = new InventoryFolderBase(new UUID("f0000000-0000-0000-0000-00000000000f"), "Test Folder", m_userID, m_rootFolderID); | ||
106 | m_scene.InventoryService.AddFolder(folder); | ||
107 | |||
108 | // Add a link to notecard 2 in Test Folder | ||
109 | item.AssetID = item.ID; // use item ID of notecard 2 | ||
110 | item.ID = new UUID("40000000-0000-0000-0000-000000000004"); | ||
111 | item.AssetType = (int)AssetType.Link; | ||
112 | item.Folder = folder.ID; | ||
113 | item.Name = "Link to notecard"; | ||
114 | m_scene.InventoryService.AddItem(item); | ||
115 | |||
116 | // Add a link to the Objects folder in Test Folder | ||
117 | item.AssetID = m_scene.InventoryService.GetFolderForType(m_userID, FolderType.Object).ID; // use item ID of Objects folder | ||
118 | item.ID = new UUID("50000000-0000-0000-0000-000000000005"); | ||
119 | item.AssetType = (int)AssetType.LinkFolder; | ||
120 | item.Folder = folder.ID; | ||
121 | item.Name = "Link to Objects folder"; | ||
122 | m_scene.InventoryService.AddItem(item); | ||
123 | |||
124 | InventoryCollection coll = m_scene.InventoryService.GetFolderContent(m_userID, m_rootFolderID); | ||
125 | m_rootDescendents = coll.Items.Count + coll.Folders.Count; | ||
126 | Console.WriteLine("Number of descendents: " + m_rootDescendents); | ||
127 | } | ||
128 | |||
129 | [Test] | ||
130 | public void Test_001_SimpleFolder() | ||
131 | { | ||
132 | TestHelpers.InMethod(); | ||
133 | |||
134 | Init(); | ||
135 | |||
136 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene); | ||
137 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
138 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
139 | |||
140 | 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>"; | ||
141 | request += m_rootFolderID; | ||
142 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map></array></map></llsd>"; | ||
143 | |||
144 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
145 | |||
146 | Assert.That(llsdresponse != null, Is.True, "Incorrect null response"); | ||
147 | Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response"); | ||
148 | Assert.That(llsdresponse.Contains("00000000-0000-0000-0000-000000000000"), Is.True, "Response should contain userID"); | ||
149 | |||
150 | string descendents = "descendents</key><integer>" + m_rootDescendents + "</integer>"; | ||
151 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents"); | ||
152 | Console.WriteLine(llsdresponse); | ||
153 | } | ||
154 | |||
155 | [Test] | ||
156 | public void Test_002_MultipleFolders() | ||
157 | { | ||
158 | TestHelpers.InMethod(); | ||
159 | |||
160 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene); | ||
161 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
162 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
163 | |||
164 | string request = "<llsd><map><key>folders</key><array>"; | ||
165 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
166 | request += m_rootFolderID; | ||
167 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
168 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
169 | request += m_notecardsFolder; | ||
170 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
171 | request += "</array></map></llsd>"; | ||
172 | |||
173 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
174 | Console.WriteLine(llsdresponse); | ||
175 | |||
176 | string descendents = "descendents</key><integer>" + m_rootDescendents + "</integer>"; | ||
177 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for root folder"); | ||
178 | descendents = "descendents</key><integer>2</integer>"; | ||
179 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for Notecard folder"); | ||
180 | |||
181 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000001"), Is.True, "Notecard 1 is missing from response"); | ||
182 | Assert.That(llsdresponse.Contains("20000000-0000-0000-0000-000000000002"), Is.True, "Notecard 2 is missing from response"); | ||
183 | } | ||
184 | |||
185 | [Test] | ||
186 | public void Test_003_Links() | ||
187 | { | ||
188 | TestHelpers.InMethod(); | ||
189 | |||
190 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene); | ||
191 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
192 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
193 | |||
194 | 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>"; | ||
195 | request += "f0000000-0000-0000-0000-00000000000f"; | ||
196 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map></array></map></llsd>"; | ||
197 | |||
198 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
199 | Console.WriteLine(llsdresponse); | ||
200 | |||
201 | string descendents = "descendents</key><integer>2</integer>"; | ||
202 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for Test Folder"); | ||
203 | |||
204 | // Make sure that the note card link is included | ||
205 | Assert.That(llsdresponse.Contains("Link to notecard"), Is.True, "Link to notecard is missing"); | ||
206 | |||
207 | //Make sure the notecard item itself is included | ||
208 | Assert.That(llsdresponse.Contains("Test Notecard 2"), Is.True, "Notecard 2 item (the source) is missing"); | ||
209 | |||
210 | // Make sure that the source item is before the link item | ||
211 | int pos1 = llsdresponse.IndexOf("Test Notecard 2"); | ||
212 | int pos2 = llsdresponse.IndexOf("Link to notecard"); | ||
213 | Assert.Less(pos1, pos2, "Source of link is after link"); | ||
214 | |||
215 | // Make sure the folder link is included | ||
216 | Assert.That(llsdresponse.Contains("Link to Objects folder"), Is.True, "Link to Objects folder is missing"); | ||
217 | |||
218 | // Make sure the objects inside the Objects folder are included | ||
219 | // Note: I'm not entirely sure this is needed, but that's what I found in the implementation | ||
220 | Assert.That(llsdresponse.Contains("Some Object"), Is.True, "Some Object item (contents of the source) is missing"); | ||
221 | |||
222 | // Make sure that the source item is before the link item | ||
223 | pos1 = llsdresponse.IndexOf("Some Object"); | ||
224 | pos2 = llsdresponse.IndexOf("Link to Objects folder"); | ||
225 | Assert.Less(pos1, pos2, "Contents of source of folder link is after folder link"); | ||
226 | } | ||
227 | |||
228 | [Test] | ||
229 | public void Test_004_DuplicateFolders() | ||
230 | { | ||
231 | TestHelpers.InMethod(); | ||
232 | |||
233 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene); | ||
234 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
235 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
236 | |||
237 | string request = "<llsd><map><key>folders</key><array>"; | ||
238 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
239 | request += m_rootFolderID; | ||
240 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
241 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
242 | request += m_notecardsFolder; | ||
243 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
244 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
245 | request += m_rootFolderID; | ||
246 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
247 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
248 | request += m_notecardsFolder; | ||
249 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
250 | request += "</array></map></llsd>"; | ||
251 | |||
252 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
253 | Console.WriteLine(llsdresponse); | ||
254 | |||
255 | string root_folder = "<key>folder_id</key><uuid>" + m_rootFolderID + "</uuid>"; | ||
256 | string notecards_folder = "<key>folder_id</key><uuid>" + m_notecardsFolder + "</uuid>"; | ||
257 | |||
258 | Assert.That(llsdresponse.Contains(root_folder), "Missing root folder"); | ||
259 | Assert.That(llsdresponse.Contains(notecards_folder), "Missing notecards folder"); | ||
260 | int count = Regex.Matches(llsdresponse, root_folder).Count; | ||
261 | Assert.AreEqual(1, count, "More than 1 root folder in response"); | ||
262 | count = Regex.Matches(llsdresponse, notecards_folder).Count; | ||
263 | Assert.AreEqual(2, count, "More than 1 notecards folder in response"); // Notecards will also be under root, so 2 | ||
264 | } | ||
265 | |||
266 | [Test] | ||
267 | public void Test_005_FolderZero() | ||
268 | { | ||
269 | TestHelpers.InMethod(); | ||
270 | |||
271 | Init(); | ||
272 | |||
273 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene); | ||
274 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
275 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
276 | |||
277 | 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>"; | ||
278 | request += UUID.Zero; | ||
279 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map></array></map></llsd>"; | ||
280 | |||
281 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
282 | |||
283 | Assert.That(llsdresponse != null, Is.True, "Incorrect null response"); | ||
284 | Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response"); | ||
285 | Assert.That(llsdresponse.Contains("bad_folders</key><array><uuid>00000000-0000-0000-0000-000000000000"), Is.True, "Folder Zero should be a bad folder"); | ||
286 | |||
287 | Console.WriteLine(llsdresponse); | ||
288 | } | ||
289 | |||
290 | } | ||
291 | |||
292 | } \ No newline at end of file | ||