diff options
author | Dr Scofield | 2008-10-08 13:45:42 +0000 |
---|---|---|
committer | Dr Scofield | 2008-10-08 13:45:42 +0000 |
commit | 1e8533772f79dc0ee6466eacad1f5991e418340d (patch) | |
tree | bc8a2c8f4079d24feb323c25ae0e743c9ac9be41 /OpenSim/Framework/Servers | |
parent | * Re-enables map item requests. (diff) | |
download | opensim-SC_OLD-1e8533772f79dc0ee6466eacad1f5991e418340d.zip opensim-SC_OLD-1e8533772f79dc0ee6466eacad1f5991e418340d.tar.gz opensim-SC_OLD-1e8533772f79dc0ee6466eacad1f5991e418340d.tar.bz2 opensim-SC_OLD-1e8533772f79dc0ee6466eacad1f5991e418340d.tar.xz |
adding OSHttpResponse test case (yeah, very primitive still)
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r-- | OpenSim/Framework/Servers/Tests/OSHttpTests.cs | 201 |
1 files changed, 175 insertions, 26 deletions
diff --git a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs b/OpenSim/Framework/Servers/Tests/OSHttpTests.cs index c6132f8..fe553c9 100644 --- a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs +++ b/OpenSim/Framework/Servers/Tests/OSHttpTests.cs | |||
@@ -30,9 +30,12 @@ using System.Collections.Specialized; | |||
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Net; | 31 | using System.Net; |
32 | using System.Net.Sockets; | 32 | using System.Net.Sockets; |
33 | using System.Text; | ||
34 | |||
33 | using HttpServer; | 35 | using HttpServer; |
34 | using HttpServer.Exceptions; | 36 | using HttpServer.Exceptions; |
35 | using HttpServer.FormDecoders; | 37 | using HttpServer.FormDecoders; |
38 | |||
36 | using NUnit.Framework; | 39 | using NUnit.Framework; |
37 | using NUnit.Framework.SyntaxHelpers; | 40 | using NUnit.Framework.SyntaxHelpers; |
38 | 41 | ||
@@ -186,64 +189,210 @@ namespace OpenSim.Framework.Servers.Tests | |||
186 | } | 189 | } |
187 | } | 190 | } |
188 | 191 | ||
192 | public class TestHttpResponse: IHttpResponse | ||
193 | { | ||
194 | public Stream Body | ||
195 | { | ||
196 | get { return _body; } | ||
197 | |||
198 | set { _body = value; } | ||
199 | } | ||
200 | private Stream _body; | ||
201 | |||
202 | public string ProtocolVersion | ||
203 | { | ||
204 | get { return _protocolVersion; } | ||
205 | set { _protocolVersion = value; } | ||
206 | } | ||
207 | private string _protocolVersion; | ||
208 | |||
209 | public bool Chunked | ||
210 | { | ||
211 | get { return _chunked; } | ||
212 | |||
213 | set { _chunked = value; } | ||
214 | } | ||
215 | private bool _chunked; | ||
216 | |||
217 | public ConnectionType Connection | ||
218 | { | ||
219 | get { return _connection; } | ||
220 | |||
221 | set { _connection = value; } | ||
222 | } | ||
223 | private ConnectionType _connection; | ||
224 | |||
225 | public Encoding Encoding | ||
226 | { | ||
227 | get { return _encoding; } | ||
228 | |||
229 | set { _encoding = value; } | ||
230 | } | ||
231 | private Encoding _encoding; | ||
232 | |||
233 | public int KeepAlive | ||
234 | { | ||
235 | get { return _keepAlive; } | ||
236 | |||
237 | set { _keepAlive = value; } | ||
238 | } | ||
239 | private int _keepAlive; | ||
240 | |||
241 | public HttpStatusCode Status | ||
242 | { | ||
243 | get { return _status; } | ||
244 | |||
245 | set { _status = value; } | ||
246 | } | ||
247 | private HttpStatusCode _status; | ||
248 | |||
249 | public string Reason | ||
250 | { | ||
251 | get { return _reason; } | ||
252 | |||
253 | set { _reason = value; } | ||
254 | } | ||
255 | private string _reason; | ||
256 | |||
257 | public long ContentLength | ||
258 | { | ||
259 | get { return _contentLength; } | ||
260 | |||
261 | set { _contentLength = value; } | ||
262 | } | ||
263 | private long _contentLength; | ||
264 | |||
265 | public string ContentType | ||
266 | { | ||
267 | get { return _contentType; } | ||
268 | |||
269 | set { _contentType = value; } | ||
270 | } | ||
271 | private string _contentType; | ||
272 | |||
273 | public bool HeadersSent | ||
274 | { | ||
275 | get { return _headersSent; } | ||
276 | } | ||
277 | private bool _headersSent; | ||
278 | |||
279 | public bool Sent | ||
280 | { | ||
281 | get { return _sent; } | ||
282 | } | ||
283 | private bool _sent; | ||
284 | |||
285 | public ResponseCookies Cookies | ||
286 | { | ||
287 | get { return _cookies; } | ||
288 | } | ||
289 | private ResponseCookies _cookies; | ||
290 | |||
291 | public TestHttpResponse() | ||
292 | { | ||
293 | _headersSent = false; | ||
294 | _sent = false; | ||
295 | } | ||
296 | |||
297 | public void AddHeader(string name, string value) {} | ||
298 | public void Send() | ||
299 | { | ||
300 | if (!_headersSent) SendHeaders(); | ||
301 | if (_sent) throw new InvalidOperationException("stuff already sent"); | ||
302 | _sent = true; | ||
303 | } | ||
304 | |||
305 | public void SendBody(byte[] buffer, int offset, int count) | ||
306 | { | ||
307 | if (!_headersSent) SendHeaders(); | ||
308 | _sent = true; | ||
309 | } | ||
310 | public void SendBody(byte[] buffer) | ||
311 | { | ||
312 | if (!_headersSent) SendHeaders(); | ||
313 | _sent = true; | ||
314 | } | ||
315 | |||
316 | public void SendHeaders() | ||
317 | { | ||
318 | if (_headersSent) throw new InvalidOperationException("headers already sent"); | ||
319 | _headersSent = true; | ||
320 | } | ||
321 | |||
322 | public void Redirect(Uri uri) {} | ||
323 | public void Redirect(string url) {} | ||
324 | } | ||
325 | |||
189 | 326 | ||
190 | public OSHttpRequest r0; | 327 | public OSHttpRequest req0; |
191 | public OSHttpRequest r1; | 328 | public OSHttpRequest req1; |
329 | |||
330 | public OSHttpResponse rsp0; | ||
192 | 331 | ||
193 | public IPEndPoint ipEP0; | 332 | public IPEndPoint ipEP0; |
194 | 333 | ||
195 | [TestFixtureSetUp] | 334 | [TestFixtureSetUp] |
196 | public void Init() | 335 | public void Init() |
197 | { | 336 | { |
198 | TestHttpRequest thr0 = new TestHttpRequest("utf-8", "text/xml", "OpenSim Test Agent", "192.168.0.1", "4711", | 337 | TestHttpRequest threq0 = new TestHttpRequest("utf-8", "text/xml", "OpenSim Test Agent", "192.168.0.1", "4711", |
199 | new string[] {"text/xml"}, | 338 | new string[] {"text/xml"}, |
200 | ConnectionType.KeepAlive, 4711, | 339 | ConnectionType.KeepAlive, 4711, |
201 | new Uri("http://127.0.0.1/admin/inventory/Dr+Who/Tardis")); | 340 | new Uri("http://127.0.0.1/admin/inventory/Dr+Who/Tardis")); |
202 | thr0.Method = "GET"; | 341 | threq0.Method = "GET"; |
203 | thr0.HttpVersion = HttpHelper.HTTP10; | 342 | threq0.HttpVersion = HttpHelper.HTTP10; |
204 | 343 | ||
205 | TestHttpRequest thr1 = new TestHttpRequest("utf-8", "text/xml", "OpenSim Test Agent", "192.168.0.1", "4711", | 344 | TestHttpRequest threq1 = new TestHttpRequest("utf-8", "text/xml", "OpenSim Test Agent", "192.168.0.1", "4711", |
206 | new string[] {"text/xml"}, | 345 | new string[] {"text/xml"}, |
207 | ConnectionType.KeepAlive, 4711, | 346 | ConnectionType.KeepAlive, 4711, |
208 | new Uri("http://127.0.0.1/admin/inventory/Dr+Who/Tardis?a=0&b=1&c=2")); | 347 | new Uri("http://127.0.0.1/admin/inventory/Dr+Who/Tardis?a=0&b=1&c=2")); |
209 | thr1.Method = "POST"; | 348 | threq1.Method = "POST"; |
210 | thr1.HttpVersion = HttpHelper.HTTP11; | 349 | threq1.HttpVersion = HttpHelper.HTTP11; |
211 | thr1.Headers["x-wuff"] = "wuffwuff"; | 350 | threq1.Headers["x-wuff"] = "wuffwuff"; |
212 | thr1.Headers["www-authenticate"] = "go away"; | 351 | threq1.Headers["www-authenticate"] = "go away"; |
213 | 352 | ||
214 | r0 = new OSHttpRequest(new TestHttpClientContext(false), thr0); | 353 | req0 = new OSHttpRequest(new TestHttpClientContext(false), threq0); |
215 | r1 = new OSHttpRequest(new TestHttpClientContext(false), thr1); | 354 | req1 = new OSHttpRequest(new TestHttpClientContext(false), threq1); |
355 | |||
356 | rsp0 = new OSHttpResponse(new TestHttpResponse()); | ||
216 | 357 | ||
217 | ipEP0 = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 4711); | 358 | ipEP0 = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 4711); |
359 | |||
218 | } | 360 | } |
219 | 361 | ||
220 | [Test] | 362 | [Test] |
221 | public void T001_SimpleOSHttpRequest() | 363 | public void T000_OSHttpRequest() |
222 | { | 364 | { |
223 | Assert.That(r0.HttpMethod, Is.EqualTo("GET")); | 365 | Assert.That(req0.HttpMethod, Is.EqualTo("GET")); |
224 | Assert.That(r0.ContentType, Is.EqualTo("text/xml")); | 366 | Assert.That(req0.ContentType, Is.EqualTo("text/xml")); |
225 | Assert.That(r0.ContentLength, Is.EqualTo(4711)); | 367 | Assert.That(req0.ContentLength, Is.EqualTo(4711)); |
226 | 368 | ||
227 | Assert.That(r1.HttpMethod, Is.EqualTo("POST")); | 369 | Assert.That(req1.HttpMethod, Is.EqualTo("POST")); |
228 | } | 370 | } |
229 | 371 | ||
230 | [Test] | 372 | [Test] |
231 | public void T002_HeaderAccess() | 373 | public void T001_OSHttpRequestHeaderAccess() |
232 | { | 374 | { |
233 | Assert.That(r1.Headers["x-wuff"], Is.EqualTo("wuffwuff")); | 375 | Assert.That(req1.Headers["x-wuff"], Is.EqualTo("wuffwuff")); |
234 | Assert.That(r1.Headers.Get("x-wuff"), Is.EqualTo("wuffwuff")); | 376 | Assert.That(req1.Headers.Get("x-wuff"), Is.EqualTo("wuffwuff")); |
377 | |||
378 | Assert.That(req1.Headers["www-authenticate"], Is.EqualTo("go away")); | ||
379 | Assert.That(req1.Headers.Get("www-authenticate"), Is.EqualTo("go away")); | ||
235 | 380 | ||
236 | Assert.That(r1.Headers["www-authenticate"], Is.EqualTo("go away")); | 381 | Assert.That(req0.RemoteIPEndPoint, Is.EqualTo(ipEP0)); |
237 | Assert.That(r1.Headers.Get("www-authenticate"), Is.EqualTo("go away")); | 382 | } |
238 | 383 | ||
239 | Assert.That(r0.RemoteIPEndPoint, Is.EqualTo(ipEP0)); | 384 | [Test] |
385 | public void T002_OSHttpRequestUriParsing() | ||
386 | { | ||
387 | Assert.That(req0.RawUrl, Is.EqualTo("/admin/inventory/Dr+Who/Tardis")); | ||
388 | Assert.That(req1.Url.ToString(), Is.EqualTo("http://127.0.0.1/admin/inventory/Dr+Who/Tardis?a=0&b=1&c=2")); | ||
240 | } | 389 | } |
241 | 390 | ||
242 | [Test] | 391 | [Test] |
243 | public void T003_UriParsing() | 392 | public void T100_OSHttpResponse() |
244 | { | 393 | { |
245 | Assert.That(r0.RawUrl, Is.EqualTo("/admin/inventory/Dr+Who/Tardis")); | 394 | rsp0.ContentType = "text/xml"; |
246 | Assert.That(r1.Url.ToString(), Is.EqualTo("http://127.0.0.1/admin/inventory/Dr+Who/Tardis?a=0&b=1&c=2")); | 395 | Assert.That(rsp0.ContentType, Is.EqualTo("text/xml")); |
247 | } | 396 | } |
248 | } | 397 | } |
249 | } | 398 | } |