aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs70
-rw-r--r--OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs135
-rw-r--r--OpenSim/Tests/Common/Setup/BaseRequestHandlerTestHelper.cs86
-rw-r--r--OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs122
4 files changed, 0 insertions, 413 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs b/OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs
deleted file mode 100644
index 2fa118d..0000000
--- a/OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs
+++ /dev/null
@@ -1,70 +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.Text;
31using NUnit.Framework;
32using OpenSim.Tests.Common.Setup;
33
34namespace OpenSim.Framework.Servers.HttpServer.Tests
35{
36 [TestFixture]
37 public class BaseRequestHandlerTests
38 {
39 private const string BASE_PATH = "/testpath";
40
41 private class BaseRequestHandlerImpl : BaseRequestHandler
42 {
43 public BaseRequestHandlerImpl(string httpMethod, string path) : base(httpMethod, path)
44 {
45 }
46 }
47
48 [Test]
49 public void TestConstructor()
50 {
51 new BaseRequestHandlerImpl(null, null);
52 }
53
54 [Test]
55 public void TestGetParams()
56 {
57 BaseRequestHandlerImpl handler = new BaseRequestHandlerImpl(null, BASE_PATH);
58
59 BaseRequestHandlerTestHelper.BaseTestGetParams(handler, BASE_PATH);
60 }
61
62 [Test]
63 public void TestSplitParams()
64 {
65 BaseRequestHandlerImpl handler = new BaseRequestHandlerImpl(null, BASE_PATH);
66
67 BaseRequestHandlerTestHelper.BaseTestSplitParams(handler, BASE_PATH);
68 }
69 }
70}
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/Tests/Common/Setup/BaseRequestHandlerTestHelper.cs b/OpenSim/Tests/Common/Setup/BaseRequestHandlerTestHelper.cs
deleted file mode 100644
index e858371..0000000
--- a/OpenSim/Tests/Common/Setup/BaseRequestHandlerTestHelper.cs
+++ /dev/null
@@ -1,86 +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.Text;
31using NUnit.Framework;
32using OpenSim.Framework;
33using OpenSim.Framework.Servers;
34using OpenSim.Framework.Servers.HttpServer;
35using OpenSim.Tests.Common.Mock;
36
37namespace OpenSim.Tests.Common.Setup
38{
39 public class BaseRequestHandlerTestHelper
40 {
41 private static string[] m_emptyStringArray = new string[] { };
42
43 public static void BaseTestGetParams(BaseRequestHandler handler, string assetsPath)
44 {
45 Assert.AreEqual(String.Empty, handler.GetParam(null), "Failed on null path.");
46 Assert.AreEqual(String.Empty, handler.GetParam(""), "Failed on empty path.");
47 Assert.AreEqual(String.Empty, handler.GetParam("s"), "Failed on short url.");
48 Assert.AreEqual(String.Empty, handler.GetParam("corruptUrl"), "Failed on corruptUrl.");
49
50 Assert.AreEqual(String.Empty, handler.GetParam(assetsPath));
51 Assert.AreEqual("/", handler.GetParam(assetsPath + "/"));
52 Assert.AreEqual("/a", handler.GetParam(assetsPath + "/a"));
53 Assert.AreEqual("/b/", handler.GetParam(assetsPath + "/b/"));
54 Assert.AreEqual("/c/d", handler.GetParam(assetsPath + "/c/d"));
55 Assert.AreEqual("/e/f/", handler.GetParam(assetsPath + "/e/f/"));
56 }
57
58 public static void BaseTestSplitParams(BaseRequestHandler handler, string assetsPath)
59 {
60 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(null), "Failed on null.");
61 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(""), "Failed on empty path.");
62 Assert.AreEqual(m_emptyStringArray, handler.SplitParams("corruptUrl"), "Failed on corrupt url.");
63
64 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(assetsPath), "Failed on empty params.");
65 Assert.AreEqual(m_emptyStringArray, handler.SplitParams(assetsPath + "/"), "Failed on single slash.");
66
67 Assert.AreEqual(new string[] { "a" }, handler.SplitParams(assetsPath + "/a"), "Failed on first segment.");
68 Assert.AreEqual(new string[] { "b" }, handler.SplitParams(assetsPath + "/b/"), "Failed on second slash.");
69 Assert.AreEqual(new string[] { "c", "d" }, handler.SplitParams(assetsPath + "/c/d"), "Failed on second segment.");
70 Assert.AreEqual(new string[] { "e", "f" }, handler.SplitParams(assetsPath + "/e/f/"), "Failed on trailing slash.");
71 }
72
73 public static byte[] EmptyByteArray = new byte[] {};
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 }
86} \ No newline at end of file
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}