Added non-Void contracts for classes previously flagged by AutoTest
This commit is contained in:
@@ -23,26 +23,40 @@ create
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (n: INTEGER)
|
||||
-- Create the router with a capacity of `n' mappings
|
||||
-- Create the router with a capacity of `n' mappings.
|
||||
require
|
||||
valid_number_of_items: n >= 0
|
||||
do
|
||||
create mappings.make (n)
|
||||
initialize (n)
|
||||
ensure
|
||||
no_handler_set: count = 0
|
||||
end
|
||||
|
||||
make_with_base_url (n: INTEGER; a_base_url: like base_url)
|
||||
-- Make router allocated for at least `n' maps,
|
||||
-- and use `a_base_url' as `base_url'
|
||||
--| This avoids prefixing all the resource string.
|
||||
require
|
||||
valid_number_of_items: n >= 0
|
||||
a_valid_base_url: (a_base_url /= Void and then a_base_url.is_empty) implies (a_base_url.starts_with ("/") and not a_base_url.ends_with ("/"))
|
||||
do
|
||||
make (n)
|
||||
check
|
||||
no_handler_set: count = 0
|
||||
-- ensured by `make'
|
||||
end
|
||||
set_base_url (a_base_url)
|
||||
end
|
||||
|
||||
initialize (n: INTEGER)
|
||||
-- Initialize router
|
||||
-- Initialize router.
|
||||
require
|
||||
valid_number_of_items: n >= 0
|
||||
do
|
||||
create mappings.make (n)
|
||||
create pre_execution_actions
|
||||
ensure
|
||||
no_handler_set: count = 0
|
||||
end
|
||||
|
||||
mappings: ARRAYED_LIST [WSF_ROUTER_ITEM]
|
||||
@@ -51,13 +65,17 @@ feature {NONE} -- Initialization
|
||||
feature -- Mapping
|
||||
|
||||
map (a_mapping: WSF_ROUTER_MAPPING)
|
||||
-- Map `a_mapping'
|
||||
-- Map `a_mapping'.
|
||||
require
|
||||
a_mapping_attached: a_mapping /= Void
|
||||
do
|
||||
map_with_request_methods (a_mapping, Void)
|
||||
end
|
||||
|
||||
map_with_request_methods (a_mapping: WSF_ROUTER_MAPPING; rqst_methods: detachable WSF_REQUEST_METHODS)
|
||||
-- Map `a_mapping' for request methods `rqst_methods'
|
||||
-- Map `a_mapping' for request methods `rqst_methods'.
|
||||
require
|
||||
a_mapping_attached: a_mapping /= Void
|
||||
do
|
||||
debug ("router")
|
||||
-- Display conflict in mapping
|
||||
@@ -76,7 +94,10 @@ feature -- Mapping
|
||||
feature -- Mapping handler
|
||||
|
||||
handle (a_resource: READABLE_STRING_8; f: WSF_ROUTER_MAPPING_FACTORY)
|
||||
-- Map the mapping created by factory `f' for resource `a_resource'
|
||||
-- Map the mapping created by factory `f' for resource `a_resource'.
|
||||
require
|
||||
a_resource_attached: a_resource /= Void
|
||||
f_attached: f /= Void
|
||||
do
|
||||
handle_with_request_methods (a_resource, f, Void)
|
||||
end
|
||||
@@ -84,6 +105,9 @@ feature -- Mapping handler
|
||||
handle_with_request_methods (a_resource: READABLE_STRING_8; f: WSF_ROUTER_MAPPING_FACTORY; rqst_methods: detachable WSF_REQUEST_METHODS)
|
||||
-- Map the mapping created by factory `f' for resource `a_resource'
|
||||
-- and only for request methods `rqst_methods'
|
||||
require
|
||||
a_resource_attached: a_resource /= Void
|
||||
f_attached: f /= Void
|
||||
do
|
||||
map_with_request_methods (f.new_mapping (a_resource), rqst_methods)
|
||||
end
|
||||
@@ -94,9 +118,14 @@ feature -- Access
|
||||
-- `dispatch' set `is_dispatched' to True
|
||||
-- if mapping was found, and associated handler executed
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
dispatch (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Dispatch request `req' among the `mappings'
|
||||
-- Set `is_dispatched' if the request were dispatched
|
||||
-- Dispatch request `req' among the `mappings'.
|
||||
-- Set `is_dispatched' if the request were dispatched.
|
||||
require
|
||||
req_attached: req /= Void
|
||||
res_attached: res /= Void
|
||||
do
|
||||
if attached dispatch_and_return_handler (req, res) then
|
||||
check is_dispatched: is_dispatched end
|
||||
@@ -105,7 +134,10 @@ feature -- Access
|
||||
|
||||
dispatch_and_return_handler (req: WSF_REQUEST; res: WSF_RESPONSE): detachable WSF_HANDLER
|
||||
-- Dispatch request `req' among the `mappings'
|
||||
-- And return the associated handler if mapping found and handler executed.
|
||||
-- And return the associated handler (violating CQS) if mapping found and handler executed.
|
||||
require
|
||||
req_attached: req /= Void
|
||||
res_attached: res /= Void
|
||||
local
|
||||
l_req_method: READABLE_STRING_8
|
||||
head_res: WSF_HEAD_RESPONSE_WRAPPER
|
||||
@@ -125,7 +157,11 @@ feature {NONE} -- Dispatch implementation
|
||||
|
||||
dispatch_and_return_handler_for_request_method (req: WSF_REQUEST; res: WSF_RESPONSE; a_request_method: READABLE_STRING_8): detachable WSF_HANDLER
|
||||
-- Dispatch request `req' among the `mappings'
|
||||
-- And return the associated handler if mapping found and handler executed.
|
||||
-- And return the associated handler (violating CQS) if mapping found and handler executed.
|
||||
require
|
||||
req_attached: req /= Void
|
||||
res_attached: res /= Void
|
||||
a_request_method_attached: a_request_method /= Void
|
||||
local
|
||||
m: WSF_ROUTER_MAPPING
|
||||
do
|
||||
@@ -151,6 +187,9 @@ feature {NONE} -- Dispatch implementation
|
||||
feature -- Status report
|
||||
|
||||
has_item_associated_with_resource (a_resource: READABLE_STRING_8; rqst_methods: detachable WSF_REQUEST_METHODS): BOOLEAN
|
||||
-- Is there a handler for `a_resource' (taking into account `rqst_methods')?
|
||||
require
|
||||
a_resource_attached: a_resource /= Void
|
||||
local
|
||||
m: WSF_ROUTER_MAPPING
|
||||
ok: BOOLEAN
|
||||
@@ -178,6 +217,9 @@ feature -- Status report
|
||||
end
|
||||
|
||||
item_associated_with_resource (a_resource: READABLE_STRING_8; rqst_methods: detachable WSF_REQUEST_METHODS): detachable WSF_ROUTER_ITEM
|
||||
-- Handler and request methods for `a_resource', taking into account `rqst_methods'
|
||||
require
|
||||
a_resource_attached: a_resource /= Void
|
||||
local
|
||||
m: WSF_ROUTER_MAPPING
|
||||
ok: BOOLEAN
|
||||
@@ -208,6 +250,8 @@ feature -- Status report
|
||||
|
||||
allowed_methods_for_request (req: WSF_REQUEST): WSF_REQUEST_METHODS
|
||||
-- Allowed methods for `req'
|
||||
require
|
||||
req_attched: req /= Void
|
||||
local
|
||||
m: WSF_ROUTER_MAPPING
|
||||
l_rqsmethods: detachable WSF_REQUEST_METHODS
|
||||
@@ -234,14 +278,18 @@ feature -- Status report
|
||||
feature -- Hook
|
||||
|
||||
execute_before (a_mapping: WSF_ROUTER_MAPPING)
|
||||
-- Execute before the handler associated with the matching mapping is executed
|
||||
-- Execute before the handler associated with `a_mapping' is executed.
|
||||
require
|
||||
a_mapping_attached: a_mapping /= Void
|
||||
do
|
||||
pre_execution_actions.call ([a_mapping])
|
||||
end
|
||||
|
||||
execute_after (a_mapping: WSF_ROUTER_MAPPING)
|
||||
-- Execute after the handler associated with the matching mapping is executed
|
||||
-- Execute after the handler associated with `a_mapping' is executed.
|
||||
--| Could be redefined to add specific hook.
|
||||
require
|
||||
a_mapping_attached: a_mapping /= Void
|
||||
do
|
||||
end
|
||||
|
||||
@@ -291,6 +339,8 @@ feature -- Request methods helper
|
||||
create Result
|
||||
Result.enable_head
|
||||
Result.lock
|
||||
ensure
|
||||
methods_head_not_void: Result /= Void
|
||||
end
|
||||
|
||||
methods_options: WSF_REQUEST_METHODS
|
||||
@@ -298,6 +348,8 @@ feature -- Request methods helper
|
||||
create Result
|
||||
Result.enable_options
|
||||
Result.lock
|
||||
ensure
|
||||
methods_options_not_void: Result /= Void
|
||||
end
|
||||
|
||||
methods_get: WSF_REQUEST_METHODS
|
||||
@@ -305,6 +357,8 @@ feature -- Request methods helper
|
||||
create Result
|
||||
Result.enable_get
|
||||
Result.lock
|
||||
ensure
|
||||
methods_get_not_void: Result /= Void
|
||||
end
|
||||
|
||||
methods_post: WSF_REQUEST_METHODS
|
||||
@@ -312,6 +366,8 @@ feature -- Request methods helper
|
||||
create Result
|
||||
Result.enable_post
|
||||
Result.lock
|
||||
ensure
|
||||
methods_post_not_void: Result /= Void
|
||||
end
|
||||
|
||||
methods_put: WSF_REQUEST_METHODS
|
||||
@@ -319,6 +375,8 @@ feature -- Request methods helper
|
||||
create Result
|
||||
Result.enable_put
|
||||
Result.lock
|
||||
ensure
|
||||
methods_put_not_void: Result /= Void
|
||||
end
|
||||
|
||||
methods_delete: WSF_REQUEST_METHODS
|
||||
@@ -326,6 +384,8 @@ feature -- Request methods helper
|
||||
create Result
|
||||
Result.enable_delete
|
||||
Result.lock
|
||||
ensure
|
||||
methods_delete_not_void: Result /= Void
|
||||
end
|
||||
|
||||
methods_head_get_post: WSF_REQUEST_METHODS
|
||||
@@ -335,6 +395,8 @@ feature -- Request methods helper
|
||||
Result.enable_get
|
||||
Result.enable_post
|
||||
Result.lock
|
||||
ensure
|
||||
methods_head_get_post_not_void: Result /= Void
|
||||
end
|
||||
|
||||
methods_get_put_delete: WSF_REQUEST_METHODS
|
||||
@@ -344,6 +406,8 @@ feature -- Request methods helper
|
||||
Result.enable_put
|
||||
Result.enable_delete
|
||||
Result.lock
|
||||
ensure
|
||||
methods_get_put_not_void: Result /= Void
|
||||
end
|
||||
|
||||
methods_head_get: WSF_REQUEST_METHODS
|
||||
@@ -352,6 +416,8 @@ feature -- Request methods helper
|
||||
Result.enable_head
|
||||
Result.enable_get
|
||||
Result.lock
|
||||
ensure
|
||||
methods_head_get_not_void: Result /= Void
|
||||
end
|
||||
|
||||
methods_get_post: WSF_REQUEST_METHODS
|
||||
@@ -360,6 +426,8 @@ feature -- Request methods helper
|
||||
Result.enable_get
|
||||
Result.enable_post
|
||||
Result.lock
|
||||
ensure
|
||||
methods_get_post_not_void: Result /= Void
|
||||
end
|
||||
|
||||
methods_put_post: WSF_REQUEST_METHODS
|
||||
@@ -368,12 +436,16 @@ feature -- Request methods helper
|
||||
Result.enable_put
|
||||
Result.enable_post
|
||||
Result.lock
|
||||
ensure
|
||||
methods_put_post_not_void: Result /= Void
|
||||
end
|
||||
|
||||
feature {NONE} -- Access: Implementation
|
||||
|
||||
request_method (req: WSF_REQUEST): READABLE_STRING_8
|
||||
-- Request method from `req' to be used in the router implementation.
|
||||
-- Request method from `req' to be used in the router implementation
|
||||
require
|
||||
req_attached: req /= Void
|
||||
local
|
||||
m: READABLE_STRING_8
|
||||
do
|
||||
@@ -403,6 +475,8 @@ feature {NONE} -- Access: Implementation
|
||||
|
||||
is_matching_request_methods (a_request_method: READABLE_STRING_8; a_rqst_methods: detachable WSF_REQUEST_METHODS): BOOLEAN
|
||||
-- `a_request_method' is matching `a_rqst_methods' contents
|
||||
require
|
||||
a_request_method_attached: a_request_method /= Void
|
||||
do
|
||||
if a_rqst_methods /= Void and then not a_rqst_methods.is_empty then
|
||||
Result := a_rqst_methods.has (a_request_method)
|
||||
@@ -411,8 +485,13 @@ feature {NONE} -- Access: Implementation
|
||||
end
|
||||
end
|
||||
|
||||
invariant
|
||||
|
||||
mappings_attached: mappings /= Void
|
||||
pre_execution_actions_attached: pre_execution_actions /= Void
|
||||
|
||||
note
|
||||
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
||||
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
Reference in New Issue
Block a user