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
|
use Test::More tests => 2;
BEGIN { use_ok('JSON::Hyper') };
use JSON;
my $hyper = JSON::Hyper->new(<<'SCHEMA');
{
"links": [
{
"rel": "self",
"href": "{id}"
},
{
"rel": "up",
"href": "{upId}"
},
{
"rel": "help",
"href": "{helpId}"
},
{
"rel": "children",
"href": "find_children?id={id}"
},
{
"rel": "meta",
"href": "relationship_history?id1={id}&id2={upId}"
}
]
}
SCHEMA
my $object = from_json(<<'OBJECT');
{
"id": "lemons",
"upId": "citrus_fruits"
}
OBJECT
my @got = sort { $a->{rel} cmp $b->{rel} }
$hyper->find_links($object, 'http://example.com/food/');
my @expected = (
JSON::Hyper::Link->new({
'rel' => 'children',
'enctype' => undef,
'href' => 'http://example.com/food/find_children?id=lemons',
'method' => undef,
'schema' => undef,
'properties' => undef,
'targetSchema' => undef
}),
JSON::Hyper::Link->new({
'rel' => 'meta',
'enctype' => undef,
'href' => 'http://example.com/food/relationship_history?id1=lemons&id2=citrus_fruits',
'method' => undef,
'schema' => undef,
'properties' => undef,
'targetSchema' => undef
}),
JSON::Hyper::Link->new({
'rel' => 'self',
'enctype' => undef,
'href' => 'http://example.com/food/lemons',
'method' => undef,
'schema' => undef,
'properties' => undef,
'targetSchema' => undef
}),
JSON::Hyper::Link->new({
'rel' => 'up',
'enctype' => undef,
'href' => 'http://example.com/food/citrus_fruits',
'method' => undef,
'schema' => undef,
'properties' => undef,
'targetSchema' => undef
}),
);
is_deeply(\@got, \@expected, 'Returned correct data.');
|