NIHVIVO-76 Working the Selenium script -- work on cleansing the database
This commit is contained in:
parent
7ba91a1698
commit
95c58ea9e3
4 changed files with 186 additions and 11 deletions
119
utilities/acceptance-tests/script/database_cleanser.rb
Normal file
119
utilities/acceptance-tests/script/database_cleanser.rb
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
=begin
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Stop the vivo application, delete all mysql tables, and start the application
|
||||||
|
again.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
-- the base URL of the vivo application: e.g. "http://localhost:8080/vivo"
|
||||||
|
-- the username and password of a Tomcat account authorized as a "manager".
|
||||||
|
-- the username and password of the MySQL account for the vivo application
|
||||||
|
-- the name of the MySQL database for the vivo application
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
What are we doing?
|
||||||
|
-- Break the URL into parts, so we can get the base Tomcat URL and the name
|
||||||
|
of the webapp.
|
||||||
|
-- Tell Tomcat's manager to stop the app.
|
||||||
|
-- Tell MySQL to drop the database and rebuild it.
|
||||||
|
-- Tell Tomcat's manager to start the app.
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
=end
|
||||||
|
require 'open-uri'
|
||||||
|
require 'property_file_reader'
|
||||||
|
|
||||||
|
class DatabaseCleanser
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
private
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Confirm that the parameters are reasonable.
|
||||||
|
#
|
||||||
|
def sanity_checks_on_parameters()
|
||||||
|
# Check that all necessary properties are here.
|
||||||
|
raise("Properties file must contain a value for 'webapp_url'") if @webapp_url == nil
|
||||||
|
raise("Properties file must contain a value for 'tomcat_username'") if @tomcat_username == nil
|
||||||
|
raise("Properties file must contain a value for 'tomcat_password'") if @tomcat_password == nil
|
||||||
|
raise("Properties file must contain a value for 'mysql_username'") if @mysql_username == nil
|
||||||
|
raise("Properties file must contain a value for 'mysql_password'") if @mysql_password == nil
|
||||||
|
raise("Properties file must contain a value for 'database_name'") if @database_name == nil
|
||||||
|
|
||||||
|
# Check that we can connect to the webapp.
|
||||||
|
begin
|
||||||
|
open(@webapp_url) {|f|}
|
||||||
|
rescue Exception
|
||||||
|
raise "Can't connect to VIVO application at '#{@webapp_url}'"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check that we can connect to the Tomcat manager app.
|
||||||
|
begin
|
||||||
|
open(@server_url + "manager/list", @tomcat_auth_options) {|f|}
|
||||||
|
rescue Exception
|
||||||
|
raise "Can't connect to Tomcat manager application at " +
|
||||||
|
"'#{@server_url + "manager/list"}', with this authorization: #{@tomcat_auth_options}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check that we can connect to the MySQL database.
|
||||||
|
args = []
|
||||||
|
args << "--user=#{@mysql_username}"
|
||||||
|
args << "--password=#{@mysql_password}"
|
||||||
|
args << "--database=#{@database_name}"
|
||||||
|
args << "--version"
|
||||||
|
result = system("mysql", *args)
|
||||||
|
raise("Can't find the 'mysql' command!") if result == nil
|
||||||
|
raise("Can't connect to MySQL database.") if !result
|
||||||
|
raise("Error connecting to MySQL database.") if $?.exitstatus != 0
|
||||||
|
end
|
||||||
|
|
||||||
|
# The Webapp URL must be a valid URL, and the path must be a single token
|
||||||
|
# (with an optional trailing slash).
|
||||||
|
#
|
||||||
|
def parse_webapp_url(webapp_url)
|
||||||
|
match = %r{(\w+://.+/)([^/]+)/?}.match(webapp_url)
|
||||||
|
if match
|
||||||
|
return [match[1], match[2]]
|
||||||
|
else
|
||||||
|
raise "Can't parse the webapp name from this URL: '#{webapp_url}'"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
public
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Get the parameters and check them
|
||||||
|
#
|
||||||
|
def initialize(properties)
|
||||||
|
@webapp_url = properties['webapp_url']
|
||||||
|
@tomcat_username = properties['tomcat_username']
|
||||||
|
@tomcat_password = properties['tomcat_password']
|
||||||
|
@mysql_username = properties['mysql_username']
|
||||||
|
@mysql_password = properties['mysql_password']
|
||||||
|
@database_name = properties['database_name']
|
||||||
|
|
||||||
|
@server_url, @webapp_name = parse_webapp_url(@webapp_url)
|
||||||
|
@tomcat_auth_options = {:http_basic_authentication => [@tomcat_username, @tomcat_password]}
|
||||||
|
|
||||||
|
sanity_checks_on_parameters()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
# Standalone calling.
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
if ARGV.length == 0
|
||||||
|
raise("No arguments - usage is: database_cleanser.rb <properties_file>")
|
||||||
|
end
|
||||||
|
if !File.file?(ARGV[0])
|
||||||
|
raise "File does not exist: '#{ARGV[0]}'."
|
||||||
|
end
|
||||||
|
|
||||||
|
properties = PropertyFileReader.read(ARGV[0])
|
||||||
|
|
||||||
|
dc = DatabaseCleanser.new(properties)
|
|
@ -0,0 +1,6 @@
|
||||||
|
webapp_url = http://localhost:8080/vivo/
|
||||||
|
tomcat_username = tomcat
|
||||||
|
tomcat_password = tomcat
|
||||||
|
mysql_username = vitrodbUsername
|
||||||
|
mysql_password = vitrodbPassword
|
||||||
|
database_name = vivo
|
39
utilities/acceptance-tests/script/property_file_reader.rb
Normal file
39
utilities/acceptance-tests/script/property_file_reader.rb
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
=begin
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
A utility class that reads a properties file and returns a hash containing the
|
||||||
|
properties.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
=end
|
||||||
|
|
||||||
|
class PropertyFileReader
|
||||||
|
# Read a properties file and return a hash.
|
||||||
|
#
|
||||||
|
# Parameters: the path to the properties file
|
||||||
|
#
|
||||||
|
# The hash includes the special property "properties_file_path", which holds
|
||||||
|
# the path to the properties file.
|
||||||
|
#
|
||||||
|
def self.read(file_path)
|
||||||
|
properties = {}
|
||||||
|
properties["properties_file_path"] = File.expand_path(file_path)
|
||||||
|
|
||||||
|
File.open(file_path) do |file|
|
||||||
|
file.each_line do |line|
|
||||||
|
line.strip!
|
||||||
|
if line.length == 0 || line[0] == ?# || line[0] == ?!
|
||||||
|
# ignore blank lines, and lines starting with '#' or '!'.
|
||||||
|
elsif line =~ /(.*?)\s*[=:]\s*(.*)/
|
||||||
|
# key and value are separated by '=' or ':' and optional whitespace.
|
||||||
|
properties[$1.strip] = $2
|
||||||
|
else
|
||||||
|
# No '=' or ':' means that the value is empty.
|
||||||
|
properties[line] = ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return properties
|
||||||
|
end
|
||||||
|
end
|
|
@ -38,6 +38,7 @@ What are we doing?
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
=end
|
=end
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
|
require 'database_cleanser'
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
<h1>Test suite results </h1>
|
<h1>Test suite results </h1>
|
||||||
|
@ -76,7 +77,7 @@ class AcceptanceRunner
|
||||||
#
|
#
|
||||||
def sanity_checks_on_parameters()
|
def sanity_checks_on_parameters()
|
||||||
confirm_is_readable_directory(@test_root_directory, "Test root directory")
|
confirm_is_readable_directory(@test_root_directory, "Test root directory")
|
||||||
if !has_sub_directories?(@test_root_directory)
|
if get_sub_directories(@test_root_directory).empty?
|
||||||
raise "Test root directory '#{@test_root_directory}' has no sub-directories."
|
raise "Test root directory '#{@test_root_directory}' has no sub-directories."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -128,25 +129,35 @@ class AcceptanceRunner
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Does this directory contain any sub-directories?
|
# Get an array of paths to all of the sub-directories in this directory.
|
||||||
#
|
#
|
||||||
def has_sub_directories?(directory_path)
|
def get_sub_directories(directory_path)
|
||||||
found_one = false
|
subs = []
|
||||||
Dir.foreach(directory_path) do |filename|
|
Dir.foreach(directory_path) do |filename|
|
||||||
if filename[0,1] != '.'
|
if filename[0,1] != '.'
|
||||||
path = File.expand_path(filename, directory_path)
|
path = File.expand_path(filename, directory_path)
|
||||||
found_one = true if File.directory?(path)
|
subs << path if File.directory?(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return found_one
|
return subs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# For each directory under the test root, cleanse the data model and run
|
||||||
|
# the test suite.
|
||||||
|
#
|
||||||
def run_all_suites()
|
def run_all_suites()
|
||||||
# get a list of all sub-directories
|
get_sub_directories(@test_root_directory).each do |suite_path|
|
||||||
# for each sub-directory
|
cleanse_data_model()
|
||||||
# -- run the cleanser
|
run_test_suite(suite_path)
|
||||||
# -- run the suite
|
end
|
||||||
puts "BOGUS run_all_suites()"
|
end
|
||||||
|
|
||||||
|
def cleanse_data_model()
|
||||||
|
puts "BOGUS cleanse_data_model()"
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_test_suite(suite_path)
|
||||||
|
puts "BOGUS run_test_suite()"
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_summary_html()
|
def create_summary_html()
|
||||||
|
|
Loading…
Add table
Reference in a new issue