aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers
diff options
context:
space:
mode:
authorlbsa712009-05-13 17:11:53 +0000
committerlbsa712009-05-13 17:11:53 +0000
commit40e95cab02b125a6c9ec7e90cab94c94b201f021 (patch)
tree6c77dce02a24ee061cf936f95faca13b41759fbe /OpenSim/Framework/Servers
parentDisabling WebFetchInventoryDescendents CAPs for the time being as it (diff)
downloadopensim-SC_OLD-40e95cab02b125a6c9ec7e90cab94c94b201f021.zip
opensim-SC_OLD-40e95cab02b125a6c9ec7e90cab94c94b201f021.tar.gz
opensim-SC_OLD-40e95cab02b125a6c9ec7e90cab94c94b201f021.tar.bz2
opensim-SC_OLD-40e95cab02b125a6c9ec7e90cab94c94b201f021.tar.xz
* Added some more tests to the GetAssetStreamHandlers
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r--OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs43
-rw-r--r--OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs4
-rw-r--r--OpenSim/Framework/Servers/Tests/CachedGetAssetStreamHandlerTests.cs37
-rw-r--r--OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs49
4 files changed, 99 insertions, 34 deletions
diff --git a/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs b/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs
index fc4eed7..9eacf24 100644
--- a/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs
+++ b/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs
@@ -60,7 +60,7 @@ namespace OpenSim.Framework.Servers
60 60
61 if (p.Length > 0) 61 if (p.Length > 0)
62 { 62 {
63 UUID assetID = UUID.Zero; 63 UUID assetID;
64 64
65 if (!UUID.TryParse(p[0], out assetID)) 65 if (!UUID.TryParse(p[0], out assetID))
66 { 66 {
@@ -70,16 +70,14 @@ namespace OpenSim.Framework.Servers
70 } 70 }
71 71
72 if (StatsManager.AssetStats != null) 72 if (StatsManager.AssetStats != null)
73 {
73 StatsManager.AssetStats.AddRequest(); 74 StatsManager.AssetStats.AddRequest();
75 }
74 76
75 AssetBase asset = GetAsset(assetID); 77 AssetBase asset = GetAsset(assetID);
76 78
77 if (asset != null) 79 if (asset != null)
78 { 80 {
79// if (asset.ContainsReferences)
80// {
81// asset.Data = ProcessOutgoingAssetData(asset.Data);
82// }
83 if (p.Length > 1 && p[1] == "data") 81 if (p.Length > 1 && p[1] == "data")
84 { 82 {
85 httpResponse.StatusCode = (int)HttpStatusCode.OK; 83 httpResponse.StatusCode = (int)HttpStatusCode.OK;
@@ -88,25 +86,15 @@ namespace OpenSim.Framework.Servers
88 } 86 }
89 else 87 else
90 { 88 {
91 XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); 89 result = GetXml(asset);
92 MemoryStream ms = new MemoryStream();
93 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
94 xw.Formatting = Formatting.Indented;
95 xs.Serialize(xw, asset);
96 xw.Flush();
97
98 ms.Seek(0, SeekOrigin.Begin);
99 //StreamReader sr = new StreamReader(ms);
100
101 result = ms.GetBuffer();
102
103 Array.Resize<byte>(ref result, (int)ms.Length);
104 } 90 }
105 } 91 }
106 else 92 else
107 { 93 {
108 if (StatsManager.AssetStats != null) 94 if (StatsManager.AssetStats != null)
95 {
109 StatsManager.AssetStats.AddNotFoundRequest(); 96 StatsManager.AssetStats.AddNotFoundRequest();
97 }
110 98
111 m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID); 99 m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID);
112 } 100 }
@@ -115,6 +103,25 @@ namespace OpenSim.Framework.Servers
115 return result; 103 return result;
116 } 104 }
117 105
106 public static byte[] GetXml(AssetBase asset)
107 {
108 byte[] result;
109 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
110 MemoryStream ms = new MemoryStream();
111 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
112 xw.Formatting = Formatting.Indented;
113 xs.Serialize(xw, asset);
114 xw.Flush();
115
116 ms.Seek(0, SeekOrigin.Begin);
117 //StreamReader sr = new StreamReader(ms);
118
119 result = ms.GetBuffer();
120
121 Array.Resize<byte>(ref result, (int)ms.Length);
122 return result;
123 }
124
118 public string ProcessAssetDataString(string data) 125 public string ProcessAssetDataString(string data)
119 { 126 {
120 Regex regex = new Regex("(creator_id|owner_id)\\s+(\\S+)"); 127 Regex regex = new Regex("(creator_id|owner_id)\\s+(\\S+)");
diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs
index 210d122..6ea95b1 100644
--- a/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs
+++ b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs
@@ -45,7 +45,7 @@ namespace OpenSim.Framework.Servers.HttpServer
45 /// Setting this property will also set IsContentTypeSet to 45 /// Setting this property will also set IsContentTypeSet to
46 /// true. 46 /// true.
47 /// </remarks> 47 /// </remarks>
48 public string ContentType 48 public virtual string ContentType
49 { 49 {
50 get 50 get
51 { 51 {
@@ -226,7 +226,7 @@ namespace OpenSim.Framework.Servers.HttpServer
226 /// <summary> 226 /// <summary>
227 /// HTTP status code. 227 /// HTTP status code.
228 /// </summary> 228 /// </summary>
229 public int StatusCode 229 public virtual int StatusCode
230 { 230 {
231 get 231 get
232 { 232 {
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;
4using NUnit.Framework; 4using NUnit.Framework;
5using OpenSim.Data; 5using OpenSim.Data;
6using OpenSim.Framework.Servers.HttpServer; 6using OpenSim.Framework.Servers.HttpServer;
7using OpenSim.Services.Interfaces;
7using OpenSim.Tests.Common; 8using OpenSim.Tests.Common;
9using OpenSim.Tests.Common.Mock;
10using OpenSim.Tests.Common.Setup;
8 11
9namespace OpenSim.Framework.Servers.Tests 12namespace OpenSim.Framework.Servers.Tests
10{ 13{
@@ -59,14 +62,34 @@ namespace OpenSim.Framework.Servers.Tests
59 BaseRequestHandlerTestHelper.BaseTestHandleMalformedGuid(handler, ASSETS_PATH); 62 BaseRequestHandlerTestHelper.BaseTestHandleMalformedGuid(handler, ASSETS_PATH);
60 } 63 }
61 64
62 //[Test] 65 [Test]
63 //public void TestHandleFetchMissingAsset() 66 public void TestHandleFetchMissingAsset()
64 //{ 67 {
68 IAssetCache assetCache = new TestAssetCache();
69 CachedGetAssetStreamHandler handler = new CachedGetAssetStreamHandler(assetCache);
70
71 GetAssetStreamHandlerTestHelpers.BaseFetchMissingAsset(handler);
72 }
73
74 [Test]
75 public void TestHandleFetchExistingAssetData()
76 {
77 CachedGetAssetStreamHandler handler;
78 OSHttpResponse response;
79 AssetBase asset = CreateTestEnvironment(out handler, out response);
80
81 GetAssetStreamHandlerTestHelpers.BaseFetchExistingAssetDataTest(asset, handler, response);
82 }
65 83
66 // byte[] emptyResult = new byte[] { }; 84 private static AssetBase CreateTestEnvironment(out CachedGetAssetStreamHandler handler, out OSHttpResponse response)
67 // CachedGetAssetStreamHandler handler = new CachedGetAssetStreamHandler(null); 85 {
86 AssetBase asset = GetAssetStreamHandlerTestHelpers.CreateCommonTestResources(out response);
87
88 IAssetCache assetDataPlugin = new TestAssetCache();
89 handler = new CachedGetAssetStreamHandler(assetDataPlugin);
68 90
69 // Assert.AreEqual(new string[] { }, handler.Handle("/assets/badGuid", null, null, null), "Failed on bad guid."); 91 assetDataPlugin.AddAsset(asset);
70 //} 92 return asset;
93 }
71 } 94 }
72} 95}
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 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Net;
3using System.Text; 4using System.Text;
5using HttpServer;
4using NUnit.Framework; 6using NUnit.Framework;
5using OpenSim.Data; 7using OpenSim.Data;
6using OpenSim.Framework.Servers.HttpServer; 8using OpenSim.Framework.Servers.HttpServer;
7using OpenSim.Tests.Common; 9using OpenSim.Tests.Common;
10using OpenSim.Tests.Common.Mock;
11using OpenSim.Tests.Common.Setup;
8 12
9namespace OpenSim.Framework.Servers.Tests 13namespace OpenSim.Framework.Servers.Tests
10{ 14{
@@ -59,13 +63,44 @@ namespace OpenSim.Framework.Servers.Tests
59 BaseRequestHandlerTestHelper.BaseTestHandleMalformedGuid(handler, ASSETS_PATH); 63 BaseRequestHandlerTestHelper.BaseTestHandleMalformedGuid(handler, ASSETS_PATH);
60 } 64 }
61 65
62 //[Test] 66 [Test]
63 //public void TestHandleFetchMissingAsset() 67 public void TestHandleFetchMissingAsset()
64 //{ 68 {
65 // byte[] emptyResult = new byte[] { }; 69 IAssetDataPlugin assetDataPlugin = new TestAssetDataPlugin();
66 // GetAssetStreamHandler handler = new GetAssetStreamHandler(null); 70 GetAssetStreamHandler handler = new GetAssetStreamHandler(assetDataPlugin);
71
72 GetAssetStreamHandlerTestHelpers.BaseFetchMissingAsset(handler);
73 }
74
75 [Test]
76 public void TestHandleFetchExistingAssetData()
77 {
78 GetAssetStreamHandler handler;
79 OSHttpResponse response;
80 AssetBase asset = CreateTestEnvironment(out handler, out response);
81
82 GetAssetStreamHandlerTestHelpers.BaseFetchExistingAssetDataTest(asset, handler, response);
83 }
67 84
68 // Assert.AreEqual(new string[] { }, handler.Handle("/assets/badGuid", null, null, null), "Failed on bad guid."); 85 [Test]
69 //} 86 public void TestHandleFetchExistingAssetXml()
87 {
88 GetAssetStreamHandler handler;
89 OSHttpResponse response;
90 AssetBase asset = CreateTestEnvironment(out handler, out response);
91
92 GetAssetStreamHandlerTestHelpers.BaseFetchExistingAssetXmlTest(asset, handler, response);
93 }
94
95 private static AssetBase CreateTestEnvironment(out GetAssetStreamHandler handler, out OSHttpResponse response)
96 {
97 AssetBase asset = GetAssetStreamHandlerTestHelpers.CreateCommonTestResources(out response);
98
99 IAssetDataPlugin assetDataPlugin = new TestAssetDataPlugin();
100 handler = new GetAssetStreamHandler(assetDataPlugin);
101
102 assetDataPlugin.CreateAsset(asset);
103 return asset;
104 }
70 } 105 }
71} 106}