diff --git a/.gitignore b/.gitignore index 251fee3..0ffb918 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ home/log.txt !.jenkins_jobs/example/builds/3 .jenkins_jobs/example/workspace/ +.png diff --git a/provision b/provision index 025d9b7..519166b 100644 --- a/provision +++ b/provision @@ -7,20 +7,20 @@ echo "Installing Ruby Dev Kit" apt-get update apt-get install -y ruby2.2 ruby2.2-dev -echo "Installing Jenkins" - - wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - - sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list' - apt-get update - apt-get -qy install jenkins - - usermod -a -G vagrant jenkins - usermod -a -G jenkins vagrant - service jenkins start - sleep 240 - java -jar /vagrant/.jenkins/jenkins-cli.jar -s http://localhost:8080 install-plugin git - java -jar /vagrant/.jenkins/jenkins-cli.jar -s http://localhost:8080 install-plugin xUnit - service jenkins restart +#echo "Installing Jenkins" + +# wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - +# sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list' +# apt-get update +# apt-get -qy install jenkins +# +# usermod -a -G vagrant jenkins +# usermod -a -G jenkins vagrant +# service jenkins start +# sleep 240 +# java -jar /vagrant/.jenkins/jenkins-cli.jar -s http://localhost:8080 install-plugin git +# java -jar /vagrant/.jenkins/jenkins-cli.jar -s http://localhost:8080 install-plugin xUnit +# service jenkins restart echo "Installing git command line tools" diff --git a/tests/Example1/features/steps/code.rb b/tests/Example1/features/steps/code.rb index 572d883..d491165 100644 --- a/tests/Example1/features/steps/code.rb +++ b/tests/Example1/features/steps/code.rb @@ -1,16 +1,17 @@ When(/^I create a user$/) do data = {} - data['user_name'] = 'User' + Time.new().to_i.to_s + '@example.org' # Create a random user name + data['user_name'] = 'User' + Time.new().to_i.to_s + '@example.org' #Use Time.new create to create a random user name data['user_password'] = 'password' - result = rest_post_call('http://localhost:4567/add_user', data) + result = rest_post_call('http://localhost:4567/add_user', data) #add user puts data - $json_result = JSON.parse(result.body) + $json_result = JSON.parse(result.body) #json_result returns status as 'User Added' end Then(/^the user is successfully created$/) do - expect($json_result['status']).to eq('User Added') + expect($json_result['status']).to eq('User Added') #confirms status returned is 'User Added' + puts "status " + $json_result['status'].to_s end When(/^I create a user which already exists$/) do @@ -24,5 +25,5 @@ end Then(/^the user is not created$/) do - expect($json_result['status']).to eq('User Already Exists') + expect($json_result['status']).to eq('User Already Exists') #confirms 'User Already Exists' end diff --git a/tests/Example2/features/steps/code.rb b/tests/Example2/features/steps/code.rb index 33894d0..559b817 100644 --- a/tests/Example2/features/steps/code.rb +++ b/tests/Example2/features/steps/code.rb @@ -1,7 +1,7 @@ Given(/^I have a user account$/) do $data = {} - $data['user_name'] = 'User' + Time.new().to_i.to_s + '@example.org' # Create a random user name + $data['user_name'] = 'User' + Time.new().to_i.to_s + '@example.org' #Use Time.new to create a random user name $data['user_password'] = 'password' rest_post_call('http://localhost:4567/add_user', $data) diff --git a/tests/Example2/features/support/config.rb b/tests/Example2/features/support/config.rb index dd600e1..28f8949 100644 --- a/tests/Example2/features/support/config.rb +++ b/tests/Example2/features/support/config.rb @@ -23,6 +23,8 @@ Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, inspector: true, js_errors: true) end +require 'test/unit' +include Test::Unit::Assertions else diff --git a/tests/Example3/P336 Private Beta Test Strategy.docx b/tests/Example3/P336 Private Beta Test Strategy.docx new file mode 100644 index 0000000..0f993ed Binary files /dev/null and b/tests/Example3/P336 Private Beta Test Strategy.docx differ diff --git a/tests/Example3/Site Problems and testing requirementsAssignment 1.docx b/tests/Example3/Site Problems and testing requirementsAssignment 1.docx new file mode 100644 index 0000000..4cc56db Binary files /dev/null and b/tests/Example3/Site Problems and testing requirementsAssignment 1.docx differ diff --git a/tests/Example3/features/invalid_login.feature b/tests/Example3/features/invalid_login.feature new file mode 100644 index 0000000..9198d55 --- /dev/null +++ b/tests/Example3/features/invalid_login.feature @@ -0,0 +1,12 @@ +Feature:Invalid login + +Scenario: incorrect user details +Given I visit the test site +When I login using incorrect details +Then an error message is displayed + +Scenario: enter correct new user and login in without password +Given I have a user account +When I visit the test site +And login with username but no password +Then I receive an error message diff --git a/tests/Example3/features/lib/access_site_and_logout.rb b/tests/Example3/features/lib/access_site_and_logout.rb new file mode 100644 index 0000000..b67b68e --- /dev/null +++ b/tests/Example3/features/lib/access_site_and_logout.rb @@ -0,0 +1,11 @@ +#access site +def access_login_page() + # Visit main page + visit('http://localhost:4567') +end + +#Logout +def logout() + click_link ('Back to menu') + click_link ('Logout') +end diff --git a/tests/Example3/features/lib/data.rb b/tests/Example3/features/lib/data.rb new file mode 100644 index 0000000..0f81032 --- /dev/null +++ b/tests/Example3/features/lib/data.rb @@ -0,0 +1,44 @@ +#Function: improves maintainability of tests - details can be easily added to or amended +#can be called by many features + +def set_details_1() +@details = Hash.new() +@details['first-name'] = "Rick" +@details['second-name'] = "Deckard" +@details['address'] = Hash.new() +@details['address']['house-number'] = "3" +@details['address']['street'] = "Tyrell Road" +@details['address']['city'] = "Plymouth" +@details['address']['postcode'] = "PL4 5AZ" +@details['sex'] = "html/body/div[1]/form/input[7]" +@details['interests'] = Hash.new() +@details['interests'][0] = "swimming" +@details['interests'][1] = "walking" +@details['interests'][2] = "cycling" +@details['car'] = Hash.new() +@details['car'][0] = "Volvo" +@details['car'][1] = "Saab" +@details['car'][2] = "Fiat" +@details['car'][3] = "Audi" +end + +def set_details_2() +@details = Hash.new() +@details['first-name'] = "Allison" +@details['second-name'] = "Queen" +@details['address'] = Hash.new() +@details['address']['house-number'] = "3" +@details['address']['street'] = "High Street" +@details['address']['city'] = "Plymouth" +@details['address']['postcode'] = "PL4 7LX" +@details['sex'] = "html/body/div[1]/form/input[8]" +@details['interests'] = Hash.new() +@details['interests'][0] = "swimming" +@details['interests'][1] = "walking" +@details['interests'][2] = "cycling" +@details['car'] = Hash.new() +@details['car'][0] = "Volvo" +@details['car'][1] = "Saab" +@details['car'][2] = "Fiat" +@details['car'][3] = "Audi" +end diff --git a/tests/Example3/features/login_logout.feature b/tests/Example3/features/login_logout.feature new file mode 100644 index 0000000..308d3a2 --- /dev/null +++ b/tests/Example3/features/login_logout.feature @@ -0,0 +1,11 @@ +Feature: Login and logout + +Scenario: Login to the web site and log out +Given I have a user account +And I am logged in +When I choose to logout +Then I am logged out of the system + +Scenario: Access form without logging in +Given I try to access the Details Form without logging in +Then I will be prevented from accessing the website and an error message will be displayed diff --git a/tests/Example3/features/steps/invalid_login.rb b/tests/Example3/features/steps/invalid_login.rb new file mode 100644 index 0000000..989a306 --- /dev/null +++ b/tests/Example3/features/steps/invalid_login.rb @@ -0,0 +1,22 @@ +When(/^I login using incorrect details$/) do +#add incorrect details ncorrect format + fill_in('username', :with => 'Incorrectuser@1234.com') + fill_in('password', :with => 'notapassword1') + click_button('Sign in') +end + +Then(/^an error message is displayed$/) do + expect(page.body).to match('Unknown User') +end + + +When(/^login with username but no password$/) do + #enter user name only - no password + fill_in('username', :with => $data['user_name']) + click_button('Sign in') +end + +Then(/^I receive an error message$/) do +#test currently fails - pop up not recognised and has no xpath - I would ask dev to amend this + expect(page.body).to match('Please fill in this field') +end diff --git a/tests/Example3/features/steps/login_logout.rb b/tests/Example3/features/steps/login_logout.rb new file mode 100644 index 0000000..38a55bf --- /dev/null +++ b/tests/Example3/features/steps/login_logout.rb @@ -0,0 +1,29 @@ +Given(/^I am logged in$/) do +#use previous step code to take you fully into the application + step 'I have a user account' + step 'I visit the test site' + step 'I login using that user account and click on the Details Form' + click_button('Submit') +end + +When(/^I choose to logout$/) do +#called from ../lib/access_site_and_logout.rb + logout() +end + +Then(/^I am logged out of the system$/) do + expect(page.body).to have_content "Please sign in" +end + +#Application can only be logged out of from initial menu - you cannot logout once inside the applcation only return to menu from final page + +Given(/^I try to access the Details Form without logging in$/) do +#hit URL without going through login + visit('http://localhost:4567/form-details') +end + +Then(/^I will be prevented from accessing the website and an error message will be displayed$/) do +#expect some kind of error message to be displayed as web page should only be accessible by logging on with valid username and password + expect(page).to have_text "Please enter valid user name and password" # this may not be the right response, I would have talk to dev to get find correct failure code and/or error message +#this step will fail as currently webpage can be hit directly without going through login +end diff --git a/tests/Example3/features/steps/submit_detail.rb b/tests/Example3/features/steps/submit_detail.rb new file mode 100644 index 0000000..326618f --- /dev/null +++ b/tests/Example3/features/steps/submit_detail.rb @@ -0,0 +1,88 @@ +Given(/^I have a user account$/) do + $data = {} + $data['user_name'] = 'User' + Time.new().to_i.to_s + '@example.org' #Use Time.new to generate a random user name + $data['user_password'] = 'password' + + rest_post_call('http://localhost:4567/add_user', $data) # add user +end + +Given(/^I visit the test site$/) do +#called from ../lib/access_site_and_logout.rb + access_login_page() +end + +When(/^I login using that user account and click on the Details Form$/) do +#Enter details into login screen and sign in + fill_in('username', :with => $data['user_name']) + fill_in('password', :with => $data['user_password']) + click_button('Sign in') + + click_link('Details form') + +end + + +Then(/^I can complete and submit the form with my details$/) do +#called from ../lib/data.rb to complete form details + set_details_1() + + fill_in('first-name', :with => @details['first-name']) + fill_in('second-name', :with => @details['second-name']) + fill_in('house_number', :with => @details['address']['house-number']) + fill_in('street', :with => @details["address"]["street"]) + fill_in('city', :with => @details["address"]["city"]) + fill_in('postcode', :with => @details["address"]["postcode"]) + find(@details["sex"]).click + check(@details["interests"][0]) + select(@details["car"][0], :from => 'cars') + click_button('Submit') +end + +Then(/^I can complete and submit the form with different details$/) do +#called from ../lib/data.rb to complete form details + set_details_2() + + fill_in('first-name', :with => @details['first-name']) + fill_in('second-name', :with => @details['second-name']) + fill_in('house_number', :with => @details['address']['house-number']) + fill_in('street', :with => @details["address"]["street"]) + fill_in('city', :with => @details["address"]["city"]) + fill_in('postcode', :with => @details["address"]["postcode"]) + find(@details["sex"]).click + check(@details["interests"][2]) + select(@details["car"][3], :from => 'cars') + click_button('Submit') +end + +Then(/^I confirm that the details are displayed correctly$/) do +#page is checked to see the correct text inputted in previous step is displayed on the results page + expect(page).to have_text "#{@details['first-name']} #{@details['second-name']}" + expect(page).to have_text "#{@details["address"]["house-number"]} #{@details["address"]["street"]} #{@details["address"]["city"]} #{@details["address"]["postcode"]}" + expect(page).to have_text "#{@details["car"][0]}".downcase + expect(page).to have_text "#{@details["interests"][0]}" + expect(find(:xpath, ".//*[@id='gender']/p")).to have_content "male" +end + +Then(/^I confirm that the different details are displayed correctly$/) do +#page is checked to see the correct text inputted in previous step is displayed on the results page + expect(page).to have_text "#{@details['first-name']} #{@details['second-name']}" + expect(page).to have_text "#{@details["address"]["house-number"]} #{@details["address"]["street"]} #{@details["address"]["city"]} #{@details["address"]["postcode"]}" + expect(page).to have_text "#{@details["interests"][2]}" + expect(page).to have_text "#{@details["car"][3]}".downcase + expect(find(:xpath, ".//*[@id='gender']/p")).to have_content "female" +end + + +Then(/I submit without completing any details$/) do + click_button ('Submit') +end + +Then(/^I confirm only the default values are present$/) do +#check to confirm defaults are displayed + expect(page).to have_content('volvo') + expect(page).to have_content('male') +#can also check to ensure things are not dispalyed + expect(page.body).to have_no_content('audi') + expect(page.body).to have_no_content('female') + expect(page.body).to have_no_content('walking') +end diff --git a/tests/Example3/features/submit_details.feature b/tests/Example3/features/submit_details.feature new file mode 100644 index 0000000..6fe5bc8 --- /dev/null +++ b/tests/Example3/features/submit_details.feature @@ -0,0 +1,22 @@ +Feature: Login in and submit details + +Scenario: Submit details +Given I have a user account +And I visit the test site +When I login using that user account and click on the Details Form +Then I can complete and submit the form with my details +And I confirm that the details are displayed correctly + +Scenario: Submit different details +Given I have a user account +And I visit the test site +When I login using that user account and click on the Details Form +Then I can complete and submit the form with different details +And I confirm that the different details are displayed correctly + +Scenario: Create new user and complete the details form +Given I have a user account +When I visit the test site +And I login using that user account and click on the Details Form +Then I submit without completing any details +And I confirm only the default values are present diff --git a/tests/Example3/features/support/config.rb b/tests/Example3/features/support/config.rb new file mode 100644 index 0000000..28f8949 --- /dev/null +++ b/tests/Example3/features/support/config.rb @@ -0,0 +1,36 @@ +require 'open-uri' +require 'net/http' +require 'rspec/expectations' +require 'json' + +require 'capybara/cucumber' + +### Allows you to use the page. commands +include Capybara::DSL + + +Capybara.default_selector = :xpath +Capybara.default_wait_time = 10 +Capybara.app_host = 'http://localhost:4567' + +Capybara.default_driver = :poltergeist +Capybara.javascript_driver = :poltergeist + +if (ENV['webdriver'] == 'poltergeist') then + + require 'capybara/poltergeist' + + Capybara.register_driver :poltergeist do |app| + Capybara::Poltergeist::Driver.new(app, inspector: true, js_errors: true) + end +require 'test/unit' +include Test::Unit::Assertions + +else + + require 'selenium-webdriver' + + Capybara.default_driver = :selenium + Capybara.javascript_driver = :selenium + +end diff --git a/tests/Example3/features/support/functions.rb b/tests/Example3/features/support/functions.rb new file mode 100644 index 0000000..2259560 --- /dev/null +++ b/tests/Example3/features/support/functions.rb @@ -0,0 +1,48 @@ +####### +# Function: rest_get_call +# Description: This function should be used to do all get requests +# Inputs: +# - url = The url that the web service is calling +# Outputs: +# - curl response +###### +def rest_get_call(url) + uri = URI.parse(url) + + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Get.new(uri.path, initheader = {'Content-Type' =>'application/json'}) + request.basic_auth $http_auth_name, $http_auth_password + response = http.request(request) + + return response +end + +####### +# Function: rest_post_call +# Description: This function should be used to do all post requests +# Inputs: +# - url = The url that the web service is calling +# - data = The data post for the post +# - body = The body for the post +# Outputs: +# - curl response +###### +def rest_post_call(url, data = nil, body = nil) + uri = URI.parse(url) + + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'}) + request.basic_auth $http_auth_name, $http_auth_password + + if (!data.nil?) then + request.set_form_data(data) + end + + if (!body.nil?) then + request.body = body + end + + response = http.request(request) + + return response +end diff --git a/tests/JSON/Difference_testing_UI-and_JSON.txt b/tests/JSON/Difference_testing_UI-and_JSON.txt new file mode 100644 index 0000000..9f5e689 --- /dev/null +++ b/tests/JSON/Difference_testing_UI-and_JSON.txt @@ -0,0 +1,21 @@ +Differences in testing a web page and JSON + + Web page testing (front-end) + + As long as the developer has provided unique field ids on the web page, tests do not need a specific path or location, testing can be undertaken using Capybara to 'assert' or Rspec 'expect'. This applies to the testing all behaviours of the web page, such as checking screen validations and verifying navigation, data integrity and field formats. + + When testing a web page there will always be a need to undertake an element of maunal testing to confirm formatting and usability of the web page. + + JSON testing (back-end API) + + JSON must be parsed so that tests can access its component parts. + + Tests need to include the exact path/location in the test code. (Using an online JSON editor can be useful in determning the path: http://www.jsoneditoronline.org/) + + Tests may fail if the format of JSON becomes corrupted so using a JSON validator such as http://jsonlint.com/ can help to identify formatting errors. + + Requirements from developers + + I would need to know the URL, routes to it and what GET and POST methods exist in order to set up the env.rb file. Architecture drawings to illustrate this are always useful. + + I need to know what parameters will be passed in and what is expected to be returned. diff --git a/tests/JSON/features/get_json.feature b/tests/JSON/features/get_json.feature new file mode 100644 index 0000000..266f414 --- /dev/null +++ b/tests/JSON/features/get_json.feature @@ -0,0 +1,61 @@ +Feature: JSON register checks + +Scenario: DT160760 + Given I have entered a title number DT160760 + When the objects for DT150760 are returned + Then title number DT1600760 is identified + And the correct DLR is identied + And the correct role code for entry 2 is identified + And the correct UPRNS entry is identified + And the correct message for the 5th migrator error is idenified + And the correct infill type for entry 1 is identified + And the correct district is identified + And the correct co-ordinates are identified + + Scenario: GR504812 + Given I have entered a title number GR504812 + When the objects for GR504812 are returned + Then title number GR504812 is identified + And the correct tenure is indentied + And the correct entry id for entry 12 is identified + And the correct application reference is identified + And the correct extractor for the 1st migrator error is identified + And the correct sub register for entry 16 is identified + And the correct edition date is identified + And the correct status for the first entry is identified + +Scenario: MS465614 + Given I have entered a title number MS465614 + When the objects for MS465614 are returned + Then title number MS465614 is identified + And the correct DLR is indentified + And the correct language for entry 5 is identified + And the correct message number for the 1st migrator error is identified + And the correct message for the 1st migrator error is identified + And the correct description for the deed in 9th entry is indentified + And the correct role code for the 12th entry is displayed + And the correct type of the map entry within the Geometry entry for the title is displayed + +Scenario: BD161882 + Given I have entered a title number BD161882 + When the object for BD161882 is returned + Then title number BD161882 is indentified + And the correct class of title is indentified + And the correct template text for entry 2 is indentified + And the correct application reference is indentified + And the correct names of proprietors in entry 7 are indentified + And the correct sub register for entry 4 is dindentified + And the correct edition date is indentified + And the correct status for the 7th entry is indentified + +Scenario: BD161870 + Given I have entered the title number BD161870 + When the objects for BD161870 are returned + Then the title number BD161870 is indentified + And correct DLR is indentified + And the correct role code for entry 1 is indentified + And the correct full text for entry 2 is indentified + And the correct text for the first infill for entry 3 is indentified + And the correct postcode for the address of the infill for entry 1 is indentified + And the correct district is indentified + And the correct properties in the index/crs entry of the Geometry are indentified diff --git a/tests/JSON/features/step_definitions/BD161870.rb b/tests/JSON/features/step_definitions/BD161870.rb new file mode 100644 index 0000000..d88365a --- /dev/null +++ b/tests/JSON/features/step_definitions/BD161870.rb @@ -0,0 +1,47 @@ +Given(/^I have entered the title number BD(\d+)$/) do |arg1| + $structure = getstubjson("BD161870") +end + +When(/^the objects for BD(\d+) are returned$/) do |arg1| + $structure_hash = JSON.parse($structure) +end + +Then(/^the title number BD(\d+) is indentified$/) do |arg1| + puts $structure_hash['title_number'] + ' - title number' + expect($structure_hash['title_number']).to eq('BD161870') +end + +Then(/^correct DLR is indentified$/) do + puts $structure_hash['dlr'] + ' - dlr' + expect($structure_hash['dlr']).to eq('Peterborough Office') +end + +Then(/^the correct role code for entry (\d+) is indentified$/) do |arg1| + puts $structure_hash['entries'][0]['role_code'] + ' - role code' + expect($structure_hash['entries'][0]['role_code']).to eq('RDES') +end + +Then(/^the correct full text for entry (\d+) is indentified$/) do |arg1| + puts $structure_hash['entries'][1]['full_text'] + ' - full text of entry' + expect($structure_hash['entries'][1]['full_text']).to eq('PROPRIETOR: %SCOTT OAKES% of 17 Kenilworth Road, *Luton* LU1 1DQ.') +end + +Then(/^the correct text for the first infill for entry (\d+) is indentified$/) do |arg1| + puts $structure_hash['entries'][2]['infills'][0]['text'] + ' - first infill' + expect($structure_hash['entries'][2]['infills'][0]['text']).to eq('01/05/2014') +end + +Then(/^the correct postcode for the address of the infill for entry (\d+) is indentified$/) do |arg1| + puts $structure_hash['entries'][0]['infills'][0]['address']['postcode'] + ' - postcode' + expect($structure_hash['entries'][0]['infills'][0]['address']['postcode']).to eq('LU1 1DQ') +end + +Then(/^the correct district is indentified$/) do + puts $structure_hash['districts'][0] + ' - district' + expect($structure_hash['districts'][0]).to eq('LUTON') +end + +Then(/^the correct properties in the index\/crs entry of the Geometry are indentified$/) do + puts $structure_hash['geometry']['index']['crs']['properties']['name'] + ' - properties in index/crs' + expect($structure_hash['geometry']['index']['crs']['properties']['name']).to eq('urn:ogc:def:crs:EPSG::27700') +end diff --git a/tests/JSON/features/step_definitions/BD161882.rb b/tests/JSON/features/step_definitions/BD161882.rb new file mode 100644 index 0000000..2f0b873 --- /dev/null +++ b/tests/JSON/features/step_definitions/BD161882.rb @@ -0,0 +1,48 @@ +Given(/^I have entered a title number BD(\d+)$/) do |arg1| + $structure = getstubjson("BD161882") +end + +When(/^the object for BD(\d+) is returned$/) do |arg1| + $structure_hash = JSON.parse($structure) +end + +Then(/^title number BD(\d+) is indentified$/) do |arg1| + puts $structure_hash['title_number'] + ' - title number' + expect($structure_hash['title_number']).to eq('BD161882') +end + +Then(/^the correct class of title is indentified$/) do + puts $structure_hash['class'] + ' - class' + expect($structure_hash['class']).to eq('Absolute') +end + +Then(/^the correct template text for entry (\d+) is indentified$/) do |arg1| + puts $structure_hash['entries'][1]['template_text'] + ' - template text' + expect($structure_hash['entries'][1]['template_text']).to eq('PROPRIETOR: *RP*') +end + +Then(/^the correct application reference is indentified$/) do + puts $structure_hash['application_reference'] + ' - application reference' + expect($structure_hash['application_reference']).to eq('MA2785A') +end + +Then(/^the correct names of proprietors in entry (\d+) are indentified$/) do |arg1| + puts $structure_hash['entries'][6]['infills'][0]['proprietors'][0]['name']['non_private_individual_name'] + ' - proprietor name' + expect($structure_hash['entries'][6]['infills'][0]['proprietors'][0]['name']['non_private_individual_name']).to eq('Preferred Mortgages Limited') + expect($structure_hash['entries'][6]['infills'][0]['proprietors'][1]['name']['non_private_individual_name']).to eq('Preferred Mortgages Limited') +end + +Then(/^the correct sub register for entry (\d+) is dindentified$/) do |arg1| + puts $structure_hash['entries'][3]['sub_register'] + ' - sub register' + expect($structure_hash['entries'][3]['sub_register']).to eq('B') +end + +Then(/^the correct edition date is indentified$/) do + puts $structure_hash['edition_date'] + ' - edition date' + expect($structure_hash['edition_date']).to eq('2014-08-28') +end + +Then(/^the correct status for the (\d+)th entry is indentified$/) do |arg1| + puts $structure_hash['entries'][6]['status'] + ' - status' + expect($structure_hash['entries'][6]['status']).to eq('Current') +end diff --git a/tests/JSON/features/step_definitions/DT160760.rb b/tests/JSON/features/step_definitions/DT160760.rb new file mode 100644 index 0000000..6541394 --- /dev/null +++ b/tests/JSON/features/step_definitions/DT160760.rb @@ -0,0 +1,48 @@ +Given(/^I have entered a title number DT(\d+)$/) do |arg1| + $structure = getstubjson("DT160760") +end + +When(/^the objects for DT150760 are returned$/) do + $structure_hash = JSON.parse($structure) +end + +Then(/^title number DT1600760 is identified$/) do + puts $structure_hash['title_number'] + ' - title number' + expect($structure_hash['title_number']).to eq('DT160760') +end + +Then(/^the correct DLR is identied$/) do + puts $structure_hash['dlr'] + ' - dlr' + expect($structure_hash['dlr']).to eq('Weymouth Office') +end + +Then(/^the correct role code for entry (\d+) is identified$/) do |arg1| + puts $structure_hash['entries'][1]['role_code'] + ' - role code' + expect($structure_hash['entries'][1]['role_code']).to eq('RSLP') +end + +Then(/^the correct UPRNS entry is identified$/) do + puts ($structure_hash['uprns'][0]).to_s + ' - uprns' + expect($structure_hash['uprns'][0]).to eq(26241363) +end + +Then(/^the correct message for the (\d+)th migrator error is idenified$/) do |arg1| + puts $structure_hash['migration_errors'][4]['message'] + ' - message' + expect($structure_hash['migration_errors'][4]['message']).to eq('Investigation code: C - No role code assigned to the register entry') +end + +Then(/^the correct infill type for entry (\d+) is identified$/) do |arg1| + puts $structure_hash['entries'][0]['infills'][0]['type'] + ' - infill type' + expect($structure_hash['entries'][0]['infills'][0]['type']).to eq('Address') +end + +Then(/^the correct district is identified$/) do + puts $structure_hash['districts'][0] + ' - district' + expect($structure_hash['districts'][0]).to eq('DORSET : WEYMOUTH AND PORTLAND') +end + +Then(/^the correct co\-ordinates are identified$/) do + puts $structure_hash['geometry']['index']['geometry']['coordinates'][0][0][0].to_s + ' - co-ordinates' + expect($structure_hash['geometry']['index']['geometry']['coordinates'][0][0][0]).to eq(368002.61) + +end diff --git a/tests/JSON/features/step_definitions/GR504812.rb b/tests/JSON/features/step_definitions/GR504812.rb new file mode 100644 index 0000000..f4ee5d6 --- /dev/null +++ b/tests/JSON/features/step_definitions/GR504812.rb @@ -0,0 +1,48 @@ +Given(/^I have entered a title number GR(\d+)$/) do |arg1| + $structure = getstubjson("GR504812") +end + +When(/^the objects for GR504812 are returned$/) do + $structure_hash = JSON.parse($structure) +end + +Then(/^title number GR504812 is identified$/) do + puts $structure_hash['title_number'] + ' - title_number' + expect($structure_hash['title_number']).to eq('GR504812') +end + +Then(/^the correct tenure is indentied$/) do + puts $structure_hash['tenure'] + ' - tenure' + expect($structure_hash['tenure']).to eq('Freehold') +end + +Then(/^the correct entry id for entry (\d+) is identified$/) do |arg1| + puts $structure_hash['entries'][11]['entry_id'] + ' - entry_id' + expect($structure_hash['entries'][11]['entry_id']).to eq('2006-09-06 11:32:12.828685') +end + +Then(/^the correct application reference is identified$/) do + puts $structure_hash['application_reference'] + ' - application reference' + expect($structure_hash['application_reference']).to eq('E006DWW') + +end + +Then(/^the correct extractor for the (\d+)st migrator error is identified$/) do |arg1| + puts $structure_hash['migration_errors'][0]['extractor'] + ' - extractor error' + expect($structure_hash['migration_errors'][0]['extractor']).to eq('Register Check') +end + +Then(/^the correct sub register for entry (\d+) is identified$/) do |arg1| + puts $structure_hash['entries'][15]['sub_register'] + ' - sub_register' + expect($structure_hash['entries'][15]['sub_register']).to eq('C') +end + +Then(/^the correct edition date is identified$/) do + puts $structure_hash['edition_date'] + ' - edition_date' + expect($structure_hash['edition_date']).to eq('2006-09-06') +end + +Then(/^the correct status for the first entry is identified$/) do + puts $structure_hash['entries'][0]['status'] + ' - status' + expect($structure_hash['entries'][0]['status']).to eq('Current') +end diff --git a/tests/JSON/features/step_definitions/MS465614.rb b/tests/JSON/features/step_definitions/MS465614.rb new file mode 100644 index 0000000..9a5b348 --- /dev/null +++ b/tests/JSON/features/step_definitions/MS465614.rb @@ -0,0 +1,47 @@ +Given(/^I have entered a title number MS(\d+)$/) do |arg1| + $structure = getstubjson("MS465614") +end + +When(/^the objects for MS(\d+) are returned$/) do |arg1| + $structure_hash = JSON.parse($structure) +end + +Then(/^title number MS(\d+) is identified$/) do |arg1| + puts $structure_hash['title_number'] + ' - title_number' + expect($structure_hash['title_number']).to eq('MS465614') +end + +Then(/^the correct DLR is indentified$/) do + puts $structure_hash['dlr'] + ' - dlr' + expect($structure_hash['dlr']).to eq('Birkenhead Office') +end + +Then(/^the correct language for entry (\d+) is identified$/) do |arg1| + puts $structure_hash['entries'][4]['language'] + ' - language' + expect($structure_hash['entries'][4]['language']).to eq('en_GB') +end + +Then(/^the correct message number for the (\d+)st migrator error is identified$/) do |arg1| + puts $structure_hash['migration_errors'][0]['message_number'].to_s + ' - migration error message number' + expect($structure_hash['migration_errors'][0]['message_number']).to eq('PE1012') +end + +Then(/^the correct message for the (\d+)st migrator error is identified$/) do |arg1| + puts $structure_hash['migration_errors'][0]['message'] + ' - migration error message' + expect($structure_hash['migration_errors'][0]['message']).to eq('Address not deconstructed in Intelligent Register for title') +end + +Then(/^the correct description for the deed in (\d+)th entry is indentified$/) do |arg1| + puts $structure_hash['entries'][8]['deeds'][0]['description'] + ' - deed description' + expect($structure_hash['entries'][8]['deeds'][0]['description']).to eq('Conveyance') +end + +Then(/^the correct role code for the (\d+)th entry is displayed$/) do |arg1| + puts $structure_hash['entries'][11]['role_code'] + ' - role code' + expect($structure_hash['entries'][11]['role_code']).to eq('DCEA') +end + +Then(/^the correct type of the map entry within the Geometry entry for the title is displayed$/) do + puts $structure_hash['geometry']['map']['type'] + ' - map type' + expect($structure_hash['geometry']['map']['type']).to eq('FeatureCollection') +end diff --git a/tests/JSON/features/support/env.rb b/tests/JSON/features/support/env.rb new file mode 100644 index 0000000..0aa81f0 --- /dev/null +++ b/tests/JSON/features/support/env.rb @@ -0,0 +1,25 @@ +require 'rubygems' +require 'net/http' + +require 'json' + + +#These are web service call passwords that can be set or default to '' +$http_auth_name = (ENV['HTTPAUTH_USERNAME'] || '') +$http_auth_password = (ENV['HTTPAUTH_PASSWORD'] || '') + +#List of URLs to access its defaulted but then possible to export a different address so it points to the cloud instead +$STUBJSON = (ENV['http://localhost:5000'] || '') +$STUBJSON = 'http://localhost:5000/' +#This function gets the json object +def getstubjson(title_number) + uri = URI.parse($STUBJSON) + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Get.new('/' + title_number) + request.basic_auth $http_auth_name, $http_auth_password + response = http.request(request) + if (response.code != '200') then + raise "Error in getting JSON for: " + title_number + end + return response.body +end \ No newline at end of file diff --git a/tests/JSON/support/env.rb b/tests/JSON/support/env.rb new file mode 100644 index 0000000..a6a3fd3 --- /dev/null +++ b/tests/JSON/support/env.rb @@ -0,0 +1,25 @@ +require 'rubygems' +require 'net/http' + +require 'json' + + +#These are web service call passwords that can be set or default to '' +$http_auth_name = (ENV['HTTPAUTH_USERNAME'] || '') +$http_auth_password = (ENV['HTTPAUTH_PASSWORD'] || '') + +#List of URLs to access its defaulted but then possible to export a different address so it points to the cloud instead +$STUBJSON = (ENV['http://localhost:5000'] || '') +$STUBJSON = 'http://localhost:5000/' +#This function gets the json object +def getstubjson(title_number) + uri = URI.parse($STUBJSON) + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Get.new('/' + title_number) + request.basic_auth $http_auth_name, $http_auth_password + response = http.request(request) + if (response.code != '200') then + raise "Error in getting JSON for: " + title_number + end + return response.body +end