TT#9309 More careful tests fix for the API embedded forcearray

Change-Id: I6222ce864590e2f29944c8eeb8645cc1f9e1b3d3
changes/98/12498/2
Irina Peshinskaya 8 years ago
parent a27a13d51b
commit c9799c6e26

@ -87,7 +87,7 @@ SKIP:{
}
$test_machine->check_bundle();
my($cf1_id) = $test_machine->get_id_from_hal($cf1->{content_collection}); #($cf1,'callforwards');
my $cf1_id = $test_machine->get_id_from_hal($cf1->{content_collection}); #($cf1,'callforwards');
cmp_ok ($cf1_id, '>', 0, "should be positive integer");
my $cf1single_uri = "/api/callforwards/$cf1_id";
my $cf1single;

@ -4,6 +4,7 @@ use warnings;
use Test::More;
use Test::Collection;
use Data::Dumper;
use Test::ForceArray qw/:all/;
my $test_machine = Test::Collection->new(
name => 'calllists',
@ -23,7 +24,7 @@ SKIP:
if ($sub1->{total_count} < 1) {
skip("Precondition not met: need a subscriber",1);
}
($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->[0]->{_links}->{self}{href} =~ m!subscribers/([0-9]*)$!;
$sub1_id = $test_machine->get_id_from_hal($sub1,'subscribers');
}
cmp_ok ($sub1_id, '>', 0, "should be positive integer");
#----
@ -71,7 +72,7 @@ SKIP:
if ($cust1->{total_count} < 1) {
skip("Precondition not met: need a customer",1);
}
($cust1_id) = $cust1->{_embedded}->{'ngcp:customers'}->[0]->{_links}{self}{href} =~ m!customers/([0-9]*)$!;
$cust1_id = $test_machine->get_id_from_hal($cust1,'customers');;
}
cmp_ok ($cust1_id, '>', 0, "should be positive integer");
@ -95,9 +96,9 @@ SKIP:
if ($sub1->{total_count} < 1) {
skip("Precondition not met: need a subscriber",1);
}
($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->[0]->{_links}{self}{href} =~ m!subscribers/([0-9]*)$!;
#$sub1_user = $sub1->{_embedded}->{'ngcp:subscribers'}->{'username'};
#$sub1_pass = $sub1->{_embedded}->{'ngcp:subscribers'}->{'webpassword'} // '';
$sub1_id = $test_machine->get_id_from_hal($sub1,'subscribers');
#$sub1_user = $test_machine->get_embedded_item($sub1,'subscribers')->{'username'};
#$sub1_pass = $test_machine->get_embedded_item($sub1,'subscribers')->{'webpassword'} // '';
cmp_ok ($sub1_id, '>', 0, "should be positive integer");

@ -18,7 +18,7 @@ SKIP:
if ($sub1->{total_count} < 1) {
skip("Precondition not met: need a subscriber",1);
}
($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->[0]->{_links}{self}{href} =~ m!subscribers/([0-9]*)$!;
$sub1_id = $test_machine->get_id_from_hal($sub1,'subscribers');
cmp_ok ($sub1_id, '>', 0, "should be positive integer");

@ -74,7 +74,7 @@ SKIP:
if ($sub1->{total_count} < 1) {
skip("Precondition not met: need a subscriber",1);
}
my ($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->[0]->{_links}{self}{href} =~ m!subscribers/([0-9]*)$!;
my $sub1_id = $test_machine->get_id_from_hal($sub1,'subscribers');
cmp_ok ($sub1_id, '>', 0, "should be positive integer");

@ -4,6 +4,7 @@ use Sipwise::Base;
use Net::Domain qw(hostfqdn);
use JSON qw();
use Test::More;
use Test::ForceArray qw/:all/;
use DateTime qw();
use DateTime::Format::Strptime qw();
@ -206,12 +207,13 @@ my @allcontracts = ();
# remove any contact we find in the collection for later check
if(ref $collection->{_links}->{'ngcp:contracts'} eq "HASH") {
my $item = get_embedded_item($collection,'contracts');
# TODO: handle hashref
ok($collection->{_embedded}->{'ngcp:contracts'}->[0]->{status} ne "terminated", "check if we don't have terminated contracts in response");
ok($collection->{_embedded}->{'ngcp:contracts'}->[0]->{type} eq "sippeering" || $collection->{_embedded}->{'ngcp:contracts'}->[0]->{type} eq "reseller", "check for correct system contract type");
ok(exists $collection->{_embedded}->{'ngcp:contracts'}->[0]->{_links}->{'ngcp:systemcontacts'}, "check presence of ngcp:systemcontacts relation");
ok(exists $collection->{_embedded}->{'ngcp:contracts'}->[0]->{_links}->{'ngcp:billingprofiles'}, "check presence of ngcp:billingprofiles relation");
delete $contracts{$collection->{_links}->{'ngcp:contracts'}->{href}};
ok($item->{status} ne "terminated", "check if we don't have terminated contracts in response");
ok($item->{type} eq "sippeering" || $item->{type} eq "reseller", "check for correct system contract type");
ok(exists $item->{_links}->{'ngcp:systemcontacts'}, "check presence of ngcp:systemcontacts relation");
ok(exists $item->{_links}->{'ngcp:billingprofiles'}, "check presence of ngcp:billingprofiles relation");
} else {
foreach my $c(@{ $collection->{_links}->{'ngcp:contracts'} }) {
delete $contracts{$c->{href}};

@ -6,6 +6,7 @@ use warnings;
use Net::Domain qw(hostfqdn);
use JSON qw();
use Test::More;
use Test::ForceArray qw/:all/;
use DateTime qw();
use DateTime::Format::Strptime qw();
@ -54,7 +55,7 @@ $req = HTTP::Request->new('GET', $uri.'/api/systemcontacts/?page=1&rows=1');
$res = $ua->request($req);
is($res->code, 200, "fetch system contacts");
my $sysct = JSON::from_json($res->decoded_content);
my $system_contact_id = $sysct->{_embedded}->{'ngcp:systemcontacts'}->[0]->{id};
my $system_contact_id = get_embedded_item($sysct, 'systemcontacts')->{id};
# first, create a contact
$req = HTTP::Request->new('POST', $uri.'/api/customercontacts/');
@ -225,11 +226,12 @@ my @allcustomers = ();
# remove any contact we find in the collection for later check
if(ref $collection->{_links}->{'ngcp:customers'} eq "HASH") {
ok($collection->{_embedded}->{'ngcp:customers'}->[0]->{type} eq "sipaccount" || $collection->{_embedded}->{'ngcp:customers'}->[0]->{type} eq "pbxaccount", "check for correct customer contract type");
ok($collection->{_embedded}->{'ngcp:customers'}->[0]->{status} ne "terminated", "check if we don't have terminated customers in response");
ok(exists $collection->{_embedded}->{'ngcp:customers'}->[0]->{_links}->{'ngcp:customercontacts'}, "check presence of ngcp:customercontacts relation");
ok(exists $collection->{_embedded}->{'ngcp:customers'}->[0]->{_links}->{'ngcp:billingprofiles'}, "check presence of ngcp:billingprofiles relation");
ok(exists $collection->{_embedded}->{'ngcp:customers'}->[0]->{_links}->{'ngcp:customerbalances'}, "check presence of ngcp:customerbalances relation");
my $item = get_embedded_item($collection,'customers');
ok( $item->{type} eq "sipaccount" || $item->{type} eq "pbxaccount", "check for correct customer contract type");
ok($item->{status} ne "terminated", "check if we don't have terminated customers in response");
ok(exists $item->{_links}->{'ngcp:customercontacts'}, "check presence of ngcp:customercontacts relation");
ok(exists $item->{_links}->{'ngcp:billingprofiles'}, "check presence of ngcp:billingprofiles relation");
ok(exists $item->{_links}->{'ngcp:customerbalances'}, "check presence of ngcp:customerbalances relation");
delete $customers{$collection->{_links}->{'ngcp:customers'}->{href}};
} else {
foreach my $c(@{ $collection->{_links}->{'ngcp:customers'} }) {

@ -4,6 +4,7 @@ use strict;
use Net::Domain qw(hostfqdn);
use JSON qw();
use Test::More;
use Test::ForceArray qw/:all/;
my $uri = $ENV{CATALYST_SERVER} || ('https://'.hostfqdn.':4443');
@ -228,8 +229,9 @@ my @allrules = ();
# remove any entry we find in the collection for later check
if(ref $collection->{_links}->{'ngcp:rewriterules'} eq "HASH") {
ok(exists $collection->{_embedded}->{'ngcp:rewriterules'}->{_links}->{'ngcp:rewriterules'}, "check presence of ngcp:rewriterules relation");
ok(exists $collection->{_embedded}->{'ngcp:rewriterules'}->{_links}->{'ngcp:rewriterulesets'}, "check presence of ngcp:rewriterulesets relation");
my $item = get_embedded_item($collection,'rewriterules');
ok(exists $item->{_links}->{'ngcp:rewriterules'}, "check presence of ngcp:rewriterules relation");
ok(exists $item->{_links}->{'ngcp:rewriterulesets'}, "check presence of ngcp:rewriterulesets relation");
delete $rules{$collection->{_links}->{'ngcp:rewriterules'}->{href}};
} else {
foreach my $c(@{ $collection->{_links}->{'ngcp:rewriterules'} }) {

@ -1308,12 +1308,29 @@ sub resource_clear_file{
print "cmd=$cmd;\n";
`$cmd`;
}
sub get_id_from_hal{
my($self,$hal,$name) = @_;
$name //= $self->name;
(my ($id)) = $hal->{_embedded}->{'ngcp:'.$name}->{_links}{self}{href} =~ m!${name}/([0-9]*)$!;
my $embedded = $self->get_embedded_item($hal,$name);
(my ($id)) = $embedded->{_links}{self}{href}=~ m!${name}/([0-9]*)$! if $embedded;
return $id;
}
sub get_embedded_item{
my($self,$hal,$name) = @_;
$name //= $self->name;
my $embedded = $hal->{_embedded}->{'ngcp:'.$name} ;
return 'ARRAY' eq ref $embedded ? $embedded->[0] : $embedded ;
}
sub get_embedded_forcearray{
my($self,$hal,$name) = @_;
$name //= $self->name;
my $embedded = $hal->{_embedded}->{'ngcp:'.$name} ;
return 'ARRAY' eq ref $embedded ? $embedded : [ $embedded ];
}
sub uri2location{
my($self,$uri) = @_;
$uri=~s/^.*?(\/api\/.*$)/$1/;

@ -0,0 +1,32 @@
package Test::ForceArray;
use strict;
use Exporter qw'import';
our @EXPORT = qw//;
our @EXPORT_OK = qw/&get_embedded_item &get_embedded_forcearray &get_id_from_hal/;
our %EXPORT_TAGS = (
DEFAULT => [qw/&get_embedded_item &get_embedded_forcearray &get_id_from_hal/],
all => [qw/&get_embedded_item &get_embedded_forcearray &get_id_from_hal/]
);
sub get_embedded_item{
my($hal,$name) = @_;
my $embedded = $hal->{_embedded}->{'ngcp:'.$name} ;
return 'ARRAY' eq ref $embedded ? $embedded->[0] : $embedded ;
}
sub get_embedded_forcearray{
my($hal,$name) = @_;
my $embedded = $hal->{_embedded}->{'ngcp:'.$name} ;
return 'ARRAY' eq ref $embedded ? $embedded : [ $embedded ];
}
sub get_id_from_hal{
my($hal,$name) = @_;
my $embedded = get_embedded_item($hal,$name);
(my ($id)) = $embedded->{_links}{self}{href} =~ m!${name}/([0-9]*)$! if $embedded;
return $id;
}
1;
Loading…
Cancel
Save