# Author: Parag Kalra, paragkalra@gmail.com # Licensed under GNU Public License - http://www.gnu.org/licenses/gpl.html package QA::Automation; use strict; use warnings; =head1 NAME QA::Automation - This module is used to execute Oracle database test cases (sql queries) and validate the automation suite =head1 DESCRIPTION This module provides tools (methods) Automate SQL query execution against Oracle database To start with, user needs to create the object by providing database connection details, result directory and some other non-mandatory parameters. As of now plan is to provide following methods: 1. create_cfg_from_uncommented_sql : This method creates cfg (configuration file) from an uncommented sql query. This cfg forms part of the automation suite that would be executed by appropriate method 2. execute_exact_count_sqls : This Method would execute all the count sqls mentioned in the cfg and compare the returned count against the count mentioned for the respective sql query. All the test cases where mismatch would be found in the count, would be marked as FAILED or else PASSED Once all the test cases (sql queries) are executed, a detailed result summary would be created in the result directory specified by the user. 3. execute_minus_match_sqls : This method would execute all the minus sqls mentioned in the cfg and would check if any data is returned or not. If returned then test cases would be marked as FAILED or else PASSED The intention is to check that data set of minus separated queries is same. Once all the test cases (sql queries) are executed, a detailed result summary would be created in the result directory specified by the user. Any many more methods are in pipe line =head1 SYNOPSIS use QA::Automation; my $qa_atm = QA::Automation -> new ( uname => "scott", passwd => "tiger", sid => "orcl", result => "home/my/dir", ORA_HOME => 1, DETAILED_RESULT => 1, CREATE_RESULT_DIR => 1, ); =head1 REQUIRES DBI DBD::Oracle File::Path =cut # Required modules use DBI; use File::Path; =head1 CONSTRUCTOR AND STARTUP =head2 new =over 4 This method creates the object required for automation of test case execution. It also creates the result directory if it does not exists and user wants to create it. =back =cut sub new { my $class = shift; my %args = @_; my $self = \%args; my $result_dir = $self->{'result'}; # if the directory doesn't exists create then create it if ((! -d $result_dir) && ($self->{'CREATE_RESULT_DIR'})){ mkpath ($result_dir); } bless $self, $class or die "Can't bless $class: $!"; return $self; } =head1 METHODS =head2 create_cfg_from_uncommented_sql =over 4 This method prepares the cfg from the sql file provided as input by the user. Pre-requisites for this method: 1. All the sql queries mentioned under the sql file should end with a semi-colon (;) 2. There should be no comments in the sql file =back =cut sub create_cfg_from_uncommented_sql { my $self = shift; my $sql = shift; # Declaring variables local $/ = ';'; # Setting the IFS to a semicolon my $input_file; my $output_file = "$self->{'result'}/SQL.out"; # Checking the existence of the input file if ( ! defined $sql){ die "Input SQL file not provided - Usage: qa_atm_obj->create_cfg_from_uncommented_sql(SQL_File>\n"; } else { $input_file = $sql; } # Processing input/output files open my $input_fh, '<', $input_file or die "Could not open the input file - $input_file\n"; open my $output_fh, '>', $output_file or die "Could not create the output file - $output_file\n"; # Looping through the file and removing all the white space and appending a new line at the end while (<$input_fh>){ $_ =~ s/\s+/ /g; $_ =~ s/^\s+//; $_ =~ s/\s$//; print $output_fh "$_\n"; } # Closing the files close $input_fh or print "Could not close the file - $input_file\n"; close $output_fh or print "Could not close the file - $output_file\n"; } =head1 AUTHOR Parag Kalra, paragkalra@gmail.com =cut 1;