aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs')
-rw-r--r--OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs109
1 files changed, 109 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..faa6fb7
--- /dev/null
+++ b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs
@@ -0,0 +1,109 @@
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;
42
43namespace OpenSim.Server.Handlers.Asset.Test
44{
45 [TestFixture]
46 public class AssetServerPostHandlerTests : OpenSimTestCase
47 {
48 [Test]
49 public void TestGoodAssetStoreRequest()
50 {
51 TestHelpers.InMethod();
52
53 UUID assetId = TestHelpers.ParseTail(0x1);
54
55 IConfigSource config = new IniConfigSource();
56 config.AddConfig("AssetService");
57 config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
58
59 AssetService assetService = new AssetService(config);
60
61 AssetServerPostHandler asph = new AssetServerPostHandler(assetService);
62
63 AssetBase asset = AssetHelpers.CreateNotecardAsset(assetId, "Hello World");
64
65 MemoryStream buffer = new MemoryStream();
66
67 XmlWriterSettings settings = new XmlWriterSettings();
68 settings.Encoding = Encoding.UTF8;
69
70 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
71 {
72 XmlSerializer serializer = new XmlSerializer(typeof(AssetBase));
73 serializer.Serialize(writer, asset);
74 writer.Flush();
75 }
76
77 buffer.Position = 0;
78 asph.Handle(null, buffer, null, null);
79
80 AssetBase retrievedAsset = assetService.Get(assetId.ToString());
81
82 Assert.That(retrievedAsset, Is.Not.Null);
83 }
84
85 [Test]
86 public void TestBadXmlAssetStoreRequest()
87 {
88 TestHelpers.InMethod();
89
90 IConfigSource config = new IniConfigSource();
91 config.AddConfig("AssetService");
92 config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
93
94 AssetService assetService = new AssetService(config);
95
96 AssetServerPostHandler asph = new AssetServerPostHandler(assetService);
97
98 MemoryStream buffer = new MemoryStream();
99 byte[] badData = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f };
100 buffer.Write(badData, 0, badData.Length);
101 buffer.Position = 0;
102
103 TestOSHttpResponse response = new TestOSHttpResponse();
104 asph.Handle(null, buffer, null, response);
105
106 Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest));
107 }
108 }
109} \ No newline at end of file