Trivial test spacing cleanups
[catagits/Catalyst-Engine-STOMP.git] / t / 02-bad-action.t
CommitLineData
bf8937b7 1use Test::More;
2
3# Tests which expect a STOMP server like ActiveMQ to exist on
4# localhost:61613, which is what you get if you just get the ActiveMQ
5# distro and run its out-of-the-box config.
6
7use Net::Stomp;
8use YAML::XS qw/ Dump Load /;
9use Data::Dumper;
10
11use FindBin;
12use lib "$FindBin::Bin";
13require 'server.pl';
14
15plan tests => 12;
16
17my $frame = $stomp->connect();
18ok($frame, 'connect to MQ server ok');
19
20my $reply_to = sprintf '%s:1', $frame->headers->{session};
21ok($frame->headers->{session}, 'got a session');
22ok(length $reply_to > 2, 'valid-looking reply_to queue');
23
24ok($stomp->subscribe( { destination => '/temp-queue/reply' } ), 'subscribe to temp queue');
25
26# Test what happens when the action crashes
27my $message = {
28 payload => { foo => 1, bar => 2 },
29 reply_to => $reply_to,
30 type => 'badaction',
31 };
32my $text = Dump($message);
33ok($text, 'compose message for badaction');
34
35$stomp->send( { destination => '/queue/testcontroller', body => $text } );
36
37my $reply_frame = $stomp->receive_frame();
38ok($reply_frame, 'got a reply');
39ok($reply_frame->headers->{destination} eq "/remote-temp-queue/$reply_to", 'came to correct temp queue');
40ok($reply_frame->body, 'has a body');
41
42my $response = Load($reply_frame->body);
43ok($response, 'YAML response ok');
44ok($response->{status} eq 'ERROR', 'is an error');
45ok($response->{error} =~ /oh noes/);
46
47ok($stomp->disconnect, 'disconnected');
48