aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Asset/Tests
diff options
context:
space:
mode:
authorubit2012-12-03 21:26:36 +0100
committerubit2012-12-03 21:26:36 +0100
commit5d4b7d537d872d27c394402d3483c2a9bd2153f0 (patch)
tree39aae50386555bf024700314fb7bee5121a9d683 /OpenSim/Server/Handlers/Asset/Tests
parentMerge branch 'ubitwork' of ssh://3dhosting.de/var/git/careminster into ubitwork (diff)
parentMerge branch 'avination' into ubitwork (diff)
downloadopensim-SC-5d4b7d537d872d27c394402d3483c2a9bd2153f0.zip
opensim-SC-5d4b7d537d872d27c394402d3483c2a9bd2153f0.tar.gz
opensim-SC-5d4b7d537d872d27c394402d3483c2a9bd2153f0.tar.bz2
opensim-SC-5d4b7d537d872d27c394402d3483c2a9bd2153f0.tar.xz
Merge branch 'ubitwork' of ssh://3dhosting.de/var/git/careminster into ubitwork
Diffstat (limited to 'OpenSim/Server/Handlers/Asset/Tests')
-rw-r--r--OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs110
1 files changed, 110 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs
new file mode 100644
index 0000000..427fa16
--- /dev/null
+++ b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs
@@ -0,0 +1,110 @@
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 OpenSimulator 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.IO;
30using System.Net;
31using System.Text;
32using System.Xml;
33using System.Xml.Serialization;
34using Nini.Config;
35using NUnit.Framework;
36using OpenMetaverse;
37using OpenSim.Framework;
38using OpenSim.Server.Handlers.Asset;
39using OpenSim.Services.AssetService;
40using OpenSim.Services.Interfaces;
41using OpenSim.Tests.Common;
42using OpenSim.Tests.Common.Mock;
43
44namespace OpenSim.Server.Handlers.Asset.Test
45{
46 [TestFixture]
47 public class AssetServerPostHandlerTests : OpenSimTestCase
48 {
49 [Test]
50 public void TestGoodAssetStoreRequest()
51 {
52 TestHelpers.InMethod();
53
54 UUID assetId = TestHelpers.ParseTail(0x1);
55
56 IConfigSource config = new IniConfigSource();
57 config.AddConfig("AssetService");
58 config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
59
60 AssetService assetService = new AssetService(config);
61
62 AssetServerPostHandler asph = new AssetServerPostHandler(assetService);
63
64 AssetBase asset = AssetHelpers.CreateNotecardAsset(assetId, "Hello World");
65
66 MemoryStream buffer = new MemoryStream();
67
68 XmlWriterSettings settings = new XmlWriterSettings();
69 settings.Encoding = Encoding.UTF8;
70
71 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
72 {
73 XmlSerializer serializer = new XmlSerializer(typeof(AssetBase));
74 serializer.Serialize(writer, asset);
75 writer.Flush();
76 }
77
78 buffer.Position = 0;
79 asph.Handle(null, buffer, null, null);
80
81 AssetBase retrievedAsset = assetService.Get(assetId.ToString());
82
83 Assert.That(retrievedAsset, Is.Not.Null);
84 }
85
86 [Test]
87 public void TestBadXmlAssetStoreRequest()
88 {
89 TestHelpers.InMethod();
90
91 IConfigSource config = new IniConfigSource();
92 config.AddConfig("AssetService");
93 config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
94
95 AssetService assetService = new AssetService(config);
96
97 AssetServerPostHandler asph = new AssetServerPostHandler(assetService);
98
99 MemoryStream buffer = new MemoryStream();
100 byte[] badData = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f };
101 buffer.Write(badData, 0, badData.Length);
102 buffer.Position = 0;
103
104 TestOSHttpResponse response = new TestOSHttpResponse();
105 asph.Handle(null, buffer, null, response);
106
107 Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest));
108 }
109 }
110} \ No newline at end of file