diff options
Diffstat (limited to 'OpenSim')
3 files changed, 562 insertions, 531 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveTestCase.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveTestCase.cs new file mode 100644 index 0000000..023c452 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveTestCase.cs | |||
@@ -0,0 +1,124 @@ | |||
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.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using NUnit.Framework; | ||
34 | using NUnit.Framework.SyntaxHelpers; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Data; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Serialization; | ||
39 | using OpenSim.Framework.Serialization.External; | ||
40 | using OpenSim.Framework.Communications; | ||
41 | using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; | ||
42 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
43 | using OpenSim.Region.Framework.Scenes; | ||
44 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
45 | using OpenSim.Services.Interfaces; | ||
46 | using OpenSim.Tests.Common; | ||
47 | using OpenSim.Tests.Common.Mock; | ||
48 | using OpenSim.Tests.Common.Setup; | ||
49 | |||
50 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | ||
51 | { | ||
52 | [TestFixture] | ||
53 | public class InventoryArchiveTestCase | ||
54 | { | ||
55 | protected ManualResetEvent mre = new ManualResetEvent(false); | ||
56 | |||
57 | /// <summary> | ||
58 | /// A raw array of bytes that we'll use to create an IAR memory stream suitable for isolated use in each test. | ||
59 | /// </summary> | ||
60 | protected byte[] m_iarStreamBytes; | ||
61 | |||
62 | /// <summary> | ||
63 | /// Stream of data representing a common IAR for load tests. | ||
64 | /// </summary> | ||
65 | protected MemoryStream m_iarStream; | ||
66 | |||
67 | protected UserAccount m_ua1 | ||
68 | = new UserAccount { | ||
69 | PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000555"), | ||
70 | FirstName = "Mr", | ||
71 | LastName = "Tiddles" }; | ||
72 | protected UserAccount m_ua2 | ||
73 | = new UserAccount { | ||
74 | PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000666"), | ||
75 | FirstName = "Lord", | ||
76 | LastName = "Lucan" }; | ||
77 | protected string m_item1Name = "b.lsl"; | ||
78 | |||
79 | [SetUp] | ||
80 | public void SetUp() | ||
81 | { | ||
82 | m_iarStream = new MemoryStream(m_iarStreamBytes); | ||
83 | } | ||
84 | |||
85 | [TestFixtureSetUp] | ||
86 | public void FixtureSetup() | ||
87 | { | ||
88 | ConstructDefaultIarBytesForTestLoad(); | ||
89 | } | ||
90 | |||
91 | protected void ConstructDefaultIarBytesForTestLoad() | ||
92 | { | ||
93 | // log4net.Config.XmlConfigurator.Configure(); | ||
94 | |||
95 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
96 | UserProfileTestUtils.CreateUserWithInventory(scene, m_ua2, "hampshire"); | ||
97 | |||
98 | string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(m_item1Name, UUID.Random()); | ||
99 | |||
100 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
101 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | ||
102 | |||
103 | InventoryItemBase item1 = new InventoryItemBase(); | ||
104 | item1.Name = m_item1Name; | ||
105 | item1.AssetID = UUID.Random(); | ||
106 | item1.GroupID = UUID.Random(); | ||
107 | item1.CreatorIdAsUuid = m_ua2.PrincipalID; | ||
108 | item1.Owner = UUID.Zero; | ||
109 | |||
110 | string item1FileName | ||
111 | = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); | ||
112 | tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1, new Dictionary<string, object>(), scene.UserAccountService)); | ||
113 | tar.Close(); | ||
114 | m_iarStreamBytes = archiveWriteStream.ToArray(); | ||
115 | } | ||
116 | |||
117 | protected void SaveCompleted( | ||
118 | Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, | ||
119 | Exception reportedException) | ||
120 | { | ||
121 | mre.Set(); | ||
122 | } | ||
123 | } | ||
124 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index de95505..edbbd81 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs | |||
@@ -50,195 +50,8 @@ using OpenSim.Tests.Common.Setup; | |||
50 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | 50 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests |
51 | { | 51 | { |
52 | [TestFixture] | 52 | [TestFixture] |
53 | public class InventoryArchiverTests | 53 | public class InventoryArchiverTests : InventoryArchiveTestCase |
54 | { | 54 | { |
55 | protected ManualResetEvent mre = new ManualResetEvent(false); | ||
56 | |||
57 | /// <summary> | ||
58 | /// A raw array of bytes that we'll use to create an IAR memory stream suitable for isolated use in each test. | ||
59 | /// </summary> | ||
60 | protected byte[] m_iarStreamBytes; | ||
61 | |||
62 | /// <summary> | ||
63 | /// Stream of data representing a common IAR for load tests. | ||
64 | /// </summary> | ||
65 | protected MemoryStream m_iarStream; | ||
66 | |||
67 | protected UserAccount m_ua1 | ||
68 | = new UserAccount { | ||
69 | PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000555"), | ||
70 | FirstName = "Mr", | ||
71 | LastName = "Tiddles" }; | ||
72 | protected UserAccount m_ua2 | ||
73 | = new UserAccount { | ||
74 | PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000666"), | ||
75 | FirstName = "Lord", | ||
76 | LastName = "Lucan" }; | ||
77 | string m_item1Name = "b.lsl"; | ||
78 | |||
79 | private void SaveCompleted( | ||
80 | Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, | ||
81 | Exception reportedException) | ||
82 | { | ||
83 | mre.Set(); | ||
84 | } | ||
85 | |||
86 | [SetUp] | ||
87 | public void SetUp() | ||
88 | { | ||
89 | m_iarStream = new MemoryStream(m_iarStreamBytes); | ||
90 | } | ||
91 | |||
92 | [TestFixtureSetUp] | ||
93 | public void FixtureSetup() | ||
94 | { | ||
95 | ConstructDefaultIarBytesForTestLoad(); | ||
96 | } | ||
97 | |||
98 | protected void ConstructDefaultIarBytesForTestLoad() | ||
99 | { | ||
100 | // log4net.Config.XmlConfigurator.Configure(); | ||
101 | |||
102 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
103 | UserProfileTestUtils.CreateUserWithInventory(scene, m_ua2, "hampshire"); | ||
104 | |||
105 | string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(m_item1Name, UUID.Random()); | ||
106 | |||
107 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
108 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | ||
109 | |||
110 | InventoryItemBase item1 = new InventoryItemBase(); | ||
111 | item1.Name = m_item1Name; | ||
112 | item1.AssetID = UUID.Random(); | ||
113 | item1.GroupID = UUID.Random(); | ||
114 | item1.CreatorIdAsUuid = m_ua2.PrincipalID; | ||
115 | item1.Owner = UUID.Zero; | ||
116 | |||
117 | string item1FileName | ||
118 | = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); | ||
119 | tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1, new Dictionary<string, object>(), scene.UserAccountService)); | ||
120 | tar.Close(); | ||
121 | m_iarStreamBytes = archiveWriteStream.ToArray(); | ||
122 | } | ||
123 | |||
124 | /// <summary> | ||
125 | /// Test saving an inventory path to a V0.1 OpenSim Inventory Archive | ||
126 | /// (subject to change since there is no fixed format yet). | ||
127 | /// </summary> | ||
128 | [Test] | ||
129 | public void TestSavePathToIarV0_1() | ||
130 | { | ||
131 | TestHelper.InMethod(); | ||
132 | // log4net.Config.XmlConfigurator.Configure(); | ||
133 | |||
134 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
135 | |||
136 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
137 | SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | ||
138 | |||
139 | // Create user | ||
140 | string userFirstName = "Jock"; | ||
141 | string userLastName = "Stirrup"; | ||
142 | string userPassword = "troll"; | ||
143 | UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); | ||
144 | UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, userPassword); | ||
145 | |||
146 | // Create asset | ||
147 | SceneObjectGroup object1; | ||
148 | SceneObjectPart part1; | ||
149 | { | ||
150 | string partName = "My Little Dog Object"; | ||
151 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
152 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
153 | Vector3 groupPosition = new Vector3(10, 20, 30); | ||
154 | Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | ||
155 | Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
156 | |||
157 | part1 | ||
158 | = new SceneObjectPart( | ||
159 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
160 | part1.Name = partName; | ||
161 | |||
162 | object1 = new SceneObjectGroup(part1); | ||
163 | scene.AddNewSceneObject(object1, false); | ||
164 | } | ||
165 | |||
166 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | ||
167 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | ||
168 | scene.AssetService.Store(asset1); | ||
169 | |||
170 | // Create item | ||
171 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | ||
172 | InventoryItemBase item1 = new InventoryItemBase(); | ||
173 | item1.Name = "My Little Dog"; | ||
174 | item1.AssetID = asset1.FullID; | ||
175 | item1.ID = item1Id; | ||
176 | InventoryFolderBase objsFolder | ||
177 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0]; | ||
178 | item1.Folder = objsFolder.ID; | ||
179 | scene.AddInventoryItem(item1); | ||
180 | |||
181 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
182 | archiverModule.OnInventoryArchiveSaved += SaveCompleted; | ||
183 | |||
184 | // Test saving a particular path | ||
185 | mre.Reset(); | ||
186 | archiverModule.ArchiveInventory( | ||
187 | Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); | ||
188 | mre.WaitOne(60000, false); | ||
189 | |||
190 | byte[] archive = archiveWriteStream.ToArray(); | ||
191 | MemoryStream archiveReadStream = new MemoryStream(archive); | ||
192 | TarArchiveReader tar = new TarArchiveReader(archiveReadStream); | ||
193 | |||
194 | //bool gotControlFile = false; | ||
195 | bool gotObject1File = false; | ||
196 | //bool gotObject2File = false; | ||
197 | string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1); | ||
198 | string expectedObject1FilePath = string.Format( | ||
199 | "{0}{1}{2}", | ||
200 | ArchiveConstants.INVENTORY_PATH, | ||
201 | InventoryArchiveWriteRequest.CreateArchiveFolderName(objsFolder), | ||
202 | expectedObject1FileName); | ||
203 | |||
204 | string filePath; | ||
205 | TarArchiveReader.TarEntryType tarEntryType; | ||
206 | |||
207 | // Console.WriteLine("Reading archive"); | ||
208 | |||
209 | while (tar.ReadEntry(out filePath, out tarEntryType) != null) | ||
210 | { | ||
211 | // Console.WriteLine("Got {0}", filePath); | ||
212 | |||
213 | // if (ArchiveConstants.CONTROL_FILE_PATH == filePath) | ||
214 | // { | ||
215 | // gotControlFile = true; | ||
216 | // } | ||
217 | |||
218 | if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml")) | ||
219 | { | ||
220 | // string fileName = filePath.Remove(0, "Objects/".Length); | ||
221 | // | ||
222 | // if (fileName.StartsWith(part1.Name)) | ||
223 | // { | ||
224 | Assert.That(expectedObject1FilePath, Is.EqualTo(filePath)); | ||
225 | gotObject1File = true; | ||
226 | // } | ||
227 | // else if (fileName.StartsWith(part2.Name)) | ||
228 | // { | ||
229 | // Assert.That(fileName, Is.EqualTo(expectedObject2FileName)); | ||
230 | // gotObject2File = true; | ||
231 | // } | ||
232 | } | ||
233 | } | ||
234 | |||
235 | // Assert.That(gotControlFile, Is.True, "No control file in archive"); | ||
236 | Assert.That(gotObject1File, Is.True, "No item1 file in archive"); | ||
237 | // Assert.That(gotObject2File, Is.True, "No object2 file in archive"); | ||
238 | |||
239 | // TODO: Test presence of more files and contents of files. | ||
240 | } | ||
241 | |||
242 | /// <summary> | 55 | /// <summary> |
243 | /// Test saving a single inventory item to a V0.1 OpenSim Inventory Archive | 56 | /// Test saving a single inventory item to a V0.1 OpenSim Inventory Archive |
244 | /// (subject to change since there is no fixed format yet). | 57 | /// (subject to change since there is no fixed format yet). |
@@ -357,30 +170,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
357 | } | 170 | } |
358 | 171 | ||
359 | /// <summary> | 172 | /// <summary> |
360 | /// Test that things work when the load path specified starts with a slash | ||
361 | /// </summary> | ||
362 | [Test] | ||
363 | public void TestLoadIarPathStartsWithSlash() | ||
364 | { | ||
365 | TestHelper.InMethod(); | ||
366 | // log4net.Config.XmlConfigurator.Configure(); | ||
367 | |||
368 | SerialiserModule serialiserModule = new SerialiserModule(); | ||
369 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
370 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
371 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | ||
372 | |||
373 | UserProfileTestUtils.CreateUserWithInventory(scene, m_ua1, "password"); | ||
374 | archiverModule.DearchiveInventory(m_ua1.FirstName, m_ua1.LastName, "/Objects", "password", m_iarStream); | ||
375 | |||
376 | InventoryItemBase foundItem1 | ||
377 | = InventoryArchiveUtils.FindItemByPath( | ||
378 | scene.InventoryService, m_ua1.PrincipalID, "/Objects/" + m_item1Name); | ||
379 | |||
380 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1 in TestLoadIarFolderStartsWithSlash()"); | ||
381 | } | ||
382 | |||
383 | /// <summary> | ||
384 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | 173 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where |
385 | /// an account exists with the creator name. | 174 | /// an account exists with the creator name. |
386 | /// </summary> | 175 | /// </summary> |
@@ -443,88 +232,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
443 | Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3"); | 232 | Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3"); |
444 | } | 233 | } |
445 | 234 | ||
446 | [Test] | ||
447 | public void TestIarV0_1WithEscapedChars() | ||
448 | { | ||
449 | TestHelper.InMethod(); | ||
450 | // log4net.Config.XmlConfigurator.Configure(); | ||
451 | |||
452 | string itemName = "You & you are a mean/man/"; | ||
453 | string humanEscapedItemName = @"You & you are a mean\/man\/"; | ||
454 | string userPassword = "meowfood"; | ||
455 | |||
456 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
457 | |||
458 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
459 | SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | ||
460 | |||
461 | // Create user | ||
462 | string userFirstName = "Jock"; | ||
463 | string userLastName = "Stirrup"; | ||
464 | UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); | ||
465 | UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "meowfood"); | ||
466 | |||
467 | // Create asset | ||
468 | SceneObjectGroup object1; | ||
469 | SceneObjectPart part1; | ||
470 | { | ||
471 | string partName = "part name"; | ||
472 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
473 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
474 | Vector3 groupPosition = new Vector3(10, 20, 30); | ||
475 | Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | ||
476 | Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
477 | |||
478 | part1 | ||
479 | = new SceneObjectPart( | ||
480 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
481 | part1.Name = partName; | ||
482 | |||
483 | object1 = new SceneObjectGroup(part1); | ||
484 | scene.AddNewSceneObject(object1, false); | ||
485 | } | ||
486 | |||
487 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | ||
488 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | ||
489 | scene.AssetService.Store(asset1); | ||
490 | |||
491 | // Create item | ||
492 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | ||
493 | InventoryItemBase item1 = new InventoryItemBase(); | ||
494 | item1.Name = itemName; | ||
495 | item1.AssetID = asset1.FullID; | ||
496 | item1.ID = item1Id; | ||
497 | InventoryFolderBase objsFolder | ||
498 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0]; | ||
499 | item1.Folder = objsFolder.ID; | ||
500 | scene.AddInventoryItem(item1); | ||
501 | |||
502 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
503 | archiverModule.OnInventoryArchiveSaved += SaveCompleted; | ||
504 | |||
505 | mre.Reset(); | ||
506 | archiverModule.ArchiveInventory( | ||
507 | Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); | ||
508 | mre.WaitOne(60000, false); | ||
509 | |||
510 | // LOAD ITEM | ||
511 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
512 | |||
513 | archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", userPassword, archiveReadStream); | ||
514 | |||
515 | InventoryItemBase foundItem1 | ||
516 | = InventoryArchiveUtils.FindItemByPath( | ||
517 | scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName); | ||
518 | |||
519 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | ||
520 | // Assert.That( | ||
521 | // foundItem1.CreatorId, Is.EqualTo(userUuid), | ||
522 | // "Loaded item non-uuid creator doesn't match that of the loading user"); | ||
523 | Assert.That( | ||
524 | foundItem1.Name, Is.EqualTo(itemName), | ||
525 | "Loaded item name doesn't match saved name"); | ||
526 | } | ||
527 | |||
528 | /// <summary> | 235 | /// <summary> |
529 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | 236 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where |
530 | /// embedded creators do not exist in the system | 237 | /// embedded creators do not exist in the system |
@@ -554,241 +261,5 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
554 | foundItem1.CreatorIdAsUuid, Is.EqualTo(m_ua1.PrincipalID), | 261 | foundItem1.CreatorIdAsUuid, Is.EqualTo(m_ua1.PrincipalID), |
555 | "Loaded item uuid creator doesn't match that of the loading user"); | 262 | "Loaded item uuid creator doesn't match that of the loading user"); |
556 | } | 263 | } |
557 | |||
558 | /// <summary> | ||
559 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | ||
560 | /// no account exists with the creator name | ||
561 | /// </summary> | ||
562 | /// Disabled since temporary profiles have not yet been implemented. | ||
563 | /// | ||
564 | //[Test] | ||
565 | //public void TestLoadIarV0_1TempProfiles() | ||
566 | //{ | ||
567 | // TestHelper.InMethod(); | ||
568 | |||
569 | // //log4net.Config.XmlConfigurator.Configure(); | ||
570 | |||
571 | // string userFirstName = "Dennis"; | ||
572 | // string userLastName = "Menace"; | ||
573 | // UUID userUuid = UUID.Parse("00000000-0000-0000-0000-000000000aaa"); | ||
574 | // string user2FirstName = "Walter"; | ||
575 | // string user2LastName = "Mitty"; | ||
576 | |||
577 | // string itemName = "b.lsl"; | ||
578 | // string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random()); | ||
579 | |||
580 | // MemoryStream archiveWriteStream = new MemoryStream(); | ||
581 | // TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | ||
582 | |||
583 | // InventoryItemBase item1 = new InventoryItemBase(); | ||
584 | // item1.Name = itemName; | ||
585 | // item1.AssetID = UUID.Random(); | ||
586 | // item1.GroupID = UUID.Random(); | ||
587 | // item1.CreatorId = OspResolver.MakeOspa(user2FirstName, user2LastName); | ||
588 | // item1.Owner = UUID.Zero; | ||
589 | |||
590 | // string item1FileName | ||
591 | // = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); | ||
592 | // tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); | ||
593 | // tar.Close(); | ||
594 | |||
595 | // MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
596 | // SerialiserModule serialiserModule = new SerialiserModule(); | ||
597 | // InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
598 | |||
599 | // // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene | ||
600 | // Scene scene = SceneSetupHelpers.SetupScene(); | ||
601 | // IUserAdminService userAdminService = scene.CommsManager.UserAdminService; | ||
602 | |||
603 | // SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | ||
604 | // userAdminService.AddUser( | ||
605 | // userFirstName, userLastName, "meowfood", String.Empty, 1000, 1000, userUuid); | ||
606 | |||
607 | // archiverModule.DearchiveInventory(userFirstName, userLastName, "/", "troll", archiveReadStream); | ||
608 | |||
609 | // // Check that a suitable temporary user profile has been created. | ||
610 | // UserProfileData user2Profile | ||
611 | // = scene.CommsManager.UserService.GetUserProfile( | ||
612 | // OspResolver.HashName(user2FirstName + " " + user2LastName)); | ||
613 | // Assert.That(user2Profile, Is.Not.Null); | ||
614 | // Assert.That(user2Profile.FirstName == user2FirstName); | ||
615 | // Assert.That(user2Profile.SurName == user2LastName); | ||
616 | |||
617 | // CachedUserInfo userInfo | ||
618 | // = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); | ||
619 | // userInfo.OnInventoryReceived += InventoryReceived; | ||
620 | |||
621 | // lock (this) | ||
622 | // { | ||
623 | // userInfo.FetchInventory(); | ||
624 | // Monitor.Wait(this, 60000); | ||
625 | // } | ||
626 | |||
627 | // InventoryItemBase foundItem = userInfo.RootFolder.FindItemByPath(itemName); | ||
628 | |||
629 | // Assert.That(foundItem.CreatorId, Is.EqualTo(item1.CreatorId)); | ||
630 | // Assert.That( | ||
631 | // foundItem.CreatorIdAsUuid, Is.EqualTo(OspResolver.HashName(user2FirstName + " " + user2LastName))); | ||
632 | // Assert.That(foundItem.Owner, Is.EqualTo(userUuid)); | ||
633 | |||
634 | // Console.WriteLine("### Successfully completed {0} ###", MethodBase.GetCurrentMethod()); | ||
635 | //} | ||
636 | |||
637 | /// <summary> | ||
638 | /// Test replication of an archive path to the user's inventory. | ||
639 | /// </summary> | ||
640 | [Test] | ||
641 | public void TestNewIarPath() | ||
642 | { | ||
643 | TestHelper.InMethod(); | ||
644 | // log4net.Config.XmlConfigurator.Configure(); | ||
645 | |||
646 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
647 | UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene); | ||
648 | |||
649 | Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>(); | ||
650 | HashSet<InventoryNodeBase> nodesLoaded = new HashSet<InventoryNodeBase>(); | ||
651 | |||
652 | string folder1Name = "1"; | ||
653 | string folder2aName = "2a"; | ||
654 | string folder2bName = "2b"; | ||
655 | |||
656 | string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1Name, UUID.Random()); | ||
657 | string folder2aArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2aName, UUID.Random()); | ||
658 | string folder2bArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2bName, UUID.Random()); | ||
659 | |||
660 | string iarPath1 = string.Join("", new string[] { folder1ArchiveName, folder2aArchiveName }); | ||
661 | string iarPath2 = string.Join("", new string[] { folder1ArchiveName, folder2bArchiveName }); | ||
662 | |||
663 | { | ||
664 | // Test replication of path1 | ||
665 | new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false) | ||
666 | .ReplicateArchivePathToUserInventory( | ||
667 | iarPath1, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
668 | foldersCreated, nodesLoaded); | ||
669 | |||
670 | List<InventoryFolderBase> folder1Candidates | ||
671 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1Name); | ||
672 | Assert.That(folder1Candidates.Count, Is.EqualTo(1)); | ||
673 | |||
674 | InventoryFolderBase folder1 = folder1Candidates[0]; | ||
675 | List<InventoryFolderBase> folder2aCandidates | ||
676 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2aName); | ||
677 | Assert.That(folder2aCandidates.Count, Is.EqualTo(1)); | ||
678 | } | ||
679 | |||
680 | { | ||
681 | // Test replication of path2 | ||
682 | new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false) | ||
683 | .ReplicateArchivePathToUserInventory( | ||
684 | iarPath2, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
685 | foldersCreated, nodesLoaded); | ||
686 | |||
687 | List<InventoryFolderBase> folder1Candidates | ||
688 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1Name); | ||
689 | Assert.That(folder1Candidates.Count, Is.EqualTo(1)); | ||
690 | |||
691 | InventoryFolderBase folder1 = folder1Candidates[0]; | ||
692 | |||
693 | List<InventoryFolderBase> folder2aCandidates | ||
694 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2aName); | ||
695 | Assert.That(folder2aCandidates.Count, Is.EqualTo(1)); | ||
696 | |||
697 | List<InventoryFolderBase> folder2bCandidates | ||
698 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2bName); | ||
699 | Assert.That(folder2bCandidates.Count, Is.EqualTo(1)); | ||
700 | } | ||
701 | } | ||
702 | |||
703 | /// <summary> | ||
704 | /// Test replication of a partly existing archive path to the user's inventory. This should create | ||
705 | /// a duplicate path without the merge option. | ||
706 | /// </summary> | ||
707 | [Test] | ||
708 | public void TestPartExistingIarPath() | ||
709 | { | ||
710 | TestHelper.InMethod(); | ||
711 | //log4net.Config.XmlConfigurator.Configure(); | ||
712 | |||
713 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
714 | UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene); | ||
715 | |||
716 | string folder1ExistingName = "a"; | ||
717 | string folder2Name = "b"; | ||
718 | |||
719 | InventoryFolderBase folder1 | ||
720 | = UserInventoryTestUtils.CreateInventoryFolder( | ||
721 | scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
722 | |||
723 | string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random()); | ||
724 | string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random()); | ||
725 | |||
726 | string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName }); | ||
727 | |||
728 | new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false) | ||
729 | .ReplicateArchivePathToUserInventory( | ||
730 | itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
731 | new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>()); | ||
732 | |||
733 | List<InventoryFolderBase> folder1PostCandidates | ||
734 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
735 | Assert.That(folder1PostCandidates.Count, Is.EqualTo(2)); | ||
736 | |||
737 | // FIXME: Temporarily, we're going to do something messy to make sure we pick up the created folder. | ||
738 | InventoryFolderBase folder1Post = null; | ||
739 | foreach (InventoryFolderBase folder in folder1PostCandidates) | ||
740 | { | ||
741 | if (folder.ID != folder1.ID) | ||
742 | { | ||
743 | folder1Post = folder; | ||
744 | break; | ||
745 | } | ||
746 | } | ||
747 | // Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID)); | ||
748 | |||
749 | List<InventoryFolderBase> folder2PostCandidates | ||
750 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1Post, "b"); | ||
751 | Assert.That(folder2PostCandidates.Count, Is.EqualTo(1)); | ||
752 | } | ||
753 | |||
754 | /// <summary> | ||
755 | /// Test replication of a partly existing archive path to the user's inventory. This should create | ||
756 | /// a merged path. | ||
757 | /// </summary> | ||
758 | [Test] | ||
759 | public void TestMergeIarPath() | ||
760 | { | ||
761 | TestHelper.InMethod(); | ||
762 | // log4net.Config.XmlConfigurator.Configure(); | ||
763 | |||
764 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
765 | UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene); | ||
766 | |||
767 | string folder1ExistingName = "a"; | ||
768 | string folder2Name = "b"; | ||
769 | |||
770 | InventoryFolderBase folder1 | ||
771 | = UserInventoryTestUtils.CreateInventoryFolder( | ||
772 | scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
773 | |||
774 | string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random()); | ||
775 | string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random()); | ||
776 | |||
777 | string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName }); | ||
778 | |||
779 | new InventoryArchiveReadRequest(scene, ua1, folder1ExistingName, (Stream)null, true) | ||
780 | .ReplicateArchivePathToUserInventory( | ||
781 | itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
782 | new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>()); | ||
783 | |||
784 | List<InventoryFolderBase> folder1PostCandidates | ||
785 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
786 | Assert.That(folder1PostCandidates.Count, Is.EqualTo(1)); | ||
787 | Assert.That(folder1PostCandidates[0].ID, Is.EqualTo(folder1.ID)); | ||
788 | |||
789 | List<InventoryFolderBase> folder2PostCandidates | ||
790 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1PostCandidates[0], "b"); | ||
791 | Assert.That(folder2PostCandidates.Count, Is.EqualTo(1)); | ||
792 | } | ||
793 | } | 264 | } |
794 | } \ No newline at end of file | 265 | } \ No newline at end of file |
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using NUnit.Framework; | ||
34 | using NUnit.Framework.SyntaxHelpers; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Data; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Serialization; | ||
39 | using OpenSim.Framework.Serialization.External; | ||
40 | using OpenSim.Framework.Communications; | ||
41 | using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; | ||
42 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
43 | using OpenSim.Region.Framework.Scenes; | ||
44 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
45 | using OpenSim.Services.Interfaces; | ||
46 | using OpenSim.Tests.Common; | ||
47 | using OpenSim.Tests.Common.Mock; | ||
48 | using OpenSim.Tests.Common.Setup; | ||
49 | |||
50 | namespace 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 | ||