diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs new file mode 100644 index 0000000..16a902d --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs | |||
@@ -0,0 +1,190 @@ | |||
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.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Net; | ||
32 | using log4net.Config; | ||
33 | using Nini.Config; | ||
34 | using NUnit.Framework; | ||
35 | using OpenMetaverse; | ||
36 | using OpenMetaverse.Packets; | ||
37 | using OpenMetaverse.StructuredData; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers; | ||
40 | using OpenSim.Framework.Servers.HttpServer; | ||
41 | using OpenSim.Region.ClientStack.Linden; | ||
42 | using OpenSim.Region.CoreModules.Framework; | ||
43 | using OpenSim.Region.Framework.Scenes; | ||
44 | using OpenSim.Region.OptionalModules.World.NPC; | ||
45 | using OpenSim.Tests.Common; | ||
46 | |||
47 | namespace OpenSim.Region.ClientStack.Linden.Tests | ||
48 | { | ||
49 | [TestFixture] | ||
50 | public class EventQueueTests : OpenSimTestCase | ||
51 | { | ||
52 | private TestScene m_scene; | ||
53 | private EventQueueGetModule m_eqgMod; | ||
54 | private NPCModule m_npcMod; | ||
55 | |||
56 | [SetUp] | ||
57 | public override void SetUp() | ||
58 | { | ||
59 | base.SetUp(); | ||
60 | |||
61 | uint port = 9999; | ||
62 | uint sslPort = 9998; | ||
63 | |||
64 | // This is an unfortunate bit of clean up we have to do because MainServer manages things through static | ||
65 | // variables and the VM is not restarted between tests. | ||
66 | MainServer.RemoveHttpServer(port); | ||
67 | |||
68 | BaseHttpServer server = new BaseHttpServer(port, false, sslPort, ""); | ||
69 | MainServer.AddHttpServer(server); | ||
70 | MainServer.Instance = server; | ||
71 | |||
72 | IConfigSource config = new IniConfigSource(); | ||
73 | config.AddConfig("Startup"); | ||
74 | config.Configs["Startup"].Set("EventQueue", "true"); | ||
75 | |||
76 | CapabilitiesModule capsModule = new CapabilitiesModule(); | ||
77 | m_eqgMod = new EventQueueGetModule(); | ||
78 | |||
79 | // For NPC test support | ||
80 | config.AddConfig("NPC"); | ||
81 | config.Configs["NPC"].Set("Enabled", "true"); | ||
82 | m_npcMod = new NPCModule(); | ||
83 | |||
84 | m_scene = new SceneHelpers().SetupScene(); | ||
85 | SceneHelpers.SetupSceneModules(m_scene, config, capsModule, m_eqgMod, m_npcMod); | ||
86 | } | ||
87 | |||
88 | [Test] | ||
89 | public void TestAddForClient() | ||
90 | { | ||
91 | TestHelpers.InMethod(); | ||
92 | // log4net.Config.XmlConfigurator.Configure(); | ||
93 | |||
94 | SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | ||
95 | |||
96 | // TODO: Add more assertions for the other aspects of event queues | ||
97 | Assert.That(MainServer.Instance.GetPollServiceHandlerKeys().Count, Is.EqualTo(1)); | ||
98 | } | ||
99 | |||
100 | [Test] | ||
101 | public void TestRemoveForClient() | ||
102 | { | ||
103 | TestHelpers.InMethod(); | ||
104 | // TestHelpers.EnableLogging(); | ||
105 | |||
106 | UUID spId = TestHelpers.ParseTail(0x1); | ||
107 | |||
108 | SceneHelpers.AddScenePresence(m_scene, spId); | ||
109 | m_scene.CloseAgent(spId, false); | ||
110 | |||
111 | // TODO: Add more assertions for the other aspects of event queues | ||
112 | Assert.That(MainServer.Instance.GetPollServiceHandlerKeys().Count, Is.EqualTo(0)); | ||
113 | } | ||
114 | |||
115 | [Test] | ||
116 | public void TestEnqueueMessage() | ||
117 | { | ||
118 | TestHelpers.InMethod(); | ||
119 | // log4net.Config.XmlConfigurator.Configure(); | ||
120 | |||
121 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | ||
122 | |||
123 | string messageName = "TestMessage"; | ||
124 | |||
125 | m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), sp.UUID); | ||
126 | |||
127 | Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID); | ||
128 | |||
129 | Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.OK)); | ||
130 | |||
131 | // Console.WriteLine("Response [{0}]", (string)eventsResponse["str_response_string"]); | ||
132 | |||
133 | OSDMap rawOsd = (OSDMap)OSDParser.DeserializeLLSDXml((string)eventsResponse["str_response_string"]); | ||
134 | OSDArray eventsOsd = (OSDArray)rawOsd["events"]; | ||
135 | |||
136 | bool foundUpdate = false; | ||
137 | foreach (OSD osd in eventsOsd) | ||
138 | { | ||
139 | OSDMap eventOsd = (OSDMap)osd; | ||
140 | |||
141 | if (eventOsd["message"] == messageName) | ||
142 | foundUpdate = true; | ||
143 | } | ||
144 | |||
145 | Assert.That(foundUpdate, Is.True, string.Format("Did not find {0} in response", messageName)); | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// Test an attempt to put a message on the queue of a user that is not in the region. | ||
150 | /// </summary> | ||
151 | [Test] | ||
152 | public void TestEnqueueMessageNoUser() | ||
153 | { | ||
154 | TestHelpers.InMethod(); | ||
155 | TestHelpers.EnableLogging(); | ||
156 | |||
157 | string messageName = "TestMessage"; | ||
158 | |||
159 | m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), TestHelpers.ParseTail(0x1)); | ||
160 | |||
161 | Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, TestHelpers.ParseTail(0x1)); | ||
162 | |||
163 | Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.BadGateway)); | ||
164 | } | ||
165 | |||
166 | /// <summary> | ||
167 | /// NPCs do not currently have an event queue but a caller may try to send a message anyway, so check behaviour. | ||
168 | /// </summary> | ||
169 | [Test] | ||
170 | public void TestEnqueueMessageToNpc() | ||
171 | { | ||
172 | TestHelpers.InMethod(); | ||
173 | // TestHelpers.EnableLogging(); | ||
174 | |||
175 | UUID npcId | ||
176 | = m_npcMod.CreateNPC( | ||
177 | "John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, new AvatarAppearance()); | ||
178 | |||
179 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
180 | |||
181 | string messageName = "TestMessage"; | ||
182 | |||
183 | m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), npc.UUID); | ||
184 | |||
185 | Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, npc.UUID); | ||
186 | |||
187 | Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.BadGateway)); | ||
188 | } | ||
189 | } | ||
190 | } \ No newline at end of file | ||