aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorlbsa712009-05-13 17:11:53 +0000
committerlbsa712009-05-13 17:11:53 +0000
commit40e95cab02b125a6c9ec7e90cab94c94b201f021 (patch)
tree6c77dce02a24ee061cf936f95faca13b41759fbe
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
-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
-rw-r--r--OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs4
-rw-r--r--OpenSim/Tests/Common/Mock/BaseAssetRepository.cs34
-rw-r--r--OpenSim/Tests/Common/Mock/TestAssetCache.cs92
-rw-r--r--OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs27
-rw-r--r--OpenSim/Tests/Common/Mock/TestAssetService.cs78
-rw-r--r--OpenSim/Tests/Common/Mock/TestOSHttpResponse.cs13
-rw-r--r--OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs64
-rw-r--r--prebuild.xml2
12 files changed, 386 insertions, 61 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}
diff --git a/OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs b/OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs
index 8f96fb3..6c50644 100644
--- a/OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs
+++ b/OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs
@@ -1,9 +1,11 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using NUnit.Framework; 4using NUnit.Framework;
5using OpenSim.Framework;
5using OpenSim.Framework.Servers; 6using OpenSim.Framework.Servers;
6using OpenSim.Framework.Servers.HttpServer; 7using OpenSim.Framework.Servers.HttpServer;
8using OpenSim.Tests.Common.Mock;
7 9
8namespace OpenSim.Tests.Common 10namespace OpenSim.Tests.Common
9{ 11{
diff --git a/OpenSim/Tests/Common/Mock/BaseAssetRepository.cs b/OpenSim/Tests/Common/Mock/BaseAssetRepository.cs
new file mode 100644
index 0000000..acfe4fe
--- /dev/null
+++ b/OpenSim/Tests/Common/Mock/BaseAssetRepository.cs
@@ -0,0 +1,34 @@
1using System.Collections.Generic;
2using OpenMetaverse;
3using OpenSim.Framework;
4
5namespace OpenSim.Tests.Common.Mock
6{
7 public class BaseAssetRepository
8 {
9 protected Dictionary<UUID, AssetBase> Assets = new Dictionary<UUID, AssetBase>();
10
11 public AssetBase FetchAsset(UUID uuid)
12 {
13 if (ExistsAsset(uuid))
14 return Assets[uuid];
15 else
16 return null;
17 }
18
19 public void CreateAsset(AssetBase asset)
20 {
21 Assets[asset.FullID] = asset;
22 }
23
24 public void UpdateAsset(AssetBase asset)
25 {
26 CreateAsset(asset);
27 }
28
29 public bool ExistsAsset(UUID uuid)
30 {
31 return Assets.ContainsKey(uuid);
32 }
33 }
34} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Mock/TestAssetCache.cs b/OpenSim/Tests/Common/Mock/TestAssetCache.cs
new file mode 100644
index 0000000..d621763
--- /dev/null
+++ b/OpenSim/Tests/Common/Mock/TestAssetCache.cs
@@ -0,0 +1,92 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenMetaverse;
5using OpenMetaverse.Packets;
6using OpenSim.Framework;
7
8namespace OpenSim.Tests.Common.Mock
9{
10 public class TestAssetCache : BaseAssetRepository, IAssetCache
11 {
12 public void AssetReceived(AssetBase asset, bool IsTexture)
13 {
14 throw new NotImplementedException();
15 }
16
17 public void AssetNotFound(UUID assetID, bool IsTexture)
18 {
19 throw new NotImplementedException();
20 }
21
22 public void Dispose()
23 {
24 throw new NotImplementedException();
25 }
26
27 public string Version
28 {
29 get { throw new NotImplementedException(); }
30 }
31
32 public string Name
33 {
34 get { throw new NotImplementedException(); }
35 }
36
37 public void Initialise()
38 {
39 throw new NotImplementedException();
40 }
41
42 public IAssetServer AssetServer
43 {
44 get { throw new NotImplementedException(); }
45 }
46
47 public void Initialise(ConfigSettings cs, IAssetServer server)
48 {
49 throw new NotImplementedException();
50 }
51
52 public void ShowState()
53 {
54 throw new NotImplementedException();
55 }
56
57 public void Clear()
58 {
59 throw new NotImplementedException();
60 }
61
62 public bool TryGetCachedAsset(UUID assetID, out AssetBase asset)
63 {
64 throw new NotImplementedException();
65 }
66
67 public void GetAsset(UUID assetID, AssetRequestCallback callback, bool isTexture)
68 {
69 throw new NotImplementedException();
70 }
71
72 public AssetBase GetAsset(UUID assetID, bool isTexture)
73 {
74 return FetchAsset(assetID);
75 }
76
77 public void AddAsset(AssetBase asset)
78 {
79 CreateAsset( asset );
80 }
81
82 public void ExpireAsset(UUID assetID)
83 {
84 throw new NotImplementedException();
85 }
86
87 public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest)
88 {
89 throw new NotImplementedException();
90 }
91 }
92}
diff --git a/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs b/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs
index 80b9ae3..b639cc9 100644
--- a/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs
+++ b/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs
@@ -37,40 +37,15 @@ namespace OpenSim.Tests.Common.Mock
37 /// mono addin plugin system starts co-operating with the unit test system. Currently no locking since unit 37 /// mono addin plugin system starts co-operating with the unit test system. Currently no locking since unit
38 /// tests are single threaded. 38 /// tests are single threaded.
39 /// </summary> 39 /// </summary>
40 public class TestAssetDataPlugin : IAssetDataPlugin 40 public class TestAssetDataPlugin : BaseAssetRepository, IAssetDataPlugin
41 { 41 {
42 public string Version { get { return "0"; } } 42 public string Version { get { return "0"; } }
43 public string Name { get { return "TestAssetDataPlugin"; } } 43 public string Name { get { return "TestAssetDataPlugin"; } }
44
45 protected Dictionary<UUID, AssetBase> Assets = new Dictionary<UUID, AssetBase>();
46 44
47 public void Initialise() {} 45 public void Initialise() {}
48 public void Initialise(string connect) {} 46 public void Initialise(string connect) {}
49 public void Dispose() {} 47 public void Dispose() {}
50 48
51 public AssetBase FetchAsset(UUID uuid)
52 {
53 if (ExistsAsset(uuid))
54 return Assets[uuid];
55 else
56 return null;
57 }
58
59 public void CreateAsset(AssetBase asset)
60 {
61 Assets[asset.FullID] = asset;
62 }
63
64 public void UpdateAsset(AssetBase asset)
65 {
66 CreateAsset(asset);
67 }
68
69 public bool ExistsAsset(UUID uuid)
70 {
71 return Assets.ContainsKey(uuid);
72 }
73
74 public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) { return new List<AssetMetadata>(count); } 49 public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) { return new List<AssetMetadata>(count); }
75 } 50 }
76} \ No newline at end of file 51} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Mock/TestAssetService.cs b/OpenSim/Tests/Common/Mock/TestAssetService.cs
new file mode 100644
index 0000000..23a1137
--- /dev/null
+++ b/OpenSim/Tests/Common/Mock/TestAssetService.cs
@@ -0,0 +1,78 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Data;
33using OpenSim.Services.Interfaces;
34
35namespace OpenSim.Tests.Common.Mock
36{
37 public class TestAssetService : IAssetService
38 {
39 private readonly Dictionary<string, AssetBase> Assets = new Dictionary<string, AssetBase>();
40
41 public AssetBase Get(string id)
42 {
43 return Assets[ id ];
44 }
45
46 public AssetMetadata GetMetadata(string id)
47 {
48 throw new System.NotImplementedException();
49 }
50
51 public byte[] GetData(string id)
52 {
53 throw new System.NotImplementedException();
54 }
55
56 public bool Get(string id, object sender, AssetRetrieved handler)
57 {
58 throw new NotImplementedException();
59 }
60
61 public string Store(AssetBase asset)
62 {
63 Assets[asset.ID] = asset;
64
65 return asset.ID;
66 }
67
68 public bool UpdateContent(string id, byte[] data)
69 {
70 throw new System.NotImplementedException();
71 }
72
73 public bool Delete(string id)
74 {
75 throw new System.NotImplementedException();
76 }
77 }
78} \ No newline at end of file
diff --git a/OpenSim/Tests/Common/Mock/TestOSHttpResponse.cs b/OpenSim/Tests/Common/Mock/TestOSHttpResponse.cs
new file mode 100644
index 0000000..d9c96f4
--- /dev/null
+++ b/OpenSim/Tests/Common/Mock/TestOSHttpResponse.cs
@@ -0,0 +1,13 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenSim.Framework.Servers.HttpServer;
5
6namespace OpenSim.Tests.Common.Mock
7{
8 public class TestOSHttpResponse : OSHttpResponse
9 {
10 public override int StatusCode { get; set; }
11 public override string ContentType { get; set; }
12 }
13}
diff --git a/OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs b/OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs
new file mode 100644
index 0000000..593beae
--- /dev/null
+++ b/OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs
@@ -0,0 +1,64 @@
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Net;
5using System.Text;
6using System.Xml;
7using System.Xml.Serialization;
8using NUnit.Framework;
9using OpenSim.Framework;
10using OpenSim.Framework.Servers;
11using OpenSim.Framework.Servers.HttpServer;
12using OpenSim.Tests.Common.Mock;
13
14namespace OpenSim.Tests.Common.Setup
15{
16 public class GetAssetStreamHandlerTestHelpers
17 {
18 public static void BaseFetchExistingAssetXmlTest(AssetBase asset, BaseGetAssetStreamHandler handler, OSHttpResponse response)
19 {
20 byte[] expected = BaseGetAssetStreamHandler.GetXml(asset);
21
22 byte[] actual = handler.Handle("/assets/" + asset.ID , null, null, response);
23
24 Assert.Greater(actual.Length, 10, "Too short xml on fetching xml without trailing slash.");
25 Assert.AreEqual(expected, actual, "Failed on fetching xml without trailing slash.");
26 // Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on first fetch.");
27
28 byte[] actual1 = handler.Handle("/assets/" + asset.ID + "/", null, null, response);
29 Assert.Greater(actual1.Length, 10, "Too short xml on fetching xml with trailing slash.");
30 Assert.AreEqual(expected, actual1, "Failed on fetching xml with trailing slash.");
31 // Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on second fetch.");
32 }
33
34 public static void BaseFetchExistingAssetDataTest(AssetBase asset, BaseGetAssetStreamHandler handler, OSHttpResponse response)
35 {
36 Assert.AreEqual(asset.Data, handler.Handle("/assets/" + asset.ID + "/data", null, null, response), "Failed on fetching data without trailing slash.");
37 Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on first fetch.");
38
39 Assert.AreEqual(asset.Data, handler.Handle("/assets/" + asset.ID + "/data/", null, null, response), "Failed on fetching data with trailing slash.");
40 Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on second fetch.");
41 }
42
43 public static AssetBase CreateCommonTestResources(out OSHttpResponse response)
44 {
45 AssetBase asset = CreateTestAsset();
46 response = new TestOSHttpResponse();
47 return asset;
48 }
49
50 public static AssetBase CreateTestAsset()
51 {
52 byte[] expected = new byte[] { 1,2,3 };
53 AssetBase asset = new AssetBase( );
54 asset.ID = Guid.NewGuid().ToString();
55 asset.Data = expected;
56 return asset;
57 }
58
59 public static void BaseFetchMissingAsset(BaseGetAssetStreamHandler handler)
60 {
61 Assert.AreEqual(BaseRequestHandlerTestHelper.EmptyByteArray, handler.Handle("/assets/" + Guid.NewGuid(), null, null, null), "Failed on bad guid.");
62 }
63 }
64}
diff --git a/prebuild.xml b/prebuild.xml
index 081e166..87e8643 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -3133,6 +3133,7 @@
3133 <Reference name="OpenSim.Framework.Servers"/> 3133 <Reference name="OpenSim.Framework.Servers"/>
3134 <Reference name="OpenSim.Framework.Servers.HttpServer"/> 3134 <Reference name="OpenSim.Framework.Servers.HttpServer"/>
3135 <Reference name="OpenSim.Data"/> 3135 <Reference name="OpenSim.Data"/>
3136 <Reference name="OpenSim.Services.Interfaces"/>
3136 <Reference name="OpenSim.Region.Communications.Local"/> 3137 <Reference name="OpenSim.Region.Communications.Local"/>
3137 <Reference name="OpenSim.Region.Framework"/> 3138 <Reference name="OpenSim.Region.Framework"/>
3138 <Reference name="OpenSim.Region.CoreModules"/> 3139 <Reference name="OpenSim.Region.CoreModules"/>
@@ -3330,6 +3331,7 @@
3330 <ReferencePath>../../../../bin/</ReferencePath> 3331 <ReferencePath>../../../../bin/</ReferencePath>
3331 <Reference name="System"/> 3332 <Reference name="System"/>
3332 <Reference name="OpenSim.Data"/> 3333 <Reference name="OpenSim.Data"/>
3334 <Reference name="OpenSim.Services.Interfaces"/>
3333 <Reference name="OpenSim.Tests.Common"/> 3335 <Reference name="OpenSim.Tests.Common"/>
3334 <Reference name="OpenSim.Framework"/> 3336 <Reference name="OpenSim.Framework"/>
3335 <Reference name="OpenSim.Framework.Servers"/> 3337 <Reference name="OpenSim.Framework.Servers"/>