test different status message and query parsing

This commit is contained in:
Emil Tin 2014-04-29 19:29:26 +02:00 committed by Dennis Luxen
parent 85148d1283
commit 2cddf90e49
5 changed files with 187 additions and 73 deletions

View File

@ -19,6 +19,16 @@ Then /^response should be well-formed$/ do
@json['status'].class.should == Fixnum
end
Then /^status code should be (\d+)$/ do |code|
@json = JSON.parse @response.body
@json['status'].should == code.to_i
end
Then /^status message should be "(.*?)"$/ do |message|
@json = JSON.parse @response.body
@json['status_message'].should == message
end
Then /^response should be a well-formed route$/ do
step "response should be well-formed"
@json['status_message'].class.should == String

View File

@ -3,6 +3,11 @@ When /^I route I should get$/ do |table|
actual = []
OSRMBackgroundLauncher.new("#{@osm_file}.osrm") do
table.hashes.each_with_index do |row,ri|
if row['request']
got = {'request' => row['request'] }
response = request_url row['request']
else
params = {}
waypoints = []
if row['from'] and row['to']
node = find_node_by_name(row['from'])
@ -14,6 +19,7 @@ When /^I route I should get$/ do |table|
waypoints << node
got = {'from' => row['from'], 'to' => row['to'] }
response = request_route waypoints, params
elsif row['waypoints']
row['waypoints'].split(',').each do |n|
node = find_node_by_name(n.strip)
@ -21,11 +27,12 @@ When /^I route I should get$/ do |table|
waypoints << node
end
got = {'waypoints' => row['waypoints'] }
response = request_route waypoints, params
else
raise "*** no waypoints"
end
end
params = {}
row.each_pair do |k,v|
if k =~ /param:(.*)/
if v=='(nil)'
@ -37,9 +44,11 @@ When /^I route I should get$/ do |table|
end
end
response = request_route(waypoints, params)
if response.code == "200" && response.body.empty? == false
if response.body.empty? == false
json = JSON.parse response.body
end
if response.body.empty? == false
if json['status'] == 0
instructions = way_list json['route_instructions']
bearings = bearing_list json['route_instructions']
@ -51,6 +60,17 @@ When /^I route I should get$/ do |table|
end
end
if table.headers.include? 'status'
got['status'] = json['status'].to_s
end
if table.headers.include? 'message'
got['message'] = json['status_message']
end
if table.headers.include? '#' # comment column
got['#'] = row['#'] # copy value so it always match
end
if response.code == "200"
if table.headers.include? 'start'
got['start'] = instructions ? json['route_summary']['start_point'] : nil
end
@ -98,14 +118,6 @@ When /^I route I should get$/ do |table|
if table.headers.include? 'distances'
got['distances'] = distances
end
if table.headers.include? 'status'
got['status'] = json['status'].to_s
end
if table.headers.include? 'message'
got['message'] = json['status_message']
end
if table.headers.include? '#' # comment column
got['#'] = row['#'] # copy value so it always match
end
end

View File

@ -26,6 +26,18 @@ rescue Timeout::Error
raise "*** osrm-routed did not respond."
end
def request_url path
uri = URI.parse"#{HOST}/#{path}"
@query = uri.to_s
Timeout.timeout(OSRM_TIMEOUT) do
Net::HTTP.get_response uri
end
rescue Errno::ECONNREFUSED => e
raise "*** osrm-routed is not running."
rescue Timeout::Error
raise "*** osrm-routed did not respond."
end
def request_route waypoints, params={}
defaults = { 'output' => 'json', 'instructions' => true, 'alt' => false }
request_path "viaroute", waypoints, defaults.merge(params)

View File

@ -0,0 +1,36 @@
@routing @query
Feature: Query message parsing
Background:
Given the profile "testbot"
Scenario: Malformed requests
Given the node locations
| node | lat | lon |
| a | 1.00 | 1.00 |
| b | 1.01 | 1.00 |
And the ways
| nodes |
| ab |
When I route I should get
| request | status | message |
| viaroute?loc=1,1&loc=1.01,1 | 0 | Found route between points |
| nonsense | 400 | Bad Request |
| nonsense?loc=1,1&loc=1.01,1 | 400 | Bad Request |
| | 400 | Query string malformed close to position 0 |
| / | 400 | Query string malformed close to position 0 |
| ? | 400 | Query string malformed close to position 0 |
| viaroute/loc= | 400 | Query string malformed close to position 9 |
| viaroute/loc=1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1,1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=x | 400 | Query string malformed close to position 9 |
| viaroute/loc=x,y | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc= | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc=1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc=1,1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc=1,1,1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc=x | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc=x,y | 400 | Query string malformed close to position 9 |

View File

@ -4,6 +4,19 @@ Feature: Status messages
Background:
Given the profile "testbot"
Scenario: Route found
Given the node map
| a | b |
Given the ways
| nodes |
| ab |
When I route I should get
| from | to | route | status | message |
| a | b | ab | 0 | Found route between points |
| b | a | ab | 0 | Found route between points |
Scenario: No route found
Given the node map
| a | b |
@ -21,3 +34,34 @@ Feature: Status messages
| c | d | cd | 0 | Found route between points |
| a | c | | 207 | Cannot find route between points |
| b | d | | 207 | Cannot find route between points |
Scenario: Malformed requests
Given the node locations
| node | lat | lon |
| a | 1.00 | 1.00 |
| b | 1.01 | 1.00 |
And the ways
| nodes |
| ab |
When I route I should get
| request | status | message |
| viaroute?loc=1,1&loc=1.01,1 | 0 | Found route between points |
| nonsense | 400 | Bad Request |
| nonsense?loc=1,1&loc=1.01,1 | 400 | Bad Request |
| | 400 | Query string malformed close to position 0 |
| / | 400 | Query string malformed close to position 0 |
| ? | 400 | Query string malformed close to position 0 |
| viaroute/loc= | 400 | Query string malformed close to position 9 |
| viaroute/loc=1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1,1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=x | 400 | Query string malformed close to position 9 |
| viaroute/loc=x,y | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc= | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc=1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc=1,1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc=1,1,1 | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc=x | 400 | Query string malformed close to position 9 |
| viaroute/loc=1,1&loc=x,y | 400 | Query string malformed close to position 9 |