1 #!/usr/brcm/ba/bin/perl
8 use lib "$FindBin::Bin/../lib";
18 Usage $FindBin::Script: [-get] [-add] [-modify] [-change] [-delete]
23 # Always remember to call disconnect for any instanciated Clearquest::REST
25 $cq->disconnect if $cq;
28 sub displayRecord (%) {
33 foreach (keys %record) {
36 if (ref $record{$_} eq 'ARRAY') {
37 display join ", ", @{$record{$_}};
38 } elsif ($record{$_}) {
46 sub displayResults (@) {
50 displayRecord %$_ foreach (@records);
52 display "Did not find any records";
56 sub testGetRecord ($$;@) {
57 my ($table, $key, @fields) = @_;
59 display "Testing get table: $table key: $key";
61 displayRecord $cq->get ($table, $key, @fields);
64 sub testFindRecord ($$;@) {
65 my ($table, $condition, @fields) = @_;
67 display "Testing find table: $table condition: $condition";
69 my ($result, $nbrRecs) = $cq->find ($table, $condition, @fields);
71 display "$nbrRecs records qualified";
73 while (my %record = $cq->getNext ($result)) {
74 displayRecord %record;
78 sub testModifyRecord ($$;%) {
79 my ($table, $key, %update) = @_;
81 display "Testing modify table: $table key: $key";
83 my $errmsg = $cq->modify ($table, $key, undef, %update);
88 sub testChangeState ($$) {
89 my ($table, $key) = @_;
91 my %record = $cq->get ($table, $key, ('State'));
93 my ($action, %update);
95 if ($record{State} eq 'Assigned') {
96 $action = 'AdminAssignToSubmit';
97 $update{Stability_Issue} = 'User Fault';
100 $update{Stability_Issue} = 'Assert';
103 display "Testing change state table: $table key: $key action: $action";
105 my $errmsg = $cq->modify ($table, $key, $action, %update);
110 sub testAddRecord ($%) {
111 my ($table, %record) = @_;
113 display "Testing adding table: $table";
115 my $errmsg = $cq->add ($table, %record);
120 sub testDeleteRecord ($$) {
121 my ($table, $key) = @_;
123 display "Testing deleting table: $table key: $key";
125 my $errmsg = $cq->delete ($table, $key);
141 # If nothing is set then do everything
142 unless ($opts{get} or
148 $opts{get} = $opts{add} = $opts{modify} = $opts{change} = 1;
151 # If we are testing add or delete then toggle on the other one
152 $opts{delete} = 1 if $opts{add};
153 $opts{add} = 1 if $opts{delete};
155 $cq = Clearquest::REST->new;
159 testGetRecord 'Project', 'Athena';
161 # Get record by condition
162 testFindRecord 'VersionInfo', 'Deprecated = 1';
164 # Get record by key with field list
165 testFindRecord 'VersionInfo', 'VersionStr = 1.0', ('VersionStr', 'Deprecated');
167 # Get record by condition with field list
168 testFindRecord 'CategorySub', 'Category="Customer-HW"', ('Category', 'CategoryType', 'SubCategory');
173 testAddRecord 'VersionInfo', (
176 Project => ['Island', '21331', 'Hera'],
178 Visibility => 'Nokia Corporation',
184 testModifyRecord ('VersionInfo', '1.0', (
187 Project => ['Island', 'Athena'],
194 testChangeState 'Defect', 't_sbx00018584';
199 testDeleteRecord 'VersionInfo', '2.0';