Initial implementation of HTTP RESPONSE EXPECTATIONS.

Added a class to test http client with httpbin.org and expectations
This commit is contained in:
jvelilla
2013-05-10 09:48:28 -03:00
parent b777e81ab1
commit 8db7d0daa3
4 changed files with 238 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
note
description: "Summary description for {HTTP_CLIENT_RESPONSE_BODY_EXPECTATION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
HTTP_CLIENT_RESPONSE_BODY_EXPECTATION
inherit
HTTP_CLIENT_RESPONSE_EXPECTATION
create
make
feature {NONE} -- Initializtion
make (a_body : detachable STRING_32)
-- Create and Initialize a body expectation
do
body := a_body
ensure
body_set : body ~ a_body
end
feature -- Result expected
expected (resp: HTTP_CLIENT_RESPONSE): BOOLEAN
-- is `body expected' equals to resp.body?
do
if body = Void and then resp.body = Void then
Result := True
elseif attached resp.body as l_body and then attached body as c_body then
Result := l_body.is_case_insensitive_equal (c_body)
end
end
feature -- Access
body : detachable STRING_32
-- expected body
;note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,27 @@
note
description: "Summary description for {HTTP_CLIENT_RESPONSE_EXPECTATION}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
HTTP_CLIENT_RESPONSE_EXPECTATION
feature
expected (resp: HTTP_CLIENT_RESPONSE): BOOLEAN
deferred
end
note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,42 @@
note
description: "Summary description for {HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION
inherit
HTTP_CLIENT_RESPONSE_EXPECTATION
create make
feature {NONE} -- Initialization
make (a_status : INTEGER_32)
do
status := a_status
ensure
status_set : status = a_status
end
feature -- Result Expected
expected (resp: HTTP_CLIENT_RESPONSE): BOOLEAN
-- is `status' expected equals to resp.status?
do
Result := status = resp.status
end
feature -- Access
status : INTEGER_32
-- status expected
;note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,121 @@
note
description: "Summary description for {TEST_HTTP_CLIENT_WITH_HTTPBIN}."
author: ""
date: "$Date$"
revision: "$Revision$"
EIS: "name=HTTP TESTING", "protocol=uri", "src=http://httpbin.org/"
class
TEST_HTTP_CLIENT_WITH_HTTPBIN
inherit
EQA_TEST_SET
feature
test_origin_ip
local
h: LIBCURL_HTTP_CLIENT
sess: HTTP_CLIENT_SESSION
resp : detachable HTTP_CLIENT_RESPONSE
l_location : detachable READABLE_STRING_8
body : STRING
context : HTTP_CLIENT_REQUEST_CONTEXT
s: READABLE_STRING_8
do
create h.make
sess := h.new_session ("http://httpbin.org/")
resp := sess.get ("",void)
assert ("Expected Status 200 ok", resp.status = 200)
end
test_status_code
local
h: LIBCURL_HTTP_CLIENT
sess: HTTP_CLIENT_SESSION
resp : detachable HTTP_CLIENT_RESPONSE
l_location : detachable READABLE_STRING_8
body : STRING
context : HTTP_CLIENT_REQUEST_CONTEXT
s: READABLE_STRING_8
do
create h.make
sess := h.new_session ("http://httpbin.org/")
assert ("Expected Status 200 ok", (create {HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION}.make(200)).expected(sess.get ("",void)) )
end
test_body
local
h: LIBCURL_HTTP_CLIENT
sess: HTTP_CLIENT_SESSION
resp : detachable HTTP_CLIENT_RESPONSE
l_location : detachable READABLE_STRING_8
body : STRING
context : HTTP_CLIENT_REQUEST_CONTEXT
s: READABLE_STRING_8
do
create h.make
sess := h.new_session ("http://httpbin.org/")
assert ("Expected no body", (create {HTTP_CLIENT_RESPONSE_BODY_EXPECTATION}.make(expected_body_get)).expected(sess.get ("get",void)) )
end
test_body_status
local
h: LIBCURL_HTTP_CLIENT
sess: HTTP_CLIENT_SESSION
resp : detachable HTTP_CLIENT_RESPONSE
l_location : detachable READABLE_STRING_8
body : STRING
context : HTTP_CLIENT_REQUEST_CONTEXT
s: READABLE_STRING_8
do
create h.make
sess := h.new_session ("http://httpbin.org/")
--assert ("Expected no body", (create {HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION}.make(200) + create {HTTP_CLIENT_RESPONSE_BODY_EXPECTATION}.make(expected_body_get)).expected(sess.get ("get",void)) )
end
test_after_post_should_continue_working
local
h: LIBCURL_HTTP_CLIENT
sess: HTTP_CLIENT_SESSION
resp : detachable HTTP_CLIENT_RESPONSE
l_location : detachable READABLE_STRING_8
body : STRING
context : HTTP_CLIENT_REQUEST_CONTEXT
s: READABLE_STRING_8
do
create h.make
sess := h.new_session ("http://httpbin.org/")
resp := sess.get ("",void)
assert ("Expected Status 200 ok", resp.status = 200)
create context.make
context.headers.put ("text/plain;charset=UTF-8", "Content-Type")
resp := sess.post ("post", context, "testing post")
assert ("Expected Status 200 ok", resp.status = 200)
sess := h.new_session ("http://httpbin.org/")
resp := sess.get ("",void)
assert ("Expected Status 200 ok", resp.status = 200)
sess := h.new_session ("http://httpbin.org/")
resp := sess.get ("redirect/1",void)
assert ("Expected Status 200 ok", resp.status = 200)
end
expected_body_get : STRING_32 = "[
{
"url": "http://httpbin.org/get",
"args": {},
"headers": {
"Host": "httpbin.org",
"Connection": "close",
"Accept": "*/*"
},
"origin": "190.177.106.187"
}
]"
end