NIHVIVO-239 Remove ruby script that had been used to run acceptance tests.

This commit is contained in:
jeb228 2010-06-03 18:58:19 +00:00
parent 7780497395
commit aed8ed6f89
9 changed files with 0 additions and 1344 deletions

View file

@ -1,180 +0,0 @@
=begin
--------------------------------------------------------------------------------
Stop the Vitro application, delete all MySQL tables from the Vitro database,
reload them from the mysqldump file, 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.
mysql_dump_file
The path to a file that contains a mysqldump of the test data model.
database_name
The name of the Vitro database in MySQL.
--------------------------------------------------------------------------------
=end
require 'open-uri'
require File.expand_path('property_file_reader', File.dirname(File.expand_path(__FILE__)))
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 'tomcat_stop_command'") if @tomcat_stop_command == nil
raise("Properties file must contain a value for 'tomcat_stop_delay'") if @tomcat_stop_delay == nil
raise("Properties file must contain a value for 'tomcat_start_command'") if @tomcat_start_command == nil
raise("Properties file must contain a value for 'tomcat_start_delay'") if @tomcat_start_delay == nil
raise("Properties file must contain a value for 'website_url'") if @website_url == 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 'mysql_dump_file'") if @mysql_dump_file == nil
raise("Properties file must contain a value for 'database_name'") if @database_name == nil
# Check that we can connect to the MySQL database.
args = []
args << "--user=#{@mysql_username}"
args << "--password=#{@mysql_password}"
args << "--database=#{@database_name}"
args << "--execute=show databases;"
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
# Check that the mysqldump file exists and is readable
if !File.exist?(@mysql_dump_file)
raise "MySQL dump file '#{@mysql_dump_file}' does not exist."
end
if !File.file?(@mysql_dump_file)
raise "MySQL dump file '#{@mysql_dump_file}' is not a file."
end
if !File.readable?(@mysql_dump_file)
raise "MySQL dump file '#{@mysql_dump_file}' is not readable."
end
end
# Issue the Tomcat stop command and pause for it to take effect.
#
def stop_the_webapp()
puts " Stopping the webapp..."
system(@tomcat_stop_command)
puts " Waiting #{@tomcat_stop_delay} seconds..."
sleep(@tomcat_stop_delay)
puts " ... stopped."
end
# Issue the Tomcat start command, pause for it to take effect, and wait
# until the server responds to an HTTP request.
#
def start_the_webapp()
puts " Starting the webapp..."
system(@tomcat_start_command)
puts " Waiting #{@tomcat_start_delay} seconds..."
sleep(@tomcat_start_delay)
begin
open(@website_url){|f|}
rescue Timeout::Error
puts ">>> HTTP request timed out!"
raise
end
puts " ... started."
end
# Tell MySQL to re-create the database and load from the dump file.
#
def drop_database_and_create_again()
args = []
args << "--user=#{@mysql_username}"
args << "--password=#{@mysql_password}"
args << "--database=#{@database_name}"
args << "--execute=drop database #{@database_name}; create database #{@database_name} character set utf8;"
result = system("mysql", *args)
raise("Can't find the 'mysql' command!") if result == nil
raise("Can't drop the MySQL database: command was 'mysql' #{args}") if !result
raise("Error code from MySQL: #{$?.exitstatus}, command was 'mysql' #{args}") if $?.exitstatus != 0
puts " Re-created the database."
args = []
args << "--user=#{@mysql_username}"
args << "--password=#{@mysql_password}"
args << "--database=#{@database_name}"
args << "--execute=source #{File.expand_path(@mysql_dump_file)};"
result = system("mysql", *args)
raise("Can't find the 'mysql' command!") if result == nil
raise("Can't load the MySQL dump file: command was 'mysql' #{args}") if !result
raise("Error code from MySQL: #{$?.exitstatus}, command was 'mysql' #{args}") if $?.exitstatus != 0
puts " Loaded the databse from the dump file."
end
# ------------------------------------------------------------------------------------
public
# ------------------------------------------------------------------------------------
# Get the parameters and check them
#
def initialize(properties)
@tomcat_stop_command = properties['tomcat_stop_command']
@tomcat_stop_delay = properties['tomcat_stop_delay'].to_i
@tomcat_start_command = properties['tomcat_start_command']
@tomcat_start_delay = properties['tomcat_start_delay'].to_i
@website_url = properties['website_url']
@mysql_username = properties['mysql_username']
@mysql_password = properties['mysql_password']
@mysql_dump_file = properties['mysql_dump_file']
@database_name = properties['database_name']
sanity_checks_on_parameters()
end
# Cleanse the database.
#
def cleanse()
stop_the_webapp()
drop_database_and_create_again()
start_the_webapp()
end
end
#
#
# ------------------------------------------------------------------------------------
# Standalone calling.
#
# Do this if this program was called from the command line. That is, if the command
# expands to the path of this file.
# ------------------------------------------------------------------------------------
#
if File.expand_path($0) == File.expand_path(__FILE__)
if ARGV.length == 0
raise("No arguments - usage is: ruby 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)
dc.cleanse()
end

View file

@ -1,23 +0,0 @@
#
# These properties tell how to set up Selenium to run a test suite.
#
website_url = http://localhost:8080/vivo/
test_root_directory = /home/jeb228/Documents/workspaces/vivo/utilities/acceptance-tests/suites
output_directory = /home/jeb228/Documents/workspaces/vivo/utilities/acceptance-tests/output
user_extensions_path = /home/jeb228/Documents/workspaces/vivo/utilities/acceptance-tests/selenium/user-extensions.js
firefox_profile_template_path = /home/jeb228/Documents/workspaces/vivo/utilities/acceptance-tests/selenium/firefox-profile
suite_timeout_limit = 210
selenium_jar_path = /home/jeb228/Documents/workspaces/vivo/utilities/acceptance-tests/selenium/selenium-server.jar
#
# These properties are needed to cleanse the data model between test suites.
#
tomcat_stop_command = /usr/local/tomcat/bin/shutdown.sh
tomcat_stop_delay = 5
tomcat_start_command = /usr/local/tomcat/bin/startup.sh
tomcat_start_delay = 180
mysql_username = vitrodbUsername
mysql_password = vitrodbPassword
mysql_dump_file = /home/jeb228/Documents/workspace/vivo/utilities/acceptance-tests/test-model/testmodeldump.sql
database_name = vivo
upload_directory = /usr/local/vivo/data/uploads

View file

@ -1,244 +0,0 @@
=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
require 'date'
require 'fileutils'
require File.expand_path('output_suite_parser', File.dirname(File.expand_path(__FILE__)))
require File.expand_path('output_summary_formatter', File.dirname(File.expand_path(__FILE__)))
require File.expand_path('property_file_reader', File.dirname(File.expand_path(__FILE__)))
class TestInfo
attr :test_name, true
attr :suite_name, true
attr :output_link, true
attr :status, true
attr :reason_for_ignoring, true
end
class SuiteInfo
attr :name, true
attr :output_link, true
attr :status, true
end
class Status
GOOD = 0
FAIR = 1
BAD = 2
def self.html_class(status)
return %w{good fair bad}[status]
end
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
if @ignored_tests_file == nil
raise("Properties file must contain a value for 'ignored_tests_file'")
end
if !File.exist?(@ignored_tests_file)
raise "Ignored tests file '#{@ignored_tests_file}' does not exist."
end
if !File.readable?(@ignored_tests_file)
raise "Ignored tests file '#{@ignored_tests_file}' is not readable."
end
if !File.file?(@ignored_tests_file)
raise "Ignored tests file '#{@ignored_tests_file}' is not a file."
end
end
# Load the list of ignored tests. Each line is [suite_name], [test_name]
#
def load_list_of_ignored_tests()
ignored_tests = []
File.open(@ignored_tests_file) do |f|
f.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*#(.*))?$/
# suite name and test name separated by ',' and optional whitespace.
# Optional comment on the end of the line, starting with a '#'
if $4 == nil
ignored_tests << [$1.strip, $2.strip, '']
else
ignored_tests << [$1.strip, $2.strip, $4]
end
else
raise "Invalid line in ignored tests file: '#{line}'"
end
end
end
return ignored_tests
end
# The CSS file for the output summary exists in the script directory.
# Copy it to the output directory.
#
def copy_css_file()
source = File.expand_path('output_summary.css', File.dirname(File.expand_path(__FILE__)))
dest = File.expand_path('summary.css', @output_directory)
FileUtils::copy_file(source, dest)
end
# ------------------------------------------------------------------------------------
public
# ------------------------------------------------------------------------------------
# Set up and get ready to process.
#
def initialize(properties)
@output_directory = properties['output_directory']
test_root_directory = properties['test_root_directory']
@ignored_tests_file = File.expand_path("ignored_tests.txt", test_root_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)
FileUtils::remove_file(@output_summary_file) if File.exist?(@output_summary_file)
@ignored_tests = load_list_of_ignored_tests()
end
# Start with an empty log file.
#
def empty_log()
FileUtils::remove_file(@log_file) if File.exist?(@log_file)
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("#{DateTime.now.strftime('%Y/%m/%d %H:%M:%S')} #{level} #{message}\n")
end
end
# Where can we find the output for this suite?
#
def output_filename(suite_name)
File.expand_path("#{suite_name}_output.html", @output_directory)
end
# Have we decided to ignore this test if it fails?
#
def ignore_test?(suite_name, test_name)
@ignored_tests.each do |t|
return true if t[0] == suite_name && t[1] == test_name
end
return false
end
# Why are we ignoring this test?
#
def get_reason_for_ignoring(suite_name, test_name)
@ignored_tests.each do |t|
return t[2] if t[0] == suite_name && t[1] == test_name
end
return ''
end
# This is the big one -- produce the output summary.
#
def summarize()
log("INFO ", "Parsing test output")
@osp = OutputSuiteParser.new(self, @log_file)
@osp.parse()
log("INFO ", "Copying CSS file to output directory")
copy_css_file()
log("INFO ", "Producing summary file")
File.open(@output_summary_file, File::CREAT | File::WRONLY) do |f|
osf = OutputSummaryFormatter.new(@osp, @log_file)
osf.format(f)
end
log("INFO ", "Summary complete")
if @osp.overall_status == Status::BAD
log("ERROR", "Tests failed.")
raise("Tests failed.")
end
end
end
#
#
# ------------------------------------------------------------------------------------
# Standalone calling.
#
# Do this if this program was called from the command line. That is, if the command
# expands to the path of this file.
# ------------------------------------------------------------------------------------
#
if File.expand_path($0) == File.expand_path(__FILE__)
if ARGV.length == 0
raise("No arguments - usage is: ruby output_manager.rb <properties_file>")
end
if !File.file?(ARGV[0])
raise "File does not exist: '#{ARGV[0]}'."
end
properties = PropertyFileReader.read(ARGV[0])
om = OutputManager.new(properties)
success = om.summarize()
end

View file

@ -1,187 +0,0 @@
=begin
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Parameters:
--------------------------------------------------------------------------------
=end
require 'date'
# This one is needed to get Time.parse() ????? Go figure.
require 'open-uri'
class OutputSuiteParser
attr :errors
attr :warnings
attr :start_time
attr :end_time
attr :elapsed_time
attr :suites
attr :tests
attr :overall_status
# ------------------------------------------------------------------------------------
private
# ------------------------------------------------------------------------------------
#
# Scan the log file for start time, end time, and the names of the suites that
# were run. Figure elapsed time also.
#
def parse_log_file()
@start_time = nil
@end_time = nil
@elapsed_time = "unknown"
@suite_names = []
File.open(@log_file) do |f|
f.each_line do |line|
md = %r{Start time: (.*)$}.match line
if md
@start_time = md[1]
end
md = %r{End time: (.*)$}.match line
if md
@end_time = md[1]
end
md = %r{Running suite (.*)$}.match line
if md
@suite_names << md[1]
end
md = %r{ERROR\s*(.*)}.match line
if md
@errors << md[1]
end
md = %r{WARN\s*(.*)}.match line
if md
@warnings << md[1]
end
end
end
if @start_time && @end_time
@elapsed_time = format_elapsed_time(@start_time, @end_time)
end
end
# Scan the output of a suite run.
#
def parse_suite_output(suite_name)
file_name = @output_manager.output_filename(suite_name)
s = SuiteInfo.new
s.name = suite_name
s.output_link = File.basename(file_name)
s.status = Status::GOOD
@suites << s
tests = []
begin
File.open(file_name) do |f|
f.each_line do |line|
md = %r{<tr class="\s*(\w+)"><td><a href="(#\w+)">([^<]*)</a></td></tr>}.match line
if md
t = TestInfo.new
t.test_name = md[3]
t.suite_name = s.name
t.output_link = s.output_link + md[2]
if md[1] == 'status_passed'
t.status = Status::GOOD
elsif @output_manager.ignore_test?(t.suite_name, t.test_name)
t.status = Status::FAIR
t.reason_for_ignoring = @output_manager.get_reason_for_ignoring(t.suite_name, t.test_name)
else
t.status = Status::BAD
end
tests << t
end
end
end
rescue Exception
log_error("Failed to parse output for suite '#{s.name}': #{$!}")
s.status = Status::BAD
end
s.status = get_worst_status(s.status, tests)
@tests = @tests.concat(tests)
end
# Look at the info from all of the suites and prepare summary info.
#
def collate_and_summarize()
status = Status::GOOD
status = Status::FAIR if !@warnings.empty?
status = Status::BAD if !@errors.empty?
@overall_status = get_worst_status(status, @suites)
end
# Find the worst status in an array of tests or suites
#
def get_worst_status(starting_status, statused)
worst = starting_status
statused.each do |s|
worst = s.status if s.status > worst
end
return worst
end
# Take two parsable time stamps and express the elapsed time as a string.
# Examples: 4h 37m 6.7s
# 15m 4s
# 55.6s
#
def format_elapsed_time(start_time_string, end_time_string)
start = Time.parse(start_time_string)
ender = Time.parse(end_time_string)
elapsed = ender - start
s = elapsed % 60
m = ((elapsed - s) / 60) % 60
h = (elapsed - s - (60 * m))/ 3600
elapsed_time = ""
elapsed_time << "#{h.to_i}h " if h > 0
elapsed_time << "#{m.to_i}m " if h > 0 || m > 0
elapsed_time << "#{s}s"
end
def log_error(message)
@output_manager.log("ERROR", message)
# By the time we get here, we've already scanned the log file for errors.
@errors << message
end
# ------------------------------------------------------------------------------------
public
# ------------------------------------------------------------------------------------
#
# Set up and get ready to process.
#
def initialize(output_manager, log_file)
@output_manager = output_manager
@log_file = log_file
@errors = []
@warnings = []
@suites = []
@tests = []
end
# Parse the output from each suite, and the log file, and munge it all together
# for easy access.
#
def parse()
parse_log_file()
@suite_names.each do |suite_name|
parse_suite_output(suite_name)
end
collate_and_summarize()
end
end

View file

@ -1,67 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
/*
Formats for the output summary from the acceptance tests.
*/
body {
background: rgb(95%, 95%, 95%);
font-family: sans-serif;
}
.heading {
border: groove;
background: white;
padding: 10px 20px 8px 20px;
margin-top: 50px;
font-size: large;
}
table {
border: thin double gray;
background: white;
}
td,th {
padding: 4px 12px 2px 12px;
}
th {
border-bottom: 1px solid black;
}
table.summary {
border: none;
background: inherit;
}
table.summary td {
padding-right: 30;
border: none;
vertical-align: top;
}
.section {
background: rgb(70%, 85%, 85%);
font-size: larger;
margin: 50px 0px 15px 0px;
padding: 4px 12px 2px 12px;
}
.good {
background: rgb(60%, 100%, 60%);
}
.bad {
background: rgb(100%, 60%, 60%);
}
.fair {
background: rgb(100%, 100%, 60%);
}
.one-word {
width: 20%;
text-align: center;
margin: 15px 0px 0px 0px;
border: 1px solid black;
}

View file

@ -1,288 +0,0 @@
=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 OutputSummaryFormatter
# ------------------------------------------------------------------------------------
private
# ------------------------------------------------------------------------------------
#
# Write the beginning of the summary file.
# This includes the HTML header, and the banner.
#
# f -- a file, already open for output.
#
def write_summary_header(f)
if @osp.overall_status == Status::BAD
status = "FAILURE"
html_class = Status::html_class(Status::BAD)
else
status = "SUCCESS"
html_class = Status::html_class(Status::GOOD)
end
f.print <<END_HEADER
<html>
<head>
<title>Summary of Acceptance Tests #{@osp.start_time}</title>
<link rel="stylesheet" type="text/css" href="summary.css">
</head>
<body>
<div class="heading">
Acceptance test results: #{@osp.start_time}
<div class="#{html_class} one-word">#{status}</div>
</div>
END_HEADER
end
# Write the first section of the summary file. This section contains
# nested tables with fixed formats, containing overall stats.
#
# f -- a file, already open for output.
#
def write_summary_stats_section(f)
how_many_tests = @osp.tests.length
how_many_pass = 0
how_many_fail = 0
how_many_ignore = 0
@osp.tests.each do |t|
how_many_pass += 1 if t.status == Status::GOOD
how_many_ignore += 1 if t.status == Status::FAIR
how_many_fail += 1 if t.status == Status::BAD
end
if how_many_pass > 0
pass_class = Status::html_class(Status::GOOD)
else
pass_class = ''
end
if how_many_fail > 0
fail_class = Status::html_class(Status::BAD)
else
fail_class = ''
end
if how_many_ignore > 0
ignore_class = Status::html_class(Status::FAIR)
else
ignore_class = ''
end
f.print <<END_STATS
<div class="section">Summary</div>
<table class="summary" cellspacing="0">
<tr>
<td>
<table cellspacing="0">
<tr><td>Start time:</td><td>#{@osp.start_time}</td></tr>
<tr><td>End time</td><td>#{@osp.end_time}</td></tr>
<tr><td>Elapsed time</td><td>#{@osp.elapsed_time}</td></tr>
</table>
</td>
<td>
<table cellspacing="0">
<tr><td>Suites</td><td>#{@osp.suites.length}</td></tr>
<tr><td>Total tests</td><td>#{@osp.tests.length}</td></tr>
<tr class="#{pass_class}"><td>Passing tests</td><td>#{how_many_pass}</td></tr>
<tr class="#{fail_class}"><td>Failing tests</td><td>#{how_many_fail}</td></tr>
<tr class="#{ignore_class}"><td>Ignored tests</td><td>#{how_many_ignore}</td></tr>
</table>
</td>
</tr>
</table>
END_STATS
end
# Write a table of failed tests to the summary file, with links
# to the detailed output for each test.
#
# While we're at it, write the list of failed tests to the console.
#
# f -- a file, already open for output.
#
def write_summary_failure_section(f)
fails = []
@osp.tests.each do |t|
fails << t if t.status == Status::BAD
end
f.print " <div class=section>Failing tests</div>\n\n <table cellspacing=\"0\">\n"
f.print " <tr><th>Suite name</th><th>Test name</th></tr>\n"
if fails.empty?
f.print " <tr>\n"
f.print " <td colspan=\"2\">No tests failed.</td>\n"
f.print " </tr>\n"
else
fails.each do |t|
f.print " <tr class=\"#{Status::html_class(t.status)}\">\n"
f.print " <td>#{t.suite_name}</td>\n"
f.print " <td><a href=\"#{t.output_link}\">#{t.test_name}</a></td>\n"
f.print " </tr>\n"
puts ">>>>>TEST FAILED: #{t.suite_name}, #{t.test_name} (not in ignored_tests.txt)"
end
end
f.print " </table>\n\n"
end
# Write a table of ignored tests to the summary file, with links
# to the detailed output for each test.
#
# f -- a file, already open for output.
#
def write_summary_ignore_section(f)
ignores = []
@osp.tests.each do |t|
ignores << t if t.status == Status::FAIR
end
f.print " <div class=section>Ignored tests</div>\n\n <table cellspacing=\"0\">\n"
f.print " <tr><th>Suite name</th><th>Test name</th><th>Reason for ignoring</th></tr>\n"
if ignores.empty?
f.print " <tr>\n"
f.print " <td colspan=\"3\">No tests ignored.</td>\n"
f.print " </tr>\n"
else
ignores.each do |t|
f.print " <tr class=\"#{Status::html_class(t.status)}\">\n"
f.print " <td>#{t.suite_name}</td>\n"
f.print " <td><a href=\"#{t.output_link}\">#{t.test_name}</a></td>\n"
f.print " <td>#{t.reason_for_ignoring}</td>\n"
f.print " </tr>\n"
end
end
f.print " </table>\n\n"
end
# Write a table of any error messages or warnings found in the log file.
#
# f -- a file, already open for output.
#
def write_error_messages_section(f)
f.print " <div class=section>Errors and warnings</div>\n"
f.print " <table cellspacing=\"0\">"
if @osp.errors.empty? && @osp.warnings.empty?
f.print " <tr><td colspan=\"2\">No errors or warnings</td></tr>"
else
@osp.errors.each() do |e|
f.print " <tr class=\"bad\"><td>ERROR</td><td>#{e}</td></tr>"
end
@osp.warnings.each() do |w|
f.print " <tr class=\"fair\"><td>WARN</td><td>#{w}</td></tr>"
end
end
f.print " </table>\n\n"
end
# Write a table of the suites to the summary file, with links
# to the detailed output for each suite.
#
# f -- a file, already open for output.
#
def write_summary_suites_section(f)
f.print " <div class=section>Suites</div>\n"
f.print " <table cellspacing=\"0\">\n"
@osp.suites.each() do |s|
f.print " <tr class=\"#{Status::html_class(s.status)}\">\n"
f.print " <td><a href=\"#{s.output_link}\">#{s.name}</a></td>\n"
f.print " </tr>\n"
end
f.print " </table>\n\n"
end
# Write a table of all tests to the summary file, with links
# to the detailed output for each test.
#
# f -- a file, already open for output.
#
def write_summary_all_tests_section(f)
f.print " <div class=section>All tests</div>\n\n <table cellspacing=\"0\">\n"
f.print " <tr><th>Suite name</th><th>Test name</th></tr>\n"
if @osp.tests.empty?
f.print " <tr>\n"
f.print " <td colspan=\"2\">No tests.</td>\n"
f.print " </tr>\n"
else
@osp.tests.each do |t|
f.print " <tr class=\"#{Status::html_class(t.status)}\">\n"
f.print " <td>#{t.suite_name}</td>\n"
f.print " <td><a href=\"#{t.output_link}\">#{t.test_name}</a></td>\n"
f.print " </tr>\n"
end
end
f.print " </table>\n\n"
end
# Copy the log to the summary file, and close the HTML tags.
#
# f -- a file, already open for output.
#
def write_summary_footer(f)
f.print " <div class=section>Log</div>\n <pre>\n"
File.open(@log_file) do |log|
FileUtils::copy_stream(log, f)
end
f.print " </pre>\n</body>\n</html>\n\n"
end
# ------------------------------------------------------------------------------------
public
# ------------------------------------------------------------------------------------
# Set up and get ready to process.
#
def initialize(output_suite_parser, log_file)
@osp = output_suite_parser
@log_file = log_file
end
def format(f)
write_summary_header(f)
write_summary_stats_section(f)
write_error_messages_section(f)
write_summary_failure_section(f)
write_summary_ignore_section(f)
write_summary_suites_section(f)
write_summary_all_tests_section(f)
write_summary_footer(f)
end
end

View file

@ -1,39 +0,0 @@
=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

View file

@ -1,230 +0,0 @@
=begin
--------------------------------------------------------------------------------
Run the acceptance tests, and summarize their output.
--------------------------------------------------------------------------------
Parameters:
-- the root directory for the tests. Probably something ending in
vivoweb/utilities/acceptance-tests/suites
-- the directory for the output.
-- the path to the user extensions script.
-- the directory of the Firefox profile template.
-- the URL of the web site under test.
--------------------------------------------------------------------------------
What are we doing?
-- Test the parameters.
-- Does each directory exist? Is it readable? writeable?
-- Does the URL produce a response?
-- Does user-extensions.js exist?
-- For each subdirectory in the suites folder:
-- Run the reset process, whatever that is.
-- Stop tomcat, reset MySql database, start tomcat
-- Find the Suite.html
-- If none, throw warning into the log and continue.
-- Run the suite, sending the output to a file named after the subdirectory
-- If failure, throw error into the log and continue.
-- Create a summary output file.
result: passed | failed -- "and" of all suites.
total time: seconds -- capture the time before and after.
number of tests: -- sum from all suites.
number of passing tests: -- sum from all suites.
number of failing tests: -- sum from all suites.
Table of links to the suite output files.
--------------------------------------------------------------------------------
=end
require 'open-uri'
require 'date'
require File.expand_path('database_cleanser', File.dirname(File.expand_path(__FILE__)))
require File.expand_path('upload_area_cleanser', 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__)))
class AcceptanceRunner
# ------------------------------------------------------------------------------------
private
# ------------------------------------------------------------------------------------
#
# Confirm that the parameters are reasonable. They point to valid files, directories,
# and URL.
#
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 'test_root_directory'") if @test_root_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 '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 'selenium_jar_path'") if @selenium_jar_path == nil
confirm_is_readable_directory(@test_root_directory, "Test root directory")
if get_sub_directories(@test_root_directory).empty?
raise "Test root directory '#{@test_root_directory}' has no sub-directories."
end
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)}'"
end
confirm_is_readable_file(@user_extensions_path, "User extensions file")
confirm_is_readable_directory(@firefox_profile_template_path, "Firefox profile template")
begin
open(@website_url) {|f|}
rescue Exception
raise "Unable to connect to web-site at '#{@website_url}'"
end
end
# Does this path point to an existing, readable directory?
#
def confirm_is_readable_directory(path, label)
confirm_is_readable(path, label)
if !File.directory?(path)
raise "#{label} '#{path}' is not a directory."
end
end
# Does this path point to an existing, readable file?
#
def confirm_is_readable_file(path, label)
confirm_is_readable(path, label)
if !File.file?(path)
raise "#{label} '#{path}' is not a file."
end
end
# Does this path point to something that exists and is readable?
#
def confirm_is_readable(path, label)
if !File.exist?(path)
raise "#{label} '#{path}' does not exist."
end
if !File.readable?(path)
raise "#{label} '#{path}' is not readable."
end
end
# Get an array of paths to all of the sub-directories in this directory.
#
def get_sub_directories(directory_path)
subs = []
Dir.foreach(directory_path) do |filename|
if filename[0,1] != '.'
path = File.expand_path(filename, directory_path)
subs << path if File.directory?(path)
end
end
return subs
end
# For each directory under the test root, cleanse the data model and run
# the test suite.
#
def run_all_suites()
time_stamp("Start time")
get_sub_directories(@test_root_directory).each do |suite_path|
suite_file_path = File.expand_path("Suite.html", suite_path)
if File.exist?(suite_file_path)
cleanse_the_model()
run_test_suite(suite_file_path)
else
log_warn("No suite file found in #{suite_path}")
end
end
time_stamp("End time")
end
# Before each suite, call the cleansers.
def cleanse_the_model()
@database_cleanser.cleanse()
@upload_area_cleanser.cleanse()
end
def run_test_suite(suite_file_path)
suite_name = File.basename(File.dirname(suite_file_path))
log_info("Running suite #{suite_name}")
puts ">>>> Running suite #{suite_name}"
output_file = @output_manager.output_filename(suite_name)
args = []
args << "-jar" << @selenium_jar_path
args << "-singleWindow"
args << "-timeout" << @suite_timeout_limit.to_s
args << "-userExtensions" << @user_extensions_path
args << "-firefoxProfileTemplate" << @firefox_profile_template_path
args << "-htmlSuite" << "*firefox" << @website_url << suite_file_path << output_file
result = system("java", *args)
raise("Can't find the 'java' command!") if result == nil
if $?.exitstatus != 0
log_warn("Suite failed: '#{suite_name}', return code was #{$?.exitstatus}")
end
end
def time_stamp(label)
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
def log_error(message)
@output_manager.log("ERROR", message)
end
# ------------------------------------------------------------------------------------
public
# ------------------------------------------------------------------------------------
# Set up and get ready to process.
#
def initialize(properties)
@website_url = properties['website_url']
@test_root_directory = properties['test_root_directory']
@user_extensions_path = properties['user_extensions_path']
@firefox_profile_template_path = properties['firefox_profile_template_path']
@suite_timeout_limit = properties['suite_timeout_limit'].to_i
@selenium_jar_path = properties['selenium_jar_path']
sanity_checks_on_parameters()
@database_cleanser = DatabaseCleanser.new(properties)
@upload_area_cleanser = UploadAreaCleanser.new(properties)
@output_manager = OutputManager.new(properties)
@output_manager.empty_log()
end
# Run all of the test suites
def run
run_all_suites()
# To collate the output from the suites, use OutputManager.new(properties).summarize()
end
end
#
#
# ------------------------------------------------------------------------------------
# Standalone calling.
# ------------------------------------------------------------------------------------
#
if ARGV.length == 0
raise("No arguments - usage is: ruby run_acceptance_test.rb <properties_file>")
end
if !File.file?(ARGV[0])
raise "File does not exist: '#{ARGV[0]}'."
end
properties = PropertyFileReader.read(ARGV[0])
ar = AcceptanceRunner.new(properties)
ar.run()

