aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-03-09 01:53:27 +0000
committerJustin Clark-Casey (justincc)2011-03-09 01:53:27 +0000
commitae507bb0600774624f876c4562391cec0111eee8 (patch)
treea44687ca003e6962dc7ab6e7d90a1c2c8689d35b /OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs
parentremove inventory service preserving code from SceneSetupHelpers too (diff)
downloadopensim-SC_OLD-ae507bb0600774624f876c4562391cec0111eee8.zip
opensim-SC_OLD-ae507bb0600774624f876c4562391cec0111eee8.tar.gz
opensim-SC_OLD-ae507bb0600774624f876c4562391cec0111eee8.tar.bz2
opensim-SC_OLD-ae507bb0600774624f876c4562391cec0111eee8.tar.xz
Split out path tests from InventoryArchiveTests. Factor common code into test case parent
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs436
1 files changed, 436 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs
new file mode 100644
index 0000000..34eeaf3
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs
@@ -0,0 +1,436 @@
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
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using System.Threading;
33using NUnit.Framework;
34using NUnit.Framework.SyntaxHelpers;
35using OpenMetaverse;
36using OpenSim.Data;
37using OpenSim.Framework;
38using OpenSim.Framework.Serialization;
39using OpenSim.Framework.Serialization.External;
40using OpenSim.Framework.Communications;
41using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
42using OpenSim.Region.CoreModules.World.Serialiser;
43using OpenSim.Region.Framework.Scenes;
44using OpenSim.Region.Framework.Scenes.Serialization;
45using OpenSim.Services.Interfaces;
46using OpenSim.Tests.Common;
47using OpenSim.Tests.Common.Mock;
48using OpenSim.Tests.Common.Setup;
49
50namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
51{
52 [TestFixture]
53 public class PathTests : InventoryArchiveTestCase
54 {
55 /// <summary>
56 /// Test saving an inventory path to a V0.1 OpenSim Inventory Archive
57 /// (subject to change since there is no fixed format yet).
58 /// </summary>
59 [Test]
60 public void TestSavePathToIarV0_1()
61 {
62 TestHelper.InMethod();
63// log4net.Config.XmlConfigurator.Configure();
64
65 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
66
67 Scene scene = SceneSetupHelpers.SetupScene("Inventory");
68 SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
69
70 // Create user
71 string userFirstName = "Jock";
72 string userLastName = "Stirrup";
73 string userPassword = "troll";
74 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
75 UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, userPassword);
76
77 // Create asset
78 SceneObjectGroup object1;
79 SceneObjectPart part1;
80 {
81 string partName = "My Little Dog Object";
82 UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
83 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
84 Vector3 groupPosition = new Vector3(10, 20, 30);
85 Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
86 Vector3 offsetPosition = new Vector3(5, 10, 15);
87
88 part1
89 = new SceneObjectPart(
90 ownerId, shape, groupPosition, rotationOffset, offsetPosition);
91 part1.Name = partName;
92
93 object1 = new SceneObjectGroup(part1);
94 scene.AddNewSceneObject(object1, false);
95 }
96
97 UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
98 AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
99 scene.AssetService.Store(asset1);
100
101 // Create item
102 UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
103 InventoryItemBase item1 = new InventoryItemBase();
104 item1.Name = "My Little Dog";
105 item1.AssetID = asset1.FullID;
106 item1.ID = item1Id;
107 InventoryFolderBase objsFolder
108 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0];
109 item1.Folder = objsFolder.ID;
110 scene.AddInventoryItem(item1);
111
112 MemoryStream archiveWriteStream = new MemoryStream();
113 archiverModule.OnInventoryArchiveSaved += SaveCompleted;
114
115 // Test saving a particular path
116 mre.Reset();
117 archiverModule.ArchiveInventory(
118 Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream);
119 mre.WaitOne(60000, false);
120
121 byte[] archive = archiveWriteStream.ToArray();
122 MemoryStream archiveReadStream = new MemoryStream(archive);
123 TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
124
125 //bool gotControlFile = false;
126 bool gotObject1File = false;
127 //bool gotObject2File = false;
128 string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1);
129 string expectedObject1FilePath = string.Format(
130 "{0}{1}{2}",
131 ArchiveConstants.INVENTORY_PATH,
132 InventoryArchiveWriteRequest.CreateArchiveFolderName(objsFolder),
133 expectedObject1FileName);
134
135 string filePath;
136 TarArchiveReader.TarEntryType tarEntryType;
137
138// Console.WriteLine("Reading archive");
139
140 while (tar.ReadEntry(out filePath, out tarEntryType) != null)
141 {
142// Console.WriteLine("Got {0}", filePath);
143
144// if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
145// {
146// gotControlFile = true;
147// }
148
149 if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml"))
150 {
151// string fileName = filePath.Remove(0, "Objects/".Length);
152//
153// if (fileName.StartsWith(part1.Name))
154// {
155 Assert.That(expectedObject1FilePath, Is.EqualTo(filePath));
156 gotObject1File = true;
157// }
158// else if (fileName.StartsWith(part2.Name))
159// {
160// Assert.That(fileName, Is.EqualTo(expectedObject2FileName));
161// gotObject2File = true;
162// }
163 }
164 }
165
166// Assert.That(gotControlFile, Is.True, "No control file in archive");
167 Assert.That(gotObject1File, Is.True, "No item1 file in archive");
168// Assert.That(gotObject2File, Is.True, "No object2 file in archive");
169
170 // TODO: Test presence of more files and contents of files.
171 }
172
173 /// <summary>
174 /// Test that things work when the load path specified starts with a slash
175 /// </summary>
176 [Test]
177 public void TestLoadIarPathStartsWithSlash()
178 {
179 TestHelper.InMethod();
180// log4net.Config.XmlConfigurator.Configure();
181
182 SerialiserModule serialiserModule = new SerialiserModule();
183 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
184 Scene scene = SceneSetupHelpers.SetupScene("inventory");
185 SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule);
186
187 UserProfileTestUtils.CreateUserWithInventory(scene, m_ua1, "password");
188 archiverModule.DearchiveInventory(m_ua1.FirstName, m_ua1.LastName, "/Objects", "password", m_iarStream);
189
190 InventoryItemBase foundItem1
191 = InventoryArchiveUtils.FindItemByPath(
192 scene.InventoryService, m_ua1.PrincipalID, "/Objects/" + m_item1Name);
193
194 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1 in TestLoadIarFolderStartsWithSlash()");
195 }
196
197 [Test]
198 public void TestIarV0_1WithEscapedChars()
199 {
200 TestHelper.InMethod();
201// log4net.Config.XmlConfigurator.Configure();
202
203 string itemName = "You & you are a mean/man/";
204 string humanEscapedItemName = @"You & you are a mean\/man\/";
205 string userPassword = "meowfood";
206
207 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
208
209 Scene scene = SceneSetupHelpers.SetupScene("Inventory");
210 SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
211
212 // Create user
213 string userFirstName = "Jock";
214 string userLastName = "Stirrup";
215 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
216 UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "meowfood");
217
218 // Create asset
219 SceneObjectGroup object1;
220 SceneObjectPart part1;
221 {
222 string partName = "part name";
223 UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
224 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
225 Vector3 groupPosition = new Vector3(10, 20, 30);
226 Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
227 Vector3 offsetPosition = new Vector3(5, 10, 15);
228
229 part1
230 = new SceneObjectPart(
231 ownerId, shape, groupPosition, rotationOffset, offsetPosition);
232 part1.Name = partName;
233
234 object1 = new SceneObjectGroup(part1);
235 scene.AddNewSceneObject(object1, false);
236 }
237
238 UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
239 AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
240 scene.AssetService.Store(asset1);
241
242 // Create item
243 UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
244 InventoryItemBase item1 = new InventoryItemBase();
245 item1.Name = itemName;
246 item1.AssetID = asset1.FullID;
247 item1.ID = item1Id;
248 InventoryFolderBase objsFolder
249 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0];
250 item1.Folder = objsFolder.ID;
251 scene.AddInventoryItem(item1);
252
253 MemoryStream archiveWriteStream = new MemoryStream();
254 archiverModule.OnInventoryArchiveSaved += SaveCompleted;
255
256 mre.Reset();
257 archiverModule.ArchiveInventory(
258 Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream);
259 mre.WaitOne(60000, false);
260
261 // LOAD ITEM
262 MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
263
264 archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", userPassword, archiveReadStream);
265
266 InventoryItemBase foundItem1
267 = InventoryArchiveUtils.FindItemByPath(
268 scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName);
269
270 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
271// Assert.That(
272// foundItem1.CreatorId, Is.EqualTo(userUuid),
273// "Loaded item non-uuid creator doesn't match that of the loading user");
274 Assert.That(
275 foundItem1.Name, Is.EqualTo(itemName),
276 "Loaded item name doesn't match saved name");
277 }
278
279 /// <summary>
280 /// Test replication of an archive path to the user's inventory.
281 /// </summary>
282 [Test]
283 public void TestNewIarPath()
284 {
285 TestHelper.InMethod();
286// log4net.Config.XmlConfigurator.Configure();
287
288 Scene scene = SceneSetupHelpers.SetupScene("inventory");
289 UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene);
290
291 Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>();
292 HashSet<InventoryNodeBase> nodesLoaded = new HashSet<InventoryNodeBase>();
293
294 string folder1Name = "1";
295 string folder2aName = "2a";
296 string folder2bName = "2b";
297
298 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1Name, UUID.Random());
299 string folder2aArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2aName, UUID.Random());
300 string folder2bArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2bName, UUID.Random());
301
302 string iarPath1 = string.Join("", new string[] { folder1ArchiveName, folder2aArchiveName });
303 string iarPath2 = string.Join("", new string[] { folder1ArchiveName, folder2bArchiveName });
304
305 {
306 // Test replication of path1
307 new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false)
308 .ReplicateArchivePathToUserInventory(
309 iarPath1, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
310 foldersCreated, nodesLoaded);
311
312 List<InventoryFolderBase> folder1Candidates
313 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1Name);
314 Assert.That(folder1Candidates.Count, Is.EqualTo(1));
315
316 InventoryFolderBase folder1 = folder1Candidates[0];
317 List<InventoryFolderBase> folder2aCandidates
318 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2aName);
319 Assert.That(folder2aCandidates.Count, Is.EqualTo(1));
320 }
321
322 {
323 // Test replication of path2
324 new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false)
325 .ReplicateArchivePathToUserInventory(
326 iarPath2, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
327 foldersCreated, nodesLoaded);
328
329 List<InventoryFolderBase> folder1Candidates
330 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1Name);
331 Assert.That(folder1Candidates.Count, Is.EqualTo(1));
332
333 InventoryFolderBase folder1 = folder1Candidates[0];
334
335 List<InventoryFolderBase> folder2aCandidates
336 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2aName);
337 Assert.That(folder2aCandidates.Count, Is.EqualTo(1));
338
339 List<InventoryFolderBase> folder2bCandidates
340 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2bName);
341 Assert.That(folder2bCandidates.Count, Is.EqualTo(1));
342 }
343 }
344
345 /// <summary>
346 /// Test replication of a partly existing archive path to the user's inventory. This should create
347 /// a duplicate path without the merge option.
348 /// </summary>
349 [Test]
350 public void TestPartExistingIarPath()
351 {
352 TestHelper.InMethod();
353 //log4net.Config.XmlConfigurator.Configure();
354
355 Scene scene = SceneSetupHelpers.SetupScene("inventory");
356 UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene);
357
358 string folder1ExistingName = "a";
359 string folder2Name = "b";
360
361 InventoryFolderBase folder1
362 = UserInventoryTestUtils.CreateInventoryFolder(
363 scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
364
365 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
366 string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());
367
368 string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });
369
370 new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false)
371 .ReplicateArchivePathToUserInventory(
372 itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
373 new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>());
374
375 List<InventoryFolderBase> folder1PostCandidates
376 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
377 Assert.That(folder1PostCandidates.Count, Is.EqualTo(2));
378
379 // FIXME: Temporarily, we're going to do something messy to make sure we pick up the created folder.
380 InventoryFolderBase folder1Post = null;
381 foreach (InventoryFolderBase folder in folder1PostCandidates)
382 {
383 if (folder.ID != folder1.ID)
384 {
385 folder1Post = folder;
386 break;
387 }
388 }
389// Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID));
390
391 List<InventoryFolderBase> folder2PostCandidates
392 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1Post, "b");
393 Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
394 }
395
396 /// <summary>
397 /// Test replication of a partly existing archive path to the user's inventory. This should create
398 /// a merged path.
399 /// </summary>
400 [Test]
401 public void TestMergeIarPath()
402 {
403 TestHelper.InMethod();
404// log4net.Config.XmlConfigurator.Configure();
405
406 Scene scene = SceneSetupHelpers.SetupScene("inventory");
407 UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene);
408
409 string folder1ExistingName = "a";
410 string folder2Name = "b";
411
412 InventoryFolderBase folder1
413 = UserInventoryTestUtils.CreateInventoryFolder(
414 scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
415
416 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
417 string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());
418
419 string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });
420
421 new InventoryArchiveReadRequest(scene, ua1, folder1ExistingName, (Stream)null, true)
422 .ReplicateArchivePathToUserInventory(
423 itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
424 new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>());
425
426 List<InventoryFolderBase> folder1PostCandidates
427 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
428 Assert.That(folder1PostCandidates.Count, Is.EqualTo(1));
429 Assert.That(folder1PostCandidates[0].ID, Is.EqualTo(folder1.ID));
430
431 List<InventoryFolderBase> folder2PostCandidates
432 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1PostCandidates[0], "b");
433 Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
434 }
435 }
436} \ No newline at end of file