aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests')
-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
7 files changed, 285 insertions, 27 deletions
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}