aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs135
-rw-r--r--OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs36
-rw-r--r--OpenSim/Tests/Common/Setup/BaseRequestHandlerTestHelper.cs12
-rw-r--r--OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs122
4 files changed, 2 insertions, 303 deletions
diff --git a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs
deleted file mode 100644
index be3f518..0000000
--- a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs
+++ /dev/null
@@ -1,135 +0,0 @@
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 System.Collections.Generic;
30using System.Net;
31using System.Text;
32using HttpServer;
33using NUnit.Framework;
34using OpenSim.Data;
35using OpenSim.Framework.Servers.HttpServer;
36using OpenSim.Tests.Common;
37using OpenSim.Tests.Common.Mock;
38using OpenSim.Tests.Common.Setup;
39
40namespace OpenSim.Framework.Servers.Tests
41{
42 [TestFixture]
43 public class GetAssetStreamHandlerTests
44 {
45 private const string ASSETS_PATH = "/assets";
46
47 [Test]
48 public void TestConstructor()
49 {
50 TestHelper.InMethod();
51
52 // GetAssetStreamHandler handler =
53 new GetAssetStreamHandler(null);
54 }
55
56 [Test]
57 public void TestGetParams()
58 {
59 TestHelper.InMethod();
60
61 GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
62 BaseRequestHandlerTestHelper.BaseTestGetParams(handler, ASSETS_PATH);
63 }
64
65 [Test]
66 public void TestSplitParams()
67 {
68 TestHelper.InMethod();
69
70 GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
71 BaseRequestHandlerTestHelper.BaseTestSplitParams(handler, ASSETS_PATH);
72 }
73
74 [Test]
75 public void TestHandleNoParams()
76 {
77 TestHelper.InMethod();
78
79 GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
80
81 BaseRequestHandlerTestHelper.BaseTestHandleNoParams(handler, ASSETS_PATH);
82 }
83
84 [Test]
85 public void TestHandleMalformedGuid()
86 {
87 TestHelper.InMethod();
88
89 GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
90
91 BaseRequestHandlerTestHelper.BaseTestHandleMalformedGuid(handler, ASSETS_PATH);
92 }
93
94 [Test]
95 public void TestHandleFetchMissingAsset()
96 {
97 GetAssetStreamHandler handler;
98 OSHttpResponse response;
99 CreateTestEnvironment(out handler, out response);
100
101 GetAssetStreamHandlerTestHelpers.BaseFetchMissingAsset(handler, response);
102 }
103
104 [Test]
105 public void TestHandleFetchExistingAssetData()
106 {
107 GetAssetStreamHandler handler;
108 OSHttpResponse response;
109 AssetBase asset = CreateTestEnvironment(out handler, out response);
110
111 GetAssetStreamHandlerTestHelpers.BaseFetchExistingAssetDataTest(asset, handler, response);
112 }
113
114 [Test]
115 public void TestHandleFetchExistingAssetXml()
116 {
117 GetAssetStreamHandler handler;
118 OSHttpResponse response;
119 AssetBase asset = CreateTestEnvironment(out handler, out response);
120
121 GetAssetStreamHandlerTestHelpers.BaseFetchExistingAssetXmlTest(asset, handler, response);
122 }
123
124 private static AssetBase CreateTestEnvironment(out GetAssetStreamHandler handler, out OSHttpResponse response)
125 {
126 AssetBase asset = GetAssetStreamHandlerTestHelpers.CreateCommonTestResources(out response);
127
128 IAssetDataPlugin assetDataPlugin = new TestAssetDataPlugin();
129 handler = new GetAssetStreamHandler(assetDataPlugin);
130
131 assetDataPlugin.StoreAsset(asset);
132 return asset;
133 }
134 }
135}
diff --git a/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs b/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs
index cef678d..5443891 100644
--- a/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs
@@ -236,42 +236,8 @@ namespace OpenSim.Services.Connectors
236 } 236 }
237 catch (Exception e) 237 catch (Exception e)
238 { 238 {
239 // Maybe we're talking to an old inventory server. Try this other thing. 239 m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetFolderContent operation failed, {0} {1} (old server?).",
240 m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetFolderContent operation failed, {0} {1} (old server?). Trying GetInventory.",
241 e.Source, e.Message); 240 e.Source, e.Message);
242
243 InventoryCollection inventory;
244 List<InventoryFolderBase> folders = null;
245 try
246 {
247 inventory = SynchronousRestSessionObjectPoster<Guid, InventoryCollection>.BeginPostObject(
248 "POST", m_ServerURI + "/GetInventory/", new Guid(userID), sessionID.ToString(), userID.ToString());
249 if (inventory != null)
250 folders = inventory.Folders;
251 }
252 catch (Exception ex)
253 {
254 m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetInventory operation also failed, {0} {1}. Giving up.",
255 e.Source, ex.Message);
256 return new InventoryCollection();
257 }
258
259 if ((folders != null) && (folders.Count > 0))
260 {
261 m_log.DebugFormat("[INVENTORY CONNECTOR]: Received entire inventory ({0} folders) for user {1}",
262 folders.Count, userID);
263
264 folders = folders.FindAll(delegate(InventoryFolderBase f) { return f.ParentID == folderID; });
265 List<InventoryItemBase> items = inventory.Items;
266 if (items != null)
267 {
268 items = items.FindAll(delegate(InventoryItemBase i) { return i.Folder == folderID; });
269 }
270
271 inventory.Items = items;
272 inventory.Folders = folders;
273 return inventory;
274 }
275 } 241 }
276 242
277 InventoryCollection nullCollection = new InventoryCollection(); 243 InventoryCollection nullCollection = new InventoryCollection();
diff --git a/OpenSim/Tests/Common/Setup/BaseRequestHandlerTestHelper.cs b/OpenSim/Tests/Common/Setup/BaseRequestHandlerTestHelper.cs
index e858371..eaf8b39 100644
--- a/OpenSim/Tests/Common/Setup/BaseRequestHandlerTestHelper.cs
+++ b/OpenSim/Tests/Common/Setup/BaseRequestHandlerTestHelper.cs
@@ -72,15 +72,5 @@ namespace OpenSim.Tests.Common.Setup
72 72
73 public static byte[] EmptyByteArray = new byte[] {}; 73 public static byte[] EmptyByteArray = new byte[] {};
74 74
75 public static void BaseTestHandleNoParams(BaseGetAssetStreamHandler handler, string assetsPath)
76 {
77 Assert.AreEqual(EmptyByteArray, handler.Handle(assetsPath, null, null, null), "Failed on empty params.");
78 Assert.AreEqual(EmptyByteArray, handler.Handle(assetsPath + "/", null, null, null), "Failed on single slash.");
79 }
80
81 public static void BaseTestHandleMalformedGuid(BaseGetAssetStreamHandler handler, string assetsPath)
82 {
83 Assert.AreEqual(EmptyByteArray, handler.Handle(assetsPath + "/badGuid", null, null, null), "Failed on bad guid.");
84 }
85 } 75 }
86} \ No newline at end of file 76}
diff --git a/OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs b/OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs
deleted file mode 100644
index ffa7283..0000000
--- a/OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs
+++ /dev/null
@@ -1,122 +0,0 @@
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 System.Collections.Generic;
30using System.IO;
31using System.Net;
32using System.Text;
33using System.Xml;
34using System.Xml.Serialization;
35using NUnit.Framework;
36using OpenMetaverse;
37using OpenSim.Framework;
38using OpenSim.Framework.Servers;
39using OpenSim.Framework.Servers.HttpServer;
40using OpenSim.Server.Base;
41using OpenSim.Tests.Common.Mock;
42
43namespace OpenSim.Tests.Common.Setup
44{
45 public class GetAssetStreamHandlerTestHelpers
46 {
47 private const string EXPECTED_CONTENT_TYPE = "application/x-metaverse-callingcard";
48
49 public static void BaseFetchExistingAssetXmlTest(AssetBase asset, BaseGetAssetStreamHandler handler, OSHttpResponse response)
50 {
51 byte[] expected = BaseGetAssetStreamHandler.GetXml(asset);
52
53 byte[] actual = handler.Handle("/assets/" + asset.ID , null, null, response);
54
55 Assert.Greater(actual.Length, 10, "Too short xml on fetching xml without trailing slash.");
56 Assert.AreEqual(expected, actual, "Failed on fetching xml without trailing slash.");
57 // Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on first fetch.");
58
59 actual = handler.Handle("/assets/" + asset.ID + "/", null, null, response);
60 Assert.Greater(actual.Length, 10, "Too short xml on fetching xml with trailing slash.");
61 Assert.AreEqual(expected, actual, "Failed on fetching xml with trailing slash.");
62 // Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on second fetch.");
63
64 actual = handler.Handle("/assets/" + asset.ID + "/badData", null, null, response);
65 Assert.Greater(actual.Length, 10, "Too short xml on fetching xml with bad trailing data.");
66 Assert.AreEqual(expected, actual, "Failed on fetching xml with bad trailing trailing slash.");
67 // Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on second fetch.");
68 }
69
70 public static void BaseFetchExistingAssetDataTest(AssetBase asset, BaseGetAssetStreamHandler handler, OSHttpResponse response)
71 {
72 Assert.AreEqual(asset.Data, handler.Handle("/assets/" + asset.ID + "/data", null, null, response), "Failed on fetching data without trailing slash.");
73 Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on first fetch.");
74 Assert.AreEqual(EXPECTED_CONTENT_TYPE, response.ContentType, "Wrong http content type on first fetch.");
75
76 Assert.AreEqual(asset.Data, handler.Handle("/assets/" + asset.ID + "/data/", null, null, response), "Failed on fetching data with trailing slash.");
77 Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on second fetch.");
78 Assert.AreEqual(EXPECTED_CONTENT_TYPE, response.ContentType, "Wrong http content type on second fetch.");
79 }
80
81 public static void BaseFetchExistingAssetMetaDataTest(AssetBase asset, BaseGetAssetStreamHandler handler, OSHttpResponse response)
82 {
83 XmlSerializer xs = new XmlSerializer(typeof(AssetMetadata));
84
85 byte[] expected = ServerUtils.SerializeResult(xs, asset.Metadata);
86
87 Assert.AreEqual(expected, handler.Handle("/assets/" + asset.ID + "/metadata", null, null, response), "Failed on fetching data without trailing slash.");
88 Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on first fetch.");
89 Assert.AreEqual(EXPECTED_CONTENT_TYPE, response.ContentType, "Wrong http content type on first fetch.");
90
91 Assert.AreEqual(expected, handler.Handle("/assets/" + asset.ID + "/metadata/", null, null, response), "Failed on fetching data with trailing slash.");
92 Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on second fetch.");
93 Assert.AreEqual(EXPECTED_CONTENT_TYPE, response.ContentType, "Wrong http content type on second fetch.");
94 }
95
96 public static AssetBase CreateCommonTestResources(out OSHttpResponse response)
97 {
98 AssetBase asset = CreateTestAsset();
99 response = new TestOSHttpResponse();
100 return asset;
101 }
102
103 public static AssetBase CreateTestAsset()
104 {
105 byte[] expected = new byte[] { 1,2,3 };
106 AssetBase asset = new AssetBase();
107 asset.ID = Guid.NewGuid().ToString();
108 asset.Data = expected;
109 asset.Type = 2;
110
111 return asset;
112 }
113
114 public static void BaseFetchMissingAsset(BaseGetAssetStreamHandler handler, OSHttpResponse response)
115 {
116 Assert.AreEqual(
117 BaseRequestHandlerTestHelper.EmptyByteArray,
118 handler.Handle("/assets/" + Guid.NewGuid(), null, null, response), "Failed on bad guid.");
119 Assert.AreEqual((int)HttpStatusCode.NotFound, response.StatusCode, "Response code wrong in BaseFetchMissingAsset");
120 }
121 }
122}