* Added some GetAssetStreamHandlerTests

* Minor tweaks to attain testability
0.6.5-rc1
lbsa71 2009-05-06 17:02:51 +00:00
parent c84abfa9b1
commit 1afdf2ee1f
5 changed files with 57 additions and 8 deletions

View File

@ -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;
/// <summary>
/// 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;
}

View File

@ -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;
/// <summary>
/// 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);

View File

@ -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
{

View File

@ -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.");
}
}
}

View File

@ -3197,6 +3197,7 @@
<ReferencePath>../../../../bin/</ReferencePath>
<Reference name="System"/>
<Reference name="OpenSim.Data"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Servers"/>
<Reference name="OpenSim.Framework.Servers.HttpServer"/>