diff options
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs')
-rw-r--r-- | OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs | 110 |
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 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Net; | ||
31 | using System.Text; | ||
32 | using System.Xml; | ||
33 | using System.Xml.Serialization; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Server.Handlers.Asset; | ||
39 | using OpenSim.Services.AssetService; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Tests.Common; | ||
42 | using OpenSim.Tests.Common.Mock; | ||
43 | |||
44 | namespace 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 | ||