Add boilderplate POD
[catagits/Catalyst-Engine-STOMP.git] / t / 12_json-message.t
1 use strict;
2 use warnings;
3 use Test::More;
4
5 # Tests which expect a STOMP server like ActiveMQ to exist on
6 # localhost:61613, which is what you get if you just get the ActiveMQ
7 # distro and run its out-of-the-box config.
8
9 eval {
10         use JSON;
11 };
12 if ($@) {
13         plan 'skip_all' => 'JSON not installed, skipping JSON-format test';
14     exit;
15 }
16
17 use FindBin;
18 use lib "$FindBin::Bin/lib";
19 use TestServer;
20
21 my $stomp = start_server();
22
23 plan tests => 11;
24
25 my $frame = $stomp->connect();
26 ok($frame, 'connect to MQ server ok');
27
28 my $reply_to = sprintf '%s:1', $frame->headers->{session};
29 ok($frame->headers->{session}, 'got a session');
30 ok(length $reply_to > 2, 'valid-looking reply_to queue');
31
32 ok($stomp->subscribe( { destination => '/temp-queue/reply' } ), 'subscribe to temp queue');
33
34 my $message = {
35                payload => { foo => 1, bar => 2 },
36                reply_to => $reply_to,
37                type => 'testaction',
38               };
39 my $text = to_json($message);
40 ok($text, 'compose message');
41
42 $stomp->send( { destination => '/queue/testjsoncontroller', body => $text } );
43
44 my $reply_frame = $stomp->receive_frame();
45 ok($reply_frame, 'got a reply');
46 ok($reply_frame->headers->{destination} eq "/remote-temp-queue/$reply_to", 'came to correct temp queue');
47 ok($reply_frame->body, 'has a body');
48
49 my $response = from_json($reply_frame->body);
50
51 ok($response, 'JSON response ok');
52 ok($response->{type} eq 'testaction_response', 'correct type');
53
54 ok($stomp->disconnect, 'disconnected');
55