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