~ubuntu-branches/ubuntu/trusty/zentyal-core/trusty

« back to all changes in this revision

Viewing changes to src/EBox/Global/t/TestStub.t

  • Committer: Package Import Robot
  • Author(s): Jorge Salamero Sanz
  • Date: 2012-08-28 10:03:33 UTC
  • Revision ID: package-import@ubuntu.com-20120828100333-oz3n5kpav4z0tl27
Tags: 2.3.21+quantal1
New upstream release for Quantal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Description:
2
 
3
 
use strict;
4
 
use warnings;
5
 
 
6
 
use Test::More tests => 21;
7
 
use Test::Exception;
8
 
 
9
 
 
10
 
use lib '../../..';
11
 
 
12
 
use EBox::TestStub;
13
 
 
14
 
use_ok 'EBox::Global::TestStub';
15
 
 
16
 
testStubsSetup();
17
 
modExistsTest();
18
 
getInstanceTest();
19
 
modInstanceTest();
20
 
changedTest();
21
 
clearTest();
22
 
 
23
 
 
24
 
 
25
 
sub testStubsSetup
26
 
{
27
 
    EBox::TestStub::fake();
28
 
    EBox::Global::TestStub::fake();
29
 
    EBox::Global::TestStub::setEBoxModule('baboon', 'EBox::Baboon');
30
 
 
31
 
      MOCK_CLASS:{
32
 
          package EBox::Baboon;
33
 
          use base 'EBox::GConfModule';
34
 
          $INC{'EBox/Baboon.pm'} =1;
35
 
          sub _create
36
 
          {
37
 
              my ($class, @optParams) = @_;
38
 
              my $self = $class->SUPER::_create(name => 'baboon', @optParams);
39
 
              return $self;
40
 
              
41
 
          }
42
 
     }
43
 
}
44
 
 
45
 
 
46
 
 
47
 
sub modExistsTest
48
 
{
49
 
  my $global = EBox::Global->getInstance();
50
 
  ok $global->modExists('baboon'), 'Checking Global modExists method agaisnt a fake module';
51
 
}
52
 
 
53
 
sub modInstanceTest
54
 
{
55
 
    my $global = EBox::Global->getInstance();
56
 
    
57
 
    foreach my $n  (0 .. 1) {
58
 
        my $baboonModule;
59
 
        lives_ok { $baboonModule = $global->modInstance('baboon') } 'modInstance';
60
 
        ok defined $baboonModule, 'Checking module returned by modInstance';
61
 
        isa_ok $baboonModule, 'EBox::GConfModule';
62
 
        isa_ok $baboonModule, 'EBox::Baboon';
63
 
   }
64
 
 
65
 
}
66
 
 
67
 
sub getInstanceTest
68
 
{
69
 
    my $global;
70
 
 
71
 
    foreach my $n (0 .. 1) {
72
 
        foreach my $readonly (0, 1) {
73
 
            lives_ok { $global = EBox::Global->getInstance($readonly) } 'EBox::Global::getInstance';
74
 
            isa_ok $global, 'EBox::Global';
75
 
        }
76
 
    }
77
 
 
78
 
}
79
 
 
80
 
sub changedTest
81
 
{
82
 
    my  $baboonModule = EBox::Global->modInstance('baboon');
83
 
    defined $baboonModule or die "Cannot get a baboon module";
84
 
    my $global = EBox::Global->getInstance();
85
 
 
86
 
    $global->modChange('baboon');
87
 
    ok $global->modIsChanged('baboon'), 'Checking modChange and modIsChanged';
88
 
    $global->modRestarted('baboon');
89
 
    ok !$global->modIsChanged('baboon'), 'Checking modRestarted and modIsChanged';
90
 
}
91
 
 
92
 
 
93
 
sub clearTest
94
 
{
95
 
    my %originalConfig = (
96
 
                      '/ebox/unrelatedToGlobal/bool'    => 1,
97
 
                      '/ebox/unrelatedToGlobal/integer' => 100,
98
 
                      '/anotherApp/string'              => 'a string',
99
 
          );
100
 
    EBox::GConfModule::TestStub::setConfig(%originalConfig); 
101
 
 
102
 
    EBox::Global::TestStub::setEBoxModule('baboon', 'EBox::Baboon');
103
 
    EBox::Global::TestStub::setEBoxModule('mandrill', 'EBox::Mandrill');
104
 
 
105
 
 
106
 
    EBox::Global::TestStub::clear();
107
 
    my %actualConfig = @{ EBox::GConfModule::TestStub::dumpConfig() };
108
 
    is_deeply(\%actualConfig, \%originalConfig, 'Checking that all keys of module global are remvoed from the config and the rest is left untouched');
109
 
}
110
 
 
111
 
1;