summaryrefslogtreecommitdiffstats
path: root/src/config-db/t/20-client_system_ref.t
blob: 93b869502143902ea67a45300e99ec9b781de0de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
use Test::More qw(no_plan);

use strict;
use warnings;

use lib '/opt/openslx/lib';

# basic init
use OpenSLX::ConfigDB;

my $configDB = OpenSLX::ConfigDB->new;
$configDB->connect();

# fetch clients & systems
my @clients = sort { $a->{id} <=> $b->{id} } $configDB->fetchClientByFilter();
is(@clients, 3, 'should have got 3 clients (default, 1 and 3)');
my $defaultClient = shift @clients;
my $client1 = shift @clients;
my $client3 = shift @clients;

my @systems = sort { $a->{id} <=> $b->{id} } $configDB->fetchSystemByFilter();
is(@systems, 3, 'should have got 3 systems (default, 1 and 3)');
my $defaultSystem = shift @systems;
my $system1 = shift @systems;
my $system3 = shift @systems;

foreach my $client ($defaultClient, $client1, $client3) {
    is(
        my @systemIDs = $configDB->fetchSystemIDsOfClient($client->{id}),
        0, "client $client->{id} has no system-IDs yet"
    );
}

foreach my $system ($defaultSystem, $system1, $system3) {
    is(
        my @clientIDs = $configDB->fetchClientIDsOfSystem($system->{id}),
        0, "system $system->{id} has no client-IDs yet"
    );
}

ok(
    $configDB->addSystemIDsToClient(1, [3]),
    'system-ID 3 has been associated to client 1'
);
is(
    my @systemIDs = sort($configDB->fetchSystemIDsOfClient(0)),
    0, "default client should have no system-ID"
);
is(
    @systemIDs = sort($configDB->fetchSystemIDsOfClient(1)),
    1, "client 1 should have one system-ID"
);
is($systemIDs[0], 3, "first system of client 1 should have ID 3");
is(
    @systemIDs = sort($configDB->fetchSystemIDsOfClient(3)),
    0, "client 3 should have no system-ID"
);
is(
    my @clientIDs = sort($configDB->fetchClientIDsOfSystem(0)),
    0, "default system should have no client-IDs"
);
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(1)),
    0, "system 1 should have no client-IDs"
);
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(3)),
    1, "system 3 should have one client-ID"
);
is($clientIDs[0], 1, "first client of system 3 should have ID 1");

ok(
    $configDB->addSystemIDsToClient(3, [1,3,3,1,3]),
    'system-IDs 1 and 3 have been associated to client 3'
);
is(
    @systemIDs = sort($configDB->fetchSystemIDsOfClient(0)),
    0, "default client should have no system-IDs"
);
is(
    @systemIDs = sort($configDB->fetchSystemIDsOfClient(1)),
    1, "client 1 should have one system-ID"
);
is($systemIDs[0], 3, "first system of client 1 should have ID 3");
is(
    @systemIDs = sort($configDB->fetchSystemIDsOfClient(3)),
    2, "client 3 should have two system-IDs"
);
is($systemIDs[0], 1, "first system of client 3 should have ID 1");
is($systemIDs[1], 3, "second system of client 3 should have ID 3");
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(0)),
    0, "default system should have no client-ID"
);
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(1)),
    1, "system 1 should have one client-ID"
);
is($clientIDs[0], 3, "first client of system 1 should have ID 3");
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(3)),
    2, "system 3 should have two client-IDs"
);
is($clientIDs[0], 1, "first client of system 3 should have ID 1");
is($clientIDs[1], 3, "second client of system 3 should have ID 3");

ok(
    $configDB->setClientIDsOfSystem(3, []),
    'client-IDs of system 3 have been set to empty array'
);
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(3)),
    0, "system 3 should have no client-IDs"
);
is(
    @systemIDs = sort($configDB->fetchSystemIDsOfClient(1)),
    0, "client 1 should have no system-IDs"
);
is(
    @systemIDs = sort($configDB->fetchSystemIDsOfClient(3)),
    1, "client 3 should have one system-ID"
);
is($systemIDs[0], 1, "first system of client 3 should have ID 1");

ok(
    $configDB->addSystemIDsToClient(1, [0]),
    'associating the default system should have no effect'
);
is(
    @systemIDs = sort($configDB->fetchSystemIDsOfClient(1)),
    0, "client 1 should still have no system-ID"
);

ok(
    $configDB->removeClientIDsFromSystem(1, [1]),
    'removing an unassociated client-ID should have no effect'
);
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(1)),
    1, "system 1 should have one client-ID"
);
ok(
    $configDB->removeClientIDsFromSystem(1, [3]),
    'removing an associated client-ID should work'
);
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(1)),
    0, "system 1 should have no more client-ID"
);

$configDB->addSystem({
    'name'      => 'sys-4',
    'export_id' => 1,
    'comment'   => 'shortlived',
});
ok(
    $configDB->addClientIDsToSystem(4, [0]),
    'default client has been associated to system 4'
);
is(
    @systemIDs = sort($configDB->fetchSystemIDsOfClient(0)),
    1, "default client should have one system-ID"
);
is($systemIDs[0], 4, "first system of default client should have ID 4");
is(
    @systemIDs = sort($configDB->fetchSystemIDsOfClient(1)),
    0, "client 1 should have no system-ID"
);
is(
    @systemIDs = sort($configDB->fetchSystemIDsOfClient(3)),
    0, "client 3 should have no system-ID"
);
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(0)),
    0, "default system should have no client-IDs"
);
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(1)),
    0, "system 1 should have no client-ID"
);
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(3)),
    0, "system 3 should have no client-IDs"
);
is(
    @clientIDs = sort($configDB->fetchClientIDsOfSystem(4)),
    1, "system 4 should have one client-ID"
);
is($clientIDs[0], 0, "first client of system 4 should have ID 0");

ok(
    $configDB->removeSystemIDsFromClient(0, [6]),
    'removing an unassociated system-ID should have no effect'
);
is(
    @clientIDs = sort($configDB->fetchSystemIDsOfClient(0)),
    1, "default client should have one system-ID"
);
ok(
    $configDB->removeSystem(4),
    'removing a system should drop client associations, too'
);
is(
    @clientIDs = sort($configDB->fetchSystemIDsOfClient(0)),
    0, "default client should have no more system-ID"
);

$configDB->disconnect();