#!/usr/bin/perl -w

#----------------------------------------------------------------------
# copyright (C) 2002 Mitel Networks Corporation
#               
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#               
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#               
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
# 
# Technical support for this program is available from e-smith, inc.
# For details, please visit our web site at www.e-smith.com or
# call us on 1 888 ESMITH 1 (US/Canada toll free) or +1 613 564 8000
#----------------------------------------------------------------------

=head1 NAME 

testing-conf -- configure testing service

=head1 DESCRIPTION

This action sets up the testing service when you first install
e-smith-test, setting the "destruction" property to 0 (non-destructive).
It is a no-op if the "destruction" property is already defined.

=begin testing

use esmith::ConfigDB;

$ENV{ESMITH_CONFIG_DB} = "00e-smith-test/configuration";
unlink $ENV{ESMITH_CONFIG_DB};

ok(my $conf         = esmith::ConfigDB->create(), "Create new config file");
ok(my $test_service = $conf->new_record('testing', {type => 'service'}), 
                      "Create new record for testing service");
isa_ok($test_service, 'esmith::DB::Record');

ok(not(defined($test_service->prop('destruction'))),
    "Testing should be absent before we run");

is(system("$^X $Original_File"), 0, "System command returned 0");
$conf = esmith::ConfigDB->open();
$test_service = $conf->get('testing');
ok(defined($test_service->prop('destruction')), "Destruction is now defined");

$test_service->set_prop('destruction', 1);
is(system("$^X $Original_File"), 0, "System command returned 0");
$conf = esmith::ConfigDB->open();
$test_service = $conf->get('testing');
is($test_service->prop('destruction'), 1,
    "Destruction is left alone if already defined");

$test_service->set_prop('destruction', 0);
is(system("$^X $Original_File"), 0, "System command returned 0");
$conf = esmith::ConfigDB->open();
$test_service = $conf->get('testing');
is($test_service->prop('destruction'), 0,
    "Destruction is left alone if already defined, even if 0");

=end testing

=cut

use strict;
use esmith::ConfigDB;

my $conf = esmith::ConfigDB->open()
    or die "Configuration database does not exist";

if (my $test_service = $conf->get('testing') 
    || $conf->new_record('testing', { type => 'service'} )) 
{
    unless (defined $test_service->prop('destruction')) 
    {
        $test_service->set_prop('destruction', 0);
    }
}

exit 0;
