diff options
author | Sean McNamara | 2011-04-10 18:28:54 -0400 |
---|---|---|
committer | Sean McNamara | 2011-04-10 18:28:54 -0400 |
commit | 9c0f3c73b1fd56ac145e866af0316a3285ddb689 (patch) | |
tree | 03541a853c2ecf5829ac296537b14d4553ad4b2e /OpenSim/Region/CoreModules/Avatar | |
parent | Merge git://opensimulator.org/git/opensim (diff) | |
parent | minor: remove mono compiler warnings (diff) | |
download | opensim-SC_OLD-9c0f3c73b1fd56ac145e866af0316a3285ddb689.zip opensim-SC_OLD-9c0f3c73b1fd56ac145e866af0316a3285ddb689.tar.gz opensim-SC_OLD-9c0f3c73b1fd56ac145e866af0316a3285ddb689.tar.bz2 opensim-SC_OLD-9c0f3c73b1fd56ac145e866af0316a3285ddb689.tar.xz |
Merge git://opensimulator.org/git/opensim
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar')
6 files changed, 875 insertions, 673 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs b/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs index a5fcb49..0babeb5 100644 --- a/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using Nini.Config; | 30 | using Nini.Config; |
31 | using OpenSim.Framework; | ||
31 | using OpenSim.Region.Framework.Interfaces; | 32 | using OpenSim.Region.Framework.Interfaces; |
32 | using OpenSim.Region.Framework.Scenes; | 33 | using OpenSim.Region.Framework.Scenes; |
33 | using OpenMetaverse; | 34 | using OpenMetaverse; |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index 6030706..01170aa 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs | |||
@@ -41,6 +41,7 @@ using OpenSim.Framework.Serialization; | |||
41 | using OpenSim.Framework.Serialization.External; | 41 | using OpenSim.Framework.Serialization.External; |
42 | using OpenSim.Region.CoreModules.World.Archiver; | 42 | using OpenSim.Region.CoreModules.World.Archiver; |
43 | using OpenSim.Region.Framework.Scenes; | 43 | using OpenSim.Region.Framework.Scenes; |
44 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
44 | using OpenSim.Region.Framework.Interfaces; | 45 | using OpenSim.Region.Framework.Interfaces; |
45 | using OpenSim.Services.Interfaces; | 46 | using OpenSim.Services.Interfaces; |
46 | 47 | ||
@@ -75,6 +76,41 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
75 | /// The stream from which the inventory archive will be loaded. | 76 | /// The stream from which the inventory archive will be loaded. |
76 | /// </value> | 77 | /// </value> |
77 | private Stream m_loadStream; | 78 | private Stream m_loadStream; |
79 | |||
80 | /// <summary> | ||
81 | /// FIXME: Do not perform this check since older versions of OpenSim do save the control file after other things | ||
82 | /// (I thought they weren't). We will need to bump the version number and perform this check on all | ||
83 | /// subsequent IAR versions only | ||
84 | /// </summary> | ||
85 | protected bool m_controlFileLoaded = true; | ||
86 | protected bool m_assetsLoaded; | ||
87 | protected bool m_inventoryNodesLoaded; | ||
88 | |||
89 | protected int m_successfulAssetRestores; | ||
90 | protected int m_failedAssetRestores; | ||
91 | protected int m_successfulItemRestores; | ||
92 | |||
93 | /// <summary> | ||
94 | /// Root destination folder for the IAR load. | ||
95 | /// </summary> | ||
96 | protected InventoryFolderBase m_rootDestinationFolder; | ||
97 | |||
98 | /// <summary> | ||
99 | /// Inventory nodes loaded from the iar. | ||
100 | /// </summary> | ||
101 | protected HashSet<InventoryNodeBase> m_loadedNodes = new HashSet<InventoryNodeBase>(); | ||
102 | |||
103 | /// <summary> | ||
104 | /// In order to load identically named folders, we need to keep track of the folders that we have already | ||
105 | /// resolved. | ||
106 | /// </summary> | ||
107 | Dictionary <string, InventoryFolderBase> m_resolvedFolders = new Dictionary<string, InventoryFolderBase>(); | ||
108 | |||
109 | /// <summary> | ||
110 | /// Record the creator id that should be associated with an asset. This is used to adjust asset creator ids | ||
111 | /// after OSP resolution (since OSP creators are only stored in the item | ||
112 | /// </summary> | ||
113 | protected Dictionary<UUID, UUID> m_creatorIdForAssetId = new Dictionary<UUID, UUID>(); | ||
78 | 114 | ||
79 | public InventoryArchiveReadRequest( | 115 | public InventoryArchiveReadRequest( |
80 | Scene scene, UserAccount userInfo, string invPath, string loadPath, bool merge) | 116 | Scene scene, UserAccount userInfo, string invPath, string loadPath, bool merge) |
@@ -100,20 +136,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
100 | /// <summary> | 136 | /// <summary> |
101 | /// Execute the request | 137 | /// Execute the request |
102 | /// </summary> | 138 | /// </summary> |
139 | /// <remarks> | ||
140 | /// Only call this once. To load another IAR, construct another request object. | ||
141 | /// </remarks> | ||
103 | /// <returns> | 142 | /// <returns> |
104 | /// A list of the inventory nodes loaded. If folders were loaded then only the root folders are | 143 | /// A list of the inventory nodes loaded. If folders were loaded then only the root folders are |
105 | /// returned | 144 | /// returned |
106 | /// </returns> | 145 | /// </returns> |
146 | /// <exception cref="System.Exception">Thrown if load fails.</exception> | ||
107 | public HashSet<InventoryNodeBase> Execute() | 147 | public HashSet<InventoryNodeBase> Execute() |
108 | { | 148 | { |
109 | try | 149 | try |
110 | { | 150 | { |
111 | string filePath = "ERROR"; | 151 | string filePath = "ERROR"; |
112 | int successfulAssetRestores = 0; | ||
113 | int failedAssetRestores = 0; | ||
114 | int successfulItemRestores = 0; | ||
115 | |||
116 | HashSet<InventoryNodeBase> loadedNodes = new HashSet<InventoryNodeBase>(); | ||
117 | 152 | ||
118 | List<InventoryFolderBase> folderCandidates | 153 | List<InventoryFolderBase> folderCandidates |
119 | = InventoryArchiveUtils.FindFolderByPath( | 154 | = InventoryArchiveUtils.FindFolderByPath( |
@@ -124,16 +159,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
124 | // Possibly provide an option later on to automatically create this folder if it does not exist | 159 | // Possibly provide an option later on to automatically create this folder if it does not exist |
125 | m_log.ErrorFormat("[INVENTORY ARCHIVER]: Inventory path {0} does not exist", m_invPath); | 160 | m_log.ErrorFormat("[INVENTORY ARCHIVER]: Inventory path {0} does not exist", m_invPath); |
126 | 161 | ||
127 | return loadedNodes; | 162 | return m_loadedNodes; |
128 | } | 163 | } |
129 | 164 | ||
130 | InventoryFolderBase rootDestinationFolder = folderCandidates[0]; | 165 | m_rootDestinationFolder = folderCandidates[0]; |
131 | archive = new TarArchiveReader(m_loadStream); | 166 | archive = new TarArchiveReader(m_loadStream); |
132 | |||
133 | // In order to load identically named folders, we need to keep track of the folders that we have already | ||
134 | // resolved | ||
135 | Dictionary <string, InventoryFolderBase> resolvedFolders = new Dictionary<string, InventoryFolderBase>(); | ||
136 | |||
137 | byte[] data; | 167 | byte[] data; |
138 | TarArchiveReader.TarEntryType entryType; | 168 | TarArchiveReader.TarEntryType entryType; |
139 | 169 | ||
@@ -142,45 +172,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
142 | if (filePath == ArchiveConstants.CONTROL_FILE_PATH) | 172 | if (filePath == ArchiveConstants.CONTROL_FILE_PATH) |
143 | { | 173 | { |
144 | LoadControlFile(filePath, data); | 174 | LoadControlFile(filePath, data); |
145 | } | 175 | } |
146 | else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) | 176 | else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) |
147 | { | 177 | { |
148 | if (LoadAsset(filePath, data)) | 178 | LoadAssetFile(filePath, data); |
149 | successfulAssetRestores++; | ||
150 | else | ||
151 | failedAssetRestores++; | ||
152 | |||
153 | if ((successfulAssetRestores) % 50 == 0) | ||
154 | m_log.DebugFormat( | ||
155 | "[INVENTORY ARCHIVER]: Loaded {0} assets...", | ||
156 | successfulAssetRestores); | ||
157 | } | 179 | } |
158 | else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH)) | 180 | else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH)) |
159 | { | 181 | { |
160 | filePath = filePath.Substring(ArchiveConstants.INVENTORY_PATH.Length); | 182 | LoadInventoryFile(filePath, entryType, data); |
161 | |||
162 | // Trim off the file portion if we aren't already dealing with a directory path | ||
163 | if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) | ||
164 | filePath = filePath.Remove(filePath.LastIndexOf("/") + 1); | ||
165 | |||
166 | InventoryFolderBase foundFolder | ||
167 | = ReplicateArchivePathToUserInventory( | ||
168 | filePath, rootDestinationFolder, resolvedFolders, loadedNodes); | ||
169 | |||
170 | if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) | ||
171 | { | ||
172 | InventoryItemBase item = LoadItem(data, foundFolder); | ||
173 | |||
174 | if (item != null) | ||
175 | { | ||
176 | successfulItemRestores++; | ||
177 | |||
178 | // If we aren't loading the folder containing the item then well need to update the | ||
179 | // viewer separately for that item. | ||
180 | if (!loadedNodes.Contains(foundFolder)) | ||
181 | loadedNodes.Add(item); | ||
182 | } | ||
183 | } | ||
184 | } | 183 | } |
185 | } | 184 | } |
186 | 185 | ||
@@ -188,10 +187,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
188 | 187 | ||
189 | m_log.DebugFormat( | 188 | m_log.DebugFormat( |
190 | "[INVENTORY ARCHIVER]: Successfully loaded {0} assets with {1} failures", | 189 | "[INVENTORY ARCHIVER]: Successfully loaded {0} assets with {1} failures", |
191 | successfulAssetRestores, failedAssetRestores); | 190 | m_successfulAssetRestores, m_failedAssetRestores); |
192 | m_log.InfoFormat("[INVENTORY ARCHIVER]: Successfully loaded {0} items", successfulItemRestores); | 191 | m_log.InfoFormat("[INVENTORY ARCHIVER]: Successfully loaded {0} items", m_successfulItemRestores); |
193 | 192 | ||
194 | return loadedNodes; | 193 | return m_loadedNodes; |
195 | } | 194 | } |
196 | finally | 195 | finally |
197 | { | 196 | { |
@@ -400,9 +399,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
400 | UUID ospResolvedId = OspResolver.ResolveOspa(item.CreatorId, m_scene.UserAccountService); | 399 | UUID ospResolvedId = OspResolver.ResolveOspa(item.CreatorId, m_scene.UserAccountService); |
401 | if (UUID.Zero != ospResolvedId) // The user exists in this grid | 400 | if (UUID.Zero != ospResolvedId) // The user exists in this grid |
402 | { | 401 | { |
402 | // m_log.DebugFormat("[INVENTORY ARCHIVER]: Found creator {0} via OSPA resolution", ospResolvedId); | ||
403 | |||
403 | item.CreatorIdAsUuid = ospResolvedId; | 404 | item.CreatorIdAsUuid = ospResolvedId; |
404 | 405 | ||
405 | // XXX: For now, don't preserve the OSPA in the creator id (which actually gets persisted to the | 406 | // Don't preserve the OSPA in the creator id (which actually gets persisted to the |
406 | // database). Instead, replace with the UUID that we found. | 407 | // database). Instead, replace with the UUID that we found. |
407 | item.CreatorId = ospResolvedId.ToString(); | 408 | item.CreatorId = ospResolvedId.ToString(); |
408 | 409 | ||
@@ -410,7 +411,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
410 | } | 411 | } |
411 | else if (item.CreatorData == null || item.CreatorData == String.Empty) | 412 | else if (item.CreatorData == null || item.CreatorData == String.Empty) |
412 | { | 413 | { |
413 | item.CreatorIdAsUuid = m_userInfo.PrincipalID; | 414 | item.CreatorId = m_userInfo.PrincipalID.ToString(); |
415 | item.CreatorIdAsUuid = new UUID(item.CreatorId); | ||
414 | } | 416 | } |
415 | 417 | ||
416 | item.Owner = m_userInfo.PrincipalID; | 418 | item.Owner = m_userInfo.PrincipalID; |
@@ -418,6 +420,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
418 | // Reset folder ID to the one in which we want to load it | 420 | // Reset folder ID to the one in which we want to load it |
419 | item.Folder = loadFolder.ID; | 421 | item.Folder = loadFolder.ID; |
420 | 422 | ||
423 | // Record the creator id for the item's asset so that we can use it later, if necessary, when the asset | ||
424 | // is loaded. | ||
425 | // FIXME: This relies on the items coming before the assets in the TAR file. Need to create stronger | ||
426 | // checks for this, and maybe even an external tool for creating OARs which enforces this, rather than | ||
427 | // relying on native tar tools. | ||
428 | m_creatorIdForAssetId[item.AssetID] = item.CreatorIdAsUuid; | ||
429 | |||
421 | m_scene.AddInventoryItem(item); | 430 | m_scene.AddInventoryItem(item); |
422 | 431 | ||
423 | return item; | 432 | return item; |
@@ -446,18 +455,38 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
446 | } | 455 | } |
447 | 456 | ||
448 | string extension = filename.Substring(i); | 457 | string extension = filename.Substring(i); |
449 | string uuid = filename.Remove(filename.Length - extension.Length); | 458 | string rawUuid = filename.Remove(filename.Length - extension.Length); |
459 | UUID assetId = new UUID(rawUuid); | ||
450 | 460 | ||
451 | if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension)) | 461 | if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension)) |
452 | { | 462 | { |
453 | sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension]; | 463 | sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension]; |
454 | 464 | ||
455 | if (assetType == (sbyte)AssetType.Unknown) | 465 | if (assetType == (sbyte)AssetType.Unknown) |
456 | m_log.WarnFormat("[INVENTORY ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, uuid); | 466 | { |
467 | m_log.WarnFormat("[INVENTORY ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, assetId); | ||
468 | } | ||
469 | else if (assetType == (sbyte)AssetType.Object) | ||
470 | { | ||
471 | if (m_creatorIdForAssetId.ContainsKey(assetId)) | ||
472 | { | ||
473 | string xmlData = Utils.BytesToString(data); | ||
474 | SceneObjectGroup sog = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); | ||
475 | foreach (SceneObjectPart sop in sog.Parts) | ||
476 | { | ||
477 | if (sop.CreatorData == null || sop.CreatorData == "") | ||
478 | { | ||
479 | sop.CreatorID = m_creatorIdForAssetId[assetId]; | ||
480 | } | ||
481 | } | ||
482 | |||
483 | data = Utils.StringToBytes(SceneObjectSerializer.ToOriginalXmlFormat(sog)); | ||
484 | } | ||
485 | } | ||
457 | 486 | ||
458 | //m_log.DebugFormat("[INVENTORY ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType); | 487 | //m_log.DebugFormat("[INVENTORY ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType); |
459 | 488 | ||
460 | AssetBase asset = new AssetBase(new UUID(uuid), "RandomName", assetType, UUID.Zero.ToString()); | 489 | AssetBase asset = new AssetBase(assetId, "From IAR", assetType, UUID.Zero.ToString()); |
461 | asset.Data = data; | 490 | asset.Data = data; |
462 | 491 | ||
463 | m_scene.AssetService.Store(asset); | 492 | m_scene.AssetService.Store(asset); |
@@ -495,7 +524,88 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
495 | majorVersion, MAX_MAJOR_VERSION)); | 524 | majorVersion, MAX_MAJOR_VERSION)); |
496 | } | 525 | } |
497 | 526 | ||
498 | m_log.InfoFormat("[INVENTORY ARCHIVER]: Loading IAR with version {0}", version); | 527 | m_controlFileLoaded = true; |
528 | m_log.InfoFormat("[INVENTORY ARCHIVER]: Loading IAR with version {0}", version); | ||
529 | } | ||
530 | |||
531 | /// <summary> | ||
532 | /// Load inventory file | ||
533 | /// </summary> | ||
534 | /// <param name="path"></param> | ||
535 | /// <param name="entryType"></param> | ||
536 | /// <param name="data"></param> | ||
537 | protected void LoadInventoryFile(string path, TarArchiveReader.TarEntryType entryType, byte[] data) | ||
538 | { | ||
539 | if (!m_controlFileLoaded) | ||
540 | throw new Exception( | ||
541 | string.Format( | ||
542 | "The IAR you are trying to load does not list {0} before {1}. Aborting load", | ||
543 | ArchiveConstants.CONTROL_FILE_PATH, ArchiveConstants.INVENTORY_PATH)); | ||
544 | |||
545 | if (m_assetsLoaded) | ||
546 | throw new Exception( | ||
547 | string.Format( | ||
548 | "The IAR you are trying to load does not list all {0} before {1}. Aborting load", | ||
549 | ArchiveConstants.INVENTORY_PATH, ArchiveConstants.ASSETS_PATH)); | ||
550 | |||
551 | path = path.Substring(ArchiveConstants.INVENTORY_PATH.Length); | ||
552 | |||
553 | // Trim off the file portion if we aren't already dealing with a directory path | ||
554 | if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) | ||
555 | path = path.Remove(path.LastIndexOf("/") + 1); | ||
556 | |||
557 | InventoryFolderBase foundFolder | ||
558 | = ReplicateArchivePathToUserInventory( | ||
559 | path, m_rootDestinationFolder, m_resolvedFolders, m_loadedNodes); | ||
560 | |||
561 | if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) | ||
562 | { | ||
563 | InventoryItemBase item = LoadItem(data, foundFolder); | ||
564 | |||
565 | if (item != null) | ||
566 | { | ||
567 | m_successfulItemRestores++; | ||
568 | |||
569 | // If we aren't loading the folder containing the item then well need to update the | ||
570 | // viewer separately for that item. | ||
571 | if (!m_loadedNodes.Contains(foundFolder)) | ||
572 | m_loadedNodes.Add(item); | ||
573 | } | ||
574 | } | ||
575 | |||
576 | m_inventoryNodesLoaded = true; | ||
499 | } | 577 | } |
578 | |||
579 | /// <summary> | ||
580 | /// Load asset file | ||
581 | /// </summary> | ||
582 | /// <param name="path"></param> | ||
583 | /// <param name="data"></param> | ||
584 | protected void LoadAssetFile(string path, byte[] data) | ||
585 | { | ||
586 | if (!m_controlFileLoaded) | ||
587 | throw new Exception( | ||
588 | string.Format( | ||
589 | "The IAR you are trying to load does not list {0} before {1}. Aborting load", | ||
590 | ArchiveConstants.CONTROL_FILE_PATH, ArchiveConstants.ASSETS_PATH)); | ||
591 | |||
592 | if (!m_inventoryNodesLoaded) | ||
593 | throw new Exception( | ||
594 | string.Format( | ||
595 | "The IAR you are trying to load does not list all {0} before {1}. Aborting load", | ||
596 | ArchiveConstants.INVENTORY_PATH, ArchiveConstants.ASSETS_PATH)); | ||
597 | |||
598 | if (LoadAsset(path, data)) | ||
599 | m_successfulAssetRestores++; | ||
600 | else | ||
601 | m_failedAssetRestores++; | ||
602 | |||
603 | if ((m_successfulAssetRestores) % 50 == 0) | ||
604 | m_log.DebugFormat( | ||
605 | "[INVENTORY ARCHIVER]: Loaded {0} assets...", | ||
606 | m_successfulAssetRestores); | ||
607 | |||
608 | m_assetsLoaded = true; | ||
609 | } | ||
500 | } | 610 | } |
501 | } \ No newline at end of file | 611 | } \ No newline at end of file |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs index 26edba4..576a154 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs | |||
@@ -109,9 +109,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
109 | 109 | ||
110 | scene.AddCommand( | 110 | scene.AddCommand( |
111 | this, "load iar", | 111 | this, "load iar", |
112 | "load iar [--merge] <first> <last> <inventory path> <password> [<IAR path>]", | 112 | "load iar [-m|--merge] <first> <last> <inventory path> <password> [<IAR path>]", |
113 | "Load user inventory archive (IAR).", | 113 | "Load user inventory archive (IAR).", |
114 | "--merge is an option which merges the loaded IAR with existing inventory folders where possible, rather than always creating new ones" | 114 | "-m|--merge is an option which merges the loaded IAR with existing inventory folders where possible, rather than always creating new ones" |
115 | + "<first> is user's first name." + Environment.NewLine | 115 | + "<first> is user's first name." + Environment.NewLine |
116 | + "<last> is user's last name." + Environment.NewLine | 116 | + "<last> is user's last name." + Environment.NewLine |
117 | + "<inventory path> is the path inside the user's inventory where the IAR should be loaded." + Environment.NewLine | 117 | + "<inventory path> is the path inside the user's inventory where the IAR should be loaded." + Environment.NewLine |
@@ -181,7 +181,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
181 | catch (EntryPointNotFoundException e) | 181 | catch (EntryPointNotFoundException e) |
182 | { | 182 | { |
183 | m_log.ErrorFormat( | 183 | m_log.ErrorFormat( |
184 | "[ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." | 184 | "[INVENTORY ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." |
185 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); | 185 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); |
186 | m_log.Error(e); | 186 | m_log.Error(e); |
187 | 187 | ||
@@ -221,7 +221,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
221 | catch (EntryPointNotFoundException e) | 221 | catch (EntryPointNotFoundException e) |
222 | { | 222 | { |
223 | m_log.ErrorFormat( | 223 | m_log.ErrorFormat( |
224 | "[ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." | 224 | "[INVENTORY ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." |
225 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); | 225 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); |
226 | m_log.Error(e); | 226 | m_log.Error(e); |
227 | 227 | ||
@@ -269,7 +269,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
269 | catch (EntryPointNotFoundException e) | 269 | catch (EntryPointNotFoundException e) |
270 | { | 270 | { |
271 | m_log.ErrorFormat( | 271 | m_log.ErrorFormat( |
272 | "[ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." | 272 | "[INVENTORY ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." |
273 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); | 273 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); |
274 | m_log.Error(e); | 274 | m_log.Error(e); |
275 | 275 | ||
@@ -317,7 +317,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
317 | catch (EntryPointNotFoundException e) | 317 | catch (EntryPointNotFoundException e) |
318 | { | 318 | { |
319 | m_log.ErrorFormat( | 319 | m_log.ErrorFormat( |
320 | "[ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." | 320 | "[INVENTORY ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." |
321 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); | 321 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); |
322 | m_log.Error(e); | 322 | m_log.Error(e); |
323 | 323 | ||
@@ -358,7 +358,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
358 | if (mainParams.Count < 6) | 358 | if (mainParams.Count < 6) |
359 | { | 359 | { |
360 | m_log.Error( | 360 | m_log.Error( |
361 | "[INVENTORY ARCHIVER]: usage is load iar [--merge] <first name> <last name> <inventory path> <user password> [<load file path>]"); | 361 | "[INVENTORY ARCHIVER]: usage is load iar [-m|--merge] <first name> <last name> <inventory path> <user password> [<load file path>]"); |
362 | return; | 362 | return; |
363 | } | 363 | } |
364 | 364 | ||
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..e5127a0 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiveTestCase.cs | |||
@@ -0,0 +1,155 @@ | |||
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 | using OpenSim.Tests.Common.Setup; | ||
48 | |||
49 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | ||
50 | { | ||
51 | [TestFixture] | ||
52 | public class InventoryArchiveTestCase | ||
53 | { | ||
54 | protected ManualResetEvent mre = new ManualResetEvent(false); | ||
55 | |||
56 | /// <summary> | ||
57 | /// A raw array of bytes that we'll use to create an IAR memory stream suitable for isolated use in each test. | ||
58 | /// </summary> | ||
59 | protected byte[] m_iarStreamBytes; | ||
60 | |||
61 | /// <summary> | ||
62 | /// Stream of data representing a common IAR for load tests. | ||
63 | /// </summary> | ||
64 | protected MemoryStream m_iarStream; | ||
65 | |||
66 | protected UserAccount m_uaMT | ||
67 | = new UserAccount { | ||
68 | PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000555"), | ||
69 | FirstName = "Mr", | ||
70 | LastName = "Tiddles" }; | ||
71 | protected UserAccount m_uaLL1 | ||
72 | = new UserAccount { | ||
73 | PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000666"), | ||
74 | FirstName = "Lord", | ||
75 | LastName = "Lucan" }; | ||
76 | protected UserAccount m_uaLL2 | ||
77 | = new UserAccount { | ||
78 | PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000777"), | ||
79 | FirstName = "Lord", | ||
80 | LastName = "Lucan" }; | ||
81 | protected string m_item1Name = "Ray Gun Item"; | ||
82 | |||
83 | [SetUp] | ||
84 | public virtual void SetUp() | ||
85 | { | ||
86 | m_iarStream = new MemoryStream(m_iarStreamBytes); | ||
87 | } | ||
88 | |||
89 | [TestFixtureSetUp] | ||
90 | public void FixtureSetup() | ||
91 | { | ||
92 | ConstructDefaultIarBytesForTestLoad(); | ||
93 | } | ||
94 | |||
95 | protected void ConstructDefaultIarBytesForTestLoad() | ||
96 | { | ||
97 | // log4net.Config.XmlConfigurator.Configure(); | ||
98 | |||
99 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
100 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
101 | SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | ||
102 | |||
103 | UserProfileTestUtils.CreateUserWithInventory(scene, m_uaLL1, "hampshire"); | ||
104 | |||
105 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
106 | |||
107 | // Create asset | ||
108 | SceneObjectGroup object1; | ||
109 | SceneObjectPart part1; | ||
110 | { | ||
111 | string partName = "Ray Gun Object"; | ||
112 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
113 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
114 | Vector3 groupPosition = new Vector3(10, 20, 30); | ||
115 | Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | ||
116 | Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
117 | |||
118 | part1 | ||
119 | = new SceneObjectPart( | ||
120 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
121 | part1.Name = partName; | ||
122 | |||
123 | object1 = new SceneObjectGroup(part1); | ||
124 | scene.AddNewSceneObject(object1, false); | ||
125 | } | ||
126 | |||
127 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | ||
128 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | ||
129 | scene.AssetService.Store(asset1); | ||
130 | |||
131 | // Create item | ||
132 | InventoryItemBase item1 = new InventoryItemBase(); | ||
133 | item1.Name = m_item1Name; | ||
134 | item1.ID = UUID.Parse("00000000-0000-0000-0000-000000000020"); | ||
135 | item1.AssetID = asset1.FullID; | ||
136 | item1.GroupID = UUID.Random(); | ||
137 | item1.CreatorIdAsUuid = m_uaLL1.PrincipalID; | ||
138 | item1.Owner = m_uaLL1.PrincipalID; | ||
139 | item1.Folder = scene.InventoryService.GetRootFolder(m_uaLL1.PrincipalID).ID; | ||
140 | scene.AddInventoryItem(item1); | ||
141 | |||
142 | archiverModule.ArchiveInventory( | ||
143 | Guid.NewGuid(), m_uaLL1.FirstName, m_uaLL1.LastName, m_item1Name, "hampshire", archiveWriteStream); | ||
144 | |||
145 | m_iarStreamBytes = archiveWriteStream.ToArray(); | ||
146 | } | ||
147 | |||
148 | protected void SaveCompleted( | ||
149 | Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, | ||
150 | Exception reportedException) | ||
151 | { | ||
152 | mre.Set(); | ||
153 | } | ||
154 | } | ||
155 | } \ 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 76d0b85..7f156f8 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs | |||
@@ -31,7 +31,6 @@ using System.IO; | |||
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Threading; | 32 | using System.Threading; |
33 | using NUnit.Framework; | 33 | using NUnit.Framework; |
34 | using NUnit.Framework.SyntaxHelpers; | ||
35 | using OpenMetaverse; | 34 | using OpenMetaverse; |
36 | using OpenSim.Data; | 35 | using OpenSim.Data; |
37 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
@@ -50,182 +49,21 @@ using OpenSim.Tests.Common.Setup; | |||
50 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | 49 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests |
51 | { | 50 | { |
52 | [TestFixture] | 51 | [TestFixture] |
53 | public class InventoryArchiverTests | 52 | public class InventoryArchiverTests : InventoryArchiveTestCase |
54 | { | 53 | { |
55 | protected ManualResetEvent mre = new ManualResetEvent(false); | 54 | protected TestScene m_scene; |
56 | 55 | protected InventoryArchiverModule m_archiverModule; | |
57 | /// <summary> | 56 | |
58 | /// Stream of data representing a common IAR that can be reused in load tests. | ||
59 | /// </summary> | ||
60 | protected MemoryStream m_iarStream; | ||
61 | |||
62 | protected UserAccount m_ua1 | ||
63 | = new UserAccount { | ||
64 | PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000555"), | ||
65 | FirstName = "Mr", | ||
66 | LastName = "Tiddles" }; | ||
67 | protected UserAccount m_ua2 | ||
68 | = new UserAccount { | ||
69 | PrincipalID = UUID.Parse("00000000-0000-0000-0000-000000000666"), | ||
70 | FirstName = "Lord", | ||
71 | LastName = "Lucan" }; | ||
72 | string m_item1Name = "b.lsl"; | ||
73 | |||
74 | private void SaveCompleted( | ||
75 | Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, | ||
76 | Exception reportedException) | ||
77 | { | ||
78 | mre.Set(); | ||
79 | } | ||
80 | |||
81 | [SetUp] | 57 | [SetUp] |
82 | public void Init() | 58 | public override void SetUp() |
83 | { | ||
84 | ConstructDefaultIarForTestLoad(); | ||
85 | } | ||
86 | |||
87 | protected void ConstructDefaultIarForTestLoad() | ||
88 | { | ||
89 | string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(m_item1Name, UUID.Random()); | ||
90 | |||
91 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
92 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | ||
93 | |||
94 | InventoryItemBase item1 = new InventoryItemBase(); | ||
95 | item1.Name = m_item1Name; | ||
96 | item1.AssetID = UUID.Random(); | ||
97 | item1.GroupID = UUID.Random(); | ||
98 | //item1.CreatorId = OspResolver.MakeOspa(m_ua2.FirstName, m_ua2.LastName); | ||
99 | //item1.CreatorId = userUuid.ToString(); | ||
100 | item1.CreatorId = m_ua2.PrincipalID.ToString(); | ||
101 | item1.Owner = UUID.Zero; | ||
102 | |||
103 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
104 | UserProfileTestUtils.CreateUserWithInventory(scene, m_ua2, "hampshire"); | ||
105 | |||
106 | string item1FileName | ||
107 | = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); | ||
108 | tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1, new Dictionary<string, object>(), scene.UserAccountService)); | ||
109 | tar.Close(); | ||
110 | m_iarStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// Test saving an inventory path to a V0.1 OpenSim Inventory Archive | ||
115 | /// (subject to change since there is no fixed format yet). | ||
116 | /// </summary> | ||
117 | [Test] | ||
118 | public void TestSavePathToIarV0_1() | ||
119 | { | 59 | { |
120 | TestHelper.InMethod(); | 60 | base.SetUp(); |
121 | // log4net.Config.XmlConfigurator.Configure(); | ||
122 | |||
123 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
124 | |||
125 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
126 | SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | ||
127 | |||
128 | // Create user | ||
129 | string userFirstName = "Jock"; | ||
130 | string userLastName = "Stirrup"; | ||
131 | string userPassword = "troll"; | ||
132 | UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); | ||
133 | UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, userPassword); | ||
134 | 61 | ||
135 | // Create asset | 62 | SerialiserModule serialiserModule = new SerialiserModule(); |
136 | SceneObjectGroup object1; | 63 | m_archiverModule = new InventoryArchiverModule(); |
137 | SceneObjectPart part1; | ||
138 | { | ||
139 | string partName = "My Little Dog Object"; | ||
140 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
141 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
142 | Vector3 groupPosition = new Vector3(10, 20, 30); | ||
143 | Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | ||
144 | Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
145 | |||
146 | part1 | ||
147 | = new SceneObjectPart( | ||
148 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
149 | part1.Name = partName; | ||
150 | |||
151 | object1 = new SceneObjectGroup(part1); | ||
152 | scene.AddNewSceneObject(object1, false); | ||
153 | } | ||
154 | |||
155 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | ||
156 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | ||
157 | scene.AssetService.Store(asset1); | ||
158 | |||
159 | // Create item | ||
160 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | ||
161 | InventoryItemBase item1 = new InventoryItemBase(); | ||
162 | item1.Name = "My Little Dog"; | ||
163 | item1.AssetID = asset1.FullID; | ||
164 | item1.ID = item1Id; | ||
165 | InventoryFolderBase objsFolder | ||
166 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0]; | ||
167 | item1.Folder = objsFolder.ID; | ||
168 | scene.AddInventoryItem(item1); | ||
169 | |||
170 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
171 | archiverModule.OnInventoryArchiveSaved += SaveCompleted; | ||
172 | |||
173 | // Test saving a particular path | ||
174 | mre.Reset(); | ||
175 | archiverModule.ArchiveInventory( | ||
176 | Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); | ||
177 | mre.WaitOne(60000, false); | ||
178 | |||
179 | byte[] archive = archiveWriteStream.ToArray(); | ||
180 | MemoryStream archiveReadStream = new MemoryStream(archive); | ||
181 | TarArchiveReader tar = new TarArchiveReader(archiveReadStream); | ||
182 | |||
183 | //bool gotControlFile = false; | ||
184 | bool gotObject1File = false; | ||
185 | //bool gotObject2File = false; | ||
186 | string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1); | ||
187 | string expectedObject1FilePath = string.Format( | ||
188 | "{0}{1}{2}", | ||
189 | ArchiveConstants.INVENTORY_PATH, | ||
190 | InventoryArchiveWriteRequest.CreateArchiveFolderName(objsFolder), | ||
191 | expectedObject1FileName); | ||
192 | |||
193 | string filePath; | ||
194 | TarArchiveReader.TarEntryType tarEntryType; | ||
195 | |||
196 | // Console.WriteLine("Reading archive"); | ||
197 | |||
198 | while (tar.ReadEntry(out filePath, out tarEntryType) != null) | ||
199 | { | ||
200 | // Console.WriteLine("Got {0}", filePath); | ||
201 | |||
202 | // if (ArchiveConstants.CONTROL_FILE_PATH == filePath) | ||
203 | // { | ||
204 | // gotControlFile = true; | ||
205 | // } | ||
206 | |||
207 | if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml")) | ||
208 | { | ||
209 | // string fileName = filePath.Remove(0, "Objects/".Length); | ||
210 | // | ||
211 | // if (fileName.StartsWith(part1.Name)) | ||
212 | // { | ||
213 | Assert.That(expectedObject1FilePath, Is.EqualTo(filePath)); | ||
214 | gotObject1File = true; | ||
215 | // } | ||
216 | // else if (fileName.StartsWith(part2.Name)) | ||
217 | // { | ||
218 | // Assert.That(fileName, Is.EqualTo(expectedObject2FileName)); | ||
219 | // gotObject2File = true; | ||
220 | // } | ||
221 | } | ||
222 | } | ||
223 | |||
224 | // Assert.That(gotControlFile, Is.True, "No control file in archive"); | ||
225 | Assert.That(gotObject1File, Is.True, "No item1 file in archive"); | ||
226 | // Assert.That(gotObject2File, Is.True, "No object2 file in archive"); | ||
227 | 64 | ||
228 | // TODO: Test presence of more files and contents of files. | 65 | m_scene = SceneSetupHelpers.SetupScene("Inventory"); |
66 | SceneSetupHelpers.SetupSceneModules(m_scene, serialiserModule, m_archiverModule); | ||
229 | } | 67 | } |
230 | 68 | ||
231 | /// <summary> | 69 | /// <summary> |
@@ -238,17 +76,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
238 | TestHelper.InMethod(); | 76 | TestHelper.InMethod(); |
239 | // log4net.Config.XmlConfigurator.Configure(); | 77 | // log4net.Config.XmlConfigurator.Configure(); |
240 | 78 | ||
241 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
242 | |||
243 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
244 | SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | ||
245 | |||
246 | // Create user | 79 | // Create user |
247 | string userFirstName = "Jock"; | 80 | string userFirstName = "Jock"; |
248 | string userLastName = "Stirrup"; | 81 | string userLastName = "Stirrup"; |
249 | string userPassword = "troll"; | 82 | string userPassword = "troll"; |
250 | UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); | 83 | UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); |
251 | UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, userPassword); | 84 | UserProfileTestUtils.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword); |
252 | 85 | ||
253 | // Create asset | 86 | // Create asset |
254 | SceneObjectGroup object1; | 87 | SceneObjectGroup object1; |
@@ -267,12 +100,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
267 | part1.Name = partName; | 100 | part1.Name = partName; |
268 | 101 | ||
269 | object1 = new SceneObjectGroup(part1); | 102 | object1 = new SceneObjectGroup(part1); |
270 | scene.AddNewSceneObject(object1, false); | 103 | m_scene.AddNewSceneObject(object1, false); |
271 | } | 104 | } |
272 | 105 | ||
273 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | 106 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); |
274 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | 107 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); |
275 | scene.AssetService.Store(asset1); | 108 | m_scene.AssetService.Store(asset1); |
276 | 109 | ||
277 | // Create item | 110 | // Create item |
278 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | 111 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); |
@@ -282,15 +115,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
282 | item1.AssetID = asset1.FullID; | 115 | item1.AssetID = asset1.FullID; |
283 | item1.ID = item1Id; | 116 | item1.ID = item1Id; |
284 | InventoryFolderBase objsFolder | 117 | InventoryFolderBase objsFolder |
285 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0]; | 118 | = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, userId, "Objects")[0]; |
286 | item1.Folder = objsFolder.ID; | 119 | item1.Folder = objsFolder.ID; |
287 | scene.AddInventoryItem(item1); | 120 | m_scene.AddInventoryItem(item1); |
288 | 121 | ||
289 | MemoryStream archiveWriteStream = new MemoryStream(); | 122 | MemoryStream archiveWriteStream = new MemoryStream(); |
290 | archiverModule.OnInventoryArchiveSaved += SaveCompleted; | 123 | m_archiverModule.OnInventoryArchiveSaved += SaveCompleted; |
291 | 124 | ||
292 | mre.Reset(); | 125 | mre.Reset(); |
293 | archiverModule.ArchiveInventory( | 126 | m_archiverModule.ArchiveInventory( |
294 | Guid.NewGuid(), userFirstName, userLastName, "Objects/" + item1Name, userPassword, archiveWriteStream); | 127 | Guid.NewGuid(), userFirstName, userLastName, "Objects/" + item1Name, userPassword, archiveWriteStream); |
295 | mre.WaitOne(60000, false); | 128 | mre.WaitOne(60000, false); |
296 | 129 | ||
@@ -346,474 +179,99 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
346 | } | 179 | } |
347 | 180 | ||
348 | /// <summary> | 181 | /// <summary> |
349 | /// Test that things work when the load path specified starts with a slash | 182 | /// Test case where a creator account exists for the creator UUID embedded in item metadata and serialized |
350 | /// </summary> | 183 | /// objects. |
184 | /// </summary> | ||
351 | [Test] | 185 | [Test] |
352 | public void TestLoadIarPathStartsWithSlash() | 186 | public void TestLoadIarCreatorAccountPresent() |
353 | { | 187 | { |
354 | TestHelper.InMethod(); | 188 | TestHelper.InMethod(); |
355 | // log4net.Config.XmlConfigurator.Configure(); | 189 | // log4net.Config.XmlConfigurator.Configure(); |
356 | |||
357 | SerialiserModule serialiserModule = new SerialiserModule(); | ||
358 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
359 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
360 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | ||
361 | |||
362 | UserProfileTestUtils.CreateUserWithInventory(scene, m_ua1, "password"); | ||
363 | archiverModule.DearchiveInventory(m_ua1.FirstName, m_ua1.LastName, "/Objects", "password", m_iarStream); | ||
364 | 190 | ||
191 | UserProfileTestUtils.CreateUserWithInventory(m_scene, m_uaLL1, "meowfood"); | ||
192 | |||
193 | m_archiverModule.DearchiveInventory(m_uaLL1.FirstName, m_uaLL1.LastName, "/", "meowfood", m_iarStream); | ||
365 | InventoryItemBase foundItem1 | 194 | InventoryItemBase foundItem1 |
366 | = InventoryArchiveUtils.FindItemByPath( | 195 | = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, m_uaLL1.PrincipalID, m_item1Name); |
367 | scene.InventoryService, m_ua1.PrincipalID, "/Objects/" + m_item1Name); | 196 | |
197 | Assert.That( | ||
198 | foundItem1.CreatorId, Is.EqualTo(m_uaLL1.PrincipalID.ToString()), | ||
199 | "Loaded item non-uuid creator doesn't match original"); | ||
200 | Assert.That( | ||
201 | foundItem1.CreatorIdAsUuid, Is.EqualTo(m_uaLL1.PrincipalID), | ||
202 | "Loaded item uuid creator doesn't match original"); | ||
203 | Assert.That(foundItem1.Owner, Is.EqualTo(m_uaLL1.PrincipalID), | ||
204 | "Loaded item owner doesn't match inventory reciever"); | ||
368 | 205 | ||
369 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1 in TestLoadIarFolderStartsWithSlash()"); | 206 | AssetBase asset1 = m_scene.AssetService.Get(foundItem1.AssetID.ToString()); |
207 | string xmlData = Utils.BytesToString(asset1.Data); | ||
208 | SceneObjectGroup sog1 = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); | ||
209 | |||
210 | Assert.That(sog1.RootPart.CreatorID, Is.EqualTo(m_uaLL1.PrincipalID)); | ||
370 | } | 211 | } |
371 | 212 | ||
372 | /// <summary> | 213 | /// <summary> |
373 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | 214 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where |
374 | /// an account exists with the creator name. | 215 | /// an account exists with the same name as the creator, though not the same id. |
375 | /// </summary> | 216 | /// </summary> |
376 | /// | ||
377 | /// This test also does some deeper probing of loading into nested inventory structures | ||
378 | [Test] | 217 | [Test] |
379 | public void TestLoadIarV0_1ExistingUsers() | 218 | public void TestLoadIarV0_1SameNameCreator() |
380 | { | 219 | { |
381 | TestHelper.InMethod(); | 220 | TestHelper.InMethod(); |
382 | //log4net.Config.XmlConfigurator.Configure(); | 221 | // log4net.Config.XmlConfigurator.Configure(); |
383 | |||
384 | SerialiserModule serialiserModule = new SerialiserModule(); | ||
385 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
386 | |||
387 | // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene | ||
388 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
389 | |||
390 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | ||
391 | 222 | ||
392 | UserProfileTestUtils.CreateUserWithInventory(scene, m_ua1, "meowfood"); | 223 | UserProfileTestUtils.CreateUserWithInventory(m_scene, m_uaMT, "meowfood"); |
393 | UserProfileTestUtils.CreateUserWithInventory(scene, m_ua2, "hampshire"); | 224 | UserProfileTestUtils.CreateUserWithInventory(m_scene, m_uaLL2, "hampshire"); |
394 | 225 | ||
395 | archiverModule.DearchiveInventory(m_ua1.FirstName, m_ua1.LastName, "/", "meowfood", m_iarStream); | 226 | m_archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "/", "meowfood", m_iarStream); |
396 | |||
397 | InventoryItemBase foundItem1 | 227 | InventoryItemBase foundItem1 |
398 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_ua1.PrincipalID, m_item1Name); | 228 | = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, m_uaMT.PrincipalID, m_item1Name); |
399 | |||
400 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | ||
401 | 229 | ||
402 | // We have to disable this check since loaded items that did find users via OSPA resolution are now only storing the | ||
403 | // UUID, not the OSPA itself. | ||
404 | // Assert.That( | ||
405 | // foundItem1.CreatorId, Is.EqualTo(item1.CreatorId), | ||
406 | // "Loaded item non-uuid creator doesn't match original"); | ||
407 | Assert.That( | 230 | Assert.That( |
408 | foundItem1.CreatorId, Is.EqualTo(m_ua2.PrincipalID.ToString()), | 231 | foundItem1.CreatorId, Is.EqualTo(m_uaLL2.PrincipalID.ToString()), |
409 | "Loaded item non-uuid creator doesn't match original"); | 232 | "Loaded item non-uuid creator doesn't match original"); |
410 | |||
411 | Assert.That( | 233 | Assert.That( |
412 | foundItem1.CreatorIdAsUuid, Is.EqualTo(m_ua2.PrincipalID), | 234 | foundItem1.CreatorIdAsUuid, Is.EqualTo(m_uaLL2.PrincipalID), |
413 | "Loaded item uuid creator doesn't match original"); | 235 | "Loaded item uuid creator doesn't match original"); |
414 | Assert.That(foundItem1.Owner, Is.EqualTo(m_ua1.PrincipalID), | 236 | Assert.That(foundItem1.Owner, Is.EqualTo(m_uaMT.PrincipalID), |
415 | "Loaded item owner doesn't match inventory reciever"); | 237 | "Loaded item owner doesn't match inventory reciever"); |
416 | |||
417 | // Now try loading to a root child folder | ||
418 | UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, m_ua1.PrincipalID, "xA"); | ||
419 | MemoryStream archiveReadStream = new MemoryStream(m_iarStream.ToArray()); | ||
420 | archiverModule.DearchiveInventory(m_ua1.FirstName, m_ua1.LastName, "xA", "meowfood", archiveReadStream); | ||
421 | |||
422 | InventoryItemBase foundItem2 | ||
423 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_ua1.PrincipalID, "xA/" + m_item1Name); | ||
424 | Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2"); | ||
425 | |||
426 | // Now try loading to a more deeply nested folder | ||
427 | UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, m_ua1.PrincipalID, "xB/xC"); | ||
428 | archiveReadStream = new MemoryStream(archiveReadStream.ToArray()); | ||
429 | archiverModule.DearchiveInventory(m_ua1.FirstName, m_ua1.LastName, "xB/xC", "meowfood", archiveReadStream); | ||
430 | |||
431 | InventoryItemBase foundItem3 | ||
432 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_ua1.PrincipalID, "xB/xC/" + m_item1Name); | ||
433 | Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3"); | ||
434 | } | ||
435 | |||
436 | [Test] | ||
437 | public void TestIarV0_1WithEscapedChars() | ||
438 | { | ||
439 | TestHelper.InMethod(); | ||
440 | // log4net.Config.XmlConfigurator.Configure(); | ||
441 | |||
442 | string itemName = "You & you are a mean/man/"; | ||
443 | string humanEscapedItemName = @"You & you are a mean\/man\/"; | ||
444 | string userPassword = "meowfood"; | ||
445 | |||
446 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
447 | |||
448 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
449 | SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | ||
450 | |||
451 | // Create user | ||
452 | string userFirstName = "Jock"; | ||
453 | string userLastName = "Stirrup"; | ||
454 | UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); | ||
455 | UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "meowfood"); | ||
456 | |||
457 | // Create asset | ||
458 | SceneObjectGroup object1; | ||
459 | SceneObjectPart part1; | ||
460 | { | ||
461 | string partName = "part name"; | ||
462 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
463 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
464 | Vector3 groupPosition = new Vector3(10, 20, 30); | ||
465 | Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | ||
466 | Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
467 | |||
468 | part1 | ||
469 | = new SceneObjectPart( | ||
470 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
471 | part1.Name = partName; | ||
472 | |||
473 | object1 = new SceneObjectGroup(part1); | ||
474 | scene.AddNewSceneObject(object1, false); | ||
475 | } | ||
476 | |||
477 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | ||
478 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | ||
479 | scene.AssetService.Store(asset1); | ||
480 | |||
481 | // Create item | ||
482 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | ||
483 | InventoryItemBase item1 = new InventoryItemBase(); | ||
484 | item1.Name = itemName; | ||
485 | item1.AssetID = asset1.FullID; | ||
486 | item1.ID = item1Id; | ||
487 | InventoryFolderBase objsFolder | ||
488 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0]; | ||
489 | item1.Folder = objsFolder.ID; | ||
490 | scene.AddInventoryItem(item1); | ||
491 | |||
492 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
493 | archiverModule.OnInventoryArchiveSaved += SaveCompleted; | ||
494 | |||
495 | mre.Reset(); | ||
496 | archiverModule.ArchiveInventory( | ||
497 | Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); | ||
498 | mre.WaitOne(60000, false); | ||
499 | |||
500 | // LOAD ITEM | ||
501 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
502 | 238 | ||
503 | archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", userPassword, archiveReadStream); | 239 | AssetBase asset1 = m_scene.AssetService.Get(foundItem1.AssetID.ToString()); |
504 | 240 | string xmlData = Utils.BytesToString(asset1.Data); | |
505 | InventoryItemBase foundItem1 | 241 | SceneObjectGroup sog1 = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); |
506 | = InventoryArchiveUtils.FindItemByPath( | ||
507 | scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName); | ||
508 | 242 | ||
509 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | 243 | Assert.That(sog1.RootPart.CreatorID, Is.EqualTo(m_uaLL2.PrincipalID)); |
510 | // Assert.That( | ||
511 | // foundItem1.CreatorId, Is.EqualTo(userUuid), | ||
512 | // "Loaded item non-uuid creator doesn't match that of the loading user"); | ||
513 | Assert.That( | ||
514 | foundItem1.Name, Is.EqualTo(itemName), | ||
515 | "Loaded item name doesn't match saved name"); | ||
516 | } | 244 | } |
517 | 245 | ||
518 | /// <summary> | 246 | /// <summary> |
519 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | 247 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where |
520 | /// embedded creators do not exist in the system | 248 | /// the creator or an account with the creator's name does not exist within the system. |
521 | /// </summary> | 249 | /// </summary> |
522 | /// | ||
523 | /// This may possibly one day get overtaken by the as yet incomplete temporary profiles feature | ||
524 | /// (as tested in the a later commented out test) | ||
525 | /// This test is currently disabled | ||
526 | [Test] | 250 | [Test] |
527 | public void TestLoadIarV0_1AbsentUsers() | 251 | public void TestLoadIarV0_1AbsentCreator() |
528 | { | 252 | { |
529 | TestHelper.InMethod(); | 253 | TestHelper.InMethod(); |
530 | //log4net.Config.XmlConfigurator.Configure(); | 254 | // log4net.Config.XmlConfigurator.Configure(); |
531 | |||
532 | string userFirstName = "Charlie"; | ||
533 | string userLastName = "Chan"; | ||
534 | UUID userUuid = UUID.Parse("00000000-0000-0000-0000-000000000999"); | ||
535 | string userItemCreatorFirstName = "Bat"; | ||
536 | string userItemCreatorLastName = "Man"; | ||
537 | //UUID userItemCreatorUuid = UUID.Parse("00000000-0000-0000-0000-000000008888"); | ||
538 | |||
539 | string itemName = "b.lsl"; | ||
540 | string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random()); | ||
541 | |||
542 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
543 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | ||
544 | |||
545 | InventoryItemBase item1 = new InventoryItemBase(); | ||
546 | item1.Name = itemName; | ||
547 | item1.AssetID = UUID.Random(); | ||
548 | item1.GroupID = UUID.Random(); | ||
549 | item1.CreatorId = OspResolver.MakeOspa(userItemCreatorFirstName, userItemCreatorLastName); | ||
550 | //item1.CreatorId = userUuid.ToString(); | ||
551 | //item1.CreatorId = "00000000-0000-0000-0000-000000000444"; | ||
552 | item1.Owner = UUID.Zero; | ||
553 | |||
554 | string item1FileName | ||
555 | = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); | ||
556 | tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1, new Dictionary<string,object>(), null)); | ||
557 | tar.Close(); | ||
558 | |||
559 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
560 | SerialiserModule serialiserModule = new SerialiserModule(); | ||
561 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
562 | |||
563 | // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene | ||
564 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
565 | |||
566 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | ||
567 | UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userUuid, "meowfood"); | ||
568 | 255 | ||
569 | archiverModule.DearchiveInventory(userFirstName, userLastName, "/", "meowfood", archiveReadStream); | 256 | UserProfileTestUtils.CreateUserWithInventory(m_scene, m_uaMT, "password"); |
257 | m_archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "/", "password", m_iarStream); | ||
570 | 258 | ||
571 | InventoryItemBase foundItem1 | 259 | InventoryItemBase foundItem1 |
572 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userUuid, itemName); | 260 | = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, m_uaMT.PrincipalID, m_item1Name); |
573 | 261 | ||
574 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | 262 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); |
575 | // Assert.That( | ||
576 | // foundItem1.CreatorId, Is.EqualTo(userUuid), | ||
577 | // "Loaded item non-uuid creator doesn't match that of the loading user"); | ||
578 | Assert.That( | 263 | Assert.That( |
579 | foundItem1.CreatorIdAsUuid, Is.EqualTo(userUuid), | 264 | foundItem1.CreatorId, Is.EqualTo(m_uaMT.PrincipalID.ToString()), |
265 | "Loaded item non-uuid creator doesn't match that of the loading user"); | ||
266 | Assert.That( | ||
267 | foundItem1.CreatorIdAsUuid, Is.EqualTo(m_uaMT.PrincipalID), | ||
580 | "Loaded item uuid creator doesn't match that of the loading user"); | 268 | "Loaded item uuid creator doesn't match that of the loading user"); |
581 | } | ||
582 | |||
583 | /// <summary> | ||
584 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | ||
585 | /// no account exists with the creator name | ||
586 | /// </summary> | ||
587 | /// Disabled since temporary profiles have not yet been implemented. | ||
588 | /// | ||
589 | //[Test] | ||
590 | //public void TestLoadIarV0_1TempProfiles() | ||
591 | //{ | ||
592 | // TestHelper.InMethod(); | ||
593 | |||
594 | // //log4net.Config.XmlConfigurator.Configure(); | ||
595 | 269 | ||
596 | // string userFirstName = "Dennis"; | 270 | AssetBase asset1 = m_scene.AssetService.Get(foundItem1.AssetID.ToString()); |
597 | // string userLastName = "Menace"; | 271 | string xmlData = Utils.BytesToString(asset1.Data); |
598 | // UUID userUuid = UUID.Parse("00000000-0000-0000-0000-000000000aaa"); | 272 | SceneObjectGroup sog1 = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); |
599 | // string user2FirstName = "Walter"; | ||
600 | // string user2LastName = "Mitty"; | ||
601 | 273 | ||
602 | // string itemName = "b.lsl"; | 274 | Assert.That(sog1.RootPart.CreatorID, Is.EqualTo(m_uaMT.PrincipalID)); |
603 | // string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random()); | ||
604 | |||
605 | // MemoryStream archiveWriteStream = new MemoryStream(); | ||
606 | // TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | ||
607 | |||
608 | // InventoryItemBase item1 = new InventoryItemBase(); | ||
609 | // item1.Name = itemName; | ||
610 | // item1.AssetID = UUID.Random(); | ||
611 | // item1.GroupID = UUID.Random(); | ||
612 | // item1.CreatorId = OspResolver.MakeOspa(user2FirstName, user2LastName); | ||
613 | // item1.Owner = UUID.Zero; | ||
614 | |||
615 | // string item1FileName | ||
616 | // = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); | ||
617 | // tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); | ||
618 | // tar.Close(); | ||
619 | |||
620 | // MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
621 | // SerialiserModule serialiserModule = new SerialiserModule(); | ||
622 | // InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
623 | |||
624 | // // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene | ||
625 | // Scene scene = SceneSetupHelpers.SetupScene(); | ||
626 | // IUserAdminService userAdminService = scene.CommsManager.UserAdminService; | ||
627 | |||
628 | // SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | ||
629 | // userAdminService.AddUser( | ||
630 | // userFirstName, userLastName, "meowfood", String.Empty, 1000, 1000, userUuid); | ||
631 | |||
632 | // archiverModule.DearchiveInventory(userFirstName, userLastName, "/", "troll", archiveReadStream); | ||
633 | |||
634 | // // Check that a suitable temporary user profile has been created. | ||
635 | // UserProfileData user2Profile | ||
636 | // = scene.CommsManager.UserService.GetUserProfile( | ||
637 | // OspResolver.HashName(user2FirstName + " " + user2LastName)); | ||
638 | // Assert.That(user2Profile, Is.Not.Null); | ||
639 | // Assert.That(user2Profile.FirstName == user2FirstName); | ||
640 | // Assert.That(user2Profile.SurName == user2LastName); | ||
641 | |||
642 | // CachedUserInfo userInfo | ||
643 | // = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); | ||
644 | // userInfo.OnInventoryReceived += InventoryReceived; | ||
645 | |||
646 | // lock (this) | ||
647 | // { | ||
648 | // userInfo.FetchInventory(); | ||
649 | // Monitor.Wait(this, 60000); | ||
650 | // } | ||
651 | |||
652 | // InventoryItemBase foundItem = userInfo.RootFolder.FindItemByPath(itemName); | ||
653 | |||
654 | // Assert.That(foundItem.CreatorId, Is.EqualTo(item1.CreatorId)); | ||
655 | // Assert.That( | ||
656 | // foundItem.CreatorIdAsUuid, Is.EqualTo(OspResolver.HashName(user2FirstName + " " + user2LastName))); | ||
657 | // Assert.That(foundItem.Owner, Is.EqualTo(userUuid)); | ||
658 | |||
659 | // Console.WriteLine("### Successfully completed {0} ###", MethodBase.GetCurrentMethod()); | ||
660 | //} | ||
661 | |||
662 | /// <summary> | ||
663 | /// Test replication of an archive path to the user's inventory. | ||
664 | /// </summary> | ||
665 | [Test] | ||
666 | public void TestNewIarPath() | ||
667 | { | ||
668 | TestHelper.InMethod(); | ||
669 | // log4net.Config.XmlConfigurator.Configure(); | ||
670 | |||
671 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
672 | UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene); | ||
673 | |||
674 | Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>(); | ||
675 | HashSet<InventoryNodeBase> nodesLoaded = new HashSet<InventoryNodeBase>(); | ||
676 | |||
677 | string folder1Name = "1"; | ||
678 | string folder2aName = "2a"; | ||
679 | string folder2bName = "2b"; | ||
680 | |||
681 | string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1Name, UUID.Random()); | ||
682 | string folder2aArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2aName, UUID.Random()); | ||
683 | string folder2bArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2bName, UUID.Random()); | ||
684 | |||
685 | string iarPath1 = string.Join("", new string[] { folder1ArchiveName, folder2aArchiveName }); | ||
686 | string iarPath2 = string.Join("", new string[] { folder1ArchiveName, folder2bArchiveName }); | ||
687 | |||
688 | { | ||
689 | // Test replication of path1 | ||
690 | new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false) | ||
691 | .ReplicateArchivePathToUserInventory( | ||
692 | iarPath1, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
693 | foldersCreated, nodesLoaded); | ||
694 | |||
695 | List<InventoryFolderBase> folder1Candidates | ||
696 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1Name); | ||
697 | Assert.That(folder1Candidates.Count, Is.EqualTo(1)); | ||
698 | |||
699 | InventoryFolderBase folder1 = folder1Candidates[0]; | ||
700 | List<InventoryFolderBase> folder2aCandidates | ||
701 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2aName); | ||
702 | Assert.That(folder2aCandidates.Count, Is.EqualTo(1)); | ||
703 | } | ||
704 | |||
705 | { | ||
706 | // Test replication of path2 | ||
707 | new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false) | ||
708 | .ReplicateArchivePathToUserInventory( | ||
709 | iarPath2, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
710 | foldersCreated, nodesLoaded); | ||
711 | |||
712 | List<InventoryFolderBase> folder1Candidates | ||
713 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1Name); | ||
714 | Assert.That(folder1Candidates.Count, Is.EqualTo(1)); | ||
715 | |||
716 | InventoryFolderBase folder1 = folder1Candidates[0]; | ||
717 | |||
718 | List<InventoryFolderBase> folder2aCandidates | ||
719 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2aName); | ||
720 | Assert.That(folder2aCandidates.Count, Is.EqualTo(1)); | ||
721 | |||
722 | List<InventoryFolderBase> folder2bCandidates | ||
723 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2bName); | ||
724 | Assert.That(folder2bCandidates.Count, Is.EqualTo(1)); | ||
725 | } | ||
726 | } | ||
727 | |||
728 | /// <summary> | ||
729 | /// Test replication of a partly existing archive path to the user's inventory. This should create | ||
730 | /// a duplicate path without the merge option. | ||
731 | /// </summary> | ||
732 | [Test] | ||
733 | public void TestPartExistingIarPath() | ||
734 | { | ||
735 | TestHelper.InMethod(); | ||
736 | //log4net.Config.XmlConfigurator.Configure(); | ||
737 | |||
738 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
739 | UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene); | ||
740 | |||
741 | string folder1ExistingName = "a"; | ||
742 | string folder2Name = "b"; | ||
743 | |||
744 | InventoryFolderBase folder1 | ||
745 | = UserInventoryTestUtils.CreateInventoryFolder( | ||
746 | scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
747 | |||
748 | string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random()); | ||
749 | string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random()); | ||
750 | |||
751 | string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName }); | ||
752 | |||
753 | new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false) | ||
754 | .ReplicateArchivePathToUserInventory( | ||
755 | itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
756 | new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>()); | ||
757 | |||
758 | List<InventoryFolderBase> folder1PostCandidates | ||
759 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
760 | Assert.That(folder1PostCandidates.Count, Is.EqualTo(2)); | ||
761 | |||
762 | // FIXME: Temporarily, we're going to do something messy to make sure we pick up the created folder. | ||
763 | InventoryFolderBase folder1Post = null; | ||
764 | foreach (InventoryFolderBase folder in folder1PostCandidates) | ||
765 | { | ||
766 | if (folder.ID != folder1.ID) | ||
767 | { | ||
768 | folder1Post = folder; | ||
769 | break; | ||
770 | } | ||
771 | } | ||
772 | // Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID)); | ||
773 | |||
774 | List<InventoryFolderBase> folder2PostCandidates | ||
775 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1Post, "b"); | ||
776 | Assert.That(folder2PostCandidates.Count, Is.EqualTo(1)); | ||
777 | } | ||
778 | |||
779 | /// <summary> | ||
780 | /// Test replication of a partly existing archive path to the user's inventory. This should create | ||
781 | /// a merged path. | ||
782 | /// </summary> | ||
783 | [Test] | ||
784 | public void TestMergeIarPath() | ||
785 | { | ||
786 | TestHelper.InMethod(); | ||
787 | // log4net.Config.XmlConfigurator.Configure(); | ||
788 | |||
789 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
790 | UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene); | ||
791 | |||
792 | string folder1ExistingName = "a"; | ||
793 | string folder2Name = "b"; | ||
794 | |||
795 | InventoryFolderBase folder1 | ||
796 | = UserInventoryTestUtils.CreateInventoryFolder( | ||
797 | scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
798 | |||
799 | string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random()); | ||
800 | string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random()); | ||
801 | |||
802 | string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName }); | ||
803 | |||
804 | new InventoryArchiveReadRequest(scene, ua1, folder1ExistingName, (Stream)null, true) | ||
805 | .ReplicateArchivePathToUserInventory( | ||
806 | itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
807 | new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>()); | ||
808 | |||
809 | List<InventoryFolderBase> folder1PostCandidates | ||
810 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
811 | Assert.That(folder1PostCandidates.Count, Is.EqualTo(1)); | ||
812 | Assert.That(folder1PostCandidates[0].ID, Is.EqualTo(folder1.ID)); | ||
813 | |||
814 | List<InventoryFolderBase> folder2PostCandidates | ||
815 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1PostCandidates[0], "b"); | ||
816 | Assert.That(folder2PostCandidates.Count, Is.EqualTo(1)); | ||
817 | } | 275 | } |
818 | } | 276 | } |
819 | } \ No newline at end of file | 277 | } \ 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..0e8f647 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs | |||
@@ -0,0 +1,478 @@ | |||
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 | using OpenSim.Tests.Common.Setup; | ||
48 | |||
49 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | ||
50 | { | ||
51 | [TestFixture] | ||
52 | public class PathTests : InventoryArchiveTestCase | ||
53 | { | ||
54 | /// <summary> | ||
55 | /// Test saving an inventory path to a V0.1 OpenSim Inventory Archive | ||
56 | /// (subject to change since there is no fixed format yet). | ||
57 | /// </summary> | ||
58 | [Test] | ||
59 | public void TestSavePathToIarV0_1() | ||
60 | { | ||
61 | TestHelper.InMethod(); | ||
62 | // log4net.Config.XmlConfigurator.Configure(); | ||
63 | |||
64 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
65 | |||
66 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
67 | SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | ||
68 | |||
69 | // Create user | ||
70 | string userFirstName = "Jock"; | ||
71 | string userLastName = "Stirrup"; | ||
72 | string userPassword = "troll"; | ||
73 | UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); | ||
74 | UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, userPassword); | ||
75 | |||
76 | // Create asset | ||
77 | SceneObjectGroup object1; | ||
78 | SceneObjectPart part1; | ||
79 | { | ||
80 | string partName = "My Little Dog Object"; | ||
81 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
82 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
83 | Vector3 groupPosition = new Vector3(10, 20, 30); | ||
84 | Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | ||
85 | Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
86 | |||
87 | part1 = new SceneObjectPart(ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
88 | part1.Name = partName; | ||
89 | |||
90 | object1 = new SceneObjectGroup(part1); | ||
91 | scene.AddNewSceneObject(object1, false); | ||
92 | } | ||
93 | |||
94 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | ||
95 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | ||
96 | scene.AssetService.Store(asset1); | ||
97 | |||
98 | // Create item | ||
99 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | ||
100 | InventoryItemBase item1 = new InventoryItemBase(); | ||
101 | item1.Name = "My Little Dog"; | ||
102 | item1.AssetID = asset1.FullID; | ||
103 | item1.ID = item1Id; | ||
104 | InventoryFolderBase objsFolder | ||
105 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0]; | ||
106 | item1.Folder = objsFolder.ID; | ||
107 | scene.AddInventoryItem(item1); | ||
108 | |||
109 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
110 | archiverModule.OnInventoryArchiveSaved += SaveCompleted; | ||
111 | |||
112 | // Test saving a particular path | ||
113 | mre.Reset(); | ||
114 | archiverModule.ArchiveInventory( | ||
115 | Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); | ||
116 | mre.WaitOne(60000, false); | ||
117 | |||
118 | byte[] archive = archiveWriteStream.ToArray(); | ||
119 | MemoryStream archiveReadStream = new MemoryStream(archive); | ||
120 | TarArchiveReader tar = new TarArchiveReader(archiveReadStream); | ||
121 | |||
122 | //bool gotControlFile = false; | ||
123 | bool gotObject1File = false; | ||
124 | //bool gotObject2File = false; | ||
125 | string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1); | ||
126 | string expectedObject1FilePath = string.Format( | ||
127 | "{0}{1}{2}", | ||
128 | ArchiveConstants.INVENTORY_PATH, | ||
129 | InventoryArchiveWriteRequest.CreateArchiveFolderName(objsFolder), | ||
130 | expectedObject1FileName); | ||
131 | |||
132 | string filePath; | ||
133 | TarArchiveReader.TarEntryType tarEntryType; | ||
134 | |||
135 | // Console.WriteLine("Reading archive"); | ||
136 | |||
137 | while (tar.ReadEntry(out filePath, out tarEntryType) != null) | ||
138 | { | ||
139 | // Console.WriteLine("Got {0}", filePath); | ||
140 | |||
141 | // if (ArchiveConstants.CONTROL_FILE_PATH == filePath) | ||
142 | // { | ||
143 | // gotControlFile = true; | ||
144 | // } | ||
145 | |||
146 | if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml")) | ||
147 | { | ||
148 | // string fileName = filePath.Remove(0, "Objects/".Length); | ||
149 | // | ||
150 | // if (fileName.StartsWith(part1.Name)) | ||
151 | // { | ||
152 | Assert.That(expectedObject1FilePath, Is.EqualTo(filePath)); | ||
153 | gotObject1File = true; | ||
154 | // } | ||
155 | // else if (fileName.StartsWith(part2.Name)) | ||
156 | // { | ||
157 | // Assert.That(fileName, Is.EqualTo(expectedObject2FileName)); | ||
158 | // gotObject2File = true; | ||
159 | // } | ||
160 | } | ||
161 | } | ||
162 | |||
163 | // Assert.That(gotControlFile, Is.True, "No control file in archive"); | ||
164 | Assert.That(gotObject1File, Is.True, "No item1 file in archive"); | ||
165 | // Assert.That(gotObject2File, Is.True, "No object2 file in archive"); | ||
166 | |||
167 | // TODO: Test presence of more files and contents of files. | ||
168 | } | ||
169 | |||
170 | /// <summary> | ||
171 | /// Test loading an IAR to various different inventory paths. | ||
172 | /// </summary> | ||
173 | [Test] | ||
174 | public void TestLoadIarToInventoryPaths() | ||
175 | { | ||
176 | TestHelper.InMethod(); | ||
177 | // log4net.Config.XmlConfigurator.Configure(); | ||
178 | |||
179 | SerialiserModule serialiserModule = new SerialiserModule(); | ||
180 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
181 | |||
182 | // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene | ||
183 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
184 | |||
185 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | ||
186 | |||
187 | UserProfileTestUtils.CreateUserWithInventory(scene, m_uaMT, "meowfood"); | ||
188 | UserProfileTestUtils.CreateUserWithInventory(scene, m_uaLL1, "hampshire"); | ||
189 | |||
190 | archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "/", "meowfood", m_iarStream); | ||
191 | InventoryItemBase foundItem1 | ||
192 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, m_item1Name); | ||
193 | |||
194 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | ||
195 | |||
196 | // Now try loading to a root child folder | ||
197 | UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, m_uaMT.PrincipalID, "xA"); | ||
198 | MemoryStream archiveReadStream = new MemoryStream(m_iarStream.ToArray()); | ||
199 | archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "xA", "meowfood", archiveReadStream); | ||
200 | |||
201 | InventoryItemBase foundItem2 | ||
202 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, "xA/" + m_item1Name); | ||
203 | Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2"); | ||
204 | |||
205 | // Now try loading to a more deeply nested folder | ||
206 | UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, m_uaMT.PrincipalID, "xB/xC"); | ||
207 | archiveReadStream = new MemoryStream(archiveReadStream.ToArray()); | ||
208 | archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "xB/xC", "meowfood", archiveReadStream); | ||
209 | |||
210 | InventoryItemBase foundItem3 | ||
211 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, "xB/xC/" + m_item1Name); | ||
212 | Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3"); | ||
213 | } | ||
214 | |||
215 | /// <summary> | ||
216 | /// Test that things work when the load path specified starts with a slash | ||
217 | /// </summary> | ||
218 | [Test] | ||
219 | public void TestLoadIarPathStartsWithSlash() | ||
220 | { | ||
221 | TestHelper.InMethod(); | ||
222 | // log4net.Config.XmlConfigurator.Configure(); | ||
223 | |||
224 | SerialiserModule serialiserModule = new SerialiserModule(); | ||
225 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
226 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
227 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | ||
228 | |||
229 | UserProfileTestUtils.CreateUserWithInventory(scene, m_uaMT, "password"); | ||
230 | archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "/Objects", "password", m_iarStream); | ||
231 | |||
232 | InventoryItemBase foundItem1 | ||
233 | = InventoryArchiveUtils.FindItemByPath( | ||
234 | scene.InventoryService, m_uaMT.PrincipalID, "/Objects/" + m_item1Name); | ||
235 | |||
236 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1 in TestLoadIarFolderStartsWithSlash()"); | ||
237 | } | ||
238 | |||
239 | [Test] | ||
240 | public void TestLoadIarPathWithEscapedChars() | ||
241 | { | ||
242 | TestHelper.InMethod(); | ||
243 | // log4net.Config.XmlConfigurator.Configure(); | ||
244 | |||
245 | string itemName = "You & you are a mean/man/"; | ||
246 | string humanEscapedItemName = @"You & you are a mean\/man\/"; | ||
247 | string userPassword = "meowfood"; | ||
248 | |||
249 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | ||
250 | |||
251 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
252 | SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | ||
253 | |||
254 | // Create user | ||
255 | string userFirstName = "Jock"; | ||
256 | string userLastName = "Stirrup"; | ||
257 | UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); | ||
258 | UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "meowfood"); | ||
259 | |||
260 | // Create asset | ||
261 | SceneObjectGroup object1; | ||
262 | SceneObjectPart part1; | ||
263 | { | ||
264 | string partName = "part name"; | ||
265 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
266 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
267 | Vector3 groupPosition = new Vector3(10, 20, 30); | ||
268 | Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | ||
269 | Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
270 | |||
271 | part1 | ||
272 | = new SceneObjectPart( | ||
273 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
274 | part1.Name = partName; | ||
275 | |||
276 | object1 = new SceneObjectGroup(part1); | ||
277 | scene.AddNewSceneObject(object1, false); | ||
278 | } | ||
279 | |||
280 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | ||
281 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | ||
282 | scene.AssetService.Store(asset1); | ||
283 | |||
284 | // Create item | ||
285 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | ||
286 | InventoryItemBase item1 = new InventoryItemBase(); | ||
287 | item1.Name = itemName; | ||
288 | item1.AssetID = asset1.FullID; | ||
289 | item1.ID = item1Id; | ||
290 | InventoryFolderBase objsFolder | ||
291 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0]; | ||
292 | item1.Folder = objsFolder.ID; | ||
293 | scene.AddInventoryItem(item1); | ||
294 | |||
295 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
296 | archiverModule.OnInventoryArchiveSaved += SaveCompleted; | ||
297 | |||
298 | mre.Reset(); | ||
299 | archiverModule.ArchiveInventory( | ||
300 | Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); | ||
301 | mre.WaitOne(60000, false); | ||
302 | |||
303 | // LOAD ITEM | ||
304 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
305 | |||
306 | archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", userPassword, archiveReadStream); | ||
307 | |||
308 | InventoryItemBase foundItem1 | ||
309 | = InventoryArchiveUtils.FindItemByPath( | ||
310 | scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName); | ||
311 | |||
312 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | ||
313 | // Assert.That( | ||
314 | // foundItem1.CreatorId, Is.EqualTo(userUuid), | ||
315 | // "Loaded item non-uuid creator doesn't match that of the loading user"); | ||
316 | Assert.That( | ||
317 | foundItem1.Name, Is.EqualTo(itemName), | ||
318 | "Loaded item name doesn't match saved name"); | ||
319 | } | ||
320 | |||
321 | /// <summary> | ||
322 | /// Test replication of an archive path to the user's inventory. | ||
323 | /// </summary> | ||
324 | [Test] | ||
325 | public void TestNewIarPath() | ||
326 | { | ||
327 | TestHelper.InMethod(); | ||
328 | // log4net.Config.XmlConfigurator.Configure(); | ||
329 | |||
330 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
331 | UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene); | ||
332 | |||
333 | Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>(); | ||
334 | HashSet<InventoryNodeBase> nodesLoaded = new HashSet<InventoryNodeBase>(); | ||
335 | |||
336 | string folder1Name = "1"; | ||
337 | string folder2aName = "2a"; | ||
338 | string folder2bName = "2b"; | ||
339 | |||
340 | string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1Name, UUID.Random()); | ||
341 | string folder2aArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2aName, UUID.Random()); | ||
342 | string folder2bArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2bName, UUID.Random()); | ||
343 | |||
344 | string iarPath1 = string.Join("", new string[] { folder1ArchiveName, folder2aArchiveName }); | ||
345 | string iarPath2 = string.Join("", new string[] { folder1ArchiveName, folder2bArchiveName }); | ||
346 | |||
347 | { | ||
348 | // Test replication of path1 | ||
349 | new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false) | ||
350 | .ReplicateArchivePathToUserInventory( | ||
351 | iarPath1, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
352 | foldersCreated, nodesLoaded); | ||
353 | |||
354 | List<InventoryFolderBase> folder1Candidates | ||
355 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1Name); | ||
356 | Assert.That(folder1Candidates.Count, Is.EqualTo(1)); | ||
357 | |||
358 | InventoryFolderBase folder1 = folder1Candidates[0]; | ||
359 | List<InventoryFolderBase> folder2aCandidates | ||
360 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2aName); | ||
361 | Assert.That(folder2aCandidates.Count, Is.EqualTo(1)); | ||
362 | } | ||
363 | |||
364 | { | ||
365 | // Test replication of path2 | ||
366 | new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false) | ||
367 | .ReplicateArchivePathToUserInventory( | ||
368 | iarPath2, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
369 | foldersCreated, nodesLoaded); | ||
370 | |||
371 | List<InventoryFolderBase> folder1Candidates | ||
372 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1Name); | ||
373 | Assert.That(folder1Candidates.Count, Is.EqualTo(1)); | ||
374 | |||
375 | InventoryFolderBase folder1 = folder1Candidates[0]; | ||
376 | |||
377 | List<InventoryFolderBase> folder2aCandidates | ||
378 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2aName); | ||
379 | Assert.That(folder2aCandidates.Count, Is.EqualTo(1)); | ||
380 | |||
381 | List<InventoryFolderBase> folder2bCandidates | ||
382 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2bName); | ||
383 | Assert.That(folder2bCandidates.Count, Is.EqualTo(1)); | ||
384 | } | ||
385 | } | ||
386 | |||
387 | /// <summary> | ||
388 | /// Test replication of a partly existing archive path to the user's inventory. This should create | ||
389 | /// a duplicate path without the merge option. | ||
390 | /// </summary> | ||
391 | [Test] | ||
392 | public void TestPartExistingIarPath() | ||
393 | { | ||
394 | TestHelper.InMethod(); | ||
395 | //log4net.Config.XmlConfigurator.Configure(); | ||
396 | |||
397 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
398 | UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene); | ||
399 | |||
400 | string folder1ExistingName = "a"; | ||
401 | string folder2Name = "b"; | ||
402 | |||
403 | InventoryFolderBase folder1 | ||
404 | = UserInventoryTestUtils.CreateInventoryFolder( | ||
405 | scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
406 | |||
407 | string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random()); | ||
408 | string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random()); | ||
409 | |||
410 | string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName }); | ||
411 | |||
412 | new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false) | ||
413 | .ReplicateArchivePathToUserInventory( | ||
414 | itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
415 | new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>()); | ||
416 | |||
417 | List<InventoryFolderBase> folder1PostCandidates | ||
418 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
419 | Assert.That(folder1PostCandidates.Count, Is.EqualTo(2)); | ||
420 | |||
421 | // FIXME: Temporarily, we're going to do something messy to make sure we pick up the created folder. | ||
422 | InventoryFolderBase folder1Post = null; | ||
423 | foreach (InventoryFolderBase folder in folder1PostCandidates) | ||
424 | { | ||
425 | if (folder.ID != folder1.ID) | ||
426 | { | ||
427 | folder1Post = folder; | ||
428 | break; | ||
429 | } | ||
430 | } | ||
431 | // Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID)); | ||
432 | |||
433 | List<InventoryFolderBase> folder2PostCandidates | ||
434 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1Post, "b"); | ||
435 | Assert.That(folder2PostCandidates.Count, Is.EqualTo(1)); | ||
436 | } | ||
437 | |||
438 | /// <summary> | ||
439 | /// Test replication of a partly existing archive path to the user's inventory. This should create | ||
440 | /// a merged path. | ||
441 | /// </summary> | ||
442 | [Test] | ||
443 | public void TestMergeIarPath() | ||
444 | { | ||
445 | TestHelper.InMethod(); | ||
446 | // log4net.Config.XmlConfigurator.Configure(); | ||
447 | |||
448 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | ||
449 | UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene); | ||
450 | |||
451 | string folder1ExistingName = "a"; | ||
452 | string folder2Name = "b"; | ||
453 | |||
454 | InventoryFolderBase folder1 | ||
455 | = UserInventoryTestUtils.CreateInventoryFolder( | ||
456 | scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
457 | |||
458 | string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random()); | ||
459 | string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random()); | ||
460 | |||
461 | string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName }); | ||
462 | |||
463 | new InventoryArchiveReadRequest(scene, ua1, folder1ExistingName, (Stream)null, true) | ||
464 | .ReplicateArchivePathToUserInventory( | ||
465 | itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID), | ||
466 | new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>()); | ||
467 | |||
468 | List<InventoryFolderBase> folder1PostCandidates | ||
469 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName); | ||
470 | Assert.That(folder1PostCandidates.Count, Is.EqualTo(1)); | ||
471 | Assert.That(folder1PostCandidates[0].ID, Is.EqualTo(folder1.ID)); | ||
472 | |||
473 | List<InventoryFolderBase> folder2PostCandidates | ||
474 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1PostCandidates[0], "b"); | ||
475 | Assert.That(folder2PostCandidates.Count, Is.EqualTo(1)); | ||
476 | } | ||
477 | } | ||
478 | } \ No newline at end of file | ||