View file

@ -1,86 +0,0 @@
=begin
--------------------------------------------------------------------------------
Remove any files from the VIVO upload area, so we have a clean area for the next
suite of tests.
--------------------------------------------------------------------------------
Parameters:
upload_directory
The path to the upload area.
--------------------------------------------------------------------------------
=end
require 'fileutils'
require File.expand_path('property_file_reader', File.dirname(File.expand_path(__FILE__)))
class UploadAreaCleanser
# ------------------------------------------------------------------------------------
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 'upload_directory'") if @upload_directory == nil
if !File.exist?(@upload_directory)
raise "Upload directory '#{@upload_directory}' does not exist."
end
if !File.readable?(@upload_directory)
raise "Upload directory '#{@upload_directory}' is not readable."
end
if !File.directory?(@upload_directory)
raise "Upload directory '#{@upload_directory}' is not a directory."
end
if !File.writable?(@upload_directory)
raise "Upload directory '#{@upload_directory}' is not writable."
end
end
# ------------------------------------------------------------------------------------
public
# ------------------------------------------------------------------------------------
# Get the parameters and check them
#
def initialize(properties)
@upload_directory = properties['upload_directory']
sanity_checks_on_parameters()
end
# Cleanse the directory
#
def cleanse()
FileUtils::rm_r(Dir.glob(File.expand_path('*', @upload_directory)), :verbose=>true)
end
end
#
#
# ------------------------------------------------------------------------------------
# Standalone calling.
#
# Do this if this program was called from the command line. That is, if the command
# expands to the path of this file.
# ------------------------------------------------------------------------------------
#
if File.expand_path($0) == File.expand_path(__FILE__)
if ARGV.length == 0
raise("No arguments - usage is: ruby upload_area_cleanser.rb <properties_file>")
end
if !File.file?(ARGV[0])
raise "File does not exist: '#{ARGV[0]}'."
end
properties = PropertyFileReader.read(ARGV[0])
uac = UploadAreaCleanser.new(properties)
uac.cleanse()
end