From 40e95cab02b125a6c9ec7e90cab94c94b201f021 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Wed, 13 May 2009 17:11:53 +0000 Subject: * Added some more tests to the GetAssetStreamHandlers --- .../Tests/CachedGetAssetStreamHandlerTests.cs | 37 ++++++++++++---- .../Servers/Tests/GetAssetStreamHandlerTests.cs | 49 ++++++++++++++++++---- 2 files changed, 72 insertions(+), 14 deletions(-) (limited to 'OpenSim/Framework/Servers/Tests') diff --git a/OpenSim/Framework/Servers/Tests/CachedGetAssetStreamHandlerTests.cs b/OpenSim/Framework/Servers/Tests/CachedGetAssetStreamHandlerTests.cs index dbb877d..b3cccfd 100644 --- a/OpenSim/Framework/Servers/Tests/CachedGetAssetStreamHandlerTests.cs +++ b/OpenSim/Framework/Servers/Tests/CachedGetAssetStreamHandlerTests.cs @@ -4,7 +4,10 @@ using System.Text; using NUnit.Framework; using OpenSim.Data; using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Services.Interfaces; using OpenSim.Tests.Common; +using OpenSim.Tests.Common.Mock; +using OpenSim.Tests.Common.Setup; namespace OpenSim.Framework.Servers.Tests { @@ -59,14 +62,34 @@ namespace OpenSim.Framework.Servers.Tests BaseRequestHandlerTestHelper.BaseTestHandleMalformedGuid(handler, ASSETS_PATH); } - //[Test] - //public void TestHandleFetchMissingAsset() - //{ + [Test] + public void TestHandleFetchMissingAsset() + { + IAssetCache assetCache = new TestAssetCache(); + CachedGetAssetStreamHandler handler = new CachedGetAssetStreamHandler(assetCache); + + GetAssetStreamHandlerTestHelpers.BaseFetchMissingAsset(handler); + } + + [Test] + public void TestHandleFetchExistingAssetData() + { + CachedGetAssetStreamHandler handler; + OSHttpResponse response; + AssetBase asset = CreateTestEnvironment(out handler, out response); + + GetAssetStreamHandlerTestHelpers.BaseFetchExistingAssetDataTest(asset, handler, response); + } - // byte[] emptyResult = new byte[] { }; - // CachedGetAssetStreamHandler handler = new CachedGetAssetStreamHandler(null); + private static AssetBase CreateTestEnvironment(out CachedGetAssetStreamHandler handler, out OSHttpResponse response) + { + AssetBase asset = GetAssetStreamHandlerTestHelpers.CreateCommonTestResources(out response); + + IAssetCache assetDataPlugin = new TestAssetCache(); + handler = new CachedGetAssetStreamHandler(assetDataPlugin); - // Assert.AreEqual(new string[] { }, handler.Handle("/assets/badGuid", null, null, null), "Failed on bad guid."); - //} + assetDataPlugin.AddAsset(asset); + return asset; + } } } diff --git a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs index 091a944..51dd79d 100644 --- a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs +++ b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs @@ -1,10 +1,14 @@ using System; using System.Collections.Generic; +using System.Net; using System.Text; +using HttpServer; using NUnit.Framework; using OpenSim.Data; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Tests.Common; +using OpenSim.Tests.Common.Mock; +using OpenSim.Tests.Common.Setup; namespace OpenSim.Framework.Servers.Tests { @@ -59,13 +63,44 @@ namespace OpenSim.Framework.Servers.Tests BaseRequestHandlerTestHelper.BaseTestHandleMalformedGuid(handler, ASSETS_PATH); } - //[Test] - //public void TestHandleFetchMissingAsset() - //{ - // byte[] emptyResult = new byte[] { }; - // GetAssetStreamHandler handler = new GetAssetStreamHandler(null); + [Test] + public void TestHandleFetchMissingAsset() + { + IAssetDataPlugin assetDataPlugin = new TestAssetDataPlugin(); + GetAssetStreamHandler handler = new GetAssetStreamHandler(assetDataPlugin); + + GetAssetStreamHandlerTestHelpers.BaseFetchMissingAsset(handler); + } + + [Test] + public void TestHandleFetchExistingAssetData() + { + GetAssetStreamHandler handler; + OSHttpResponse response; + AssetBase asset = CreateTestEnvironment(out handler, out response); + + GetAssetStreamHandlerTestHelpers.BaseFetchExistingAssetDataTest(asset, handler, response); + } - // Assert.AreEqual(new string[] { }, handler.Handle("/assets/badGuid", null, null, null), "Failed on bad guid."); - //} + [Test] + public void TestHandleFetchExistingAssetXml() + { + GetAssetStreamHandler handler; + OSHttpResponse response; + AssetBase asset = CreateTestEnvironment(out handler, out response); + + GetAssetStreamHandlerTestHelpers.BaseFetchExistingAssetXmlTest(asset, handler, response); + } + + private static AssetBase CreateTestEnvironment(out GetAssetStreamHandler handler, out OSHttpResponse response) + { + AssetBase asset = GetAssetStreamHandlerTestHelpers.CreateCommonTestResources(out response); + + IAssetDataPlugin assetDataPlugin = new TestAssetDataPlugin(); + handler = new GetAssetStreamHandler(assetDataPlugin); + + assetDataPlugin.CreateAsset(asset); + return asset; + } } } -- cgit v1.1