diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs | 90 |
1 files changed, 88 insertions, 2 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs index 9e24bce..fb24f58 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | ||
29 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
30 | using System.Net; | 31 | using System.Net; |
31 | using log4net.Config; | 32 | using log4net.Config; |
@@ -33,11 +34,14 @@ using Nini.Config; | |||
33 | using NUnit.Framework; | 34 | using NUnit.Framework; |
34 | using OpenMetaverse; | 35 | using OpenMetaverse; |
35 | using OpenMetaverse.Packets; | 36 | using OpenMetaverse.Packets; |
37 | using OpenMetaverse.StructuredData; | ||
36 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
37 | using OpenSim.Framework.Servers; | 39 | using OpenSim.Framework.Servers; |
38 | using OpenSim.Framework.Servers.HttpServer; | 40 | using OpenSim.Framework.Servers.HttpServer; |
39 | using OpenSim.Region.ClientStack.Linden; | 41 | using OpenSim.Region.ClientStack.Linden; |
40 | using OpenSim.Region.CoreModules.Framework; | 42 | using OpenSim.Region.CoreModules.Framework; |
43 | using OpenSim.Region.Framework.Scenes; | ||
44 | using OpenSim.Region.OptionalModules.World.NPC; | ||
41 | using OpenSim.Tests.Common; | 45 | using OpenSim.Tests.Common; |
42 | using OpenSim.Tests.Common.Mock; | 46 | using OpenSim.Tests.Common.Mock; |
43 | 47 | ||
@@ -47,6 +51,8 @@ namespace OpenSim.Region.ClientStack.Linden.Tests | |||
47 | public class EventQueueTests : OpenSimTestCase | 51 | public class EventQueueTests : OpenSimTestCase |
48 | { | 52 | { |
49 | private TestScene m_scene; | 53 | private TestScene m_scene; |
54 | private EventQueueGetModule m_eqgMod; | ||
55 | private NPCModule m_npcMod; | ||
50 | 56 | ||
51 | [SetUp] | 57 | [SetUp] |
52 | public override void SetUp() | 58 | public override void SetUp() |
@@ -69,10 +75,15 @@ namespace OpenSim.Region.ClientStack.Linden.Tests | |||
69 | config.Configs["Startup"].Set("EventQueue", "true"); | 75 | config.Configs["Startup"].Set("EventQueue", "true"); |
70 | 76 | ||
71 | CapabilitiesModule capsModule = new CapabilitiesModule(); | 77 | CapabilitiesModule capsModule = new CapabilitiesModule(); |
72 | EventQueueGetModule eqgModule = new EventQueueGetModule(); | 78 | m_eqgMod = new EventQueueGetModule(); |
79 | |||
80 | // For NPC test support | ||
81 | config.AddConfig("NPC"); | ||
82 | config.Configs["NPC"].Set("Enabled", "true"); | ||
83 | m_npcMod = new NPCModule(); | ||
73 | 84 | ||
74 | m_scene = new SceneHelpers().SetupScene(); | 85 | m_scene = new SceneHelpers().SetupScene(); |
75 | SceneHelpers.SetupSceneModules(m_scene, config, capsModule, eqgModule); | 86 | SceneHelpers.SetupSceneModules(m_scene, config, capsModule, m_eqgMod, m_npcMod); |
76 | } | 87 | } |
77 | 88 | ||
78 | [Test] | 89 | [Test] |
@@ -101,5 +112,80 @@ namespace OpenSim.Region.ClientStack.Linden.Tests | |||
101 | // TODO: Add more assertions for the other aspects of event queues | 112 | // TODO: Add more assertions for the other aspects of event queues |
102 | Assert.That(MainServer.Instance.GetPollServiceHandlerKeys().Count, Is.EqualTo(0)); | 113 | Assert.That(MainServer.Instance.GetPollServiceHandlerKeys().Count, Is.EqualTo(0)); |
103 | } | 114 | } |
115 | |||
116 | [Test] | ||
117 | public void TestEnqueueMessage() | ||
118 | { | ||
119 | TestHelpers.InMethod(); | ||
120 | // log4net.Config.XmlConfigurator.Configure(); | ||
121 | |||
122 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | ||
123 | |||
124 | string messageName = "TestMessage"; | ||
125 | |||
126 | m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), sp.UUID); | ||
127 | |||
128 | Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID); | ||
129 | |||
130 | Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.OK)); | ||
131 | |||
132 | // Console.WriteLine("Response [{0}]", (string)eventsResponse["str_response_string"]); | ||
133 | |||
134 | OSDMap rawOsd = (OSDMap)OSDParser.DeserializeLLSDXml((string)eventsResponse["str_response_string"]); | ||
135 | OSDArray eventsOsd = (OSDArray)rawOsd["events"]; | ||
136 | |||
137 | bool foundUpdate = false; | ||
138 | foreach (OSD osd in eventsOsd) | ||
139 | { | ||
140 | OSDMap eventOsd = (OSDMap)osd; | ||
141 | |||
142 | if (eventOsd["message"] == messageName) | ||
143 | foundUpdate = true; | ||
144 | } | ||
145 | |||
146 | Assert.That(foundUpdate, Is.True, string.Format("Did not find {0} in response", messageName)); | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// Test an attempt to put a message on the queue of a user that is not in the region. | ||
151 | /// </summary> | ||
152 | [Test] | ||
153 | public void TestEnqueueMessageNoUser() | ||
154 | { | ||
155 | TestHelpers.InMethod(); | ||
156 | TestHelpers.EnableLogging(); | ||
157 | |||
158 | string messageName = "TestMessage"; | ||
159 | |||
160 | m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), TestHelpers.ParseTail(0x1)); | ||
161 | |||
162 | Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, TestHelpers.ParseTail(0x1)); | ||
163 | |||
164 | Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.BadGateway)); | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// NPCs do not currently have an event queue but a caller may try to send a message anyway, so check behaviour. | ||
169 | /// </summary> | ||
170 | [Test] | ||
171 | public void TestEnqueueMessageToNpc() | ||
172 | { | ||
173 | TestHelpers.InMethod(); | ||
174 | // TestHelpers.EnableLogging(); | ||
175 | |||
176 | UUID npcId | ||
177 | = m_npcMod.CreateNPC( | ||
178 | "John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, new AvatarAppearance()); | ||
179 | |||
180 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
181 | |||
182 | string messageName = "TestMessage"; | ||
183 | |||
184 | m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), npc.UUID); | ||
185 | |||
186 | Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, npc.UUID); | ||
187 | |||
188 | Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.BadGateway)); | ||
189 | } | ||
104 | } | 190 | } |
105 | } \ No newline at end of file | 191 | } \ No newline at end of file |