App-Dochazka-REST

 view release on metacpan or  search on metacpan

t/model/activity.t  view on Meta::CPAN

# ************************************************************************* 
# Copyright (c) 2014-2015, SUSE LLC
# 
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 
# 3. Neither the name of SUSE LLC nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# ************************************************************************* 
#
# basic unit tests for activities
#

#!perl
use 5.012;
use strict;
use warnings;

#use App::CELL::Test::LogToFile;
use App::CELL qw( $meta $site );
use Data::Dumper;
use App::Dochazka::REST::ConnBank qw( $dbix_conn );
use App::Dochazka::REST::Model::Activity qw( aid_by_code aid_exists code_exists get_all_activities );
use App::Dochazka::REST::Test;
use Test::Fatal;
use Test::More;
use Test::Warnings;


note( "initialize, connect to database, and set up a testing plan" );
initialize_regression_test();

note( 'spawn two activity objects' );
my $act = App::Dochazka::REST::Model::Activity->spawn;
isa_ok( $act, 'App::Dochazka::REST::Model::Activity' );
my $act2 = App::Dochazka::REST::Model::Activity->spawn;
isa_ok( $act2, 'App::Dochazka::REST::Model::Activity' );

note( 'they are the same' );
ok( $act->compare( $act2 ) );

note( 'set a property' );
my $a = "prdy vody";
$act->remark( $a );
$act2->remark( $a );
is( $act->remark, $a );
is( $act2->remark, $a );
ok( $act->compare( $act2 ) );  # still the same
ok( $act2->compare( $act ) );

$act2->remark( "jine fody" );
ok( ! $act->compare( $act2 ) );  # different

note( 'reset the activities' );
$act->reset;
$act2->reset;
ok( $act->compare( $act2 ) );
foreach my $prop ( qw( aid code long_desc disabled ) ) {
    is( $act->{$prop}, undef );
    is( $act2->{$prop}, undef );
}

note( 'test existence and viability of initial set of activities' );
note( 'this also conducts positive tests of load_by_code and load_by_aid' );
foreach my $actdef ( @{ $site->DOCHAZKA_ACTIVITY_DEFINITIONS } ) {
    my $status = App::Dochazka::REST::Model::Activity->load_by_code( $dbix_conn, $actdef->{code} );
    is( $status->code, 'DISPATCH_RECORDS_FOUND' ); 
    is( $status->level, 'OK' );
    $act = $status->payload; 
    is( $act->code, $actdef->{code} );
    is( $act->long_desc, $actdef->{long_desc} );
    is( $act->remark, 'dbinit' );
    is( $act->disabled, 0 );
    $status = App::Dochazka::REST::Model::Activity->load_by_aid( $dbix_conn, $act->aid );
    is( $status->level, 'OK' );
    is( $status->code, 'DISPATCH_RECORDS_FOUND' ); 
    $act2 = $status->payload;
    is_deeply( $act, $act2 );
}

note( 'test get_all_activities function' );
my $status = get_all_activities( $dbix_conn );
is( $status->level, 'OK' );
is( $status->code, 'DISPATCH_RECORDS_FOUND' );
is( scalar( @{ $status->payload } ), scalar( @{ $site->DOCHAZKA_ACTIVITY_DEFINITIONS } ) );



( run in 1.121 second using v1.01-cache-2.11-cpan-54e63673c56 )