From 1afdf2ee1fda020926d85f2763617b0bace5d03a Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Wed, 6 May 2009 17:02:51 +0000 Subject: * Added some GetAssetStreamHandlerTests * Minor tweaks to attain testability --- .../Servers/CachedGetAssetStreamHandler.cs | 4 +-- OpenSim/Framework/Servers/GetAssetStreamHandler.cs | 14 +++++--- .../Servers/HttpServer/BaseRequestHandler.cs | 4 +-- .../Servers/Tests/GetAssetStreamHandlerTests.cs | 42 ++++++++++++++++++++++ prebuild.xml | 1 + 5 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs 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 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); // private OpenAsset_Main m_assetManager; - private IAssetCache m_assetProvider; + private readonly IAssetCache m_assetProvider; /// /// Constructor. @@ -58,7 +58,7 @@ namespace OpenSim.Framework.Servers public CachedGetAssetStreamHandler(IAssetCache assetProvider) : base("GET", "/assets") { - m_log.Info("[REST]: In Get Request"); + // m_log.Info("[REST]: In Get Request"); // m_assetManager = assetManager; m_assetProvider = assetProvider; } 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 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); // private OpenAsset_Main m_assetManager; - private IAssetDataPlugin m_assetProvider; + private readonly IAssetDataPlugin m_assetProvider; /// /// Constructor. @@ -58,7 +58,7 @@ namespace OpenSim.Framework.Servers public GetAssetStreamHandler(IAssetDataPlugin assetProvider) : base("GET", "/assets") { - m_log.Info("[REST]: In Get Request"); + // m_log.Info("[REST]: In Get Request"); // m_assetManager = assetManager; m_assetProvider = assetProvider; } @@ -66,10 +66,9 @@ namespace OpenSim.Framework.Servers public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { - string param = GetParam(path); byte[] result = new byte[] { }; - string[] p = param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries); + string[] p = SplitParams(path); if (p.Length > 0) { @@ -127,6 +126,13 @@ namespace OpenSim.Framework.Servers return result; } + public string[] SplitParams(string path) + { + string param = GetParam(path); + + return param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries); + } + // private byte[] ProcessOutgoingAssetData(byte[] assetData) // { // 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; namespace OpenSim.Framework.Servers.HttpServer { - public class BaseRequestHandler + public abstract class BaseRequestHandler { public virtual string ContentType { @@ -56,7 +56,7 @@ namespace OpenSim.Framework.Servers.HttpServer get { return m_path; } } - protected string GetParam(string path) + public string GetParam(string path) { try { 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 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; + +namespace OpenSim.Framework.Servers.Tests +{ + [TestFixture] + public class GetAssetStreamHandlerTests + { + [Test] + public void TestConstructor() + { + GetAssetStreamHandler handler = new GetAssetStreamHandler( null ); + } + + [Test] + public void TestGetParams() + { + GetAssetStreamHandler handler = new GetAssetStreamHandler(null); + + Assert.AreEqual("", handler.GetParam("/assets")); + Assert.AreEqual("/", handler.GetParam("/assets/")); + Assert.AreEqual("/a", handler.GetParam("/assets/a")); + Assert.AreEqual("/b/", handler.GetParam("/assets/b/")); + Assert.AreEqual("/c/d", handler.GetParam("/assets/c/d")); + Assert.AreEqual("/e/f/", handler.GetParam("/assets/e/f/")); + } + + [Test] + public void TestSplitParams() + { + GetAssetStreamHandler handler = new GetAssetStreamHandler(null); + + Assert.AreEqual(new string[] { }, handler.SplitParams("/assets"), "Failed on empty params."); + Assert.AreEqual(new string[] { }, handler.SplitParams("/assets/"), "Failed on single slash."); + Assert.AreEqual(new string[] { "a" }, handler.SplitParams("/assets/a"), "Failed on first segment."); + Assert.AreEqual(new string[] { "b" }, handler.SplitParams("/assets/b/"), "Failed on second slash."); + } + + } +} diff --git a/prebuild.xml b/prebuild.xml index 95be0bc..5e51ff6 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -3197,6 +3197,7 @@ ../../../../bin/ + -- cgit v1.1