NIHVIVO-76 Moving features into the OutputManager
This commit is contained in:
parent
bc6606afd5
commit
b67d626eba
2 changed files with 120 additions and 29 deletions
88
utilities/acceptance-tests/script/output_manager.rb
Normal file
88
utilities/acceptance-tests/script/output_manager.rb
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
=begin
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Stop the Vitro application, delete all MySQL tables from the Vitro database, and
|
||||||
|
start the application again.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
tomcat_stop_command
|
||||||
|
A "shell" command that will stop the Tomcat server.
|
||||||
|
tomcat_stop_delay
|
||||||
|
Number of seconds to wait after the tomcat_stop_command returns before
|
||||||
|
proceeding.
|
||||||
|
tomcat_start_command
|
||||||
|
A "shell" command that will start the Tomcat server.
|
||||||
|
tomcat_start_delay
|
||||||
|
Number of seconds to wait after the tomcat_start_command returns before
|
||||||
|
proceeding.
|
||||||
|
mysql_username
|
||||||
|
A user account that has authority to drop the Vitro database in MySQL.
|
||||||
|
mysql_password
|
||||||
|
The password for mysql_username.
|
||||||
|
database_name
|
||||||
|
The name of the Vitro database in MySQL.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
=end
|
||||||
|
|
||||||
|
class OutputManager
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
private
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Confirm that the output directory parameter is reasonable.
|
||||||
|
#
|
||||||
|
def sanity_checks_on_parameters()
|
||||||
|
if @output_directory == nil
|
||||||
|
raise("Properties file must contain a value for 'output_directory'")
|
||||||
|
end
|
||||||
|
|
||||||
|
if !File.exist?(@output_directory)
|
||||||
|
raise "Output directory '#{@output_directory}' does not exist."
|
||||||
|
end
|
||||||
|
|
||||||
|
if !File.readable?(@output_directory)
|
||||||
|
raise "Output directory '#{@output_directory}' is not readable."
|
||||||
|
end
|
||||||
|
|
||||||
|
if !File.directory?(@output_directory)
|
||||||
|
raise "Output directory '#{@output_directory}' is not a directory."
|
||||||
|
end
|
||||||
|
|
||||||
|
if !File.writable?(@output_directory)
|
||||||
|
raise "Output directory '#{@output_directory}' is not writable."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
public
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
# Set up and get ready to process.
|
||||||
|
#
|
||||||
|
def initialize(properties)
|
||||||
|
@output_directory = properties['output_directory']
|
||||||
|
|
||||||
|
sanity_checks_on_parameters()
|
||||||
|
|
||||||
|
@log_file = File.expand_path("log_file.txt", @output_directory)
|
||||||
|
@output_summary_file = File.expand_path("summary.html", @output_directory)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Write a message to the log file
|
||||||
|
#
|
||||||
|
def log(level, message)
|
||||||
|
File.open(@log_file, File::CREAT | File::APPEND | File::WRONLY) do |f|
|
||||||
|
f.print("#{level} #{message}\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def output_filename(suite_name)
|
||||||
|
File.expand_path("#{suite_name}_output.html", @output_directory)
|
||||||
|
end
|
||||||
|
|
||||||
|
def summarize()
|
||||||
|
end
|
||||||
|
end
|
|
@ -38,8 +38,10 @@ What are we doing?
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
=end
|
=end
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
|
require 'date'
|
||||||
require File.expand_path('database_cleanser', File.dirname(File.expand_path(__FILE__)))
|
require File.expand_path('database_cleanser', File.dirname(File.expand_path(__FILE__)))
|
||||||
require File.expand_path('property_file_reader', File.dirname(File.expand_path(__FILE__)))
|
require File.expand_path('property_file_reader', File.dirname(File.expand_path(__FILE__)))
|
||||||
|
require File.expand_path('output_manager', File.dirname(File.expand_path(__FILE__)))
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
<h1>Test suite results </h1>
|
<h1>Test suite results </h1>
|
||||||
|
@ -79,7 +81,6 @@ class AcceptanceRunner
|
||||||
def sanity_checks_on_parameters()
|
def sanity_checks_on_parameters()
|
||||||
raise("Properties file must contain a value for 'website_url'") if @website_url == nil
|
raise("Properties file must contain a value for 'website_url'") if @website_url == nil
|
||||||
raise("Properties file must contain a value for 'test_root_directory'") if @test_root_directory == nil
|
raise("Properties file must contain a value for 'test_root_directory'") if @test_root_directory == nil
|
||||||
raise("Properties file must contain a value for 'output_directory'") if @output_directory == nil
|
|
||||||
raise("Properties file must contain a value for 'user_extensions_path'") if @user_extensions_path == nil
|
raise("Properties file must contain a value for 'user_extensions_path'") if @user_extensions_path == nil
|
||||||
raise("Properties file must contain a value for 'firefox_profile_template_path'") if @firefox_profile_template_path == nil
|
raise("Properties file must contain a value for 'firefox_profile_template_path'") if @firefox_profile_template_path == nil
|
||||||
raise("Properties file must contain a value for 'suite_timeout_limit'") if @suite_timeout_limit == nil
|
raise("Properties file must contain a value for 'suite_timeout_limit'") if @suite_timeout_limit == nil
|
||||||
|
@ -90,11 +91,6 @@ class AcceptanceRunner
|
||||||
raise "Test root directory '#{@test_root_directory}' has no sub-directories."
|
raise "Test root directory '#{@test_root_directory}' has no sub-directories."
|
||||||
end
|
end
|
||||||
|
|
||||||
confirm_is_readable_directory(@output_directory, "Output directory")
|
|
||||||
if !File.writable?(@output_directory)
|
|
||||||
raise "Output directory '#{@output_directory}' is not writable."
|
|
||||||
end
|
|
||||||
|
|
||||||
if File.basename(@user_extensions_path) != "user-extensions.js"
|
if File.basename(@user_extensions_path) != "user-extensions.js"
|
||||||
raise "User extensions file must be named 'user-extensions.js', not '#{File.basename(@user_extensions_path)}'"
|
raise "User extensions file must be named 'user-extensions.js', not '#{File.basename(@user_extensions_path)}'"
|
||||||
end
|
end
|
||||||
|
@ -155,26 +151,30 @@ class AcceptanceRunner
|
||||||
# the test suite.
|
# the test suite.
|
||||||
#
|
#
|
||||||
def run_all_suites()
|
def run_all_suites()
|
||||||
|
time_stamp("Start time")
|
||||||
get_sub_directories(@test_root_directory).each do |suite_path|
|
get_sub_directories(@test_root_directory).each do |suite_path|
|
||||||
suite_file_path = File.expand_path("Suite.html", suite_path)
|
suite_file_path = File.expand_path("Suite.html", suite_path)
|
||||||
if File.exist?(suite_file_path)
|
if File.exist?(suite_file_path)
|
||||||
cleanse_data_model()
|
# BOGUS - disable the tests.
|
||||||
|
# cleanse_data_model()
|
||||||
|
# BOGUS - disable the tests.
|
||||||
run_test_suite(suite_file_path)
|
run_test_suite(suite_file_path)
|
||||||
|
else
|
||||||
|
log_warn("No suite file found in #{suite_path}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
time_stamp("End time")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Before each suite, call the cleanser.
|
# Before each suite, call the cleanser.
|
||||||
def cleanse_data_model()
|
def cleanse_data_model()
|
||||||
# puts "BOGUS cleanse_data_model()"
|
|
||||||
@database_cleanser.cleanse()
|
@database_cleanser.cleanse()
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_test_suite(suite_file_path)
|
def run_test_suite(suite_file_path)
|
||||||
puts "BOGUS run_test_suite(#{suite_file_path})"
|
|
||||||
|
|
||||||
suite_name = File.basename(File.dirname(suite_file_path))
|
suite_name = File.basename(File.dirname(suite_file_path))
|
||||||
output_file = File.expand_path("#{suite_name}_output.html", @output_directory)
|
log_info("Running suite #{suite_name}")
|
||||||
|
output_file = @output_manager.output_filename(suite_name)
|
||||||
|
|
||||||
args = []
|
args = []
|
||||||
args << "-jar" << @selenium_jar_path
|
args << "-jar" << @selenium_jar_path
|
||||||
|
@ -184,26 +184,31 @@ class AcceptanceRunner
|
||||||
args << "-firefoxProfileTemplate" << @firefox_profile_template_path
|
args << "-firefoxProfileTemplate" << @firefox_profile_template_path
|
||||||
args << "-htmlSuite" << "*firefox" << @website_url << suite_file_path << output_file
|
args << "-htmlSuite" << "*firefox" << @website_url << suite_file_path << output_file
|
||||||
|
|
||||||
result = system("java", *args)
|
# result = system("java", *args)
|
||||||
raise("Can't find the 'java' command!") if result == nil
|
# raise("Can't find the 'java' command!") if result == nil
|
||||||
if !result
|
# if $?.exitstatus != 0
|
||||||
puts ">>>> result: #{result}"
|
# log_error("Suite failed at '#{suite_file_path}: return code was #{$?.exitstatus}, command was 'java' #{args}")
|
||||||
puts ">>>> $?: #{$?}"
|
# end
|
||||||
log_error("Can't run the suite at '#{suite_file_path}: command was 'java' #{args}") if !result
|
|
||||||
elsif $?.exitstatus != 0
|
|
||||||
log_error("Suite failed at '#{suite_file_path}: return code was #{$?.exitstatus}, command was 'java' #{args}")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_summary_html()
|
def time_stamp(label)
|
||||||
puts "BOGUS create_summary_html()"
|
log_info("#{label}: #{DateTime.now.strftime('%Y/%m/%d %H:%M:%S')}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def log_info(message)
|
||||||
|
@output_manager.log("INFO ", message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def log_warn(message)
|
||||||
|
@output_manager.log("WARN ", message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_error(message)
|
def log_error(message)
|
||||||
File.open(@log_file, File::CREAT | File::APPEND | File::WRONLY) do |f|
|
@output_manager.log("ERROR", message)
|
||||||
f.print(message + "\n")
|
end
|
||||||
end
|
|
||||||
puts "LOG LOG: '#{message}'"
|
def create_summary_html()
|
||||||
|
@output_manager.summarize()
|
||||||
end
|
end
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------------
|
||||||
|
@ -215,7 +220,6 @@ class AcceptanceRunner
|
||||||
def initialize(properties)
|
def initialize(properties)
|
||||||
@website_url = properties['website_url']
|
@website_url = properties['website_url']
|
||||||
@test_root_directory = properties['test_root_directory']
|
@test_root_directory = properties['test_root_directory']
|
||||||
@output_directory = properties['output_directory']
|
|
||||||
@user_extensions_path = properties['user_extensions_path']
|
@user_extensions_path = properties['user_extensions_path']
|
||||||
@firefox_profile_template_path = properties['firefox_profile_template_path']
|
@firefox_profile_template_path = properties['firefox_profile_template_path']
|
||||||
@suite_timeout_limit = properties['suite_timeout_limit'].to_i
|
@suite_timeout_limit = properties['suite_timeout_limit'].to_i
|
||||||
|
@ -224,8 +228,7 @@ class AcceptanceRunner
|
||||||
sanity_checks_on_parameters()
|
sanity_checks_on_parameters()
|
||||||
|
|
||||||
@database_cleanser = DatabaseCleanser.new(properties)
|
@database_cleanser = DatabaseCleanser.new(properties)
|
||||||
|
@output_manager = OutputManager.new(properties)
|
||||||
@log_file = File.expand_path("log_file.txt", @output_directory)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue