-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathpayload_constructor.t
64 lines (50 loc) · 1.33 KB
/
payload_constructor.t
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
#!/usr/bin/perl -w
use 5.010;
use strict;
use warnings;
use autodie;
use Exobrain::Test;
package Exobrain::Test::Message;
use Moose;
sub summary { "Dummy summary"; } # The role requires this
sub namespace { "Test" ; } # ...and this
BEGIN { with 'Exobrain::Message'; }
payload 'foo' => (isa => 'Str');
has 'bar' => (isa => 'Int', is => 'ro');
package main;
use Test::More;
my $obj = Exobrain::Test::Message->new(
foo=> 'Foo',
bar => 42,
timestamp=>1000,
namespace => 'TEST',
source => 'TEST',
nosend => 1,
);
my $meta = $obj->meta;
is($obj->foo, 'Foo', "foo is set");
is($obj->bar, 42, "bar is set");
is($obj->timestamp, 1000, "Timestamp manual setting works");
is($obj->data->{foo}, 'Foo', "Foo is in data packet");
is(scalar (keys %{$obj->data}), 1, "Only one attribute in data packet");
ok(
! $meta->get_attribute('bar')->does('Exobrain::Message::Trait::Payload'),
"Bar is not a payload attribute"
);
ok(
$meta->get_attribute('foo')->does('Exobrain::Message::Trait::Payload'),
"Foo is a payload attribute"
);
my $time = time();
my $obj2 = Exobrain::Test::Message->new(
foo=> 'Foo',
bar => 42,
namespace => 'TEST',
source => 'TEST',
nosend => 1,
);
ok (
abs($time - $obj2->timestamp) < 1000,
"Auto timestamps work " . $obj2->timestamp
);
done_testing;