29 using System.Collections.Generic;
32 using System.Reflection;
36 using NUnit.Framework;
38 using OpenSim.Framework;
39 using OpenSim.Framework.Servers;
40 using OpenSim.Framework.Servers.HttpServer;
41 using OpenSim.Region.CoreModules.Scripting.LSLHttp;
42 using OpenSim.Region.Framework.Scenes;
43 using OpenSim.Region.ScriptEngine.Shared;
44 using OpenSim.Region.ScriptEngine.Shared.Api;
45 using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
46 using OpenSim.Services.Interfaces;
47 using OpenSim.Tests.Common;
49 namespace OpenSim.
Region.ScriptEngine.Shared.Tests
57 private Scene m_scene;
68 Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
77 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
88 MainServer.RemoveHttpServer(port);
91 MainServer.AddHttpServer(server);
92 MainServer.Instance = server;
100 SceneHelpers.SetupSceneModules(m_scene,
new IniConfigSource(), m_engine, m_urlModule);
103 m_scriptItem = TaskInventoryHelpers.AddScript(m_scene.AssetService, so.RootPart);
108 m_lslApi.Initialize(m_engine, so.RootPart, m_scriptItem);
114 MainServer.Instance.Stop();
120 TestHelpers.InMethod();
122 m_lslApi.llRequestURL();
123 string returnedUri = m_engine.PostedEvents[m_scriptItem.ItemID][0].Params[2].ToString();
127 Assert.That(m_lslApi.llGetFreeURLs().value, Is.EqualTo(m_urlModule.TotalUrls - 1));
132 m_lslApi.llReleaseURL(
"GARBAGE");
133 Assert.That(m_lslApi.llGetFreeURLs().value, Is.EqualTo(m_urlModule.TotalUrls - 1));
138 m_lslApi.llReleaseURL(
"http://example.com");
139 Assert.That(m_lslApi.llGetFreeURLs().value, Is.EqualTo(m_urlModule.TotalUrls - 1));
144 m_lslApi.llReleaseURL(returnedUri);
145 Assert.That(m_lslApi.llGetFreeURLs().value, Is.EqualTo(m_urlModule.TotalUrls));
147 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(returnedUri);
149 bool gotExpectedException =
false;
153 using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
156 catch (WebException e)
160 gotExpectedException =
true;
163 Assert.That(gotExpectedException, Is.True);
168 m_lslApi.llReleaseURL(returnedUri);
169 Assert.That(m_lslApi.llGetFreeURLs().value, Is.EqualTo(m_urlModule.TotalUrls));
176 TestHelpers.InMethod();
178 string requestId = m_lslApi.llRequestURL();
179 Assert.That(requestId, Is.Not.EqualTo(UUID.Zero.ToString()));
184 Assert.That(m_lslApi.llGetFreeURLs().value, Is.EqualTo(m_urlModule.TotalUrls - 1));
186 Assert.That(m_engine.PostedEvents.ContainsKey(m_scriptItem.ItemID));
188 List<EventParams> events = m_engine.PostedEvents[m_scriptItem.ItemID];
189 Assert.That(events.Count, Is.EqualTo(1));
191 Assert.That(eventParams.EventName, Is.EqualTo(
"http_request"));
194 string rawReturnKey = eventParams.Params[0].ToString();
195 string method = eventParams.Params[1].ToString();
196 returnedUri = eventParams.Params[2].ToString();
198 Assert.That(UUID.TryParse(rawReturnKey, out returnKey), Is.True);
199 Assert.That(method, Is.EqualTo(ScriptBaseClass.URL_REQUEST_GRANTED));
200 Assert.That(Uri.IsWellFormedUriString(returnedUri, UriKind.Absolute), Is.True);
205 string testResponse =
"Hello World";
207 m_engine.ClearPostedEvents();
208 m_engine.PostEventHook
209 += (itemId, evp) => m_lslApi.llHTTPResponse(evp.Params[0].ToString(), 200, testResponse);
213 AssertHttpResponse(returnedUri, testResponse);
215 Assert.That(m_engine.PostedEvents.ContainsKey(m_scriptItem.ItemID));
217 List<EventParams> events = m_engine.PostedEvents[m_scriptItem.ItemID];
218 Assert.That(events.Count, Is.EqualTo(1));
220 Assert.That(eventParams.EventName, Is.EqualTo(
"http_request"));
223 string rawReturnKey = eventParams.Params[0].ToString();
224 string method = eventParams.Params[1].ToString();
225 string body = eventParams.Params[2].ToString();
227 Assert.That(UUID.TryParse(rawReturnKey, out returnKey), Is.True);
228 Assert.That(method, Is.EqualTo(
"GET"));
229 Assert.That(body, Is.EqualTo(
""));
233 private void AssertHttpResponse(
string uri,
string expectedResponse)
235 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
237 using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
239 using (Stream stream = webResponse.GetResponseStream())
241 using (StreamReader reader =
new StreamReader(stream))
243 Assert.That(reader.ReadToEnd(), Is.EqualTo(expectedResponse));
Contains all LSL ll-functions. This class will be in Default AppDomain.
This module provides external URLs for in-world scripts.
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Represents an item in a task inventory
void TestFixureTearDown()
Tests for HTTP related functions in LSL
Helpers for setting up scenes.
Holds all the data required to execute a scripting event.