aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs')
-rw-r--r--OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs115
1 files changed, 115 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
new file mode 100644
index 0000000..0419134
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/UserInventoryHelpers.cs
@@ -0,0 +1,115 @@
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
28using System;
29using OpenMetaverse;
30using OpenSim.Framework;
31using OpenSim.Region.Framework.Scenes;
32using OpenSim.Services.Interfaces;
33
34namespace OpenSim.Tests.Common
35{
36 /// <summary>
37 /// Utility functions for carrying out user inventory tests.
38 /// </summary>
39 public static class UserInventoryHelpers
40 {
41 public static readonly string PATH_DELIMITER = "/";
42
43 public static InventoryItemBase CreateInventoryItem(
44 Scene scene, string itemName, UUID itemId, string folderPath, UUID userId)
45 {
46 InventoryItemBase item = new InventoryItemBase();
47 item.Name = itemName;
48 item.AssetID = AssetHelpers.CreateAsset(scene, userId).FullID;
49 item.ID = itemId;
50
51 // Really quite bad since the objs folder could be moved in the future and confuse the tests
52 InventoryFolderBase objsFolder = scene.InventoryService.GetFolderForType(userId, AssetType.Object);
53
54 item.Folder = objsFolder.ID;
55 scene.AddInventoryItem(item);
56
57 return item;
58 }
59
60 /// <summary>
61 /// Create inventory folders starting from the user's root folder.
62 /// </summary>
63 ///
64 /// Ignores any existing folders with the same name
65 ///
66 /// <param name="inventoryService"></param>
67 /// <param name="userId"></param>
68 /// <param name="path">
69 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER
70 /// </param>
71 /// <returns>
72 /// The folder created. If the path contains multiple folders then the last one created is returned.
73 /// Will return null if the root folder could not be found.
74 /// </returns>
75 public static InventoryFolderBase CreateInventoryFolder(
76 IInventoryService inventoryService, UUID userId, string path)
77 {
78 InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId);
79
80 if (null == rootFolder)
81 return null;
82
83 return CreateInventoryFolder(inventoryService, rootFolder, path);
84 }
85
86 /// <summary>
87 /// Create inventory folders starting from a given parent folder
88 /// </summary>
89 ///
90 /// Ignores any existing folders with the same name
91 ///
92 /// <param name="inventoryService"></param>
93 /// <param name="parentFolder"></param>
94 /// <param name="path">
95 /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER
96 /// </param>
97 /// <returns>
98 /// The folder created. If the path contains multiple folders then the last one created is returned.
99 /// </returns>
100 public static InventoryFolderBase CreateInventoryFolder(
101 IInventoryService inventoryService, InventoryFolderBase parentFolder, string path)
102 {
103 string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
104
105 InventoryFolderBase newFolder
106 = new InventoryFolderBase(UUID.Random(), components[0], parentFolder.Owner, parentFolder.ID);
107 inventoryService.AddFolder(newFolder);
108
109 if (components.Length > 1)
110 return CreateInventoryFolder(inventoryService, newFolder, components[1]);
111 else
112 return newFolder;
113 }
114 }
115} \ No newline at end of file