diff options
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventory2HandlerTests.cs | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventory2HandlerTests.cs b/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventory2HandlerTests.cs new file mode 100644 index 0000000..653e791 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventory2HandlerTests.cs | |||
@@ -0,0 +1,170 @@ | |||
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.Linq; | ||
31 | using System.Net; | ||
32 | using System.Text.RegularExpressions; | ||
33 | using log4net; | ||
34 | using log4net.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Capabilities.Handlers; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using OpenSim.Tests.Common; | ||
43 | |||
44 | namespace OpenSim.Capabilities.Handlers.FetchInventory.Tests | ||
45 | { | ||
46 | [TestFixture] | ||
47 | public class FetchInventory2HandlerTests : OpenSimTestCase | ||
48 | { | ||
49 | private UUID m_userID = UUID.Random(); | ||
50 | private Scene m_scene; | ||
51 | private UUID m_rootFolderID; | ||
52 | private UUID m_notecardsFolder; | ||
53 | private UUID m_objectsFolder; | ||
54 | |||
55 | private void Init() | ||
56 | { | ||
57 | // Create an inventory that looks like this: | ||
58 | // | ||
59 | // /My Inventory | ||
60 | // <other system folders> | ||
61 | // /Objects | ||
62 | // Object 1 | ||
63 | // Object 2 | ||
64 | // Object 3 | ||
65 | // /Notecards | ||
66 | // Notecard 1 | ||
67 | // Notecard 2 | ||
68 | // Notecard 3 | ||
69 | // Notecard 4 | ||
70 | // Notecard 5 | ||
71 | |||
72 | m_scene = new SceneHelpers().SetupScene(); | ||
73 | |||
74 | m_scene.InventoryService.CreateUserInventory(m_userID); | ||
75 | |||
76 | m_rootFolderID = m_scene.InventoryService.GetRootFolder(m_userID).ID; | ||
77 | |||
78 | InventoryFolderBase of = m_scene.InventoryService.GetFolderForType(m_userID, AssetType.Object); | ||
79 | m_objectsFolder = of.ID; | ||
80 | |||
81 | // Add 3 objects | ||
82 | InventoryItemBase item; | ||
83 | for (int i = 1; i <= 3; i++) | ||
84 | { | ||
85 | item = new InventoryItemBase(new UUID("b0000000-0000-0000-0000-0000000000b" + i), m_userID); | ||
86 | item.AssetID = UUID.Random(); | ||
87 | item.AssetType = (int)AssetType.Object; | ||
88 | item.Folder = m_objectsFolder; | ||
89 | item.Name = "Object " + i; | ||
90 | m_scene.InventoryService.AddItem(item); | ||
91 | } | ||
92 | |||
93 | InventoryFolderBase ncf = m_scene.InventoryService.GetFolderForType(m_userID, AssetType.Notecard); | ||
94 | m_notecardsFolder = ncf.ID; | ||
95 | |||
96 | // Add 5 notecards | ||
97 | for (int i = 1; i <= 5; i++) | ||
98 | { | ||
99 | item = new InventoryItemBase(new UUID("10000000-0000-0000-0000-00000000000" + i), m_userID); | ||
100 | item.AssetID = UUID.Random(); | ||
101 | item.AssetType = (int)AssetType.Notecard; | ||
102 | item.Folder = m_notecardsFolder; | ||
103 | item.Name = "Notecard " + i; | ||
104 | m_scene.InventoryService.AddItem(item); | ||
105 | } | ||
106 | |||
107 | } | ||
108 | |||
109 | [Test] | ||
110 | public void Test_001_RequestOne() | ||
111 | { | ||
112 | TestHelpers.InMethod(); | ||
113 | |||
114 | Init(); | ||
115 | |||
116 | FetchInventory2Handler handler = new FetchInventory2Handler(m_scene.InventoryService, m_userID); | ||
117 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
118 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
119 | |||
120 | string request = "<llsd><map><key>items</key><array><map><key>item_id</key><uuid>"; | ||
121 | request += "10000000-0000-0000-0000-000000000001"; // Notecard 1 | ||
122 | request += "</uuid></map></array></map></llsd>"; | ||
123 | |||
124 | string llsdresponse = handler.FetchInventoryRequest(request, "/FETCH", string.Empty, req, resp); | ||
125 | |||
126 | Assert.That(llsdresponse != null, Is.True, "Incorrect null response"); | ||
127 | Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response"); | ||
128 | Assert.That(llsdresponse.Contains(m_userID.ToString()), Is.True, "Response should contain userID"); | ||
129 | |||
130 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000001"), Is.True, "Response does not contain item uuid"); | ||
131 | Assert.That(llsdresponse.Contains("Notecard 1"), Is.True, "Response does not contain item Name"); | ||
132 | Console.WriteLine(llsdresponse); | ||
133 | } | ||
134 | |||
135 | [Test] | ||
136 | public void Test_002_RequestMany() | ||
137 | { | ||
138 | TestHelpers.InMethod(); | ||
139 | |||
140 | Init(); | ||
141 | |||
142 | FetchInventory2Handler handler = new FetchInventory2Handler(m_scene.InventoryService, m_userID); | ||
143 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
144 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
145 | |||
146 | string request = "<llsd><map><key>items</key><array>"; | ||
147 | request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000001</uuid></map>"; // Notecard 1 | ||
148 | request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000002</uuid></map>"; // Notecard 2 | ||
149 | request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000003</uuid></map>"; // Notecard 3 | ||
150 | request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000004</uuid></map>"; // Notecard 4 | ||
151 | request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000005</uuid></map>"; // Notecard 5 | ||
152 | request += "</array></map></llsd>"; | ||
153 | |||
154 | string llsdresponse = handler.FetchInventoryRequest(request, "/FETCH", string.Empty, req, resp); | ||
155 | |||
156 | Assert.That(llsdresponse != null, Is.True, "Incorrect null response"); | ||
157 | Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response"); | ||
158 | Assert.That(llsdresponse.Contains(m_userID.ToString()), Is.True, "Response should contain userID"); | ||
159 | |||
160 | Console.WriteLine(llsdresponse); | ||
161 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000001"), Is.True, "Response does not contain notecard 1"); | ||
162 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000002"), Is.True, "Response does not contain notecard 2"); | ||
163 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000003"), Is.True, "Response does not contain notecard 3"); | ||
164 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000004"), Is.True, "Response does not contain notecard 4"); | ||
165 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000005"), Is.True, "Response does not contain notecard 5"); | ||
166 | } | ||
167 | |||
168 | } | ||
169 | |||
170 | } \ No newline at end of file | ||