OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
InventoryArchiveLoadPathTests.cs
Go to the documentation of this file.
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.Region.CoreModules.Avatar.Inventory.Archiver;
40 using OpenSim.Region.CoreModules.World.Serialiser;
41 using OpenSim.Region.Framework.Scenes;
42 using OpenSim.Region.Framework.Scenes.Serialization;
43 using OpenSim.Services.Interfaces;
44 using OpenSim.Tests.Common;
45 
46 namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
47 {
48  [TestFixture]
50  {
54  [Test]
56  {
57  TestHelpers.InMethod();
58 // log4net.Config.XmlConfigurator.Configure();
59 
60  SerialiserModule serialiserModule = new SerialiserModule();
61  InventoryArchiverModule archiverModule = new InventoryArchiverModule();
62 
63  // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene
64  Scene scene = new SceneHelpers().SetupScene();
65 
66  SceneHelpers.SetupSceneModules(scene, serialiserModule, archiverModule);
67 
68  UserAccountHelpers.CreateUserWithInventory(scene, m_uaMT, "meowfood");
69  UserAccountHelpers.CreateUserWithInventory(scene, m_uaLL1, "hampshire");
70 
71  archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "/", "meowfood", m_iarStream);
72  InventoryItemBase foundItem1
73  = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, m_item1Name);
74 
75  Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
76 
77  // Now try loading to a root child folder
78  UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, m_uaMT.PrincipalID, "xA", false);
79  MemoryStream archiveReadStream = new MemoryStream(m_iarStream.ToArray());
80  archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "xA", "meowfood", archiveReadStream);
81 
82  InventoryItemBase foundItem2
83  = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, "xA/" + m_item1Name);
84  Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2");
85 
86  // Now try loading to a more deeply nested folder
87  UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, m_uaMT.PrincipalID, "xB/xC", false);
88  archiveReadStream = new MemoryStream(archiveReadStream.ToArray());
89  archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "xB/xC", "meowfood", archiveReadStream);
90 
91  InventoryItemBase foundItem3
92  = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, "xB/xC/" + m_item1Name);
93  Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3");
94  }
95 
99  [Test]
101  {
102  TestHelpers.InMethod();
103 // log4net.Config.XmlConfigurator.Configure();
104 
105  SerialiserModule serialiserModule = new SerialiserModule();
106  InventoryArchiverModule archiverModule = new InventoryArchiverModule();
107  Scene scene = new SceneHelpers().SetupScene();
108  SceneHelpers.SetupSceneModules(scene, serialiserModule, archiverModule);
109 
110  UserAccountHelpers.CreateUserWithInventory(scene, m_uaMT, "password");
111  archiverModule.DearchiveInventory(UUID.Random(), m_uaMT.FirstName, m_uaMT.LastName, "/Objects", "password", m_iarStream);
112 
113  InventoryItemBase foundItem1
114  = InventoryArchiveUtils.FindItemByPath(
115  scene.InventoryService, m_uaMT.PrincipalID, "/Objects/" + m_item1Name);
116 
117  Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1 in TestLoadIarFolderStartsWithSlash()");
118  }
119 
120  [Test]
122  {
123  TestHelpers.InMethod();
124 // log4net.Config.XmlConfigurator.Configure();
125 
126  string itemName = "You & you are a mean/man/";
127  string humanEscapedItemName = @"You & you are a mean\/man\/";
128  string userPassword = "meowfood";
129 
130  InventoryArchiverModule archiverModule = new InventoryArchiverModule();
131 
132  Scene scene = new SceneHelpers().SetupScene();
133  SceneHelpers.SetupSceneModules(scene, archiverModule);
134 
135  // Create user
136  string userFirstName = "Jock";
137  string userLastName = "Stirrup";
138  UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
139  UserAccountHelpers.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "meowfood");
140 
141  // Create asset
142  SceneObjectGroup object1;
143  SceneObjectPart part1;
144  {
145  string partName = "part name";
146  UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
147  PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
148  Vector3 groupPosition = new Vector3(10, 20, 30);
149  Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
150  Vector3 offsetPosition = new Vector3(5, 10, 15);
151 
152  part1
153  = new SceneObjectPart(
154  ownerId, shape, groupPosition, rotationOffset, offsetPosition);
155  part1.Name = partName;
156 
157  object1 = new SceneObjectGroup(part1);
158  scene.AddNewSceneObject(object1, false);
159  }
160 
161  UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
162  AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
163  scene.AssetService.Store(asset1);
164 
165  // Create item
166  UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
167  InventoryItemBase item1 = new InventoryItemBase();
168  item1.Name = itemName;
169  item1.AssetID = asset1.FullID;
170  item1.ID = item1Id;
171  InventoryFolderBase objsFolder
172  = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, userId, "Objects")[0];
173  item1.Folder = objsFolder.ID;
174  scene.AddInventoryItem(item1);
175 
176  MemoryStream archiveWriteStream = new MemoryStream();
177  archiverModule.OnInventoryArchiveSaved += SaveCompleted;
178 
179  mre.Reset();
180  archiverModule.ArchiveInventory(
181  UUID.Random(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream);
182  mre.WaitOne(60000, false);
183 
184  // LOAD ITEM
185  MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
186 
187  archiverModule.DearchiveInventory(UUID.Random(), userFirstName, userLastName, "Scripts", userPassword, archiveReadStream);
188 
189  InventoryItemBase foundItem1
190  = InventoryArchiveUtils.FindItemByPath(
191  scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName);
192 
193  Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
194 // Assert.That(
195 // foundItem1.CreatorId, Is.EqualTo(userUuid),
196 // "Loaded item non-uuid creator doesn't match that of the loading user");
197  Assert.That(
198  foundItem1.Name, Is.EqualTo(itemName),
199  "Loaded item name doesn't match saved name");
200  }
201 
205  [Test]
206  public void TestNewIarPath()
207  {
208  TestHelpers.InMethod();
209 // log4net.Config.XmlConfigurator.Configure();
210 
211  Scene scene = new SceneHelpers().SetupScene();
212  UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
213 
214  Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>();
215  HashSet<InventoryNodeBase> nodesLoaded = new HashSet<InventoryNodeBase>();
216 
217  string folder1Name = "1";
218  string folder2aName = "2a";
219  string folder2bName = "2b";
220 
221  string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1Name, UUID.Random());
222  string folder2aArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2aName, UUID.Random());
223  string folder2bArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2bName, UUID.Random());
224 
225  string iarPath1 = string.Join("", new string[] { folder1ArchiveName, folder2aArchiveName });
226  string iarPath2 = string.Join("", new string[] { folder1ArchiveName, folder2bArchiveName });
227 
228  {
229  // Test replication of path1
230  new InventoryArchiveReadRequest(UUID.Random(), null, scene.InventoryService, scene.AssetService, scene.UserAccountService, ua1, null, (Stream)null, false)
231  .ReplicateArchivePathToUserInventory(
232  iarPath1, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
233  foldersCreated, nodesLoaded);
234 
235  List<InventoryFolderBase> folder1Candidates
236  = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1Name);
237  Assert.That(folder1Candidates.Count, Is.EqualTo(1));
238 
239  InventoryFolderBase folder1 = folder1Candidates[0];
240  List<InventoryFolderBase> folder2aCandidates
241  = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1, folder2aName);
242  Assert.That(folder2aCandidates.Count, Is.EqualTo(1));
243  }
244 
245  {
246  // Test replication of path2
247  new InventoryArchiveReadRequest(UUID.Random(), null, scene.InventoryService, scene.AssetService, scene.UserAccountService, ua1, null, (Stream)null, false)
248  .ReplicateArchivePathToUserInventory(
249  iarPath2, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
250  foldersCreated, nodesLoaded);
251 
252  List<InventoryFolderBase> folder1Candidates
253  = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1Name);
254  Assert.That(folder1Candidates.Count, Is.EqualTo(1));
255 
256  InventoryFolderBase folder1 = folder1Candidates[0];
257 
258  List<InventoryFolderBase> folder2aCandidates
259  = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1, folder2aName);
260  Assert.That(folder2aCandidates.Count, Is.EqualTo(1));
261 
262  List<InventoryFolderBase> folder2bCandidates
263  = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1, folder2bName);
264  Assert.That(folder2bCandidates.Count, Is.EqualTo(1));
265  }
266  }
267 
272  [Test]
274  {
275  TestHelpers.InMethod();
276  //log4net.Config.XmlConfigurator.Configure();
277 
278  Scene scene = new SceneHelpers().SetupScene();
279  UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
280 
281  string folder1ExistingName = "a";
282  string folder2Name = "b";
283 
284  InventoryFolderBase folder1
285  = UserInventoryHelpers.CreateInventoryFolder(
286  scene.InventoryService, ua1.PrincipalID, folder1ExistingName, false);
287 
288  string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
289  string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());
290 
291  string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });
292 
293  new InventoryArchiveReadRequest(UUID.Random(), null, scene.InventoryService, scene.AssetService, scene.UserAccountService, ua1, null, (Stream)null, false)
294  .ReplicateArchivePathToUserInventory(
295  itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
296  new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>());
297 
298  List<InventoryFolderBase> folder1PostCandidates
299  = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
300  Assert.That(folder1PostCandidates.Count, Is.EqualTo(2));
301 
302  // FIXME: Temporarily, we're going to do something messy to make sure we pick up the created folder.
303  InventoryFolderBase folder1Post = null;
304  foreach (InventoryFolderBase folder in folder1PostCandidates)
305  {
306  if (folder.ID != folder1.ID)
307  {
308  folder1Post = folder;
309  break;
310  }
311  }
312 // Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID));
313 
314  List<InventoryFolderBase> folder2PostCandidates
315  = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1Post, "b");
316  Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
317  }
318 
323  [Test]
324  public void TestMergeIarPath()
325  {
326  TestHelpers.InMethod();
327 // log4net.Config.XmlConfigurator.Configure();
328 
329  Scene scene = new SceneHelpers().SetupScene();
330  UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene);
331 
332  string folder1ExistingName = "a";
333  string folder2Name = "b";
334 
335  InventoryFolderBase folder1
336  = UserInventoryHelpers.CreateInventoryFolder(
337  scene.InventoryService, ua1.PrincipalID, folder1ExistingName, false);
338 
339  string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
340  string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());
341 
342  string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });
343 
344  new InventoryArchiveReadRequest(UUID.Random(), null, scene.InventoryService, scene.AssetService, scene.UserAccountService, ua1, folder1ExistingName, (Stream)null, true)
345  .ReplicateArchivePathToUserInventory(
346  itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
347  new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>());
348 
349  List<InventoryFolderBase> folder1PostCandidates
350  = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
351  Assert.That(folder1PostCandidates.Count, Is.EqualTo(1));
352  Assert.That(folder1PostCandidates[0].ID, Is.EqualTo(folder1.ID));
353 
354  List<InventoryFolderBase> folder2PostCandidates
355  = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, folder1PostCandidates[0], "b");
356  Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
357  }
358  }
359 }
360 
void TestPartExistingIarPath()
Test replication of a partly existing archive path to the user's inventory. This should create a dupl...
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49
void TestNewIarPath()
Test replication of an archive path to the user's inventory.
This module loads and saves OpenSimulator inventory archives
Inventory Item - contains all the properties associated with an individual inventory piece...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
Interactive OpenSim region server
Definition: OpenSim.cs:55
UUID ID
A UUID containing the ID for the inventory node itself
void TestMergeIarPath()
Test replication of a partly existing archive path to the user's inventory. This should create a merg...
void TestLoadIarPathStartsWithSlash()
Test that things work when the load path specified starts with a slash
void TestLoadIarToInventoryPaths()
Test loading an IAR to various different inventory paths.