|
|
|
@ -187,6 +187,21 @@ has 'QUERY_PARAMS' =>(
|
|
|
|
|
isa => 'Str',
|
|
|
|
|
default => '',
|
|
|
|
|
);
|
|
|
|
|
has 'PAGE' =>(
|
|
|
|
|
is => 'rw',
|
|
|
|
|
isa => 'Str',
|
|
|
|
|
default => '1',
|
|
|
|
|
);
|
|
|
|
|
has 'ROWS' =>(
|
|
|
|
|
is => 'rw',
|
|
|
|
|
isa => 'Str',
|
|
|
|
|
default => '1',
|
|
|
|
|
);
|
|
|
|
|
has 'NO_COUNT' =>(
|
|
|
|
|
is => 'rw',
|
|
|
|
|
isa => 'Str',
|
|
|
|
|
default => '',
|
|
|
|
|
);
|
|
|
|
|
has 'URI_CUSTOM_STORE' =>(
|
|
|
|
|
is => 'rw',
|
|
|
|
|
isa => 'Str',
|
|
|
|
@ -374,6 +389,12 @@ sub get_uri_collection{
|
|
|
|
|
$name //= $self->name;
|
|
|
|
|
return $self->normalize_uri("/api/".$name.($name ? "/" : "").($self->QUERY_PARAMS ? "?".$self->QUERY_PARAMS : ""));
|
|
|
|
|
}
|
|
|
|
|
sub get_uri_collection_paged{
|
|
|
|
|
my($self,$name) = @_;
|
|
|
|
|
my $uri = $self->get_uri_collection($name);
|
|
|
|
|
return $uri.($uri !~/\?/ ? '?':'&').'page='.($self->PAGE // '1').'&rows='.($self->ROWS // '1').($self->NO_COUNT ? '&no_count=1' : '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub get_uri_get{
|
|
|
|
|
my($self,$query_string, $name) = @_;
|
|
|
|
|
$name //= $self->name;
|
|
|
|
@ -407,7 +428,7 @@ sub get_item_hal{
|
|
|
|
|
}
|
|
|
|
|
if(!$resitem){
|
|
|
|
|
my ($reshal, $location,$total_count,$reshal_collection);
|
|
|
|
|
$uri //= $self->get_uri_collection($name)."?page=1&rows=1";
|
|
|
|
|
$uri //= $self->get_uri_collection_paged($name);
|
|
|
|
|
#print "uri=$uri;";
|
|
|
|
|
my($res,$list_collection,$req) = $self->check_item_get($self->normalize_uri($uri));
|
|
|
|
|
($reshal,$location,$total_count,$reshal_collection) = $self->get_hal_from_collection($list_collection,$name);
|
|
|
|
@ -767,27 +788,33 @@ sub check_methods{
|
|
|
|
|
ok(exists $opts->{methods} && ref $opts->{methods} eq "ARRAY", "$self->{name}: check for valid 'methods' in body");
|
|
|
|
|
foreach my $opt(keys %{$self->methods->{$area}->{all}} ) {
|
|
|
|
|
if(exists $self->methods->{$area}->{allowed}->{$opt}){
|
|
|
|
|
ok(grep(/^$opt$/, @hopts), "$self->{name}: check for existence of '$opt' in Allow header");
|
|
|
|
|
ok(grep(/^$opt$/, @{ $opts->{methods} }), "$self->{name}: check for existence of '$opt' in body");
|
|
|
|
|
ok((grep { /^$opt$/ } @hopts), "$self->{name}: check for existence of '$opt' in Allow header");
|
|
|
|
|
ok((grep { /^$opt$/ } @{ $opts->{methods} }), "$self->{name}: check for existence of '$opt' in body");
|
|
|
|
|
}else{
|
|
|
|
|
ok(!grep(/^$opt$/, @hopts), "$self->{name}: check for absence of '$opt' in Allow header");
|
|
|
|
|
ok(!grep(/^$opt$/, @{ $opts->{methods} }), "$self->{name}: check for absence of '$opt' in body");
|
|
|
|
|
ok((!grep { /^$opt$/ } @hopts), "$self->{name}: check for absence of '$opt' in Allow header");
|
|
|
|
|
ok((!grep { /^$opt$/ } @{ $opts->{methods} }), "$self->{name}: check for absence of '$opt' in body");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub check_list_collection{
|
|
|
|
|
my($self, $check_embedded_cb) = @_;
|
|
|
|
|
my $nexturi = $self->get_uri_collection."?page=1&rows=5";
|
|
|
|
|
my $nexturi = $self->get_uri_collection_paged;
|
|
|
|
|
my @href = ();
|
|
|
|
|
my $test_info_prefix = "$self->{name}: check_list_collection: ";
|
|
|
|
|
do {
|
|
|
|
|
#print "nexturi=$nexturi;\n";
|
|
|
|
|
my ($res,$list_collection) = $self->check_item_get($nexturi);
|
|
|
|
|
my $selfuri = $self->normalize_uri($list_collection->{_links}->{self}->{href});
|
|
|
|
|
is($selfuri, $nexturi, "$self->{name}: check _links.self.href of collection");
|
|
|
|
|
my $sub_sort_params = sub {my $str = $_[0]; return (substr $str, 0, (index $str, '?') + 1) . join('&', sort split /&/, substr $str, ((index $str, '?') + 1))};
|
|
|
|
|
$selfuri = $sub_sort_params->($selfuri);
|
|
|
|
|
$nexturi = $sub_sort_params->($nexturi);
|
|
|
|
|
is($selfuri, $nexturi, $test_info_prefix."check _links.self.href of collection");
|
|
|
|
|
my $colluri = URI->new($selfuri);
|
|
|
|
|
if(($list_collection->{total_count} && $list_collection->{total_count} > 0 ) || !$self->ALLOW_EMPTY_COLLECTION){
|
|
|
|
|
ok($list_collection->{total_count} > 0, "$self->{name}: check 'total_count' of collection");
|
|
|
|
|
if(
|
|
|
|
|
((!$self->NO_COUNT) && $list_collection->{total_count} && is_int($list_collection->{total_count}) && $list_collection->{total_count} > 0 )
|
|
|
|
|
|| !$self->ALLOW_EMPTY_COLLECTION){
|
|
|
|
|
ok($list_collection->{total_count} > 0, $test_info_prefix."check 'total_count' of collection");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my %q = $colluri->query_form;
|
|
|
|
@ -800,10 +827,12 @@ sub check_list_collection{
|
|
|
|
|
} else {
|
|
|
|
|
ok(exists $list_collection->{_links}->{prev}->{href}, "$self->{name}: check existence of 'prev'");
|
|
|
|
|
}
|
|
|
|
|
if(($rows != 0) && ($list_collection->{total_count} / $rows) <= $page) {
|
|
|
|
|
ok(!exists $list_collection->{_links}->{next}->{href}, "$self->{name}: check absence of 'next' on last page");
|
|
|
|
|
} else {
|
|
|
|
|
ok(exists $list_collection->{_links}->{next}->{href}, "$self->{name}: check existence of 'next'");
|
|
|
|
|
if (!$self->NO_COUNT) {
|
|
|
|
|
if(($rows != 0) && ($list_collection->{total_count} / $rows) <= $page) {
|
|
|
|
|
ok(!exists $list_collection->{_links}->{next}->{href}, $test_info_prefix."check absence of 'next' on last page");
|
|
|
|
|
} else {
|
|
|
|
|
ok(exists $list_collection->{_links}->{next}->{href}, $test_info_prefix."check existence of 'next'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($list_collection->{_links}->{next}->{href}) {
|
|
|
|
@ -813,9 +842,11 @@ sub check_list_collection{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $hal_name = $self->get_hal_name;
|
|
|
|
|
if(($list_collection->{total_count} && $list_collection->{total_count} > 0 ) || !$self->ALLOW_EMPTY_COLLECTION){
|
|
|
|
|
ok(((ref $list_collection->{_links}->{$hal_name} eq "ARRAY" ) ||
|
|
|
|
|
(ref $list_collection->{_links}->{$hal_name} eq "HASH" ) ), "$self->{name}: check if 'ngcp:".$self->name."' is array/hash-ref");
|
|
|
|
|
if(($list_collection->{total_count} && is_int($list_collection->{total_count}) && $list_collection->{total_count} > 0 ) || !$self->ALLOW_EMPTY_COLLECTION){
|
|
|
|
|
if (! ok(((ref $list_collection->{_links}->{$hal_name} eq "ARRAY" ) ||
|
|
|
|
|
(ref $list_collection->{_links}->{$hal_name} eq "HASH" ) ), $test_info_prefix."check if 'ngcp:".$self->name."' is array/hash-ref")) {
|
|
|
|
|
diag($list_collection->{_links}->{$hal_name});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1033,6 +1064,9 @@ sub check_bundle{
|
|
|
|
|
if($self->methods->{collection}->{allowed}->{GET}){
|
|
|
|
|
$listed = $self->check_list_collection();
|
|
|
|
|
$self->check_created_listed($listed);
|
|
|
|
|
$self->NO_COUNT('1');
|
|
|
|
|
$self->check_list_collection();
|
|
|
|
|
$self->NO_COUNT('');
|
|
|
|
|
}
|
|
|
|
|
# test model item
|
|
|
|
|
if(@$listed && !$self->NO_ITEM_MODULE){
|
|
|
|
@ -1393,5 +1427,11 @@ sub clear_cache{
|
|
|
|
|
`$cmd`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub is_int {
|
|
|
|
|
my $val = shift;
|
|
|
|
|
if($val =~ /^[+-]?[0-9]+$/) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
1;
|
|
|
|
|