* Added some GetAssetStreamHandlerTests
* Minor tweaks to attain testability0.6.5-rc1
parent
c84abfa9b1
commit
1afdf2ee1f
|
@ -48,7 +48,7 @@ namespace OpenSim.Framework.Servers
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
// private OpenAsset_Main m_assetManager;
|
// private OpenAsset_Main m_assetManager;
|
||||||
private IAssetCache m_assetProvider;
|
private readonly IAssetCache m_assetProvider;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
|
@ -58,7 +58,7 @@ namespace OpenSim.Framework.Servers
|
||||||
public CachedGetAssetStreamHandler(IAssetCache assetProvider)
|
public CachedGetAssetStreamHandler(IAssetCache assetProvider)
|
||||||
: base("GET", "/assets")
|
: base("GET", "/assets")
|
||||||
{
|
{
|
||||||
m_log.Info("[REST]: In Get Request");
|
// m_log.Info("[REST]: In Get Request");
|
||||||
// m_assetManager = assetManager;
|
// m_assetManager = assetManager;
|
||||||
m_assetProvider = assetProvider;
|
m_assetProvider = assetProvider;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace OpenSim.Framework.Servers
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
// private OpenAsset_Main m_assetManager;
|
// private OpenAsset_Main m_assetManager;
|
||||||
private IAssetDataPlugin m_assetProvider;
|
private readonly IAssetDataPlugin m_assetProvider;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
|
@ -58,7 +58,7 @@ namespace OpenSim.Framework.Servers
|
||||||
public GetAssetStreamHandler(IAssetDataPlugin assetProvider)
|
public GetAssetStreamHandler(IAssetDataPlugin assetProvider)
|
||||||
: base("GET", "/assets")
|
: base("GET", "/assets")
|
||||||
{
|
{
|
||||||
m_log.Info("[REST]: In Get Request");
|
// m_log.Info("[REST]: In Get Request");
|
||||||
// m_assetManager = assetManager;
|
// m_assetManager = assetManager;
|
||||||
m_assetProvider = assetProvider;
|
m_assetProvider = assetProvider;
|
||||||
}
|
}
|
||||||
|
@ -66,10 +66,9 @@ namespace OpenSim.Framework.Servers
|
||||||
public override byte[] Handle(string path, Stream request,
|
public override byte[] Handle(string path, Stream request,
|
||||||
OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||||
{
|
{
|
||||||
string param = GetParam(path);
|
|
||||||
byte[] result = new byte[] { };
|
byte[] result = new byte[] { };
|
||||||
|
|
||||||
string[] p = param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries);
|
string[] p = SplitParams(path);
|
||||||
|
|
||||||
if (p.Length > 0)
|
if (p.Length > 0)
|
||||||
{
|
{
|
||||||
|
@ -127,6 +126,13 @@ namespace OpenSim.Framework.Servers
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string[] SplitParams(string path)
|
||||||
|
{
|
||||||
|
string param = GetParam(path);
|
||||||
|
|
||||||
|
return param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
}
|
||||||
|
|
||||||
// private byte[] ProcessOutgoingAssetData(byte[] assetData)
|
// private byte[] ProcessOutgoingAssetData(byte[] assetData)
|
||||||
// {
|
// {
|
||||||
// string data = Encoding.ASCII.GetString(assetData);
|
// string data = Encoding.ASCII.GetString(assetData);
|
||||||
|
|
|
@ -29,7 +29,7 @@ using System;
|
||||||
|
|
||||||
namespace OpenSim.Framework.Servers.HttpServer
|
namespace OpenSim.Framework.Servers.HttpServer
|
||||||
{
|
{
|
||||||
public class BaseRequestHandler
|
public abstract class BaseRequestHandler
|
||||||
{
|
{
|
||||||
public virtual string ContentType
|
public virtual string ContentType
|
||||||
{
|
{
|
||||||
|
@ -56,7 +56,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
get { return m_path; }
|
get { return m_path; }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string GetParam(string path)
|
public string GetParam(string path)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -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.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -3197,6 +3197,7 @@
|
||||||
|
|
||||||
<ReferencePath>../../../../bin/</ReferencePath>
|
<ReferencePath>../../../../bin/</ReferencePath>
|
||||||
<Reference name="System"/>
|
<Reference name="System"/>
|
||||||
|
<Reference name="OpenSim.Data"/>
|
||||||
<Reference name="OpenSim.Framework"/>
|
<Reference name="OpenSim.Framework"/>
|
||||||
<Reference name="OpenSim.Framework.Servers"/>
|
<Reference name="OpenSim.Framework.Servers"/>
|
||||||
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
|
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
|
||||||
|
|
Loading…
Reference in New Issue