[Rt-commit] [svn] r1577 - Business-SLA/trunk/lib/Business
leira at pallas.eruditorum.org
leira at pallas.eruditorum.org
Wed Sep 29 02:09:14 EDT 2004
Author: leira
Date: Wed Sep 29 02:09:13 2004
New Revision: 1577
Modified:
Business-SLA/trunk/lib/Business/SLA.pm
Log:
Initial test suite.
Modified: Business-SLA/trunk/lib/Business/SLA.pm
==============================================================================
--- Business-SLA/trunk/lib/Business/SLA.pm (original)
+++ Business-SLA/trunk/lib/Business/SLA.pm Wed Sep 29 02:09:13 2004
@@ -55,7 +55,7 @@
Linda Julien
Best Practical Solutions, LLC
- julien at bestpractical.com
+ leira at bestpractical.com
http://www.bestpractical.com
=head1 COPYRIGHT
@@ -89,6 +89,21 @@
Takes a Business::Hours object.
+=begin testing
+
+use_ok (Business::Hours);
+use_ok (Business::SLA);
+
+my $sla = new Business::SLA;
+is(ref($sla), 'Business::SLA');
+
+my $bizhours = Business::Hours->new();
+$sla->SetBusinessHours($bizhours);
+
+is($sla->BusinessHours, $bizhours, "Returned same Business Hours");
+
+=end testing
+
=cut
sub SetBusinessHours {
@@ -118,6 +133,21 @@
Takes a string which is the hash key for the desired SLA.
+=begin testing
+
+use_ok (Business::Hours);
+use_ok (Business::SLA);
+
+my $sla = new Business::SLA;
+
+my $val = "aaa";
+
+$sla->SetInHoursDefault($val);
+
+is($sla->InHoursDefault, $val, "Returned same InHoursDefault");
+
+=end testing
+
=cut
sub SetInHoursDefault {
@@ -145,6 +175,21 @@
Takes a string which is the hash key for the desired SLA.
+=begin testing
+
+use_ok (Business::Hours);
+use_ok (Business::SLA);
+
+my $sla = new Business::SLA;
+
+my $val = "aaa";
+
+$sla->SetOutOfHoursDefault($val);
+
+is($sla->OutOfHoursDefault, $val, "Returned same OutOfHoursDefault");
+
+=end testing
+
=cut
sub SetOutOfHoursDefault {
@@ -167,6 +212,53 @@
}
+=begin testing
+
+use_ok (Business::Hours);
+use_ok (Business::SLA);
+
+my $sla = new Business::SLA;
+
+my $bizhours = Business::Hours->new();
+
+# pick a date that's during business hours
+$starttime = 0;
+($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+while ($wday == 0 || $wday == 6) {
+ $starttime += ( 24 * 60 * 60);
+ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+}
+while ( $hour < 9 || $hour >= 18 ) {
+ $starttime += ( 4 * 60);
+ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+}
+
+# with Business::Hours set
+$sla->SetBusinessHours($bizhours);
+is($sla->IsInHours($starttime), 1, "Time is in business hours");
+
+# with Business::Hours unset
+$sla->SetBusinessHours(undef);
+is($sla->IsInHours($starttime), 1, "Time is in business hours");
+
+# pick a date that's not during business hours
+$starttime = 0;
+($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
+while ( $xwday != 0 ) {
+ $starttime += ( 24 * 60 * 60);
+ ($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
+}
+
+# with Business::Hours set
+$sla->SetBusinessHours($bizhours);
+is($sla->IsInHours($starttime), 0, "Time is in business hours");
+
+# with Business::Hours unset
+$sla->SetBusinessHours(undef);
+is($sla->IsInHours($starttime), 1, "Time is in business hours");
+
+=end testing
+
=head2 IsInHours
Returns 1 if the date passed in is in business hours, and 0 otherwise.
@@ -198,6 +290,60 @@
Takes a date in Unix time format (number of seconds since the epoch).
+=begin testing
+
+use_ok (Business::Hours);
+use_ok (Business::SLA);
+
+my $sla = new Business::SLA;
+
+# set the defaults
+my $inhoursval = "aaa";
+$sla->SetInHoursDefault($inhoursval);
+
+my $outofhoursval = "bbb";
+$sla->SetOutOfHoursDefault($outofhoursval);
+
+my $bizhours = Business::Hours->new();
+
+# pick a date that's during business hours
+$starttime = 0;
+($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+while ($wday == 0 || $wday == 6) {
+ $starttime += ( 24 * 60 * 60);
+ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+}
+while ( $hour < 9 || $hour >= 18 ) {
+ $starttime += ( 4 * 60);
+ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+}
+
+# with Business::Hours set
+$sla->SetBusinessHours($bizhours);
+is($sla->SLA($starttime), $inhoursval, "Got correct SLA value");
+
+# with Business::Hours unset
+$sla->SetBusinessHours(undef);
+is($sla->SLA($starttime), $inhoursval, "Got correct SLA value");
+
+# pick a date that's not during business hours
+$starttime = 0;
+($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
+while ( $xwday != 0 ) {
+ $starttime += ( 24 * 60 * 60);
+ ($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
+}
+
+# with Business::Hours set
+$sla->SetBusinessHours($bizhours);
+is($sla->SLA($starttime), $outofhoursval, "Got correct SLA value");
+
+# with Business::Hours unset
+$sla->SetBusinessHours(undef);
+is($sla->SLA($starttime), $inhoursval, "Got correct SLA value");
+
+=end testing
+
=cut
sub SLA {
@@ -216,6 +362,12 @@
Adds an SLA value. Takes a string (the hash key) and a hash.
+=begin testing
+
+# add is tested in AddBusinessMinutes/AddRealMinutes
+
+=end testing
+
=cut
sub Add {
@@ -235,12 +387,28 @@
Takes the hash key for the SLA.
+=begin testing
+
+use_ok (Business::SLA);
+
+my $sla = new Business::SLA;
+
+$sla->Add('aaa', ( 'RealMinutes' => 120,
+ 'BusinessMinutes' => 60, ));
+
+is($sla->AddRealMinutes('aaa'), 120,
+ "Got real minutes for added SLA");
+
+=end testing
+
=cut
sub AddRealMinutes {
my $self = shift;
my $sla = shift;
+ return undef unless defined $sla;
+
my $minutes;
if ($self->{'hash'} && $self->{'hash'}->{$sla}) {
$minutes = $self->{'hash'}->{$sla}->{'RealMinutes'};
@@ -257,6 +425,28 @@
Takes the hash key for the SLA.
+=begin testing
+
+use_ok (Business::SLA);
+
+my $sla = new Business::SLA;
+
+$sla->Add('aaa', ( 'RealMinutes' => 120,
+ 'BusinessMinutes' => 60, ));
+
+# with no business minutes set
+is($sla->AddBusinessMinutes('aaa'), undef,
+ "Got business minutes for added SLA without Business Hours");
+
+my $bizhours = Business::Hours->new();
+$sla->SetBusinessHours($bizhours);
+
+# with no business minutes set
+is($sla->AddBusinessMinutes('aaa'), 60,
+ "Got business minutes for added SLA with Business Hours");
+
+=end testing
+
=cut
sub AddBusinessMinutes {
@@ -286,6 +476,21 @@
Takes a date in Unix time format (number of seconds since the epoch)
and the hash key for the SLA.
+=begin testing
+
+use_ok (Business::SLA);
+
+my $sla = new Business::SLA;
+
+$sla->Add('aaa', ( 'RealMinutes' => 10,
+ 'BusinessMinutes' => undef, ));
+
+my $time = time();
+
+is($sla->Starts($time, 'aaa'), $time, "Get starting time");
+
+=end testing
+
=cut
sub Starts {
@@ -307,6 +512,21 @@
Takes a date in Unix time format (number of seconds since the epoch)
and the hash key for the SLA.
+=begin testing
+
+use_ok (Business::SLA);
+
+my $sla = new Business::SLA;
+
+$sla->Add('aaa', ( 'RealMinutes' => 10,
+ 'BusinessMinutes' => undef, ));
+
+my $time = time();
+
+is($sla->Due($time, 'aaa'), $time + (10 * 60), "Get starting time");
+
+=end testing
+
=cut
sub Due {
More information about the Rt-commit
mailing list