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