diff options
Diffstat (limited to 'OpenSim/Tests/Robust/Clients/Inventory/InventoryClient.cs')
-rw-r--r-- | OpenSim/Tests/Robust/Clients/Inventory/InventoryClient.cs | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/OpenSim/Tests/Robust/Clients/Inventory/InventoryClient.cs b/OpenSim/Tests/Robust/Clients/Inventory/InventoryClient.cs new file mode 100644 index 0000000..0280b73 --- /dev/null +++ b/OpenSim/Tests/Robust/Clients/Inventory/InventoryClient.cs | |||
@@ -0,0 +1,206 @@ | |||
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.Text; | ||
31 | using System.Reflection; | ||
32 | |||
33 | using OpenMetaverse; | ||
34 | using NUnit.Framework; | ||
35 | |||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Services.Connectors; | ||
39 | |||
40 | using OpenSim.Tests.Common; | ||
41 | |||
42 | namespace Robust.Tests | ||
43 | { | ||
44 | [TestFixture] | ||
45 | public class InventoryClient | ||
46 | { | ||
47 | // private static readonly ILog m_log = | ||
48 | // LogManager.GetLogger( | ||
49 | // MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private UUID m_userID = new UUID("00000000-0000-0000-0000-333333333333"); | ||
52 | private UUID m_rootFolderID; | ||
53 | private UUID m_notecardsFolder; | ||
54 | private UUID m_objectsFolder; | ||
55 | |||
56 | [Test] | ||
57 | public void Inventory_001_CreateInventory() | ||
58 | { | ||
59 | TestHelpers.InMethod(); | ||
60 | XInventoryServicesConnector m_Connector = new XInventoryServicesConnector(DemonServer.Address); | ||
61 | |||
62 | // Create an inventory that looks like this: | ||
63 | // | ||
64 | // /My Inventory | ||
65 | // <other system folders> | ||
66 | // /Objects | ||
67 | // Some Object | ||
68 | // /Notecards | ||
69 | // Notecard 1 | ||
70 | // Notecard 2 | ||
71 | // /Test Folder | ||
72 | // Link to notecard -> /Notecards/Notecard 2 | ||
73 | // Link to Objects folder -> /Objects | ||
74 | |||
75 | bool success = m_Connector.CreateUserInventory(m_userID); | ||
76 | Assert.IsTrue(success, "Failed to create user inventory"); | ||
77 | |||
78 | m_rootFolderID = m_Connector.GetRootFolder(m_userID).ID; | ||
79 | Assert.AreNotEqual(m_rootFolderID, UUID.Zero, "Root folder ID must not be UUID.Zero"); | ||
80 | |||
81 | InventoryFolderBase of = m_Connector.GetFolderForType(m_userID, FolderType.Object); | ||
82 | Assert.IsNotNull(of, "Failed to retrieve Objects folder"); | ||
83 | m_objectsFolder = of.ID; | ||
84 | Assert.AreNotEqual(m_objectsFolder, UUID.Zero, "Objects folder ID must not be UUID.Zero"); | ||
85 | |||
86 | // Add an object | ||
87 | InventoryItemBase item = new InventoryItemBase(new UUID("b0000000-0000-0000-0000-00000000000b"), m_userID); | ||
88 | item.AssetID = UUID.Random(); | ||
89 | item.AssetType = (int)AssetType.Object; | ||
90 | item.Folder = m_objectsFolder; | ||
91 | item.Name = "Some Object"; | ||
92 | item.Description = string.Empty; | ||
93 | success = m_Connector.AddItem(item); | ||
94 | Assert.IsTrue(success, "Failed to add object to inventory"); | ||
95 | |||
96 | InventoryFolderBase ncf = m_Connector.GetFolderForType(m_userID, FolderType.Notecard); | ||
97 | Assert.IsNotNull(of, "Failed to retrieve Notecards folder"); | ||
98 | m_notecardsFolder = ncf.ID; | ||
99 | Assert.AreNotEqual(m_notecardsFolder, UUID.Zero, "Notecards folder ID must not be UUID.Zero"); | ||
100 | m_notecardsFolder = ncf.ID; | ||
101 | |||
102 | // Add a notecard | ||
103 | item = new InventoryItemBase(new UUID("10000000-0000-0000-0000-000000000001"), m_userID); | ||
104 | item.AssetID = UUID.Random(); | ||
105 | item.AssetType = (int)AssetType.Notecard; | ||
106 | item.Folder = m_notecardsFolder; | ||
107 | item.Name = "Test Notecard 1"; | ||
108 | item.Description = string.Empty; | ||
109 | success = m_Connector.AddItem(item); | ||
110 | Assert.IsTrue(success, "Failed to add Notecard 1 to inventory"); | ||
111 | // Add another notecard | ||
112 | item.ID = new UUID("20000000-0000-0000-0000-000000000002"); | ||
113 | item.AssetID = new UUID("a0000000-0000-0000-0000-00000000000a"); | ||
114 | item.Name = "Test Notecard 2"; | ||
115 | item.Description = string.Empty; | ||
116 | success = m_Connector.AddItem(item); | ||
117 | Assert.IsTrue(success, "Failed to add Notecard 2 to inventory"); | ||
118 | |||
119 | // Add a folder | ||
120 | InventoryFolderBase folder = new InventoryFolderBase(new UUID("f0000000-0000-0000-0000-00000000000f"), "Test Folder", m_userID, m_rootFolderID); | ||
121 | folder.Type = (int)FolderType.None; | ||
122 | success = m_Connector.AddFolder(folder); | ||
123 | Assert.IsTrue(success, "Failed to add Test Folder to inventory"); | ||
124 | |||
125 | // Add a link to notecard 2 in Test Folder | ||
126 | item.AssetID = item.ID; // use item ID of notecard 2 | ||
127 | item.ID = new UUID("40000000-0000-0000-0000-000000000004"); | ||
128 | item.AssetType = (int)AssetType.Link; | ||
129 | item.Folder = folder.ID; | ||
130 | item.Name = "Link to notecard"; | ||
131 | item.Description = string.Empty; | ||
132 | success = m_Connector.AddItem(item); | ||
133 | Assert.IsTrue(success, "Failed to add link to notecard to inventory"); | ||
134 | |||
135 | // Add a link to the Objects folder in Test Folder | ||
136 | item.AssetID = m_Connector.GetFolderForType(m_userID, FolderType.Object).ID; // use item ID of Objects folder | ||
137 | item.ID = new UUID("50000000-0000-0000-0000-000000000005"); | ||
138 | item.AssetType = (int)AssetType.LinkFolder; | ||
139 | item.Folder = folder.ID; | ||
140 | item.Name = "Link to Objects folder"; | ||
141 | item.Description = string.Empty; | ||
142 | success = m_Connector.AddItem(item); | ||
143 | Assert.IsTrue(success, "Failed to add link to objects folder to inventory"); | ||
144 | |||
145 | InventoryCollection coll = m_Connector.GetFolderContent(m_userID, m_rootFolderID); | ||
146 | Assert.IsNotNull(coll, "Failed to retrieve contents of root folder"); | ||
147 | Assert.Greater(coll.Folders.Count, 0, "Root folder does not have any subfolders"); | ||
148 | |||
149 | coll = m_Connector.GetFolderContent(m_userID, folder.ID); | ||
150 | Assert.IsNotNull(coll, "Failed to retrieve contents of Test Folder"); | ||
151 | Assert.AreEqual(coll.Items.Count + coll.Folders.Count, 2, "Test Folder is expected to have exactly 2 things inside"); | ||
152 | |||
153 | } | ||
154 | |||
155 | [Test] | ||
156 | public void Inventory_002_MultipleItemsRequest() | ||
157 | { | ||
158 | TestHelpers.InMethod(); | ||
159 | XInventoryServicesConnector m_Connector = new XInventoryServicesConnector(DemonServer.Address); | ||
160 | |||
161 | // Prefetch Notecard 1, will be cached from here on | ||
162 | InventoryItemBase item = new InventoryItemBase(new UUID("10000000-0000-0000-0000-000000000001"), m_userID); | ||
163 | item = m_Connector.GetItem(item); | ||
164 | Assert.NotNull(item, "Failed to get Notecard 1"); | ||
165 | Assert.AreEqual("Test Notecard 1", item.Name, "Wrong name for Notecard 1"); | ||
166 | |||
167 | UUID[] uuids = new UUID[2]; | ||
168 | uuids[0] = item.ID; | ||
169 | uuids[1] = new UUID("20000000-0000-0000-0000-000000000002"); | ||
170 | |||
171 | InventoryItemBase[] items = m_Connector.GetMultipleItems(m_userID, uuids); | ||
172 | Assert.NotNull(items, "Failed to get multiple items"); | ||
173 | Assert.IsTrue(items.Length == 2, "Requested 2 items, but didn't receive 2 items"); | ||
174 | |||
175 | // Now they should both be cached | ||
176 | items = m_Connector.GetMultipleItems(m_userID, uuids); | ||
177 | Assert.NotNull(items, "(Repeat) Failed to get multiple items"); | ||
178 | Assert.IsTrue(items.Length == 2, "(Repeat) Requested 2 items, but didn't receive 2 items"); | ||
179 | |||
180 | // This item doesn't exist, but [0] does, and it's cached. | ||
181 | uuids[1] = new UUID("bb000000-0000-0000-0000-0000000000bb"); | ||
182 | // Fetching should return 2 items, but [1] should be null | ||
183 | items = m_Connector.GetMultipleItems(m_userID, uuids); | ||
184 | Assert.NotNull(items, "(Three times) Failed to get multiple items"); | ||
185 | Assert.IsTrue(items.Length == 2, "(Three times) Requested 2 items, but didn't receive 2 items"); | ||
186 | Assert.AreEqual("Test Notecard 1", items[0].Name, "(Three times) Wrong name for Notecard 1"); | ||
187 | Assert.IsNull(items[1], "(Three times) Expecting 2nd item to be null"); | ||
188 | |||
189 | // Now both don't exist | ||
190 | uuids[0] = new UUID("aa000000-0000-0000-0000-0000000000aa"); | ||
191 | items = m_Connector.GetMultipleItems(m_userID, uuids); | ||
192 | Assert.Null(items[0], "Request to multiple non-existent items is supposed to return null [0]"); | ||
193 | Assert.Null(items[1], "Request to multiple non-existent items is supposed to return null [1]"); | ||
194 | |||
195 | // This item exists, and it's not cached | ||
196 | uuids[1] = new UUID("b0000000-0000-0000-0000-00000000000b"); | ||
197 | // Fetching should return 2 items, but [0] should be null | ||
198 | items = m_Connector.GetMultipleItems(m_userID, uuids); | ||
199 | Assert.NotNull(items, "(Four times) Failed to get multiple items"); | ||
200 | Assert.IsTrue(items.Length == 2, "(Four times) Requested 2 items, but didn't receive 2 items"); | ||
201 | Assert.AreEqual("Some Object", items[1].Name, "(Four times) Wrong name for Some Object"); | ||
202 | Assert.IsNull(items[0], "(Four times) Expecting 1st item to be null"); | ||
203 | |||
204 | } | ||
205 | } | ||
206 | } | ||