From 3a9b67c8ad09af15323e8c8b95a3a1aff5c25a83 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Tue, 7 Feb 2012 16:05:19 +0100 Subject: [PATCH] Better code to test similar functions but with chunked input --- .../server/wsf/tests/src/test_wsf_request.e | 14 +++++- .../src/test_wsf_request_chunked_input.e | 44 +++++-------------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/library/server/wsf/tests/src/test_wsf_request.e b/library/server/wsf/tests/src/test_wsf_request.e index bf9407f5..5a60b8b5 100644 --- a/library/server/wsf/tests/src/test_wsf_request.e +++ b/library/server/wsf/tests/src/test_wsf_request.e @@ -161,7 +161,7 @@ feature {NONE} -- Events do get_http_session if attached http_session as sess then - if attached sess.get (a_url, ctx) as res and then not res.error_occurred and then attached res.body as l_body then + if attached sess.get (a_url, adapted_context (ctx)) as res and then not res.error_occurred and then attached res.body as l_body then assert ("Good answer got=%""+l_body+"%" expected=%""+a_expected_body+"%"", l_body.same_string (a_expected_body)) else assert ("Request %""+a_url+"%" failed", False) @@ -173,7 +173,7 @@ feature {NONE} -- Events do get_http_session if attached http_session as sess then - if attached sess.post (a_url, ctx, Void) as res and then not res.error_occurred and then attached res.body as l_body then + if attached sess.post (a_url, adapted_context (ctx), Void) as res and then not res.error_occurred and then attached res.body as l_body then assert ("Good answer got=%""+l_body+"%" expected=%""+a_expected_body+"%"", l_body.same_string (a_expected_body)) else assert ("Request %""+a_url+"%" failed", False) @@ -181,6 +181,16 @@ feature {NONE} -- Events end end + adapted_context (ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_REQUEST_CONTEXT + do + if ctx /= Void then + Result := ctx + else + create Result.make + end +-- Result.set_proxy ("127.0.0.1", 8888) --| inspect traffic with http://www.fiddler2.com/ + end + feature -- Test routines test_get_request_01 diff --git a/library/server/wsf/tests/src/test_wsf_request_chunked_input.e b/library/server/wsf/tests/src/test_wsf_request_chunked_input.e index c213a73a..24a2bc5a 100644 --- a/library/server/wsf/tests/src/test_wsf_request_chunked_input.e +++ b/library/server/wsf/tests/src/test_wsf_request_chunked_input.e @@ -13,50 +13,30 @@ class inherit TEST_WSF_REQUEST redefine + adapted_context, test_get_request_01, test_post_request_01 end +feature {NONE} -- Helpers + + adapted_context (ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_REQUEST_CONTEXT + do + Result := Precursor (ctx) + Result.headers.extend ("chunked", "Transfer-Encoding") +-- Result.set_proxy ("127.0.0.1", 8888) --| inspect traffic with http://www.fiddler2.com/ + end + feature -- Test routines test_get_request_01 - -- New test routine - local - ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT do - get_http_session - if attached http_session as sess then --- create ctx.make --- ctx.set_proxy ("127.0.0.1", 8888) --| debugging with http://www.fiddler2.com/ - - test_get_request ("get/01", ctx, "get-01") - test_get_request ("get/01/?foo=bar", ctx, "get-01(foo=bar)") - test_get_request ("get/01/?foo=bar&abc=def", ctx, "get-01(foo=bar&abc=def)") - test_get_request ("get/01/?lst=a&lst=b", ctx, "get-01(lst=[a,b])") - else - assert ("not_implemented", False) - end + Precursor end test_post_request_01 - -- New test routine - local - ctx: HTTP_CLIENT_REQUEST_CONTEXT do - get_http_session - if attached http_session as sess then - create ctx.make - ctx.add_form_parameter ("id", "123") - ctx.headers.extend ("chunked", "Transfer-Encoding") --- ctx.set_proxy ("127.0.0.1", 8888) --| debugging with http://www.fiddler2.com/ - - test_post_request ("post/01", ctx, "post-01 : id=123") - test_post_request ("post/01/?foo=bar", ctx, "post-01(foo=bar) : id=123") - test_post_request ("post/01/?foo=bar&abc=def", ctx, "post-01(foo=bar&abc=def) : id=123") - test_post_request ("post/01/?lst=a&lst=b", ctx, "post-01(lst=[a,b]) : id=123") - else - assert ("not_implemented", False) - end + Precursor end end