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
|
#!perl
package MyObject;
# vim:ft=perl:
# For testing purposes -- Object with 'id' attribute.
@ISA = qw(RT::Client::REST::Object);
sub id {
my $self = shift;
if (@_) {
$self->{_id} = shift;
}
return $self->{_id};
}
sub rt_type { 'myobject' }
sub _attributes {
{ id => {}, }
}
package main;
use strict;
use warnings;
use Test::More tests => 38;
use Test::Exception;
use constant METHODS => (
'new', 'to_form',
'from_form', '_generate_methods',
'store', 'retrieve',
'param', 'rt',
'cf', 'search',
'count', 'use_single_rt',
'use_autostore', 'use_autoget',
'use_autosync', 'be_transparent',
'autostore', 'autosync',
'autoget',
);
BEGIN {
use_ok('RT::Client::REST::Object');
}
my $obj;
lives_ok {
$obj = RT::Client::REST::Object->new;
}
'Object can get successfully created';
for my $method (METHODS) {
can_ok( $obj, $method );
}
use RT::Client::REST;
my $rt = RT::Client::REST->new;
for my $method (qw(retrieve)) {
my $obj = MyObject->new; # local copy;
throws_ok {
$obj->$method;
}
'RT::Client::REST::Object::RequiredAttributeUnsetException',
"won't go on without 'rt' set";
lives_ok {
$obj->rt($rt)
}
"Successfully set 'rt'";
throws_ok {
$obj->$method;
}
'RT::Client::REST::Object::RequiredAttributeUnsetException',
"won't go on without 'id' set";
lives_ok {
$obj->id(1);
}
"Successfully set 'id' to 1";
throws_ok {
$obj->$method;
}
'RT::Client::REST::RequiredAttributeUnsetException',
"rt object is not correctly initialized";
}
for my $method (qw(store count search)) {
my $obj = MyObject->new; # local copy;
throws_ok {
$obj->$method;
}
'RT::Client::REST::Object::RequiredAttributeUnsetException',
"won't go on without 'rt' set";
lives_ok {
$obj->rt($rt)
}
"Successfully set 'rt'";
lives_ok {
$obj->id(1);
}
"Successfully set 'id' to 1";
throws_ok {
$obj->$method;
}
'RT::Client::REST::RequiredAttributeUnsetException',
"rt object is not correctly initialized";
}
|