diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs | 131 |
1 files changed, 86 insertions, 45 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index 3fb2c8c..0218f86 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs | |||
@@ -55,12 +55,58 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
55 | { | 55 | { |
56 | protected ManualResetEvent mre = new ManualResetEvent(false); | 56 | protected ManualResetEvent mre = new ManualResetEvent(false); |
57 | 57 | ||
58 | /// <summary> | ||
59 | /// Stream of data representing a common IAR that can be reused in load tests. | ||
60 | /// </summary> | ||
61 | protected MemoryStream m_iarStream; | ||
62 | |||
63 | protected UserAccount m_ua1 | ||
64 | = new UserAccount { | ||
65 | PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000555"), | ||
66 | FirstName = "Mr", | ||
67 | LastName = "Tiddles" }; | ||
68 | protected UserAccount m_ua2 | ||
69 | = new UserAccount { | ||
70 | PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000666"), | ||
71 | FirstName = "Lord", | ||
72 | LastName = "Lucan" }; | ||
73 | string m_item1Name = "b.lsl"; | ||
74 | |||
58 | private void SaveCompleted( | 75 | private void SaveCompleted( |
59 | Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, | 76 | Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, |
60 | Exception reportedException) | 77 | Exception reportedException) |
61 | { | 78 | { |
62 | mre.Set(); | 79 | mre.Set(); |
63 | } | 80 | } |
81 | |||
82 | [SetUp] | ||
83 | public void Init() | ||
84 | { | ||
85 | ConstructDefaultIarForTestLoad(); | ||
86 | } | ||
87 | |||
88 | protected void ConstructDefaultIarForTestLoad() | ||
89 | { | ||
90 | string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(m_item1Name, UUID.Random()); | ||
91 | |||
92 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
93 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | ||
94 | |||
95 | InventoryItemBase item1 = new InventoryItemBase(); | ||
96 | item1.Name = m_item1Name; | ||
97 | item1.AssetID = UUID.Random(); | ||
98 | item1.GroupID = UUID.Random(); | ||
99 | item1.CreatorId = OspResolver.MakeOspa(m_ua2.FirstName, m_ua2.LastName); | ||
100 | //item1.CreatorId = userUuid.ToString(); | ||
101 | //item1.CreatorId = "00000000-0000-0000-0000-000000000444"; | ||
102 | item1.Owner = UUID.Zero; | ||
103 | |||
104 | string item1FileName | ||
105 | = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); | ||
106 | tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); | ||
107 | tar.Close(); | ||
108 | m_iarStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
109 | } | ||
64 | 110 | ||
65 | /// <summary> | 111 | /// <summary> |
66 | /// Test saving an inventory path to a V0.1 OpenSim Inventory Archive | 112 | /// Test saving an inventory path to a V0.1 OpenSim Inventory Archive |
@@ -122,6 +168,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
122 | MemoryStream archiveWriteStream = new MemoryStream(); | 168 | MemoryStream archiveWriteStream = new MemoryStream(); |
123 | archiverModule.OnInventoryArchiveSaved += SaveCompleted; | 169 | archiverModule.OnInventoryArchiveSaved += SaveCompleted; |
124 | 170 | ||
171 | // Test saving a particular path | ||
125 | mre.Reset(); | 172 | mre.Reset(); |
126 | archiverModule.ArchiveInventory( | 173 | archiverModule.ArchiveInventory( |
127 | Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); | 174 | Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); |
@@ -148,7 +195,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
148 | 195 | ||
149 | while (tar.ReadEntry(out filePath, out tarEntryType) != null) | 196 | while (tar.ReadEntry(out filePath, out tarEntryType) != null) |
150 | { | 197 | { |
151 | Console.WriteLine("Got {0}", filePath); | 198 | // Console.WriteLine("Got {0}", filePath); |
152 | 199 | ||
153 | // if (ArchiveConstants.CONTROL_FILE_PATH == filePath) | 200 | // if (ArchiveConstants.CONTROL_FILE_PATH == filePath) |
154 | // { | 201 | // { |
@@ -297,6 +344,30 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
297 | } | 344 | } |
298 | 345 | ||
299 | /// <summary> | 346 | /// <summary> |
347 | /// Test that things work when the load path specified starts with a slash | ||
348 | /// </summary> | ||
349 | [Test] | ||
350 | public void TestLoadIarPathStartsWithSlash() | ||
351 | { | ||
352 | TestHelper.InMethod(); | ||
353 | // log4net.Config.XmlConfigurator.Configure(); | ||
354 | |||
355 | SerialiserModule serialiserModule = new SerialiserModule(); | ||
356 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); | ||
357 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
358 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | ||
359 | |||
360 | UserProfileTestUtils.CreateUserWithInventory(scene, m_ua1, "password"); | ||
361 | archiverModule.DearchiveInventory(m_ua1.FirstName, m_ua1.LastName, "/Objects", "password", m_iarStream); | ||
362 | |||
363 | InventoryItemBase foundItem1 | ||
364 | = InventoryArchiveUtils.FindItemByPath( | ||
365 | scene.InventoryService, m_ua1.PrincipalID, "/Objects/" + m_item1Name); | ||
366 | |||
367 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1 in TestLoadIarFolderStartsWithSlash()"); | ||
368 | } | ||
369 | |||
370 | /// <summary> | ||
300 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | 371 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where |
301 | /// an account exists with the creator name. | 372 | /// an account exists with the creator name. |
302 | /// </summary> | 373 | /// </summary> |
@@ -308,34 +379,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
308 | TestHelper.InMethod(); | 379 | TestHelper.InMethod(); |
309 | //log4net.Config.XmlConfigurator.Configure(); | 380 | //log4net.Config.XmlConfigurator.Configure(); |
310 | 381 | ||
311 | string userFirstName = "Mr"; | ||
312 | string userLastName = "Tiddles"; | ||
313 | UUID userUuid = UUID.Parse("00000000-0000-0000-0000-000000000555"); | ||
314 | string userItemCreatorFirstName = "Lord"; | ||
315 | string userItemCreatorLastName = "Lucan"; | ||
316 | UUID userItemCreatorUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); | ||
317 | |||
318 | string item1Name = "b.lsl"; | ||
319 | string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1Name, UUID.Random()); | ||
320 | |||
321 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
322 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | ||
323 | |||
324 | InventoryItemBase item1 = new InventoryItemBase(); | ||
325 | item1.Name = item1Name; | ||
326 | item1.AssetID = UUID.Random(); | ||
327 | item1.GroupID = UUID.Random(); | ||
328 | item1.CreatorId = OspResolver.MakeOspa(userItemCreatorFirstName, userItemCreatorLastName); | ||
329 | //item1.CreatorId = userUuid.ToString(); | ||
330 | //item1.CreatorId = "00000000-0000-0000-0000-000000000444"; | ||
331 | item1.Owner = UUID.Zero; | ||
332 | |||
333 | string item1FileName | ||
334 | = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); | ||
335 | tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); | ||
336 | tar.Close(); | ||
337 | |||
338 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
339 | SerialiserModule serialiserModule = new SerialiserModule(); | 382 | SerialiserModule serialiserModule = new SerialiserModule(); |
340 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); | 383 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); |
341 | 384 | ||
@@ -344,15 +387,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
344 | 387 | ||
345 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | 388 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); |
346 | 389 | ||
347 | UserProfileTestUtils.CreateUserWithInventory( | 390 | UserProfileTestUtils.CreateUserWithInventory(scene, m_ua1, "meowfood"); |
348 | scene, userFirstName, userLastName, userUuid, "meowfood"); | 391 | UserProfileTestUtils.CreateUserWithInventory(scene, m_ua2, "hampshire"); |
349 | UserProfileTestUtils.CreateUserWithInventory( | ||
350 | scene, userItemCreatorFirstName, userItemCreatorLastName, userItemCreatorUuid, "hampshire"); | ||
351 | 392 | ||
352 | archiverModule.DearchiveInventory(userFirstName, userLastName, "/", "meowfood", archiveReadStream); | 393 | archiverModule.DearchiveInventory(m_ua1.FirstName, m_ua1.LastName, "/", "meowfood", m_iarStream); |
353 | 394 | ||
354 | InventoryItemBase foundItem1 | 395 | InventoryItemBase foundItem1 |
355 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userUuid, item1Name); | 396 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_ua1.PrincipalID, m_item1Name); |
356 | 397 | ||
357 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | 398 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); |
358 | 399 | ||
@@ -362,31 +403,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
362 | // foundItem1.CreatorId, Is.EqualTo(item1.CreatorId), | 403 | // foundItem1.CreatorId, Is.EqualTo(item1.CreatorId), |
363 | // "Loaded item non-uuid creator doesn't match original"); | 404 | // "Loaded item non-uuid creator doesn't match original"); |
364 | Assert.That( | 405 | Assert.That( |
365 | foundItem1.CreatorId, Is.EqualTo(userItemCreatorUuid.ToString()), | 406 | foundItem1.CreatorId, Is.EqualTo(m_ua2.PrincipalID.ToString()), |
366 | "Loaded item non-uuid creator doesn't match original"); | 407 | "Loaded item non-uuid creator doesn't match original"); |
367 | 408 | ||
368 | Assert.That( | 409 | Assert.That( |
369 | foundItem1.CreatorIdAsUuid, Is.EqualTo(userItemCreatorUuid), | 410 | foundItem1.CreatorIdAsUuid, Is.EqualTo(m_ua2.PrincipalID), |
370 | "Loaded item uuid creator doesn't match original"); | 411 | "Loaded item uuid creator doesn't match original"); |
371 | Assert.That(foundItem1.Owner, Is.EqualTo(userUuid), | 412 | Assert.That(foundItem1.Owner, Is.EqualTo(m_ua1.PrincipalID), |
372 | "Loaded item owner doesn't match inventory reciever"); | 413 | "Loaded item owner doesn't match inventory reciever"); |
373 | 414 | ||
374 | // Now try loading to a root child folder | 415 | // Now try loading to a root child folder |
375 | UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, userUuid, "xA"); | 416 | UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, m_ua1.PrincipalID, "xA"); |
376 | archiveReadStream = new MemoryStream(archiveReadStream.ToArray()); | 417 | MemoryStream archiveReadStream = new MemoryStream(m_iarStream.ToArray()); |
377 | archiverModule.DearchiveInventory(userFirstName, userLastName, "xA", "meowfood", archiveReadStream); | 418 | archiverModule.DearchiveInventory(m_ua1.FirstName, m_ua1.LastName, "xA", "meowfood", archiveReadStream); |
378 | 419 | ||
379 | InventoryItemBase foundItem2 | 420 | InventoryItemBase foundItem2 |
380 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userUuid, "xA/" + item1Name); | 421 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_ua1.PrincipalID, "xA/" + m_item1Name); |
381 | Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2"); | 422 | Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2"); |
382 | 423 | ||
383 | // Now try loading to a more deeply nested folder | 424 | // Now try loading to a more deeply nested folder |
384 | UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, userUuid, "xB/xC"); | 425 | UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, m_ua1.PrincipalID, "xB/xC"); |
385 | archiveReadStream = new MemoryStream(archiveReadStream.ToArray()); | 426 | archiveReadStream = new MemoryStream(archiveReadStream.ToArray()); |
386 | archiverModule.DearchiveInventory(userFirstName, userLastName, "xB/xC", "meowfood", archiveReadStream); | 427 | archiverModule.DearchiveInventory(m_ua1.FirstName, m_ua1.LastName, "xB/xC", "meowfood", archiveReadStream); |
387 | 428 | ||
388 | InventoryItemBase foundItem3 | 429 | InventoryItemBase foundItem3 |
389 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userUuid, "xB/xC/" + item1Name); | 430 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_ua1.PrincipalID, "xB/xC/" + m_item1Name); |
390 | Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3"); | 431 | Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3"); |
391 | } | 432 | } |
392 | 433 | ||