--0-2074727828-1314953190=:37105
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hi I have write the following code and Now I have been asked to write a uni=
t test case for this code. But neither I have=A0 any idea how to write a un=
it test case nor I have ever experience with it. So in this case I am askin=
g your help.=0A=0A#!/usr/bin/perl=0A=0A###=0A## The program is called by ma=
in.pl=0A## dependent conf file is the property.conf located=0A## under the =
config folder in the home directory=0A###=0A=0Ause strict;=0Ause DBI;=0Ause=
File::Basename;=0Ause Cwd qw(realpath);=0A=0Amy $home =3D dirname( realpat=
h( $0 ));=0A=0Amy %config =3D &readConfigFile($home."/config/global.conf");=
=0Amy $db =3D &createDbConnection($config{'user'},$config{'passwd'},$confi g=
{'dbalias'});=0A=0Amy $stmt =3D $db->prepare("select job,OCCURRENCE,retenti=
on_days from CONFIG.PROCESS_LOG");=0A$stmt->execute();=0A=0Amy %prunehash;=
=0Awhile(my [at] row =3D stmt->fetchrow_array) {=0A=A0=A0=A0 $prunehash{$row[0]=
..':~:'.$row[1]} =3D $row[2];=0A}=0A$stmt->finish;=0A=0Aforeach (keys %prune=
hash) {=0A=A0=A0=A0 my ($job,$occ) =3D split(':~:',$_);=0A=A0=A0=A0 my $ret=
days =3D $prunehash{$_};=0A=A0=A0=A0 my $delstmt =3D $db->prepare("delete f=
rom LOG.PROCESS_LOG where days (CURRENT_TIMESTAMP - LOG.PROCESS_LOG.WHEN) >=
".$retdays." and LOG.PROCESS_LOG.JOB =3D '".$job."' and LOG.PROCESS_LOG.OC=
CURRENCE =3D ".$occ." ");=0A=A0=A0=A0 =0A=A0=A0=A0 $delstmt->execute;=0A=A0=
=A0=A0 $delstmt->finish;=0A}=0A=0A=0A$db->disconnect;=0A=0A## SubRoutines.=
=0A=0Asub config {=0A=A0=A0=A0 my ($flname) =3D [at] _;=0A=A0=A0=A0 my %chash;=
=0A=A0=A0=A0 open(FILE, "<$flname") || return 1; # die ("cannot open");=0A=
=0A=A0=A0=A0 # loading conf from file=0A=A0=A0=A0 while (<FILE>) {=0A=A0=A0=
=A0 =A0=A0=A0 chop $_ and next if (/^#/ || $_ eq "\n");=0A=A0=A0=A0 =A0=A0=
=A0 my ($name, $value)=3D/(.*)=3D(.*)/;=0A=A0=A0=A0 =A0=A0=A0 next if ((!$n=
ame) || (!$value));=0A=0A=A0=A0=A0 =A0=A0=A0 $name=3D&trim($name);=0A=A0=A0=
=A0 =A0=A0=A0 $value=3D&trim($value);=0A=0A=A0=A0=A0 =A0=A0=A0 next if (( $=
name eq "") ||( $value eq ""));=0A=A0=A0=A0 =A0=A0=A0 $chash{$name} =3D $va=
lue;=0A=A0=A0=A0 }=0A=A0=A0=A0 close(FILE);=0A=0A=A0=A0=A0 return %chash;=
=0A}=0A=0Asub createDbConnection {=0A=A0=A0=A0 my ($uid,$passwd,$dbalias) =
=3D [at] _;=0A=A0=A0=A0 return DBI->connect ("dbi:DB2:$dbalias", $uid, $passwd)=
or die 'Unable to connect'=0A=A0=A0=A0 =0A}=0A=0Asub trim {=0A=A0=A0=A0 (m=
y $str)=3D( [at] _);=0A=A0=A0=A0 $str =3D~ s/^\s+|\s+$//g;=0A=A0=A0=A0 return $s=
tr;=0A}=0A################################################## ######=0Aglobal=
..conf=A0 contents=0A=0Auser=3D=0A=0Apasswd=3D=0A=0Adbalias=3D=0A=0A=0 AThans=
& Regards in advance=0ARatul.
--0-2074727828-1314953190=:37105--
