diff --git a/Rakefile b/Rakefile index 7419e8cb1..6b09d01f1 100644 --- a/Rakefile +++ b/Rakefile @@ -68,6 +68,7 @@ def write_server_ini osm_file ramIndex=#{osm_file}.osrm.ramIndex fileIndex=#{osm_file}.osrm.fileIndex namesData=#{osm_file}.osrm.names + timestamp=#{osm_file}.osrm.timestamp EOF File.open( 'server.ini', 'w') {|f| f.write( s ) } end diff --git a/features/step_definitions/processing.rb b/features/step_definitions/processing.rb index 323604e1d..29b865e39 100644 --- a/features/step_definitions/processing.rb +++ b/features/step_definitions/processing.rb @@ -61,6 +61,7 @@ Given /^the preprocessed files for "([^"]*)" are present and up to date$/ do |ar File.exists?("#{area}.osrm.edges").should == true File.exists?("#{area}.osrm.ramIndex").should == true File.exists?("#{area}.osrm.fileIndex").should == true + File.exists?("#{area}.osrm.tiemstamp").should == true end Then /^I should see the file "([^"]*)"$/ do |file| diff --git a/features/step_definitions/requests.rb b/features/step_definitions/requests.rb new file mode 100644 index 000000000..df26ff29e --- /dev/null +++ b/features/step_definitions/requests.rb @@ -0,0 +1,24 @@ +When /^I request \/(.*)$/ do |path| + osrm_kill + reprocess + OSRMLauncher.new do + @response = request_path path + end +end + +Then /^I should get a response/ do + @response.code.should == "200" + @response.body.should_not == nil + @response.body.should_not == '' +end + +Then /^response should be valid JSON$/ do + @json = JSON.parse @response.body +end + +Then /^response should be well-formed$/ do + @json['version'].class.should == Float + @json['status'].class.should == Fixnum + @json['transactionId'].class.should == String +end + diff --git a/features/step_definitions/routing.rb b/features/step_definitions/routing.rb index 96a4bc1a2..eebb5211e 100644 --- a/features/step_definitions/routing.rb +++ b/features/step_definitions/routing.rb @@ -12,25 +12,13 @@ When /^I request a route from "([^"]*)" to "([^"]*)"$/ do |a,b| @response = request_route "#{locations[a][0]},#{locations[a][1]}", "#{locations[b][0]},#{locations[b][1]}" end -Then /^I should get a response/ do - @response.code.should == "200" - @response.body.should_not == nil - @response.body.should_not == '' -end - -Then /^response should be valid JSON$/ do - @json = JSON.parse @response.body -end - -Then /^response should be well-formed$/ do - @json['version'].class.should == Float - @json['status'].class.should == Fixnum +Then /^response should be a well-formed route$/ do + step "response should be well-formed" @json['status_message'].class.should == String @json['route_summary'].class.should == Hash @json['route_geometry'].class.should == String @json['route_instructions'].class.should == Array @json['via_points'].class.should == Array - @json['transactionId'].class.should == String end Then /^a route should be found$/ do @@ -46,7 +34,7 @@ end Then /^I should get a valid response$/ do step "I should get a response" step "response should be valid JSON" - step "response should be well-formed" + step "response should be a well-formed route" #step "no error should be reported in terminal" end diff --git a/features/step_definitions/timestamp.rb b/features/step_definitions/timestamp.rb new file mode 100644 index 000000000..53d4083a8 --- /dev/null +++ b/features/step_definitions/timestamp.rb @@ -0,0 +1,7 @@ +Then /^I should get a valid timestamp/ do + step "I should get a response" + step "response should be valid JSON" + step "response should be well-formed" + @json['timestamp'].class.should == String + @json['timestamp'].should == OSM_TIMESTAMP +end diff --git a/features/support/config.rb b/features/support/config.rb index c66cdde5f..f5d9efc03 100644 --- a/features/support/config.rb +++ b/features/support/config.rb @@ -23,6 +23,7 @@ edgesData=#{@osm_file}.osrm.edges ramIndex=#{@osm_file}.osrm.ramIndex fileIndex=#{@osm_file}.osrm.fileIndex namesData=#{@osm_file}.osrm.names +timestamp=#{@osm_file}.osrm.timestamp EOF File.open( 'server.ini', 'w') {|f| f.write( s ) } end diff --git a/features/support/data.rb b/features/support/data.rb index 88f211be5..2c31af83a 100644 --- a/features/support/data.rb +++ b/features/support/data.rb @@ -198,9 +198,14 @@ def prepared? File.exist?("#{@osm_file}.osrm.hsgr") end +def write_timestamp + File.open( "#{@osm_file}.osrm.timestamp", 'w') {|f| f.write(OSM_TIMESTAMP) } +end + def reprocess Dir.chdir TEST_FOLDER do write_osm + write_timestamp convert_osm_to_pbf unless extracted? log_preprocess_info diff --git a/features/support/request.rb b/features/support/request.rb new file mode 100644 index 000000000..6d4cd1288 --- /dev/null +++ b/features/support/request.rb @@ -0,0 +1,14 @@ +require 'net/http' + +HOST = 'http://localhost:5000' + +def request_path path + @query = path + log path + uri = URI.parse "#{HOST}/#{path}" + Net::HTTP.get_response uri +rescue Errno::ECONNREFUSED => e + raise "*** osrm-routed is not running." +rescue Timeout::Error + raise "*** osrm-routed did not respond." +end diff --git a/features/support/route.rb b/features/support/route.rb index 13540d867..de7fe3afe 100644 --- a/features/support/route.rb +++ b/features/support/route.rb @@ -1,17 +1,8 @@ -require 'net/http' DESTINATION_REACHED = 15 #OSRM instruction code - def request_route a,b - @query = "http://localhost:5000/viaroute?loc=#{a}&loc=#{b}&output=json&instructions=true&alt=false" - #log @query - uri = URI.parse @query - Net::HTTP.get_response uri -rescue Errno::ECONNREFUSED => e - raise "*** osrm-routed is not running." -rescue Timeout::Error - raise "*** osrm-routed did not respond." + request_path "viaroute?loc=#{a}&loc=#{b}&output=json&instructions=true&alt=false" end def parse_response response diff --git a/features/timestamp/timestamp.feature b/features/timestamp/timestamp.feature new file mode 100644 index 000000000..7886bad7a --- /dev/null +++ b/features/timestamp/timestamp.feature @@ -0,0 +1,12 @@ +@timestamp +Feature: Timestamp + + Scenario: Request timestamp + Given the node map + | a | b | + And the ways + | nodes | + | ab | + When I request /timestamp + Then I should get a valid timestamp +