summaryrefslogtreecommitdiffstats
path: root/config-db/t/20-client_system_ref.t
diff options
context:
space:
mode:
authorOliver Tappe2007-12-27 23:35:57 +0100
committerOliver Tappe2007-12-27 23:35:57 +0100
commit230200926c8332c8b6d16e5f4146b34ed8c403bb (patch)
treea3ebbb270e815b5125028fe94072511f94d1c2b8 /config-db/t/20-client_system_ref.t
parent* Changed naming scheme for exports from <vendor-os>:<type> to (diff)
downloadcore-230200926c8332c8b6d16e5f4146b34ed8c403bb.tar.gz
core-230200926c8332c8b6d16e5f4146b34ed8c403bb.tar.xz
core-230200926c8332c8b6d16e5f4146b34ed8c403bb.zip
* added more tests for basic DB-features: group, global_info and
client_system_ref git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1435 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'config-db/t/20-client_system_ref.t')
-rw-r--r--config-db/t/20-client_system_ref.t138
1 files changed, 138 insertions, 0 deletions
diff --git a/config-db/t/20-client_system_ref.t b/config-db/t/20-client_system_ref.t
new file mode 100644
index 00000000..ab7a3b2a
--- /dev/null
+++ b/config-db/t/20-client_system_ref.t
@@ -0,0 +1,138 @@
+use Test::More qw(no_plan);
+
+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(
+ @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(
+ @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 more 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->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->disconnect();