diff options
author | lbsa71 | 2009-05-06 17:02:51 +0000 |
---|---|---|
committer | lbsa71 | 2009-05-06 17:02:51 +0000 |
commit | 1afdf2ee1fda020926d85f2763617b0bace5d03a (patch) | |
tree | a41a85656d8dd3a185adf55f3f09473dcb758b1f /OpenSim/Framework | |
parent | Thank you kindly, Fly-Man- for a patch that: (diff) | |
download | opensim-SC-1afdf2ee1fda020926d85f2763617b0bace5d03a.zip opensim-SC-1afdf2ee1fda020926d85f2763617b0bace5d03a.tar.gz opensim-SC-1afdf2ee1fda020926d85f2763617b0bace5d03a.tar.bz2 opensim-SC-1afdf2ee1fda020926d85f2763617b0bace5d03a.tar.xz |
* Added some GetAssetStreamHandlerTests
* Minor tweaks to attain testability
Diffstat (limited to '')
4 files changed, 56 insertions, 8 deletions
diff --git a/OpenSim/Framework/Servers/CachedGetAssetStreamHandler.cs b/OpenSim/Framework/Servers/CachedGetAssetStreamHandler.cs index 39041df..fb217d1 100644 --- a/OpenSim/Framework/Servers/CachedGetAssetStreamHandler.cs +++ b/OpenSim/Framework/Servers/CachedGetAssetStreamHandler.cs | |||
@@ -48,7 +48,7 @@ namespace OpenSim.Framework.Servers | |||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
49 | 49 | ||
50 | // private OpenAsset_Main m_assetManager; | 50 | // private OpenAsset_Main m_assetManager; |
51 | private IAssetCache m_assetProvider; | 51 | private readonly IAssetCache m_assetProvider; |
52 | 52 | ||
53 | /// <summary> | 53 | /// <summary> |
54 | /// Constructor. | 54 | /// Constructor. |
@@ -58,7 +58,7 @@ namespace OpenSim.Framework.Servers | |||
58 | public CachedGetAssetStreamHandler(IAssetCache assetProvider) | 58 | public CachedGetAssetStreamHandler(IAssetCache assetProvider) |
59 | : base("GET", "/assets") | 59 | : base("GET", "/assets") |
60 | { | 60 | { |
61 | m_log.Info("[REST]: In Get Request"); | 61 | // m_log.Info("[REST]: In Get Request"); |
62 | // m_assetManager = assetManager; | 62 | // m_assetManager = assetManager; |
63 | m_assetProvider = assetProvider; | 63 | m_assetProvider = assetProvider; |
64 | } | 64 | } |
diff --git a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs index c935d2a..1b87496 100644 --- a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs +++ b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs | |||
@@ -48,7 +48,7 @@ namespace OpenSim.Framework.Servers | |||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
49 | 49 | ||
50 | // private OpenAsset_Main m_assetManager; | 50 | // private OpenAsset_Main m_assetManager; |
51 | private IAssetDataPlugin m_assetProvider; | 51 | private readonly IAssetDataPlugin m_assetProvider; |
52 | 52 | ||
53 | /// <summary> | 53 | /// <summary> |
54 | /// Constructor. | 54 | /// Constructor. |
@@ -58,7 +58,7 @@ namespace OpenSim.Framework.Servers | |||
58 | public GetAssetStreamHandler(IAssetDataPlugin assetProvider) | 58 | public GetAssetStreamHandler(IAssetDataPlugin assetProvider) |
59 | : base("GET", "/assets") | 59 | : base("GET", "/assets") |
60 | { | 60 | { |
61 | m_log.Info("[REST]: In Get Request"); | 61 | // m_log.Info("[REST]: In Get Request"); |
62 | // m_assetManager = assetManager; | 62 | // m_assetManager = assetManager; |
63 | m_assetProvider = assetProvider; | 63 | m_assetProvider = assetProvider; |
64 | } | 64 | } |
@@ -66,10 +66,9 @@ namespace OpenSim.Framework.Servers | |||
66 | public override byte[] Handle(string path, Stream request, | 66 | public override byte[] Handle(string path, Stream request, |
67 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | 67 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) |
68 | { | 68 | { |
69 | string param = GetParam(path); | ||
70 | byte[] result = new byte[] { }; | 69 | byte[] result = new byte[] { }; |
71 | 70 | ||
72 | string[] p = param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries); | 71 | string[] p = SplitParams(path); |
73 | 72 | ||
74 | if (p.Length > 0) | 73 | if (p.Length > 0) |
75 | { | 74 | { |
@@ -127,6 +126,13 @@ namespace OpenSim.Framework.Servers | |||
127 | return result; | 126 | return result; |
128 | } | 127 | } |
129 | 128 | ||
129 | public string[] SplitParams(string path) | ||
130 | { | ||
131 | string param = GetParam(path); | ||
132 | |||
133 | return param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries); | ||
134 | } | ||
135 | |||
130 | // private byte[] ProcessOutgoingAssetData(byte[] assetData) | 136 | // private byte[] ProcessOutgoingAssetData(byte[] assetData) |
131 | // { | 137 | // { |
132 | // string data = Encoding.ASCII.GetString(assetData); | 138 | // string data = Encoding.ASCII.GetString(assetData); |
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs b/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs index 9334972..5ad4520 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs | |||
@@ -29,7 +29,7 @@ using System; | |||
29 | 29 | ||
30 | namespace OpenSim.Framework.Servers.HttpServer | 30 | namespace OpenSim.Framework.Servers.HttpServer |
31 | { | 31 | { |
32 | public class BaseRequestHandler | 32 | public abstract class BaseRequestHandler |
33 | { | 33 | { |
34 | public virtual string ContentType | 34 | public virtual string ContentType |
35 | { | 35 | { |
@@ -56,7 +56,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
56 | get { return m_path; } | 56 | get { return m_path; } |
57 | } | 57 | } |
58 | 58 | ||
59 | protected string GetParam(string path) | 59 | public string GetParam(string path) |
60 | { | 60 | { |
61 | try | 61 | try |
62 | { | 62 | { |
diff --git a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs new file mode 100644 index 0000000..d399274 --- /dev/null +++ b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs | |||
@@ -0,0 +1,42 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using NUnit.Framework; | ||
5 | |||
6 | namespace OpenSim.Framework.Servers.Tests | ||
7 | { | ||
8 | [TestFixture] | ||
9 | public class GetAssetStreamHandlerTests | ||
10 | { | ||
11 | [Test] | ||
12 | public void TestConstructor() | ||
13 | { | ||
14 | GetAssetStreamHandler handler = new GetAssetStreamHandler( null ); | ||
15 | } | ||
16 | |||
17 | [Test] | ||
18 | public void TestGetParams() | ||
19 | { | ||
20 | GetAssetStreamHandler handler = new GetAssetStreamHandler(null); | ||
21 | |||
22 | Assert.AreEqual("", handler.GetParam("/assets")); | ||
23 | Assert.AreEqual("/", handler.GetParam("/assets/")); | ||
24 | Assert.AreEqual("/a", handler.GetParam("/assets/a")); | ||
25 | Assert.AreEqual("/b/", handler.GetParam("/assets/b/")); | ||
26 | Assert.AreEqual("/c/d", handler.GetParam("/assets/c/d")); | ||
27 | Assert.AreEqual("/e/f/", handler.GetParam("/assets/e/f/")); | ||
28 | } | ||
29 | |||
30 | [Test] | ||
31 | public void TestSplitParams() | ||
32 | { | ||
33 | GetAssetStreamHandler handler = new GetAssetStreamHandler(null); | ||
34 | |||
35 | Assert.AreEqual(new string[] { }, handler.SplitParams("/assets"), "Failed on empty params."); | ||
36 | Assert.AreEqual(new string[] { }, handler.SplitParams("/assets/"), "Failed on single slash."); | ||
37 | Assert.AreEqual(new string[] { "a" }, handler.SplitParams("/assets/a"), "Failed on first segment."); | ||
38 | Assert.AreEqual(new string[] { "b" }, handler.SplitParams("/assets/b/"), "Failed on second slash."); | ||
39 | } | ||
40 | |||
41 | } | ||
42 | } | ||